]> rtime.felk.cvut.cz Git - l4.git/blob - l4/mk/Makeconf
update
[l4.git] / l4 / mk / Makeconf
1 # -*- Makefile -*-
2 # vim:set ft=make:
3 #
4 # DROPS (Dresden Realtime OPerating System) Component
5 #
6 # Make configuration file
7 #
8 # This file is included by all Makefile-templates. This file defines macros
9 # for div commands, sets general DROPS-Makefile variables, ensures the
10 # dependencies from the various Makeconf.locals, defines the messages for
11 # div actions, and permits the dependency-creation on clean-rules.
12 #
13 # The macros BUILD_MULTIPLE_ARCHITECTURES and BUILD_ONE_ARCHITECTURE are
14 # defined here.
15 #
16 # BUILD_MULTIPLE_ARCHITECTURES is set if ARCHS is set to multiple
17 # architectures in the Makefile. If ARCHS is not set, the default value
18 # l4_i386 will be assumed, not defining BUILD_MULTIPLE_ARCHITECTURES.
19 # In the muli-arch case, binary.inc triggers build the files into subdirs,
20 # dir-name is the architecture. Then, make is called recursively with ARCH
21 # set to one architecture.
22 #
23 # BUILD_ONE_ARCHITECTURE is set if ARCH contains one architecture, and we
24 # actually build files (in subdirs for multi-arch case, in the same dir in
25 # the single-arch case).
26
27 ifeq ($(origin _L4DIR_MK_MAKECONF),undefined)
28 _L4DIR_MK_MAKECONF=y
29
30 MAKEFLAGS        += -R
31
32 # the default target is all
33 all::
34
35 # make .general.d dependent on the role-file
36 $(if $(ROLE),$(OBJ_DIR)/.general.d: $(L4DIR)/mk/$(ROLE))
37
38 SYSTEM_TARGET_arm     = arm-linux-
39 SYSTEM_TARGET_ppc32   = powerpc-linux-
40 SYSTEM_TARGET_sparc   = sparc-elf-
41 SYSTEM_TARGET         = $(SYSTEM_TARGET_$(ARCH))
42
43 CARCHFLAGS_amd64    = -mno-red-zone
44 ASFLAGS_amd64       = -m64
45 LDFLAGS_amd64      += -m elf_x86_64 -z max-page-size=0x1000 -z common-page-size=0x1000
46
47 LD_EMULATION_CHOICE_amd64   = elf_x86_64
48 LD_EMULATION_CHOICE_arm     = armelf armelf_linux_eabi
49 LD_EMULATION_CHOICE_ppc32   = elf32ppc
50 LD_EMULATION_CHOICE_x86     = elf_i386
51 LD_EMULATION_CHOICE_sparc   = sparcleon
52
53 OFORMAT_amd64     = elf64-x86-64
54 OFORMAT_arm       = elf32-littlearm
55 OFORMAT_ppc32     = elf32-powerpc
56 OFORMAT_x86       = elf32-i386
57 OFORMAT_sparc     = elf32-sparc
58 OFORMAT           = $(OFORMAT_$(ARCH))
59
60 BFD_ARCH_amd64    = i386
61 BFD_ARCH_arm      = arm
62 BFD_ARCH_ppc32    = powerpc
63 BFD_ARCH_x86      = i386
64 BFD_ARCH_sparc    = sparc
65 BFD_ARCH          = $(BFD_ARCH_$(ARCH))
66
67 L4_KIP_ADDR_amd64   ?= 0x6ffff000
68 L4_KIP_ADDR_arm     ?= 0xaffff000
69 L4_KIP_ADDR_ppc32   ?= 0xaffff000
70 L4_KIP_ADDR_x86     ?= 0xaffff000
71 L4_KIP_ADDR_sparc   ?= 0xaffff000
72 L4_KIP_ADDR         ?= $(L4_KIP_ADDR_$(ARCH))
73
74 L4_KIP_OFFS_SYS_INVOKE   = 0x800
75 L4_KIP_OFFS_SYS_DEBUGGER = 0x900
76
77 L4_STACK_ADDR_amd64     ?= 0x70000000
78 L4_STACK_ADDR_arm       ?= 0xb0000000
79 L4_STACK_ADDR_ppc32     ?= 0xb0000000
80 L4_STACK_ADDR_x86       ?= 0xb0000000
81 L4_STACK_ADDR_sparc     ?= 0xb0000000
82 L4_STACK_ADDR           ?= $(L4_STACK_ADDR_$(ARCH))
83 L4_STACK_SIZE           ?= $(if $(L4_STACK_SIZE_MAIN_THREAD),$(L4_STACK_SIZE_MAIN_THREAD),0x8000)
84
85 # This is quite bad: There is no other chance to disable the page-alignedment
86 # of the linker. The linker aligns the first section at 0x100000 for AMD64!
87 # We don't want this. Be careful for interactions with objcopy -S!
88 #LDNMAGIC           ?= -n
89 #LDFLAGS_amd64      += $(LDNMAGIC)
90
91 VERBOSE          = $(if $(CONFIG_VERBOSE),,@)
92 DEPEND_VERBOSE   = $(if $(CONFIG_DEPEND_VERBOSE),,@)
93 DROPS_STDDIR     = $(patsubst "%",%,$(CONFIG_DROPS_STDDIR))
94 DROPS_INSTDIR    = $(patsubst "%",%,$(CONFIG_DROPS_INSTDIR))
95 RAM_SIZE_MB      = $(CONFIG_RAM_SIZE_MB)
96 RAM_BASE         = $(CONFIG_RAM_BASE)
97 ARM_PLATFORM_TYPE= $(patsubst "%",%,$(CONFIG_ARM_PLATFORM_TYPE))
98 PPC_PLATFORM_TYPE= $(patsubst "%",%,$(CONFIG_PPC_PLATFORM_TYPE))
99 SPARC_PLATFORM_TYPE= $(patsubst "%",%,$(CONFIG_SPARC_PLATFORM_TYPE))
100 CPU              = $(patsubst "%",%,$(CONFIG_CPU))
101 BUILD_ABI        = $(patsubst "%",%,$(CONFIG_BUILD_ABI))
102 BUILD_ARCH       = $(patsubst "%",%,$(CONFIG_BUILD_ARCH))
103 LABEL            = $(patsubst "%",%,$(CONFIG_LABEL))
104
105 CARCHFLAGS_x86_586        = -march=i586
106 CARCHFLAGS_x86_pentium    = -march=i586
107 CARCHFLAGS_x86_pentiummmx = -march=pentium-mmx
108 CARCHFLAGS_x86_pentiumpro = -march=pentiumpro
109 CARCHFLAGS_x86_686        = -march=i686
110 CARCHFLAGS_x86_pentium2   = -march=pentium2
111 CARCHFLAGS_x86_pentium3   = -march=pentium3
112 CARCHFLAGS_x86_pentiumm   = -march=pentium-m
113 CARCHFLAGS_x86_pentium4   = -march=pentium4
114 CARCHFLAGS_x86_prescott   = -march=prescott
115 CARCHFLAGS_x86_nocona     = -march=nocona
116 CARCHFLAGS_x86_core2      = -march=core2
117 CARCHFLAGS_x86_K6         = -march=k6
118 CARCHFLAGS_x86_K7         = -march=athlon
119 CARCHFLAGS_x86_athlon4    = -march=athlon-4
120 CARCHFLAGS_x86_K8         = -march=k8
121 CARCHFLAGS_x86_opteron    = -march=opteron
122
123 CARCHFLAGS_arm_armv4      = -march=armv4
124 CARCHFLAGS_arm_armv4t     = -march=armv4t
125 CARCHFLAGS_arm_armv5      = -march=armv5
126 CARCHFLAGS_arm_armv5t     = -march=armv5t
127 CARCHFLAGS_arm_armv5te    = -march=armv5te
128 CARCHFLAGS_arm_armv6      = -march=armv6
129 CARCHFLAGS_arm_armv6t2    = -march=armv6t2
130 CARCHFLAGS_arm_armv6zk    = -march=armv6zk
131 CARCHFLAGS_arm_armv7a     = -march=armv7-a
132 CARCHFLAGS_arm_armv7r     = -march=armv7-r
133
134 IDL_SYSTEMS     = x86-l4f
135
136 CC_x86          = $(SYSTEM_TARGET)gcc -m32
137 CC_amd64        = $(SYSTEM_TARGET)gcc -m64
138 CC_arm          = $(SYSTEM_TARGET)gcc
139 CC_ppc32        = $(SYSTEM_TARGET)gcc -m32
140 CC_sparc        = $(SYSTEM_TARGET)gcc -m32
141 CXX_x86         = $(SYSTEM_TARGET)g++ -m32
142 CXX_amd64       = $(SYSTEM_TARGET)g++ -m64
143 CXX_arm         = $(SYSTEM_TARGET)g++
144 CXX_ppc32       = $(SYSTEM_TARGET)g++ -m32
145 CXX_sparc       = $(SYSTEM_TARGET)g++ -m32
146
147 SYSTEMS_ABI    := x86-l4f amd64-l4f arm-l4f ppc32-l4f sparc-l4f
148 SYSTEMS_PLAIN  := x86     amd64     arm     ppc32     sparc
149
150 AR              = $(SYSTEM_TARGET)ar
151 AS              = $(SYSTEM_TARGET)as
152 AWKP            = gawk --posix
153 CC              = $(if $(USE_CCACHE),ccache) $(CC_$(BUILD_ARCH))
154 CXX             = $(if $(USE_CCACHE),ccache) $(CXX_$(BUILD_ARCH))
155 CP              = cp
156 DICE_SRCDIR     ?= $(L4DIR)/../dice
157 DICE_OBJDIR     ?= $(DICE_SRCDIR)
158 DICE            = $(firstword $(wildcard $(DICE_OBJDIR)/src/dice \
159                                 $(DROPS_STDDIR)/tool/bin/dice \
160                                  $(shell which dice 2>/dev/null) ) \
161                                  did_not_find_dice___please_install_dice )
162 DICE_CPP_NAME   = cpp0
163
164 DICE_INCDIR     ?= $(DICE_SRCDIR)/include
165
166 DOXYGEN         ?= doxygen
167 ECHO            = echo
168 ELF_PATCHER     = $(OBJ_BASE)/tool/elf-patcher/elf-patcher
169
170 GENOFFSETS      = $(L4DIR)/tool/bin/genoffsets.pl
171 GOSH            = $(firstword $(wildcard $(L4DIR)/../tools/gosh/gosh \
172                                 $(DROPS_STDDIR)/tool/bin/gosh \
173                                  $(shell which gosh 2>/dev/null) ) \
174                                  did_not_find_gosh___please_install_gosh )
175 HOST_CC         = gcc
176 HOST_CXX        = g++
177 INDENT          = indent -sob
178 INSTALL         = install
179 LD              = $(SYSTEM_TARGET)ld
180 LATEX           = latex
181 PDFLATEX        = pdflatex
182 GREP            = GREP_OPTIONS= grep
183 LN              = ln
184 MKDIR           = mkdir -p
185 MKFLAGS         +=$(MKFLAGS_$@)
186 NM              = $(SYSTEM_TARGET)nm
187 OBJCOPY         = $(SYSTEM_TARGET)objcopy
188 PKG_CONFIG      = pkg-config
189 PWDCMD          = sh -c pwd
190 RANLIB          = $(SYSTEM_TARGET)ranlib
191 RM              = rm -f
192 SCRUB           = $(RM) $(wildcard *.old) $(wildcard *~) $(wildcard *.bak) \
193                         $(wildcard \#*\#)
194 SED             = sed
195 SHELL           = bash
196 SIZE            = $(SYSTEM_TARGET)size
197 STRIP           = $(SYSTEM_TARGET)strip
198 SVN             = svn
199 TR              = tr
200 GEN_DOPECODE    = $(L4DIR)/tool/gen_dopecode/gen_dopecode
201 ABS2REL         = $(L4DIR)/tool/bin/abs2rel.sh
202 # it's optional to be able to set it as environment variable
203 FIASCOUX        ?= $(L4DIR)/../kernel/fiasco/build-ux/fiasco
204 PAGER           ?= less
205 DISASM_CMD      ?= $(SYSTEM_TARGET)objdump -lCSd $(1) | $(PAGER)
206 IMAGES_DIR      ?= $(OBJ_BASE)/images
207
208
209 # functions that are handy
210 absfilename_target_dir_needs_to_exist = $(foreach w,$(1),$(addsuffix /$(notdir $(w)),$(shell cd $(dir $(w)) 2>/dev/null&&$(PWDCMD))))
211 absfilename     = $(shell $(L4DIR)/mk/rel2abs.sh $(1))
212 findfile        = $(firstword $(wildcard $(addsuffix /$(1),$(2))) $(1)_NOT_FOUND)
213 is_dir          = $(shell test -d '$(1)' && echo yes)
214
215 # include this one early to be able to set OBJ_BASE
216 -include $(L4DIR)/Makeconf.local
217
218 ifeq ($(filter $(IGNORE_OBJDIR_TARGETS),$(MAKECMDGOALS)),)
219 # output directory
220  ifeq ($(O)$(OBJ_BASE),)
221   $(error need to give builddir with O=.../builddir)
222  else
223   ifneq ($(O),)
224    ifeq ($(filter-out undefined environment,$(origin OBJ_BASE)),)
225     OBJ_BASE := $(call absfilename, $(O))
226     export OBJ_BASE
227     # prevent passing O to sub-makes, because it may be a relative path
228     # not valid there
229     override O =
230     MAKEOVERRIDES := $(filter-out O=%,$(MAKEOVERRIDES))
231    endif
232   endif
233  endif
234 endif
235
236 ifeq ($(origin L4DIR_ABS),undefined)
237 L4DIR_ABS      := $(call absfilename,$(L4DIR))
238 endif
239 ifeq ($(origin PKGDIR_ABS),undefined)
240 PKGDIR_ABS     := $(call absfilename,$(PKGDIR))
241 endif
242 ifeq ($(origin SRC_DIR),undefined)
243 SRC_DIR        := $(shell pwd)
244 endif
245 ifeq ($(origin SRC_BASE_ABS),undefined)
246 SRC_BASE     ?= $(L4DIR)
247 SRC_BASE_ABS := $(call absfilename,$(SRC_BASE))
248 export SRC_BASE_ABS
249 endif
250 ifeq ($(origin OBJ_DIR),undefined)
251 OBJ_DIR        := $(subst $(SRC_BASE_ABS),$(OBJ_BASE),$(SRC_DIR))
252 endif
253 ifeq ($(origin PKGDIR_OBJ),undefined)
254 PKGDIR_OBJ     := $(call absfilename,$(OBJ_DIR)/$(PKGDIR))
255 endif
256
257 # if PKGDIR is not in L4DIR, we have an external package, so make up some
258 # build-dir for it
259 ifneq ($(patsubst $(L4DIR_ABS)/%,,$(PKGDIR_ABS)),)
260 ifneq ($(filter-out $(OBJ_BASE)/ext-pkg%,$(PKGDIR_OBJ)),)
261 PKGDIR_OBJ     := $(OBJ_BASE)/ext-pkg$(PKGDIR_OBJ)
262 OBJ_DIR        := $(OBJ_BASE)/ext-pkg$(OBJ_DIR)
263 endif
264 endif
265
266 # sanity check the object dir
267 ifneq ($(SRC_BASE_ABS),$(OBJ_BASE))
268 ifeq ($(SRC_DIR),$(OBJ_DIR))
269 $(warning Sorry, your object or source path became garbled.)
270 $(warning OBJ_BASE: $(OBJ_BASE))
271 $(warning SRC_BASE_ABS: $(SRC_BASE_ABS))
272 $(warning SRC_DIR: $(SRC_DIR))
273 $(warning OBJ_DIR: $(OBJ_DIR))
274 $(warning PKGDIR: $(PKGDIR))
275 $(warning L4DIR_ABS: $(L4DIR_ABS))
276 $(warning PKGDIR_ABS: $(PKGDIR_ABS))
277 $(warning PKGDIR_OBJ: $(PKGDIR_OBJ))
278 $(error Please investigate.)
279 endif
280 endif
281
282
283 OBJ_DIR_EXPORT = $(OBJ_DIR)
284 export OBJ_DIR_EXPORT
285
286 VPATH_SRC_BASE ?= $(SRC_DIR)
287
288 # Makeconf.local handling
289 # dont use -include here, as we have special build conditions in $(L4DIR)/
290 ifeq ($(origin BID_ROOT_CONF),undefined)
291 BID_ROOT_CONF := $(call absfilename, $(OBJ_BASE))/.config.all
292 endif
293 ifeq ($(filter $(IGNORE_OBJDIR_TARGETS),$(MAKECMDGOALS)),)
294 ifeq ($(wildcard $(BID_ROOT_CONF)),)
295 ifeq ($(BID_IGN_ROOT_CONF),)
296 $(error No configuration file found in build directory "$(OBJ_BASE)". Please run "make O=/path/to/objdir config" in "$(L4DIR_ABS)" or specify a valid build directory)
297 endif
298 else
299 include $(BID_ROOT_CONF)
300 endif
301 endif
302
303 # if we're working on a program that wants the RAM_BASE be considered in its
304 # linking address, source a possible privately configured one
305 ifneq ($(RELOC_PHYS),)
306 -include $(OBJ_BASE)/Makeconf.ram_base
307 BID_RAM_BASE_DEP := $(if $(wildcard $(OBJ_BASE)/Makeconf.ram_base),$(OBJ_BASE)/Makeconf.ram_base)
308 endif
309
310 INCLUDE_MAKE_RULES += $(if $(LABEL),$(L4DIR)/Makeconf.$(LABEL))
311
312 ifneq ($(strip $(wildcard $(INCLUDE_MAKE_RULES))),)
313 -include $(wildcard $(INCLUDE_MAKE_RULES))
314 endif
315
316 -include $(OBJ_BASE)/Makeconf.local
317 ifneq ($(PKGDIR_ABS),)
318 -include $(PKGDIR_ABS)/Makeconf.local
319 endif
320 # if it is not already set, we use this in the local dir
321 MAKECONFLOCAL ?= Makeconf.local
322 -include $(MAKECONFLOCAL)
323
324 DROPS_STDDIR    ?= /home/drops
325 ifeq ($(STATICFILE),)
326 STATICFILE      = $(OBJ_BASE)/pkg/STATIC $(L4DIR)/pkg/STATIC
327 endif
328
329 # a nasty workaround for make-3.79/make-3.80. The former needs an additional
330 # $$ for $-quotation when calling a function.
331 BID_IDENT       = $(1)
332 ifeq ($(call BID_IDENT,$$),)
333 BID_DOLLARQUOTE = $$
334 endif
335 BID_COMMA       = ,
336
337 ifneq ($(PL),)
338 PL_j := -j $(PL)
339 export PL
340 endif
341
342 include $(L4DIR)/mk/config.inc
343
344 ifneq ($(CONFIG_HAVE_LDSO),)
345 # MAKEDEP-call:
346 # arg1 - compiler binary name
347 # arg2 - [opt] compiler target. Will be written as target within the
348 #              dependency file
349 # arg3 - [opt] name of the dependency file. If unset, .<arg2>.d will be used.
350 # arg4 - [opt] alternative binary name
351 ifeq ($(origin BID_LIBGENDEP_PATHS), undefined)
352  ifeq ($(HOST_SYSTEM),linux)
353    BID_LIBGENDEP_PATHS := \
354       $(firstword $(wildcard $(call absfilename, $(OBJ_BASE)/tool/gendep/64 \
355         $(DROPS_STDDIR)/tool/lib/64))):$(firstword $(wildcard $(call absfilename, \
356         $(OBJ_BASE)/tool/gendep/32 $(DROPS_STDDIR)/tool/lib/32 )))
357  endif
358
359  ifeq ($(HOST_SYSTEM),darwin)
360    BID_LIBGENDEP_PATHS := \
361      $(firstword $(wildcard $(call absfilename, $(OBJ_BASE)/tool/gendep \
362                                                 $(DROPS_STDDIR)/tool/lib)))
363  endif
364 endif
365
366 ifeq ($(HOST_SYSTEM),linux)
367   LD_GENDEP_PREFIX = LD_PRELOAD=libgendep.so LD_LIBRARY_PATH=$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):)$(BID_LIBGENDEP_PATHS)
368 endif
369 ifeq ($(HOST_SYSTEM),darwin)
370   LD_GENDEP_PREFIX = DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=$(BID_LIBGENDEP_PATHS)/libgendep.so
371 endif
372 MAKEDEP=$(LD_GENDEP_PREFIX) \
373                 GENDEP_TARGET=$(if $(2),$(2),$@) \
374                 GENDEP_BINARY=$(1) $(if $(3),GENDEP_DEPFILE=$(3)) \
375                 $(if $(4),GENDEP_BINARY_ALT1=$(4))
376 endif
377
378 # macros used here and in packages
379 checkcc   = $(shell if $(CC) $(1) -o /dev/null -c -x c \
380                     /dev/null > /dev/null 2>&1; then echo "$(1)"; fi)
381 checkcxx  = $(shell if $(CXX) $(1) -o /dev/null -c -x c++ \
382                     /dev/null > /dev/null 2>&1; then echo "$(1)"; fi)
383
384 # the gcc specific variables: version, base dir, include dir, gcc lib
385 # note: determining these variables is slow, and the values should
386 #       be set in .config.all. However, this is the place were
387 #       they are determined on a 'make config' in $(L4DIR)
388 GCCVERSION_f    = $(shell $(CC) -dumpversion | sed -e 's/\(.*\)\..*/\1/')
389 GCCMAJORVERSION_f=$(shell $(CC) -dumpversion | sed -e 's/\([^.]*\).*/\1/')
390 GCCMINORVERSION_f=$(shell $(CC) -dumpversion | sed -e 's/[^.]*\.\([^.]*\).*/\1/')
391 GCCSUBVERSION_f = $(shell $(CC) -dumpversion | sed -e 's/.*\.\(.*\)/\1/')
392 LDVERSION_f     = $(shell $(LD) -v | sed -e 's/.* \([0-9]\)\.\([^. ]*\).*/\1\2/')
393 GCCSYSLIBDIRS_f = $(shell LC_ALL=C $(CC) -print-search-dirs | sed '/^libraries:/{s/^libraries: /-L/;s/:/ -L/g;q;};d')
394 GCCDIR_f        = $(shell LC_ALL=C $(CC) -print-search-dirs|sed -ne 's+^install: \(.*[^/][^/]*\)/+\1+p' )
395 GCCLIBDIR_f     = $(shell LC_ALL=C $(CC) -print-file-name=)
396 GCCLIB_f        = $(shell $(CC) -print-libgcc-file-name)
397 GCCLIB_EH_f     = $(filter /%,$(shell $(CC) -print-file-name=libgcc_eh.a))
398 GCCINCDIR_f     = $(addprefix $(call GCCDIR_f),/include /include-fixed)
399 GCCNOSTACKPROTOPT_f= $(call checkcc,-fno-stack-protector)
400
401 GCCINCDIR       = $(GCCDIR)/include $(GCCDIR)/include-fixed
402 I_GCCINCDIR     = $(addprefix -I,$(GCCINCDIR))
403
404 ifneq ($(PKGDIR),)
405   ifeq ($(origin PKGNAME),undefined)
406     PKGNAME := $(notdir $(shell cd $(PKGDIR);pwd))
407   endif
408 endif
409
410 ifeq ($(V),1)
411   VERBOSE =
412 endif
413 ifeq ($(V),0)
414   VERBOSE = @
415 endif
416
417 ifeq ($(D),1)
418   DEBUG_MODE = y
419 endif
420
421 ifeq ($(CONFIG_RELEASE_MODE),y)
422 DEFINES         += -DL4BID_RELEASE_MODE
423 endif
424
425 ifeq ($(ARCH),arm)
426 ifeq ($(RAM_BASE),)
427 $(error RAM_BASE not given, needed for ARM architecture builds.)
428 endif
429 else #arch != arm
430   RAM_BASE      = 0x0
431 endif
432
433 ifneq ($(filter linux l4linux host,$(MODE)),)
434 HOST_LINK      := 1
435 endif
436
437 #
438 # SUBDIR handling, not within the OBJ-*/ dirs
439 #
440 ifeq ($(SYSTEM),)
441 ifneq ($(SUBDIRS),)
442 .PHONY: $(SUBDIRS)
443 $(SUBDIRS):
444         $(VERBOSE)PWD=$(PWD)/$@ $(MAKE) -C $@ all
445
446 # we know that SUBDIRS isn't empty, hence we can avoid the dir-test
447 scrub clean cleanall::
448         $(VERBOSE)set -e; $(foreach i,$(SUBDIRS), \
449                 PWD=$(PWD)/$(i) $(MAKE) -C $(i) $@ $(MKFLAGS) $(MKFLAGS_$(i));)
450
451 install:: $(SUBDIRS)
452         $(VERBOSE)set -e; $(foreach i,$(SUBDIRS), \
453                 PWD=$(PWD)/$(i) $(MAKE) -C $(i) $@ $(MKFLAGS) $(MKFLAGS_$(i));)
454
455 endif
456
457 all:: $(OBJ_DIR)/Makefile
458
459 $(OBJ_DIR)/Makefile: $(L4DIR)/mk/Makeconf
460         $(VERBOSE)install -d $(dir $@)
461         $(VERBOSE)echo '# automatically created -- modifications will be lost' > $@
462         $(VERBOSE)echo 'SRC := $(SRC_DIR)'                                    >> $@
463         $(VERBOSE)echo 'OBJ := $(OBJ_BASE)'                                   >> $@
464         $(VERBOSE)echo '.PHONY: x $$(MAKECMDGOALS)'                           >> $@
465         $(VERBOSE)echo 'x:'                                                   >> $@
466         $(VERBOSE)echo '        @PWD=$$(SRC) $$(MAKE) -C $$(SRC) O=$$(OBJ)'    >> $@
467         $(VERBOSE)echo '$$(MAKECMDGOALS):'                                    >> $@
468         $(VERBOSE)echo '        @PWD=$$(SRC) $$(MAKE) -C $$(SRC) O=$$(OBJ) $$@'>> $@
469
470 else
471 # we are within an OBJ-*/ dir, create dummy target
472 $(SUBDIRS):
473 endif
474
475 #
476 # Dependency section
477 #
478 #
479
480 # the general dependencies: All generated files depend on ".general.d".
481 # ".general.d" itself depends on the mk-Makeconf, the optional
482 # Makeconf.local, the .config.all, the packet-Makeconf.local and the
483 # Makeconf.local. This ensures a rebuilt if any of the configuration-
484 # or make-files changes.
485 #
486 # We have this nasty if-readable-magic to allow the files to disappear
487 # or to appear. Depending on if the according makeconf exists now, the
488 # if-readable magic .general.d is used on existance or non-existence.
489
490 BID_DEPEND_GENERAL_D_COND = \
491         if [ -r $(1) ] ; then echo -e '$@: $(1)\n$(1):\n' >>$@ ; \
492           else echo '$$(if $$(wildcard $(1)), $@: FORCE)' >>$@; fi
493
494 ifeq ($(SYSTEM),)
495 GENERAL_D_LOC := $(OBJ_DIR)/.general.d
496 else
497 GENERAL_D_LOC := .general.d
498 endif
499
500 $(GENERAL_D_LOC): $(L4DIR)/mk/Makeconf $(EXTRA_GENERAL_D_DEP)
501         @$(BUILD_MESSAGE)
502         @install -d $(dir $@)
503         $(DEPEND_VERBOSE)echo '$@: $(SRC_DIR)/Makefile ' > $@
504         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
505                 $(OBJ_BASE)/.config.all)
506         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
507                 $(OBJ_BASE)/Makeconf.local)
508         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
509                 $(L4DIR)/Makeconf.local)
510         $(DEPEND_VERBOSE)$(foreach m,$(wildcard $(INCLUDE_MAKE_RULES)),\
511                 $(call BID_DEPEND_GENERAL_D_COND,$(m)); )
512         $(if $(PKGDIR_ABS),$(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
513                 $(PKGDIR_ABS)/Makeconf.local))
514         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
515                 $(MAKECONFLOCAL))
516
517 DEPS    += $(GENERAL_D_LOC)
518
519
520 #
521 # Messages
522 #
523
524 # coloring on color-capable terminals
525 # enabled by setting CONFIG_BID_COLORED_PHASES to y
526 ifeq ($(CONFIG_BID_COLORED_PHASES),y)
527 ifeq ($(COLOR_TERMINAL),y)
528   EMPHSTART = '\033[34;1m'
529   EMPHSTOP  = '\033[0m'
530 else
531   EMPHSTART =
532   EMPHSTOP  =
533 endif
534 endif
535
536 AR_MESSAGE                 ?= echo -e "  ==> Archiving into $@"
537 BUILD_MESSAGE              ?= echo -e "  ... Building $@"
538 BUILT_MESSAGE              ?= echo -e $(EMPHSTART)'  ==> "$@" built'$(EMPHSTOP)
539 COMP_MESSAGE               ?= echo -e "  ... Compiling $@"
540 COMP_P_MESSAGE             ?= echo -e "  ... Compiling PIC $@"
541 COMP_PR_MESSAGE            ?= echo -e "  ... Compiling PROFILE $@"
542 GEN_MESSAGE                ?= echo -e "  ... Generating $@"
543 LINK_MESSAGE               ?= echo -e "  ==> Linking $@"
544 LINK_SHARED_MESSAGE        ?= echo -e "  ==> Linking to shared $@"
545 LINK_PARTIAL_MESSAGE       ?= echo -e "  ==> Partial linking to $@"
546 DEP_MESSAGE                ?= echo -e "  ... Building dependencies for $<"
547 CLEAN_MESSAGE              ?= echo -e "  ... Removing created files"
548 CLEANALL_MESSAGE           ?= echo -e "  ... Removing all created files"
549 INSTALL_LINK_MESSAGE       ?= echo -e "  ==> Updating symlinks"
550 INSTALL_DOC_MESSAGE        ?= echo -e "  ==> Installing $(<) documentation"
551 INSTALL_DOC_LOCAL_MESSAGE  ?= echo -e "  ==> Installing $(<) documentation locally"
552 INSTALL_MESSAGE            ?= echo -e "  ==> Installing $^"
553 INSTALL_LOCAL_MESSAGE      ?= echo -e "  ==> Installing $(<) to local build-tree"
554 UPDATE_HTML_MESSAGE        ?= echo -e "  ! You should remake your doc directory in $(1)"
555
556 # allows an include $(DEPSVAR) at the end of the makefile
557 # but prevents rebuilding them on a scrub, clean, cleanall and help
558 ifneq ($(filter scrub clean cleanall help,$(MAKECMDGOALS)),)
559 DEPSVAR =
560 else
561 DEPSVAR = $(DEPS)
562 endif
563
564 #
565 # Some rules
566 #
567
568 # addfileheader-rule: allows "make addfileheader main.c server.c"-like
569 # commands and automatically inserts the path within the package
570 # options may be passed with $(ADDFILEHEADER_OPTIONS)
571 ADDFILEHEADER_PREFIX = $(patsubst $(call absfilename,$(PKGDIR)/)%,\
572                                   $(PKGNAME)/%,$(call absfilename,./))
573 ADDFILEHEADER_FILES = $(filter-out addfileheader,$(MAKECMDGOALS))
574 addfileheader:
575         addfileheader $(ADDFILEHEADER_OPTIONS) -p $(ADDFILEHEADER_PREFIX) $(ADDFILEHEADER_FILES)
576         
577
578 .PHONY: FORCE
579
580 #
581 # Common functions
582 #
583
584 # 1: name
585 # 2: output file
586 # 3: inc path (one only)
587 # 4: libs
588 # 5: requires_libs
589 generate_pcfile =                                                            \
590         mkdir -p $(dir $(2))                                                 \
591         ;echo -n                                                    > $(2)   \
592         $(if $(3),;echo "incdir=/empty_incdir"                     >> $(2))  \
593         ;echo "Name: $(1)"                                         >> $(2)   \
594         ;echo "Version: 0"                                         >> $(2)   \
595         ;echo "Description: L4 library"                            >> $(2)   \
596         $(if $(3),;echo "Cflags: $(addprefix -I\$${incdir}/,$(3))" >> $(2))  \
597         $(if $(4),;echo "Libs: $(sort $(4))"                       >> $(2))  \
598         $(if $(5),;echo "Requires: $(5)"                           >> $(2))  \
599         $(if $(BID_GEN_CONTROL),;echo "Provides: $(1)"             >> $(PKGDIR)/Control) \
600         $(if $(BID_GEN_CONTROL),;echo "Requires: $(5)"             >> $(PKGDIR)/Control) ;
601
602
603 endif   # _L4DIR_MK_MAKECONF undefined