]> 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 EXTRA_GENERAL_D_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 BID_INT_NOEXC=n
343 ifeq ($(MODE_NOEXC),y)
344 BID_INT_NOEXC=y
345 endif
346
347 include $(L4DIR)/mk/config.inc
348
349 ifneq ($(CONFIG_HAVE_LDSO),)
350 # MAKEDEP-call:
351 # arg1 - compiler binary name
352 # arg2 - [opt] compiler target. Will be written as target within the
353 #              dependency file
354 # arg3 - [opt] name of the dependency file. If unset, .<arg2>.d will be used.
355 # arg4 - [opt] alternative binary name
356 ifeq ($(origin BID_LIBGENDEP_PATHS), undefined)
357  ifeq ($(HOST_SYSTEM),linux)
358    BID_LIBGENDEP_PATHS := \
359       $(firstword $(wildcard $(call absfilename, $(OBJ_BASE)/tool/gendep/64 \
360         $(DROPS_STDDIR)/tool/lib/64))):$(firstword $(wildcard $(call absfilename, \
361         $(OBJ_BASE)/tool/gendep/32 $(DROPS_STDDIR)/tool/lib/32 )))
362  endif
363
364  ifeq ($(HOST_SYSTEM),darwin)
365    BID_LIBGENDEP_PATHS := \
366      $(firstword $(wildcard $(call absfilename, $(OBJ_BASE)/tool/gendep \
367                                                 $(DROPS_STDDIR)/tool/lib)))
368  endif
369 endif
370
371 ifeq ($(HOST_SYSTEM),linux)
372   LD_GENDEP_PREFIX = LD_PRELOAD=libgendep.so LD_LIBRARY_PATH=$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):)$(BID_LIBGENDEP_PATHS)
373 endif
374 ifeq ($(HOST_SYSTEM),darwin)
375   LD_GENDEP_PREFIX = DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=$(BID_LIBGENDEP_PATHS)/libgendep.so
376 endif
377 MAKEDEP=$(LD_GENDEP_PREFIX) \
378                 GENDEP_TARGET=$(if $(2),$(2),$@) \
379                 GENDEP_BINARY=$(1) $(if $(3),GENDEP_DEPFILE=$(3)) \
380                 $(if $(4),GENDEP_BINARY_ALT1=$(4))
381 endif
382
383 # macros used here and in packages
384 checkcc   = $(shell if $(CC) $(1) -o /dev/null -c -x c \
385                     /dev/null > /dev/null 2>&1; then echo "$(1)"; fi)
386 checkcxx  = $(shell if $(CXX) $(1) -o /dev/null -c -x c++ \
387                     /dev/null > /dev/null 2>&1; then echo "$(1)"; fi)
388
389 # the gcc specific variables: version, base dir, include dir, gcc lib
390 # note: determining these variables is slow, and the values should
391 #       be set in .config.all. However, this is the place were
392 #       they are determined on a 'make config' in $(L4DIR)
393 GCCVERSION_f    = $(shell $(CC) -dumpversion | sed -e 's/\(.*\)\..*/\1/')
394 GCCMAJORVERSION_f=$(shell $(CC) -dumpversion | sed -e 's/\([^.]*\).*/\1/')
395 GCCMINORVERSION_f=$(shell $(CC) -dumpversion | sed -e 's/[^.]*\.\([^.]*\).*/\1/')
396 GCCSUBVERSION_f = $(shell $(CC) -dumpversion | sed -e 's/.*\.\(.*\)/\1/')
397 LDVERSION_f     = $(shell $(LD) -v | sed -e 's/.* \([0-9]\)\.\([^. ]*\).*/\1\2/')
398 GCCSYSLIBDIRS_f = $(shell LC_ALL=C $(CC) -print-search-dirs | sed '/^libraries:/{s/^libraries: /-L/;s/:/ -L/g;q;};d')
399 GCCDIR_f        = $(shell LC_ALL=C $(CC) -print-search-dirs|sed -ne 's+^install: \(.*[^/][^/]*\)/+\1+p' )
400 GCCLIBDIR_f     = $(shell LC_ALL=C $(CC) -print-file-name=)
401 GCCLIB_f        = $(shell $(CC) -print-libgcc-file-name)
402 GCCLIB_EH_f     = $(filter /%,$(shell $(CC) -print-file-name=libgcc_eh.a))
403 GCCINCDIR_f     = $(addprefix $(call GCCDIR_f),/include /include-fixed)
404 GCCNOSTACKPROTOPT_f= $(call checkcc,-fno-stack-protector)
405
406 GCCINCDIR       = $(GCCDIR)/include $(GCCDIR)/include-fixed
407 I_GCCINCDIR     = $(addprefix -I,$(GCCINCDIR))
408
409 ifneq ($(PKGDIR),)
410   ifeq ($(origin PKGNAME),undefined)
411     PKGNAME := $(notdir $(shell cd $(PKGDIR);pwd))
412   endif
413 endif
414
415 ifeq ($(V),1)
416   VERBOSE =
417 endif
418 ifeq ($(V),0)
419   VERBOSE = @
420 endif
421
422 ifeq ($(D),1)
423   DEBUG_MODE = y
424 endif
425
426 ifeq ($(CONFIG_RELEASE_MODE),y)
427 DEFINES         += -DL4BID_RELEASE_MODE
428 endif
429
430 ifeq ($(ARCH),arm)
431 ifeq ($(RAM_BASE),)
432 $(error RAM_BASE not given, needed for ARM architecture builds.)
433 endif
434 else #arch != arm
435   RAM_BASE      = 0x0
436 endif
437
438 ifneq ($(filter linux l4linux host,$(MODE)),)
439 HOST_LINK      := 1
440 endif
441
442 #
443 # SUBDIR handling, not within the OBJ-*/ dirs
444 #
445 ifeq ($(SYSTEM),)
446 ifneq ($(SUBDIRS),)
447 .PHONY: $(SUBDIRS)
448 $(SUBDIRS):
449         $(VERBOSE)PWD=$(PWD)/$@ $(MAKE) -C $@ all
450
451 # we know that SUBDIRS isn't empty, hence we can avoid the dir-test
452 scrub clean cleanall::
453         $(VERBOSE)set -e; $(foreach i,$(SUBDIRS), \
454                 PWD=$(PWD)/$(i) $(MAKE) -C $(i) $@ $(MKFLAGS) $(MKFLAGS_$(i));)
455
456 install:: $(SUBDIRS)
457         $(VERBOSE)set -e; $(foreach i,$(SUBDIRS), \
458                 PWD=$(PWD)/$(i) $(MAKE) -C $(i) $@ $(MKFLAGS) $(MKFLAGS_$(i));)
459
460 endif
461
462 all:: $(OBJ_DIR)/Makefile
463
464 $(OBJ_DIR)/Makefile: $(L4DIR)/mk/Makeconf
465         $(VERBOSE)install -d $(dir $@)
466         $(VERBOSE)echo '# automatically created -- modifications will be lost' > $@
467         $(VERBOSE)echo 'SRC := $(SRC_DIR)'                                    >> $@
468         $(VERBOSE)echo 'OBJ := $(OBJ_BASE)'                                   >> $@
469         $(VERBOSE)echo '.PHONY: x $$(MAKECMDGOALS)'                           >> $@
470         $(VERBOSE)echo 'x:'                                                   >> $@
471         $(VERBOSE)echo '        @PWD=$$(SRC) $$(MAKE) -C $$(SRC) O=$$(OBJ)'    >> $@
472         $(VERBOSE)echo '$$(MAKECMDGOALS):'                                    >> $@
473         $(VERBOSE)echo '        @PWD=$$(SRC) $$(MAKE) -C $$(SRC) O=$$(OBJ) $$@'>> $@
474
475 else
476 # we are within an OBJ-*/ dir, create dummy target
477 $(SUBDIRS):
478 endif
479
480 #
481 # Dependency section
482 #
483 #
484
485 # the general dependencies: All generated files depend on ".general.d".
486 # ".general.d" itself depends on the mk-Makeconf, the optional
487 # Makeconf.local, the .config.all, the packet-Makeconf.local and the
488 # Makeconf.local. This ensures a rebuilt if any of the configuration-
489 # or make-files changes.
490 #
491 # We have this nasty if-readable-magic to allow the files to disappear
492 # or to appear. Depending on if the according makeconf exists now, the
493 # if-readable magic .general.d is used on existance or non-existence.
494
495 BID_DEPEND_GENERAL_D_COND = \
496         if [ -r $(1) ] ; then echo -e '$@: $(1)\n$(1):\n' >>$@ ; \
497           else echo '$$(if $$(wildcard $(1)), $@: FORCE)' >>$@; fi
498
499 ifeq ($(SYSTEM),)
500 GENERAL_D_LOC := $(OBJ_DIR)/.general.d
501 else
502 GENERAL_D_LOC := .general.d
503 endif
504
505 $(GENERAL_D_LOC): $(L4DIR)/mk/Makeconf $(EXTRA_GENERAL_D_DEP)
506         @$(BUILD_MESSAGE)
507         @install -d $(dir $@)
508         $(DEPEND_VERBOSE)echo '$@: $(SRC_DIR)/Makefile ' > $@
509         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
510                 $(OBJ_BASE)/.config.all)
511         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
512                 $(OBJ_BASE)/Makeconf.local)
513         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
514                 $(L4DIR)/Makeconf.local)
515         $(DEPEND_VERBOSE)$(foreach m,$(wildcard $(INCLUDE_MAKE_RULES)),\
516                 $(call BID_DEPEND_GENERAL_D_COND,$(m)); )
517         $(if $(PKGDIR_ABS),$(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
518                 $(PKGDIR_ABS)/Makeconf.local))
519         $(DEPEND_VERBOSE)$(call BID_DEPEND_GENERAL_D_COND,\
520                 $(MAKECONFLOCAL))
521
522 DEPS    += $(GENERAL_D_LOC)
523
524
525 #
526 # Messages
527 #
528
529 # coloring on color-capable terminals
530 # enabled by setting CONFIG_BID_COLORED_PHASES to y
531 ifeq ($(CONFIG_BID_COLORED_PHASES),y)
532 ifeq ($(COLOR_TERMINAL),y)
533   EMPHSTART = '\033[34;1m'
534   EMPHSTOP  = '\033[0m'
535 else
536   EMPHSTART =
537   EMPHSTOP  =
538 endif
539 endif
540
541 AR_MESSAGE                 ?= echo -e "  ==> Archiving into $@"
542 BUILD_MESSAGE              ?= echo -e "  ... Building $@"
543 BUILT_MESSAGE              ?= echo -e $(EMPHSTART)'  ==> "$@" built'$(EMPHSTOP)
544 COMP_MESSAGE               ?= echo -e "  ... Compiling $@"
545 COMP_P_MESSAGE             ?= echo -e "  ... Compiling PIC $@"
546 COMP_PR_MESSAGE            ?= echo -e "  ... Compiling PROFILE $@"
547 GEN_MESSAGE                ?= echo -e "  ... Generating $@"
548 LINK_MESSAGE               ?= echo -e "  ==> Linking $@"
549 LINK_SHARED_MESSAGE        ?= echo -e "  ==> Linking to shared $@"
550 LINK_PARTIAL_MESSAGE       ?= echo -e "  ==> Partial linking to $@"
551 DEP_MESSAGE                ?= echo -e "  ... Building dependencies for $<"
552 CLEAN_MESSAGE              ?= echo -e "  ... Removing created files"
553 CLEANALL_MESSAGE           ?= echo -e "  ... Removing all created files"
554 INSTALL_LINK_MESSAGE       ?= echo -e "  ==> Updating symlinks"
555 INSTALL_DOC_MESSAGE        ?= echo -e "  ==> Installing $(<) documentation"
556 INSTALL_DOC_LOCAL_MESSAGE  ?= echo -e "  ==> Installing $(<) documentation locally"
557 INSTALL_MESSAGE            ?= echo -e "  ==> Installing $^"
558 INSTALL_LOCAL_MESSAGE      ?= echo -e "  ==> Installing $(<) to local build-tree"
559 UPDATE_HTML_MESSAGE        ?= echo -e "  ! You should remake your doc directory in $(1)"
560
561 # allows an include $(DEPSVAR) at the end of the makefile
562 # but prevents rebuilding them on a scrub, clean, cleanall and help
563 ifneq ($(filter scrub clean cleanall help,$(MAKECMDGOALS)),)
564 DEPSVAR =
565 else
566 DEPSVAR = $(DEPS)
567 endif
568
569 #
570 # Some rules
571 #
572
573 # addfileheader-rule: allows "make addfileheader main.c server.c"-like
574 # commands and automatically inserts the path within the package
575 # options may be passed with $(ADDFILEHEADER_OPTIONS)
576 ADDFILEHEADER_PREFIX = $(patsubst $(call absfilename,$(PKGDIR)/)%,\
577                                   $(PKGNAME)/%,$(call absfilename,./))
578 ADDFILEHEADER_FILES = $(filter-out addfileheader,$(MAKECMDGOALS))
579 addfileheader:
580         addfileheader $(ADDFILEHEADER_OPTIONS) -p $(ADDFILEHEADER_PREFIX) $(ADDFILEHEADER_FILES)
581         
582
583 .PHONY: FORCE
584
585 #
586 # Common functions
587 #
588
589 # 1: name
590 # 2: output file
591 # 3: inc path (one only)
592 # 4: libs
593 # 5: requires_libs
594 generate_pcfile =                                                            \
595         mkdir -p $(dir $(2))                                                 \
596         ;echo -n                                                    > $(2)   \
597         $(if $(3),;echo "incdir=/empty_incdir"                     >> $(2))  \
598         ;echo "Name: $(1)"                                         >> $(2)   \
599         ;echo "Version: 0"                                         >> $(2)   \
600         ;echo "Description: L4 library"                            >> $(2)   \
601         $(if $(3),;echo "Cflags: $(addprefix -I\$${incdir}/,$(3))" >> $(2))  \
602         $(if $(4),;echo "Libs: $(sort $(4))"                       >> $(2))  \
603         $(if $(5),;echo "Requires: $(5)"                           >> $(2))  \
604         $(if $(BID_GEN_CONTROL),;echo "Provides: $(1)"             >> $(PKGDIR)/Control) \
605         $(if $(BID_GEN_CONTROL),;echo "Requires: $(5)"             >> $(PKGDIR)/Control) ;
606
607
608 endif   # _L4DIR_MK_MAKECONF undefined