]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/Makefile
05566909ba069d5488982240913162c560fca684
[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 $(T)),)
54 this:
55         set -e;                                                       \
56         test -f $(TEMPLDIR)/globalconfig.out.$(T);                    \
57         bdir=T-$(DFLBUILDDIR)-$(T);                                   \
58         rm -rf $$bdir;                                                \
59         $(call buildmakefile,T-$(DFLBUILDDIR)-$(T));                  \
60         cp $(TEMPLDIR)/globalconfig.out.$(T) $$bdir/globalconfig.out; \
61         $(MAKE) -C $$bdir
62 endif
63
64 $(DFLBUILDDIR): fiasco.builddir.create
65         $(MAKE) -C $@ -j$(PL)
66
67 all:    fiasco man
68
69 clean cleanall:
70         set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
71
72 purge: cleanall
73         $(RM) -r $(DFLBUILDDIR)
74
75 man:
76         set -e; for i in $(MANSUBDIRS); do $(MAKE) -C $$i; done
77
78 fiasco.builddir.create:
79         [ -e $(DFLBUILDDIR)/Makefile ] ||                        \
80                 ($(call buildmakefile,$(DFLBUILDDIR)))
81         [ -f $(DFLBUILDDIR)/globalconfig.out ] || {              \
82                 cp  $(TEMPLDIR)/globalconfig.out.$(DFL_TEMPLATE) \
83                         $(DFLBUILDDIR)/globalconfig.out;         \
84         }
85
86 config $(filter config %config,$(MAKECMDGOALS)): fiasco.builddir.create
87         $(MAKE) -C $(DFLBUILDDIR) $@
88
89 fiasco: fiasco.builddir.create
90         $(MAKE) -C $(DFLBUILDDIR) -j$(PL)
91
92 checkallseq:
93         error=0;                                                      \
94         $(RM) -r $(ALLBUILDDIR);                                      \
95         for X in $(TEST_TEMPLATES); do                                \
96                 echo -e "\n= Building configuration: $$X\n\n";        \
97                 $(call buildmakefile,$(ALLBUILDDIR)/$$X);             \
98                 cp $(TEMPLDIR)/globalconfig.out.$$X                   \
99                    $(ALLBUILDDIR)/$$X/globalconfig.out;               \
100                 if $(MAKE) -C $(ALLBUILDDIR)/$$X -j$(PL); then        \
101                         [ -z "$(KEEP_BUILD_DIRS)" ] &&                \
102                            $(RM) -r $(ALLBUILDDIR)/$$X;               \
103                 else                                                  \
104                         error=$$?;                                    \
105                         failed="$$failed $$X";                        \
106                 fi                                                    \
107         done;                                                         \
108         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                         \
109         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
110         exit $$error;
111
112 checkall l4check:
113         $(RM) -r $(ALLBUILDDIR)
114         $(MAKE) dobuildparallel SHELL=bash
115
116 .PHONY: dobuildparallel checkallp
117
118 dobuildparallel: $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES))
119         error=0;                                                              \
120         echo "======================================================";        \
121         for d in $(TEST_TEMPLATES); do                                        \
122           if [ -e $(ALLBUILDDIR)/$$d/build.failed ]; then                     \
123             error=1; failed="$$failed $$d";                                   \
124           fi;                                                                 \
125         done;                                                                 \
126         for f in $$failed; do echo "====== Failed Build Log: $$f ======";     \
127           tail -60 $(ALLBUILDDIR)/$$f/build.log;                              \
128         done;                                                                 \
129         rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                                 \
130         [ "$$failed" ] && echo -e "\nFailed configurations:$$failed";         \
131         exit $$error;
132
133 $(addprefix $(ALLBUILDDIR)/,$(TEST_TEMPLATES)):
134         $(call buildmakefile,$@)
135         cp $(TEMPLDIR)/globalconfig.out.$(patsubst $(ALLBUILDDIR)/%,%,$@)     \
136            $@/globalconfig.out
137         $(MAKE) -C $@ 2>&1 | tee $@/build.log;                                \
138         if [ $${PIPESTATUS[0]} = 0 ];                                         \
139         then [ -z "$(KEEP_BUILD_DIRS)" ] && $(RM) -r $@;                      \
140         else echo $${PIPESTATUS[0]} > $@/build.failed; fi
141
142 list:
143         @echo "Templates:"
144         @echo $(TEST_TEMPLATES)
145
146 randcheck:
147         $(RM) -r $(RANDBUILDDIR);                                     \
148         $(call buildmakefile,$(RANDBUILDDIR)/b);                      \
149         while true; do                                                \
150                 $(RM) $(RANDBUILDDIR)/b/globalconfig.out;             \
151                 $(MAKE) -C $(RANDBUILDDIR)/b randconfig;              \
152                 fn=$$(cat $(RANDBUILDDIR)/b/globalconfig.out          \
153                       | grep -e "^CONFIG_" | sort | sha1sum           \
154                       | cut -f1 -d\   );                              \
155                 if [ -e "ok-$$fn" -o -e "failed-$$fn" ]; then         \
156                   echo "Configuration $$fn already checked."          \
157                   continue;                                           \
158                 fi;                                                   \
159                 if $(MAKE) -C $(RANDBUILDDIR)/b -j$(PL); then         \
160                         cp $(RANDBUILDDIR)/b/globalconfig.out         \
161                           $(RANDBUILDDIR)/ok-$$fn;                    \
162                 else                                                  \
163                         [ -n "$$STOP_ON_ERROR" ] && exit 1;           \
164                         cp -a $(RANDBUILDDIR)/b                       \
165                               $(RANDBUILDDIR)/failed-$$fn;            \
166                 fi;                                                   \
167         done
168
169 randcheckstop:
170         $(MAKE) STOP_ON_ERROR=1 randcheck
171
172 randcheckagain:
173         for f in $(RANDBUILDDIR)/failed-*; do                         \
174                 if $(MAKE) -C $$f -j$(PL); then                       \
175                         $(RM) -rf $$f;                                \
176                 else                                                  \
177                         [ -n "$$STOP_ON_ERROR" ] && exit 1;           \
178                 fi                                                    \
179         done
180
181 randcheckagainstop:
182         $(MAKE) STOP_ON_ERROR=1 randcheckagain
183
184 help:
185         @echo
186         @echo "fiasco                    Builds the default configuration ($(DFL_TEMPLATE))"
187         @echo "T=template                Build a certain configuration"
188         @echo "checkall                  Build all template configurations in one go"
189         @echo "list                      List templates"
190         @echo
191         @echo "config menuconfig xconfig oldconfig"
192         @echo "                          Configure kernel in \"$(DFLBUILDDIR)\""
193         @echo "$(DFLBUILDDIR)                     Build kernel in \"$(DFLBUILDDIR)\""
194         @echo "clean cleanall            clean or cleanall in \"$(CLEANSUBDIRS)\""
195         @echo "purge                     cleanall, remove \"$(DFLBUILDDIR)\" and build helper"
196         @echo
197         @echo "Creating a custom kernel:"
198         @echo
199         @echo "  Create a build directory with:"
200         @echo "     make BUILDDIR=builddir"
201         @echo "  Then build the kernel:"
202         @echo "     cd builddir"
203         @echo "     make config"
204         @echo "     make"
205         @echo
206         @echo "Call \"make help\" in the build directory for more information on build targets."
207         @echo
208         @echo "Default target: $(DFLBUILDDIR)"
209         @echo
210
211 .PHONY: man install clean cleanall fiasco.builddir.create fiasco \
212         l4check checkall config oldconfig menuconfig nconfig xconfig \
213         randcheck randcheckstop help