]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/Makefile
4d157d3be044973821631f532c0297a545a9a44f
[l4.git] / kernel / fiasco / src / Makefile
1 srcdir          ?= NOT_SET
2 tooldir         := $(srcdir)/../tool
3
4 CONFIG_BANNER_STRING ?= "Fiasco - prepare for world domination"
5
6 .PHONY: all do-all test-all config textconfig menuconfig xconfig \
7         oldconfig regenconfig mrproper doc help update nconfig
8
9 all:
10
11 help:
12         @echo "Possible targets are:"
13         @echo "  menuconfig     - configure Fiasco (ncurses mode)"
14         @echo "  config         - like menuconfig"
15         @echo "  textconfig     - line-oriented config"
16         @echo "  xconfig        - configure Fiasco (graphical mode)"
17         @echo "  all            - Fiasco binary"
18         @echo "  clean          - clear all auto-generated files in auto"
19         @echo "  cleanall       - like clean + dependencies"
20         @echo "  mrproper       - like cleanall + config files"
21         @echo "  update         - update Fiasco and preprocess using svn"
22         @echo "  DEPS           - dependencies between kernel object files"
23         @echo "  DEPS.ps        - graphical (ps) representation of DEPS"
24         @echo "  DEPS.svg       - graphical (svg) representation of DEPS"
25         @echo "  DEPS.tred.ps   - transitive reduction of DEPS.ps"
26         @echo "  DEPS.tred.svg  - transitive reduction of DEPS.svg"
27         @echo "  doc            - doxygen HTML documentation into docs/"
28         @echo "  TAGS tags      - create tags files"
29
30
31 ifneq ($(srcdir),NOT_SET)
32 Makefile: $(srcdir)/templates/Makefile.builddir.templ
33         perl -p -i -e '$$s = "$(srcdir)"; s/\@SRCDIR\@/$$s/' \
34                         < $< >$@
35 endif
36
37 ifneq ($(MAKECMDGOALS),help)
38
39 ifeq ($(srcdir),NOT_SET)
40 all $(filter config %config,$(MAKECMDGOALS)):
41         @echo "======================================================================"
42         @echo " Building Fiasco in the src directory is not possible!"
43         @echo ""
44         @echo " Go to the Fiasco root directory and create your build directory with"
45         @echo "    cd .. && make BUILDDIR=build-dir"
46         @echo "======================================================================"
47         @exit 1
48
49 else # srcdir != NOT_SET
50
51 all: globalconfig.h
52
53 ifeq ($(filter config %config,$(MAKECMDGOALS)),)
54
55 -include globalconfig.out
56
57 # use patsubst here to prevent confusion of syntax highlighting editors :-)
58 CONFIG_XARCH    := $(patsubst "%",%,$(CONFIG_XARCH))
59 CONFIG_ABI      := $(patsubst "%",%,$(CONFIG_ABI))
60
61 ifeq ("$(CONFIG_XARCH)","")
62
63 all: menuconfig
64         @echo "========================================================="
65         @echo "Now run make again to build!"
66         @echo "========================================================="
67         @exit 1
68
69 else # ! no XARCH
70 ifeq ("$(CONFIG_ABI)","")
71 all:
72         @echo "========================================================="
73         @echo "ERROR: No ABI version set (run 'make menuconfig')!"
74         @echo "========================================================="
75         @exit 1
76 else # ! no ABI
77
78
79 # At this point, globalconfig.out is up-to-date.  Update Modules and
80 # .Modules.deps, then restart using Makefile.sub1, Makefile.sub2.
81 #
82
83 # Read Make configuration
84 include $(srcdir)/Makeconf
85
86 include $(MODULES_FILE)
87 MODULES_FILES += $(srcdir)/Modules.generic
88
89 ifdef SUBSYSTEMS
90  _modules_read_ = true
91 endif
92
93 ifdef _modules_read_
94 GENERATED_MODULES = $(foreach subsys, $(SUBSYSTEMS), \
95                       $(INTERFACES_$(subsys)))
96 ALL = $(foreach subsys, $(SUBSYSTEMS), $($(subsys)) $($(subsys)_EXTRA))
97
98 $(foreach m, $(GENERATED_MODULES), auto/stamp-$(m).ready): $(MODULES_FILES)
99
100 .PRECIOUS: .Modules.deps
101 .Modules.deps: $(MODULES_FILES) globalconfig.h source
102         @mkdir -p auto
103         @echo "Cleaning up build directory"
104         $(VERBOSE)$(RM_R) *.o fiasco *.d .*.d .*.d.new *.d.new
105         $(VERBOSE)$(RM_R) auto/*.cc auto/*.h auto/*.S auto/stamp-*.ready
106         @echo "Creating $@"
107         @($(foreach mod, $(GENERATED_MODULES),                          \
108             echo 'auto/stamp-$(mod).ready:                              \
109                   $(addsuffix .cpp,$(call eval_impl,$(mod)))';          \
110             echo '$(patsubst %,auto/%.cc,$(call eval_impl,$(mod)))'     \
111                  'auto/$(mod).h auto/$(mod)_i.h:                        \
112                   auto/stamp-$(mod).ready ;                             \
113                   @[ -e $$@ ] || { $$(RM) $$<; $$(MAKE) $$<; }';        \
114           )) > $@.new
115         @($(foreach subsys, $(SUBSYSTEMS),                                    \
116             echo 'IFDEPS += $(addprefix ., $(addsuffix .cc.d,                 \
117                               $(foreach in,$(INTERFACES_$(subsys)),           \
118                                 $(call eval_impl,$(in)))))' ;                 \
119             echo 'CXXSRC_$(subsys) += $(addsuffix .cc,                        \
120                                         $(foreach in,$(INTERFACES_$(subsys)), \
121                                           $(call eval_impl,$(in))))';         \
122             echo 'OBJ_$(subsys) += $$(CXXSRC_$(subsys):.cc=.o)                \
123                                    $$(CSRC_$(subsys):.c=.o)                   \
124                                    $$(ASSRC_$(subsys):.S=.o)' ; ) ) >> $@.new
125         @echo "GENERATED_MODULES = $(GENERATED_MODULES)" >> $@.new
126         @echo "ALL = $(ALL)" >> $@.new
127         @echo "_modules_deps_read_ = true" >> $@.new
128         @mv $@.new $@
129
130 endif # _modules_read_
131
132
133 # Makefile.sub1: Create source files.
134
135
136 .PHONY: create-sources
137 create-sources: $(MODULES_FILES) globalconfig.h .Modules.deps 
138         $(MAKE) srcdir=$(srcdir) objbase=$(objbase) -f $(srcdir)/Makefile.sub1 
139 auto/stamp-%.ready: $(MODULES_FILES) globalconfig.h .Modules.deps 
140         $(MAKE) srcdir=$(srcdir) objbase=$(objbase) -f $(srcdir)/Makefile.sub1 $@
141
142 DEPS_FILES=DEPS DEPS.a4 DEPS.tred
143
144 #
145 # Makefile.sub2: Create everything else.
146 #
147 all doc $(addsuffix .ps,$(DEPS_FILES)) $(addsuffix .svg,$(DEPS_FILES)) TAGS tags: \
148   $(MODULES_FILES) .Modules.deps create-sources globalconfig.h
149         $(MAKE) srcdir=$(srcdir) objbase=$(objbase) -f $(srcdir)/Makefile.sub2 $@
150
151 %.o %_t: $(MODULES_FILES) .Modules.deps create-sources globalconfig.h
152         $(MAKE) srcdir=$(srcdir) objbase=$(objbase) -f $(srcdir)/Makefile.sub2 $@
153
154
155 # Divert any target we do not explicitly mention in this Makefile to
156 # Makefile.sub2.  (Unfortunately 1, this does not work for file
157 # targets that already exist in this directory.  Unfortunately 2,
158 # .DEFAULT does not accept prerequisites, so we must "make
159 # create-sources" manually.)
160 .DEFAULT: 
161         $(MAKE) create-sources
162         $(MAKE) srcdir=$(srcdir) objbase=$(objbase) -f $(srcdir)/Makefile.sub2 $@
163
164 # Well, we need to provide some empty rules for some targets to
165 # prevent the above catch-all from running amok.
166 Makerules.local $(srcdir)/Makeconf.local $(objbase)/Makeconf.local \
167    $(objbase)/.Host-config: ;
168
169 %: %.o                          # delete implicit rule
170
171 endif # ! no ABI
172 endif # ! no XARCH
173 endif # ! config xconfig menuconfig oldconfig
174
175 auto:
176         test -e auto || mkdir auto
177
178 source:
179         test -e source || ln -sf $(srcdir) source
180
181
182 BSP_DIR            := $(srcdir)/kern/arm/bsp $(srcdir)/kern/ppc32/bsp $(srcdir)/kern/sparc/bsp
183 KCONFIG_FILE       := Kconfig
184 KCONFIG_SRC_FILE   := $(srcdir)/Kconfig
185 KCONFIG_BSP_FILES  := $(shell find $(BSP_DIR) -name Kconfig -follow -print)
186
187 kconfig_call = $(MAKE) -C $(tooldir)/kconfig O=$(objbase) \
188                Kconfig=$(KCONFIG_FILE) \
189                KCONFIG_AUTOHEADER=globalconfig.h \
190                KCONFIG_TRISTATE=config/tristate.conf \
191                KCONFIG_CONFIG=globalconfig.out \
192                KCONFIG_AUTOCONFIG=config/auto.conf \
193                KERNELVERSION=SVN MENUCONFIG_COLOR=blackbg \
194                INCLUDE_PPC32=$(INCLUDE_PPC32) \
195                INCLUDE_SPARC=$(INCLUDE_SPARC) \
196                fiasco_srcdir=$(srcdir)/..
197
198 $(KCONFIG_FILE): $(KCONFIG_SRC_FILE) $(KCONFIG_BSP_FILES) $(srcdir)/Makefile
199         @$(tooldir)/gen_kconfig $(KCONFIG_SRC_FILE) $(KCONFIG_FILE) $(KCONFIG_BSP_FILES)
200
201 globalconfig.out: $(KCONFIG_FILE)
202         +$(kconfig_call) oldconfig
203
204 globalconfig.h: globalconfig.out
205         +$(kconfig_call) silentoldconfig
206
207 config: $(KCONFIG_FILE)
208         +$(kconfig_call) menuconfig silentoldconfig
209
210 textconfig: $(KCONFIG_FILE)
211         +$(kconfig_call) config silentoldconfig
212
213 menuconfig oldconfig xconfig gconfig nconfig randconfig allyesconfig allnoconfig: $(KCONFIG_FILE)
214         +$(kconfig_call) $@ silentoldconfig
215
216 ifneq ($(filter clean cleanall mrproper,$(MAKECMDGOALS)),)
217
218 # Try to suck in clean targets from subsystems' Makefile fragments
219 ifdef _modules_read_
220 MAKERULES_SUBSYS = $(foreach subsys, $(SUBSYSTEMS), $(firstword $(wildcard $(addsuffix /Makerules.$(subsys),$(addprefix $(srcdir)/,$(VPATH)) $(srcdir)))))
221 -include $(MAKERULES_SUBSYS)
222 endif
223
224 .DEFAULT:
225
226 .PHONY: clean cleanall mrproper \
227         $(foreach subsys, $(SUBSYSTEMS), clean-$(subsys)) \
228         $(foreach subsys, $(SUBSYSTEMS), cleanall-$(subsys))
229
230 clean: $(foreach subsys, $(SUBSYSTEMS), clean-$(subsys))
231         $(RM) $(ALL)
232         $(RM) *.o fiasco
233         $(RM) auto/*.cc auto/*.h auto/*.S auto/stamp-*.ready
234         $(RM) .Clean-auto .Compiler-config
235
236 cleanall: clean $(foreach subsys, $(SUBSYSTEMS), cleanall-$(subsys))
237         $(foreach subdir, $(SUBDIRS), $(RM) $(subdir)/*.d $(subdir)/.*.d)
238         $(RM) *.d .*.d .*.d.new *.d.new *~
239         $(RM) globalconfig.h globalconfig.h.old Circular
240         $(RM) .Modules.deps source
241
242 mrproper: cleanall
243         $(RM_R) globalconfig.out Modules.* DEPS*
244         $(RM_R) auto docs config scripts
245
246 endif # clean, cleanall, mrproper
247
248 update:
249         cd $(srcdir)/.. && svn update
250         cd $(dir $(PREPROCESS))/.. && svn update
251
252 endif # srcdir != NOT_SET
253
254 endif # MAKECMDGOALS != help
255