]> 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 DFL_TEMPLATE    := ia32-1
17 PL              ?= 1
18
19 getdir          = $(shell                                               \
20                     bd="$(1)";                                          \
21                     if [ "$${bd\#/}" = "$$bd" -a                        \
22                          "$${bd\#*..}" = "$$bd" ]; then                 \
23                       relp="..";                                        \
24                       while [ "$${bd\#*/}" != "$$bd" ]; do              \
25                         relp="$$relp/..";                               \
26                         bd="$${bd\#*/}";                                \
27                       done;                                             \
28                       echo "$$relp";                                    \
29                     else                                                \
30                       pwd;                                              \
31                     fi                                                  \
32                   )
33
34 buildmakefile = mkdir -p "$(1)";                                             \
35                 perl -p -i -e '$$s = "$(CURDIR)/src"; s/\@SRCDIR\@/$$s/' \
36                         < $(MAKEFILETEMPL) > $(1)/Makefile
37
38 ifneq ($(strip $(B)),)
39 BUILDDIR := $(B)
40 endif
41 ifneq ($(strip $(BUILDDIR)),)
42 builddir:
43                 @echo "Creating build directory \"$(BUILDDIR)\"..."
44                 @if [ -e "$(BUILDDIR)" ]; then                  \
45                         echo "Already exists, aborting.";       \
46                         exit 1;                                 \
47                 fi
48                 @$(call buildmakefile,$(BUILDDIR))
49                 @echo "done."
50 endif
51
52 ifneq ($(strip $(T)),)
53 this:
54                 set -e;                                                       \
55                 test -f $(TEMPLDIR)/globalconfig.out.$(T);                    \
56                 bdir=T-$(DFLBUILDDIR)-$(T);                                   \
57                 rm -rf $$bdir;                                                \
58                 $(call buildmakefile,T-$(DFLBUILDDIR)-$(T));                  \
59                 cp $(TEMPLDIR)/globalconfig.out.$(T) $$bdir/globalconfig.out; \
60                 $(MAKE) -C $$bdir
61 endif
62
63 $(DFLBUILDDIR): fiasco.builddir.create
64                 $(MAKE) -C $@ -j$(PL)
65
66 all:            fiasco man
67
68 clean cleanall:
69                 set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
70
71 purge: cleanall
72                 $(RM) -r $(DFLBUILDDIR)
73
74 man:
75                 set -e; for i in $(MANSUBDIRS); do $(MAKE) -C $$i; done
76
77 fiasco.builddir.create:
78                 [ -e $(DFLBUILDDIR)/Makefile ] ||                        \
79                         ($(call buildmakefile,$(DFLBUILDDIR)))
80                 [ -f $(DFLBUILDDIR)/globalconfig.out ] || {              \
81                         cp  $(TEMPLDIR)/globalconfig.out.$(DFL_TEMPLATE) \
82                                 $(DFLBUILDDIR)/globalconfig.out;         \
83                 }
84
85 config $(filter config %config,$(MAKECMDGOALS)): fiasco.builddir.create
86                 $(MAKE) -C $(DFLBUILDDIR) $@
87
88 fiasco: fiasco.builddir.create
89                 $(MAKE) -C $(DFLBUILDDIR) -j$(PL)
90
91 checkall l4check:
92                 error=0;                                                      \
93                 $(RM) -r $(ALLBUILDDIR);                                      \
94                 for X in $(TEST_TEMPLATES); do                                \
95                         echo -e "\n= Building configuration: $$X\n\n";        \
96                         $(call buildmakefile,$(ALLBUILDDIR)/$$X);             \
97                         cp $(TEMPLDIR)/globalconfig.out.$$X                   \
98                            $(ALLBUILDDIR)/$$X/globalconfig.out;               \
99                         if $(MAKE) -C $(ALLBUILDDIR)/$$X -j$(PL); then        \
100                                 [ -z "$(KEEP_BUILD_DIRS)" ] &&                \
101                                    $(RM) -r $(ALLBUILDDIR)/$$X;               \
102                         else                                                  \
103                                 error=$$?;                                    \
104                                 failed="$$failed $$X";                        \
105                         fi                                                    \
106                 done;                                                         \
107                 rmdir $(ALLBUILDDIR) >/dev/null 2>&1;                         \
108                 [ "$$failed" ] && echo -e "\nFailed configurations:$$failed"; \
109                 exit $$error;
110
111 list:
112                 @echo "Templates:"
113                 @echo $(patsubst $(TEMPLDIR)/globalconfig.out.%,%,$(wildcard $(TEMPLDIR)/globalconfig.out.*))
114
115 randcheck:
116                 $(RM) -r $(RANDBUILDDIR);                                     \
117                 $(call buildmakefile,$(RANDBUILDDIR)/b);                      \
118                 while true; do                                                \
119                         $(MAKE) -C $(RANDBUILDDIR)/b randconfig;              \
120                         fn=$$(cat $(RANDBUILDDIR)/b/globalconfig.out          \
121                               | grep -e "^CONFIG_" | sort | sha1sum           \
122                               | cut -f1 -d\   );                              \
123                         if [ -e "ok-$$fn" -o -e "failed-$$fn" ]; then         \
124                           echo "Configuration $$fn already checked."          \
125                           continue;                                           \
126                         fi;                                                   \
127                         if $(MAKE) -C $(RANDBUILDDIR)/b -j$(PL); then         \
128                                 cp $(RANDBUILDDIR)/b/globalconfig.out         \
129                                   $(RANDBUILDDIR)/ok-$$fn;                    \
130                         else                                                  \
131                                 [ -n "$$STOP_ON_ERROR" ] && exit 1;           \
132                                 cp -a $(RANDBUILDDIR)/b                       \
133                                       $(RANDBUILDDIR)/failed-$$fn;            \
134                         fi;                                                   \
135                 done
136
137 randcheckstop:
138                 $(MAKE) STOP_ON_ERROR=1 randcheck
139
140 randcheckagain:
141                 for f in $(RANDBUILDDIR)/failed-*; do                         \
142                         if $(MAKE) -C $$f -j$(PL); then                       \
143                                 $(RM) -rf $$f;                                \
144                         else                                                  \
145                                 [ -n "$$STOP_ON_ERROR" ] && exit 1;           \
146                         fi                                                    \
147                 done
148
149 randcheckagainstop:
150                 $(MAKE) STOP_ON_ERROR=1 randcheckagain
151
152 help:
153                 @echo
154                 @echo "fiasco                    Builds the default configuration ($(DFL_TEMPLATE))"
155                 @echo "T=template                Build a certain configuration"
156                 @echo "checkall                  Build all template configurations in one go"
157                 @echo "list                      List templates"
158                 @echo
159                 @echo "config menuconfig xconfig oldconfig"
160                 @echo "                          Configure kernel in \"$(DFLBUILDDIR)\""
161                 @echo "$(DFLBUILDDIR)                     Build kernel in \"$(DFLBUILDDIR)\""
162                 @echo "clean cleanall            clean or cleanall in \"$(CLEANSUBDIRS)\""
163                 @echo "purge                     cleanall, remove \"$(DFLBUILDDIR)\" and build helper"
164                 @echo
165                 @echo "Creating a custom kernel:"
166                 @echo
167                 @echo "  Create a build directory with:"
168                 @echo "     make BUILDDIR=builddir"
169                 @echo "  Then build the kernel:"
170                 @echo "     cd builddir"
171                 @echo "     make config"
172                 @echo "     make"
173                 @echo
174                 @echo "Call \"make help\" in the build directory for more information on build targets."
175                 @echo
176                 @echo "Default target: $(DFLBUILDDIR)"
177                 @echo
178
179 .PHONY:         man install clean cleanall fiasco.builddir.create fiasco \
180                 l4check checkall config oldconfig menuconfig nconfig xconfig \
181                 randcheck randcheckstop help