]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/Makefile
update
[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 PL              ?= 1
19
20 getdir          = $(shell                                               \
21                     bd="$(1)";                                          \
22                     if [ "$${bd\#/}" = "$$bd" -a                        \
23                          "$${bd\#*..}" = "$$bd" ]; then                 \
24                       relp="..";                                        \
25                       while [ "$${bd\#*/}" != "$$bd" ]; do              \
26                         relp="$$relp/..";                               \
27                         bd="$${bd\#*/}";                                \
28                       done;                                             \
29                       echo "$$relp";                                    \
30                     else                                                \
31                       pwd;                                              \
32                     fi                                                  \
33                   )
34
35 buildmakefile = mkdir -p "$(1)";                                         \
36                 perl -p -i -e '$$s = "$(CURDIR)/src"; s/\@SRCDIR\@/$$s/' \
37                         < $(MAKEFILETEMPL) > $(1)/Makefile
38
39 ifneq ($(strip $(B)),)
40 BUILDDIR := $(B)
41 endif
42 ifneq ($(strip $(BUILDDIR)),)
43 builddir:
44         @echo "Creating build directory \"$(BUILDDIR)\"..."
45         @if [ -e "$(BUILDDIR)" ]; then                  \
46                 echo "Already exists, aborting.";       \
47                 exit 1;                                 \
48         fi
49         @$(call buildmakefile,$(BUILDDIR))
50         @echo "done."
51 endif
52
53 ifneq ($(strip $(O)),)
54 builddir:
55         @if [ ! -e "$(O)" ]; then                       \
56           echo "build directory does not exist: '$(O)'";\
57                 exit 1;                                 \
58         fi
59         @$(call buildmakefile,$(O))
60         @$(MAKE) -C $(O)
61
62 %:
63         @if [ ! -e "$(O)" ]; then                       \
64           echo "build directory does not exist: '$(O)'";\
65                 exit 1;                                 \
66         fi
67         @$(call buildmakefile,$(O))
68         @$(MAKE) -C $(O) $@
69 endif
70
71 ifneq ($(strip $(T)),)
72 this:
73         set -e;                                                       \
74         test -f $(TEMPLDIR)/globalconfig.out.$(T);                    \
75         bdir=T-$(DFLBUILDDIR)-$(T);                                   \
76         rm -rf $$bdir;                                                \
77         $(call buildmakefile,T-$(DFLBUILDDIR)-$(T));                  \
78         cp $(TEMPLDIR)/globalconfig.out.$(T) $$bdir/globalconfig.out; \
79         $(MAKE) -C $$bdir
80 endif
81
82 $(DFLBUILDDIR): fiasco.builddir.create
83         $(MAKE) -C $@ -j$(PL)
84
85 all:    fiasco man
86
87 clean cleanall:
88         set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
89
90 purge: cleanall
91         $(RM) -r $(DFLBUILDDIR)
92
93 man:
94         set -e; for i in $(MANSUBDIRS); do $(MAKE) -C $$i; done
95
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;         \
102         }
103
104 config $(filter config %config,$(MAKECMDGOALS)): fiasco.builddir.create
105         $(MAKE) -C $(DFLBUILDDIR) $@
106
107 fiasco: fiasco.builddir.create
108         $(MAKE) -C $(DFLBUILDDIR) -j$(PL)
109
110 checkallseq:
111         @error=0;                                                     \
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;               \
121                 else                                                  \
122                         error=$$?;                                    \
123                         failed="$$failed $$X";                        \
124                 fi                                                    \
125         done;                                                         \
126         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                         \
127         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
128         exit $$error;
129
130 checkall l4check:
131         $(RM) -r $(ALLBUILDDIR)
132         $(MAKE) dobuildparallel SHELL=bash
133
134 .PHONY: dobuildparallel checkallp
135
136 dobuildparallel: $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES))
137         @error=0;                                                             \
138         echo "======================================================";        \
139         for d in $(TEST_TEMPLATES); do                                        \
140           if [ -e $(ALLBUILDDIR)/$$d/build.failed ]; then                     \
141             error=1; failed="$$failed $$d";                                   \
142           fi;                                                                 \
143         done;                                                                 \
144         for f in $$failed; do echo "====== Failed Build Log: $$f ======";     \
145           tail -60 $(ALLBUILDDIR)/$$f/build.log;                              \
146         done;                                                                 \
147         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                                 \
148         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed";         \
149         exit $$error;
150
151 $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES)):
152         $(call buildmakefile,$@)
153         cp $(TEMPLDIR)/globalconfig.out.$(patsubst $(ALLBUILDDIR)/%,%,$@)     \
154            $@/globalconfig.out
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
159
160 list:
161         @echo "Templates:"
162         @echo $(TEST_TEMPLATES)
163
164 RANDBUILDMAXTIME   = $(shell $$((2 * 3600)))
165 RANDBUILDONERUN    = 50
166 RANDBUILDDIRS      = $(foreach idx,$(shell seq $(RANDBUILDONERUN)),$(RANDBUILDDIR)/b-$(idx))
167 RANDBUILDAGAINDIRS = $(wildcard $(RANDBUILDDIR)/failed-*)
168
169 .PHONY: $(RANDBUILDAGAINDIRS)
170
171 randcheck:
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;   \
176         while [ "$$d" = 0                                         \
177                 -o $$(date +%s) -lt $$(($$starttime + $$d)) ]; do \
178           $(MAKE) dobuildrandparallel SHELL=bash;                            \
179           if [ $$(ls $(RANDBUILDDIR) | grep -c failed-)                      \
180                -gt $$(($(RANDBUILDONERUN) / 2)) ];                           \
181           then break; fi;                                                    \
182         done;                                                                \
183         echo "$$(ls $(RANDBUILDDIR) | grep -c failed-) directories"          \
184              "failed to build.";                                             \
185         echo "Build time: $$((($$(date +%s) - $$starttime) / 60)) minutes."
186
187
188 randchecktimed:
189         @$(MAKE) randcheck RANDBUILDTIME=$(RANDBUILDMAXTIME)
190
191 dobuildrandparallel: $(RANDBUILDDIRS)
192
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);     \
197           rm -r $(1);                                           \
198         elif [ -n "$(3)" ]; then                                \
199           [ -n "$$STOP_ON_ERROR" ] && exit 1;                   \
200           mv $(1) $(RANDBUILDDIR)/failed-$(2);                  \
201         fi
202 endef
203
204 $(RANDBUILDDIRS):
205         cp -a $(RANDBUILDDIR)/build-templ $@
206         until                                                 \
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           \
212               | cut -f1 -d\   );                              \
213         if [ -e "ok-$$fn" -o -e "failed-$$fn" ]; then         \
214           echo "Configuration $$fn already checked."          \
215           continue;                                           \
216         fi;                                                   \
217         $(call rand_build_a_dir,$@,$$fn,1)
218
219 $(RANDBUILDAGAINDIRS):
220         +$(call rand_build_a_dir,$@,$(patsubst $(RANDBUILDDIR)/failed-%,%,$@))
221
222 randcheckstop:
223         $(MAKE) STOP_ON_ERROR=1 randcheck
224
225 randcheckagain_bash: $(RANDBUILDAGAINDIRS)
226
227 randcheckagain:
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."
231
232 randcheckagainstop:
233         $(MAKE) STOP_ON_ERROR=1 randcheckagain
234
235 randcheckstat:
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-)"
240
241 randcheckstatloop:
242         @while true; do \
243           $(MAKE) --no-print-directory randcheckstat; \
244           sleep 5; \
245         done
246
247 help:
248         @echo
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"
253         @echo
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"
259         @echo
260         @echo "Creating a custom kernel:"
261         @echo
262         @echo "  Create a build directory with:"
263         @echo "     make BUILDDIR=builddir"
264         @echo "  Then build the kernel:"
265         @echo "     cd builddir"
266         @echo "     make config"
267         @echo "     make"
268         @echo
269         @echo "Call \"make help\" in the build directory for more information on build targets."
270         @echo
271         @echo "Default target: $(DFLBUILDDIR)"
272         @echo
273
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