3 # GLOBAL Makefile for FIASCO
7 ALLBUILDDIR := build-all
8 RANDBUILDDIR := build-rand
9 TEMPLDIR := src/templates
10 MAKEFILETEMPL := $(TEMPLDIR)/Makefile.builddir.templ
12 INSTALLSUBDIRS := $(MANSUBDIRS)
13 CLEANSUBDIRS := $(MANSUBDIRS) $(wildcard $(DFLBUILDDIR))
14 CONFIG_FILE := $(TEMPLDIR)/globalconfig.out
15 TEST_TEMPLATES := $(patsubst $(CONFIG_FILE).%,%,$(wildcard $(CONFIG_FILE).*))
16 TEST_TEMPLATES := $(if $(TEMPLATE_FILTER),$(filter $(TEMPLATE_FILTER),$(TEST_TEMPLATES)),$(TEST_TEMPLATES))
17 DFL_TEMPLATE := ia32-1
22 if [ "$${bd\#/}" = "$$bd" -a \
23 "$${bd\#*..}" = "$$bd" ]; then \
25 while [ "$${bd\#*/}" != "$$bd" ]; do \
35 buildmakefile = mkdir -p "$(1)"; \
36 perl -p -i -e '$$s = "$(CURDIR)/src"; s/\@SRCDIR\@/$$s/' \
37 < $(MAKEFILETEMPL) > $(1)/Makefile
39 ifneq ($(strip $(B)),)
42 ifneq ($(strip $(BUILDDIR)),)
44 @echo "Creating build directory \"$(BUILDDIR)\"..."
45 @if [ -e "$(BUILDDIR)" ]; then \
46 echo "Already exists, aborting."; \
49 @$(call buildmakefile,$(BUILDDIR))
53 ifneq ($(strip $(O)),)
55 @if [ ! -e "$(O)" ]; then \
56 echo "build directory does not exist: '$(O)'";\
59 @$(call buildmakefile,$(O))
63 @if [ ! -e "$(O)" ]; then \
64 echo "build directory does not exist: '$(O)'";\
67 @$(call buildmakefile,$(O))
71 ifneq ($(strip $(T)),)
74 test -f $(TEMPLDIR)/globalconfig.out.$(T); \
75 bdir=T-$(DFLBUILDDIR)-$(T); \
77 $(call buildmakefile,T-$(DFLBUILDDIR)-$(T)); \
78 cp $(TEMPLDIR)/globalconfig.out.$(T) $$bdir/globalconfig.out; \
82 $(DFLBUILDDIR): fiasco.builddir.create
88 set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
91 $(RM) -r $(DFLBUILDDIR)
94 set -e; for i in $(MANSUBDIRS); do $(MAKE) -C $$i; done
96 fiasco.builddir.create:
97 [ -e $(DFLBUILDDIR)/Makefile ] || \
98 ($(call buildmakefile,$(DFLBUILDDIR)))
99 [ -f $(DFLBUILDDIR)/globalconfig.out ] || { \
100 cp $(TEMPLDIR)/globalconfig.out.$(DFL_TEMPLATE) \
101 $(DFLBUILDDIR)/globalconfig.out; \
104 config $(filter config %config,$(MAKECMDGOALS)): fiasco.builddir.create
105 $(MAKE) -C $(DFLBUILDDIR) $@
107 fiasco: fiasco.builddir.create
108 $(MAKE) -C $(DFLBUILDDIR) -j$(PL)
112 $(RM) -r $(ALLBUILDDIR); \
113 for X in $(TEST_TEMPLATES); do \
114 echo -e "\n= Building configuration: $$X\n\n"; \
115 $(call buildmakefile,$(ALLBUILDDIR)/$$X); \
116 cp $(TEMPLDIR)/globalconfig.out.$$X \
117 $(ALLBUILDDIR)/$$X/globalconfig.out; \
118 if $(MAKE) -C $(ALLBUILDDIR)/$$X -j$(PL); then \
119 [ -z "$(KEEP_BUILD_DIRS)" ] && \
120 $(RM) -r $(ALLBUILDDIR)/$$X; \
123 failed="$$failed $$X"; \
126 rmdir $(ALLBUILDDIR) >/dev/null 2>&1; \
127 [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
131 $(RM) -r $(ALLBUILDDIR)
132 $(MAKE) dobuildparallel SHELL=bash
134 .PHONY: dobuildparallel checkallp
136 dobuildparallel: $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES))
138 echo "======================================================"; \
139 for d in $(TEST_TEMPLATES); do \
140 if [ -e $(ALLBUILDDIR)/$$d/build.failed ]; then \
141 error=1; failed="$$failed $$d"; \
144 for f in $$failed; do echo "====== Failed Build Log: $$f ======"; \
145 tail -60 $(ALLBUILDDIR)/$$f/build.log; \
147 rmdir $(ALLBUILDDIR) >/dev/null 2>&1; \
148 [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
151 $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES)):
152 $(call buildmakefile,$@)
153 cp $(TEMPLDIR)/globalconfig.out.$(patsubst $(ALLBUILDDIR)/%,%,$@) \
155 $(MAKE) -C $@ 2>&1 | tee $@/build.log; \
156 if [ $${PIPESTATUS[0]} = 0 ]; \
157 then [ -z "$(KEEP_BUILD_DIRS)" ] && $(RM) -r $@; \
158 else echo $${PIPESTATUS[0]} > $@/build.failed; fi; true
162 @echo $(TEST_TEMPLATES)
164 RANDBUILDMAXTIME = $(shell $$((2 * 3600)))
166 RANDBUILDDIRS = $(foreach idx,$(shell seq $(RANDBUILDONERUN)),$(RANDBUILDDIR)/b-$(idx))
167 RANDBUILDAGAINDIRS = $(wildcard $(RANDBUILDDIR)/failed-*)
169 .PHONY: $(RANDBUILDAGAINDIRS)
172 $(RM) -r $(RANDBUILDDIR)
173 $(call buildmakefile,$(RANDBUILDDIR)/build-templ);
174 starttime=$$(date +%s); \
175 if [ -z "$$RANDBUILDTIME" ]; then d=0; else d=$$RANDBUILDTIME; fi; \
177 -o $$(date +%s) -lt $$(($$starttime + $$d)) ]; do \
178 $(MAKE) dobuildrandparallel SHELL=bash; \
179 if [ $$(ls $(RANDBUILDDIR) | grep -c failed-) \
180 -gt $$(($(RANDBUILDONERUN) / 2)) ]; \
183 echo "$$(ls $(RANDBUILDDIR) | grep -c failed-) directories" \
184 "failed to build."; \
185 echo "Build time: $$((($$(date +%s) - $$starttime) / 60)) minutes."
189 @$(MAKE) randcheck RANDBUILDTIME=$(RANDBUILDMAXTIME)
191 dobuildrandparallel: $(RANDBUILDDIRS)
193 define rand_build_a_dir
194 $(MAKE) -C $(1) 2>&1 | tee -a $(1)/build.log; \
195 if [ $${PIPESTATUS[0]} = 0 ]; then \
196 cp $(1)/globalconfig.out $(RANDBUILDDIR)/ok-$(2); \
198 elif [ -n "$(3)" ]; then \
199 [ -n "$$STOP_ON_ERROR" ] && exit 1; \
200 mv $(1) $(RANDBUILDDIR)/failed-$(2); \
205 cp -a $(RANDBUILDDIR)/build-templ $@
207 $(MAKE) -C $@ randconfig | tee -a $@/build.log; \
208 $(MAKE) -C $@ oldconfig | tee -a $@/build.log; \
209 do [ $${PIPESTATUS[0]} != 0 ]; done
210 +fn=$$(cat $@/globalconfig.out \
211 | grep -e "^CONFIG_" | sort | sha1sum \
213 if [ -e "ok-$$fn" -o -e "failed-$$fn" ]; then \
214 echo "Configuration $$fn already checked." \
217 $(call rand_build_a_dir,$@,$$fn,1)
219 $(RANDBUILDAGAINDIRS):
220 +$(call rand_build_a_dir,$@,$(patsubst $(RANDBUILDDIR)/failed-%,%,$@))
223 $(MAKE) STOP_ON_ERROR=1 randcheck
225 randcheckagain_bash: $(RANDBUILDAGAINDIRS)
228 $(MAKE) randcheckagain_bash SHELL=bash
229 @echo "Processed $(words $(RANDBUILDAGAINDIRS)) build directories."
230 @echo "$$(ls -d $(RANDBUILDDIR)/failed-* | wc -l) directories remain to fail."
233 $(MAKE) STOP_ON_ERROR=1 randcheckagain
236 @find $(RANDBUILDDIR) -name 'ok-*' | tool/configstat
237 @echo "Building: $$(ls $(RANDBUILDDIR) | grep -c b-) " \
238 "Ok: $$(ls $(RANDBUILDDIR) | grep -c ok-) " \
239 "Failed: $$(ls $(RANDBUILDDIR) | grep -c failed-)"
243 $(MAKE) --no-print-directory randcheckstat; \
249 @echo "fiasco Builds the default configuration ($(DFL_TEMPLATE))"
250 @echo "T=template Build a certain configuration"
251 @echo "checkall Build all template configurations in one go"
252 @echo "list List templates"
254 @echo "config menuconfig xconfig oldconfig"
255 @echo " Configure kernel in \"$(DFLBUILDDIR)\""
256 @echo "$(DFLBUILDDIR) Build kernel in \"$(DFLBUILDDIR)\""
257 @echo "clean cleanall clean or cleanall in \"$(CLEANSUBDIRS)\""
258 @echo "purge cleanall, remove \"$(DFLBUILDDIR)\" and build helper"
260 @echo "Creating a custom kernel:"
262 @echo " Create a build directory with:"
263 @echo " make BUILDDIR=builddir"
264 @echo " Then build the kernel:"
269 @echo "Call \"make help\" in the build directory for more information on build targets."
271 @echo "Default target: $(DFLBUILDDIR)"
274 .PHONY: man install clean cleanall fiasco.builddir.create fiasco \
275 l4check checkall config oldconfig menuconfig nconfig xconfig \
276 randcheck randcheckstop randcheckagain_bash randcheckstat \
277 randcheckstatloop help