]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/Makefile
fiasco: bootstrap: better to comment, not to force the undeclired param be 0.
[l4.git] / kernel / fiasco / Makefile
1 #
2 #
3 # GLOBAL Makefile for FIASCO
4
5 # enviroment
6 DFLBUILDDIR     := build
7 ALLBUILDDIR     := build-all
8 RANDBUILDDIR    := build-rand
9 TEMPLDIR        := src/templates
10 MAKEFILETEMPL   := $(TEMPLDIR)/Makefile.builddir.templ
11 MANSUBDIRS      := man
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
18
19 buildmakefile = mkdir -p "$(1)";                                        \
20                 perl -p -e '$$s = "$(CURDIR)/src"; s/\@SRCDIR\@/$$s/'   \
21                         < $(MAKEFILETEMPL) > $(1)/Makefile
22
23 ifneq ($(strip $(B)),)
24 BUILDDIR := $(B)
25 endif
26 ifneq ($(strip $(BUILDDIR)),)
27 builddir:
28         @echo "Creating build directory \"$(BUILDDIR)\"..."
29         @if [ -e "$(BUILDDIR)" ]; then                  \
30                 echo "Already exists, aborting.";       \
31                 exit 1;                                 \
32         fi
33         @$(call buildmakefile,$(BUILDDIR))
34         @echo "done."
35 endif
36
37 ifneq ($(strip $(O)),)
38 builddir:
39         @if [ ! -e "$(O)" ]; then                       \
40           echo "build directory does not exist: '$(O)'";\
41                 exit 1;                                 \
42         fi
43         @$(call buildmakefile,$(O))
44         @$(MAKE) -C $(O)
45
46 %:
47         @if [ ! -e "$(O)" ]; then                       \
48           echo "build directory does not exist: '$(O)'";\
49                 exit 1;                                 \
50         fi
51         @$(call buildmakefile,$(O))
52         @$(MAKE) -C $(O) $@
53 endif
54
55 ifneq ($(strip $(T)),)
56 this:
57         set -e;                                                       \
58         test -f $(TEMPLDIR)/globalconfig.out.$(T);                    \
59         bdir=T-$(DFLBUILDDIR)-$(T);                                   \
60         rm -rf $$bdir;                                                \
61         $(call buildmakefile,T-$(DFLBUILDDIR)-$(T));                  \
62         cp $(TEMPLDIR)/globalconfig.out.$(T) $$bdir/globalconfig.out; \
63         $(MAKE) -C $$bdir olddefconfig;                               \
64         $(MAKE) -C $$bdir
65 endif
66
67 $(DFLBUILDDIR): fiasco.builddir.create
68         $(MAKE) -C $@
69
70 all:    fiasco man
71
72 clean cleanall:
73         set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
74
75 purge: cleanall
76         $(RM) -r $(DFLBUILDDIR)
77
78 man:
79         set -e; for i in $(MANSUBDIRS); do $(MAKE) -C $$i; done
80
81 fiasco.builddir.create:
82         [ -e $(DFLBUILDDIR)/Makefile ] ||                        \
83                 ($(call buildmakefile,$(DFLBUILDDIR)))
84         [ -f $(DFLBUILDDIR)/globalconfig.out ] || {              \
85                 cp  $(TEMPLDIR)/globalconfig.out.$(DFL_TEMPLATE) \
86                         $(DFLBUILDDIR)/globalconfig.out;         \
87                 $(MAKE) -C $(DFLBUILDDIR) olddefconfig;          \
88         }
89
90 config $(filter config %config,$(MAKECMDGOALS)): fiasco.builddir.create
91         $(MAKE) -C $(DFLBUILDDIR) $@
92
93 fiasco: fiasco.builddir.create
94         $(MAKE) -C $(DFLBUILDDIR)
95
96 checkallseq:
97         @error=0;                                                     \
98         $(RM) -r $(ALLBUILDDIR);                                      \
99         for X in $(TEST_TEMPLATES); do                                \
100                 echo -e "\n= Building configuration: $$X\n\n";        \
101                 $(call buildmakefile,$(ALLBUILDDIR)/$$X);             \
102                 cp $(TEMPLDIR)/globalconfig.out.$$X                   \
103                    $(ALLBUILDDIR)/$$X/globalconfig.out;               \
104                 if $(MAKE) -C $(ALLBUILDDIR)/$$X; then                \
105                         [ -z "$(KEEP_BUILD_DIRS)" ] &&                \
106                            $(RM) -r $(ALLBUILDDIR)/$$X;               \
107                 else                                                  \
108                         error=$$?;                                    \
109                         failed="$$failed $$X";                        \
110                 fi                                                    \
111         done;                                                         \
112         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                         \
113         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
114         exit $$error;
115
116 checkall l4check:
117         $(RM) -r $(ALLBUILDDIR)
118         $(MAKE) dobuildparallel SHELL=bash
119
120 .PHONY: dobuildparallel checkallp
121
122 dobuildparallel: $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES))
123         @error=0;                                                             \
124         echo "======================================================";        \
125         for d in $(TEST_TEMPLATES); do                                        \
126           if [ -e $(ALLBUILDDIR)/$$d/build.failed ]; then                     \
127             error=1; failed="$$failed $$d";                                   \
128           fi;                                                                 \
129         done;                                                                 \
130         for f in $$failed; do echo "====== Failed Build Log: $$f ======";     \
131           tail -60 $(ALLBUILDDIR)/$$f/build.log;                              \
132         done;                                                                 \
133         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                                 \
134         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed";         \
135         exit $$error;
136
137 $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES)):
138         $(call buildmakefile,$@)
139         cp $(TEMPLDIR)/globalconfig.out.$(patsubst $(ALLBUILDDIR)/%,%,$@)     \
140            $@/globalconfig.out
141         INCLUDE_PPC32=y INCLUDE_SPARC=y                                       \
142         $(MAKE) -C $@ olddefconfig 2>&1 | tee -a $@/build.log
143         INCLUDE_PPC32=y INCLUDE_SPARC=y                                       \
144         $(MAKE) -C $@ 2>&1 | tee -a $@/build.log;                             \
145         if [ $${PIPESTATUS[0]} = 0 -o -e $@/buildcheck.ignore ];              \
146         then [ -z "$(KEEP_BUILD_DIRS)" ] && $(RM) -r $@;                      \
147         else echo $${PIPESTATUS[0]} > $@/build.failed; fi; true
148
149 list:
150         @echo "Templates:"
151         @echo $(TEST_TEMPLATES)
152
153 RANDBUILDMAXTIME   = $(shell $$((2 * 3600)))
154 RANDBUILDONERUN    = 50
155 RANDBUILDDIRS      = $(foreach idx,$(shell seq $(RANDBUILDONERUN)),$(RANDBUILDDIR)/b-$(idx))
156 RANDBUILDAGAINDIRS = $(wildcard $(RANDBUILDDIR)/failed-*)
157
158 .PHONY: $(RANDBUILDAGAINDIRS)
159
160 randcheck:
161         $(RM) -r $(RANDBUILDDIR)
162         $(call buildmakefile,$(RANDBUILDDIR)/build-templ);
163         starttime=$$(date +%s);                                              \
164         if [ -z "$$RANDBUILDTIME" ]; then d=0; else d=$$RANDBUILDTIME; fi;   \
165         while [ "$$d" = 0                                         \
166                 -o $$(date +%s) -lt $$(($$starttime + $$d)) ]; do \
167           $(MAKE) dobuildrandparallel SHELL=bash;                            \
168           if [ $$(ls $(RANDBUILDDIR) | grep -c failed-)                      \
169                -gt $$(($(RANDBUILDONERUN) / 2)) ];                           \
170           then break; fi;                                                    \
171         done;                                                                \
172         echo "$$(ls $(RANDBUILDDIR) | grep -c failed-) directories"          \
173              "failed to build.";                                             \
174         echo "Build time: $$((($$(date +%s) - $$starttime) / 60)) minutes."
175
176
177 randchecktimed:
178         @$(MAKE) randcheck RANDBUILDTIME=$(RANDBUILDMAXTIME)
179
180 dobuildrandparallel: $(RANDBUILDDIRS)
181
182 define rand_build_a_dir
183         $(MAKE) -C $(1) 2>&1 | tee -a $(1)/build.log;           \
184         if [ $${PIPESTATUS[0]} = 0 ]; then                      \
185           cp $(1)/globalconfig.out $(RANDBUILDDIR)/ok-$(2);     \
186           rm -r $(1);                                           \
187         elif [ -n "$(3)" ]; then                                \
188           [ -n "$$STOP_ON_ERROR" ] && exit 1;                   \
189           mv $(1) $(RANDBUILDDIR)/failed-$(2);                  \
190         fi
191 endef
192
193 $(RANDBUILDDIRS):
194         cp -a $(RANDBUILDDIR)/build-templ $@
195         until                                                 \
196           INCLUDE_PPC32=y INCLUDE_SPARC=y                     \
197             $(MAKE) -C $@ randconfig | tee -a $@/build.log;   \
198           INCLUDE_PPC32=y INCLUDE_SPARC=y                     \
199             $(MAKE) -C $@ oldconfig  | tee -a $@/build.log;   \
200         do [ $${PIPESTATUS[0]} != 0 ]; done
201         +fn=$$(cat $@/globalconfig.out                        \
202               | grep -e "^CONFIG_" | sort | sha1sum           \
203               | cut -f1 -d\   );                              \
204         if [ -e "ok-$$fn" -o -e "failed-$$fn" ]; then         \
205           echo "Configuration $$fn already checked."          \
206           continue;                                           \
207         fi;                                                   \
208         $(call rand_build_a_dir,$@,$$fn,1)
209
210 $(RANDBUILDAGAINDIRS):
211         +$(call rand_build_a_dir,$@,$(patsubst $(RANDBUILDDIR)/failed-%,%,$@))
212
213 randcheckstop:
214         $(MAKE) STOP_ON_ERROR=1 randcheck
215
216 randcheckagain_bash: $(RANDBUILDAGAINDIRS)
217
218 randcheckagain:
219         $(MAKE) randcheckagain_bash SHELL=bash
220         @echo "Processed $(words $(RANDBUILDAGAINDIRS)) build directories."
221         @echo "$$(ls -d $(RANDBUILDDIR)/failed-* | wc -l) directories remain to fail."
222
223 randcheckagainstop:
224         $(MAKE) STOP_ON_ERROR=1 randcheckagain
225
226 randcheckstat:
227         @find $(RANDBUILDDIR) -name 'ok-*' | tool/configstat
228         @echo "Building: $$(ls $(RANDBUILDDIR) | grep -c b-)    " \
229               "Ok: $$(ls $(RANDBUILDDIR) | grep -c ok-)    "      \
230               "Failed: $$(ls $(RANDBUILDDIR) | grep -c failed-)"
231
232 randcheckstatloop:
233         @while true; do \
234           $(MAKE) --no-print-directory randcheckstat; \
235           sleep 5; \
236         done
237
238 remotemake:
239         @r=$(word 1,$(REMOTEOPTS)); h=$${r%:*}; p=$${r#*:};                           \
240         ssh $$h mkdir -p $$p;                                                         \
241         rsync -aP --delete Makefile src tool $$r;                                              \
242         ssh $$h "cd $$p && make $(wordlist 2,$(words $(REMOTEOPTS)),$(REMOTEOPTS))";  \
243         echo "Returned from $$r."
244
245 help:
246         @echo
247         @echo "fiasco                    Builds the default configuration ($(DFL_TEMPLATE))"
248         @echo "T=template                Build a certain configuration"
249         @echo "checkall                  Build all template configurations in one go"
250         @echo "list                      List templates"
251         @echo
252         @echo "config menuconfig xconfig oldconfig"
253         @echo "                          Configure kernel in \"$(DFLBUILDDIR)\""
254         @echo "$(DFLBUILDDIR)                     Build kernel in \"$(DFLBUILDDIR)\""
255         @echo "clean cleanall            clean or cleanall in \"$(CLEANSUBDIRS)\""
256         @echo "purge                     cleanall, remove \"$(DFLBUILDDIR)\" and build helper"
257         @echo
258         @echo "Creating a custom kernel:"
259         @echo
260         @echo "  Create a build directory with:"
261         @echo "     make BUILDDIR=builddir"
262         @echo "  Then build the kernel:"
263         @echo "     cd builddir"
264         @echo "     make config"
265         @echo "     make"
266         @echo
267         @echo "Call \"make help\" in the build directory for more information on build targets."
268         @echo
269         @echo "Default target: $(DFLBUILDDIR)"
270         @echo
271
272 .PHONY: man install clean cleanall fiasco.builddir.create fiasco \
273         l4check checkall config oldconfig menuconfig nconfig xconfig \
274         randcheck randcheckstop randcheckagain_bash randcheckstat \
275         randcheckstatloop help