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