4 # DROPS (Dresden Realtime OPerating System) Component
6 # Makefile-Include for compiling templates (prog.mk, lib.mk)
8 # Makefile-Include for binary and lib directories
9 # Definitions for building the Makefile.inc, building dependencies,
10 # compiler configuration.
12 # If SYSTEM is defined and we do not clean, we generate Makefile.inc. This file
13 # holds the dependencies of the targets. Is also contains the definitions of
14 # variables holding the objects of the related targets. In a multiple
15 # architecture makefile, Makefile.inc will be built in arch-specific subdirs,
16 # like the other components built.
18 # Most compiler- and linker-flag variables are defined in such a way that
19 # using them in the rule will expand all the target- and
20 # architecture-specific definitions.
22 # The relink-rule is defined in this file.
24 # The dependencies for compiling files are defined here, the dep-files are
25 # generated with names .(source-file).d for .c, .cc and .S-files.
27 # Clean-rules are defined here.
30 $(GENERAL_D_LOC): $(L4DIR)/mk/binary.inc $(L4DIR)/mk/modes.inc
32 # our default Makefile-name in the OBJ-Subdirs
33 BID_OBJ_Makefile ?= Makefile
35 ifeq ($(SYSTEM),) # if we have no system yet, build the subdirs
36 #################################################################
38 # we have NO system defined in $(SYSTEM), we are in the src/ dir
40 #################################################################
43 SYSTEMS ?= $(SYSTEMS_ABI)
46 $(strip $(if $(DEPENDS_PKGS), \
47 $(strip $(foreach i,$(DEPENDS_PKGS), \
48 $(if $(strip $(wildcard $(OBJ_BASE)/pc/$(i).pc)),,$(i))))))
50 ifneq ($(BID_MISSING_PCS),)
51 # clear SYSTEMS to prevent building anything
53 text := $(shell echo -e "\033[32mPackage dependencies missing: \033[1m$(BID_MISSING_PCS)\033[22m; skipping directory '$(SRC_DIR)'.\033[0m")
54 $(if $(BID_FAIL_ON_MISSING),$(error $(text)), $(info $(text)))
57 # intersection with BUILD_SYSTEMS
59 # filter the systems from the local SYSTEMS variable ($2), that match
60 # the build-architecture.
61 # args: $(1) - build architecture (one from BUILD_SYSTEMS)
63 # 1. check, if both systems are the same (optionally reduced by the CPU)
64 # 2. check, if at least the arch matches (and optionally the cpu)
65 FILTER_SYSTEM = $(shell echo $(2)|$(AWKP) '\
66 BEGIN{m=s="$(1)";sub("_[^-]*","",m)}\
68 if(m==$$i||s==$$i){print s}else\
69 if(index(m,$$i)==1||index(s,$$i)==1)\
70 {t=s;sub("-.*","",t);print t}}}')
72 # print that system of the SYSTEMS variable that actually matched with
73 # $(BUILD_SYSTEMS) to the given system
74 # args: $(1) - build architecture (SYSTEM)
76 # + do nearly the same as in FILTER_SYSTEM, but additionally check if
77 # the resulting system matches $(1). If so, print the according pattern from
79 BID_ORIG_SYSTEM = $(shell echo $(2)|$(AWKP) '\
80 BEGIN{m=s="$(1)";sub("_[^-]*","",m)}\
82 if(m==$$i||s==$$i){if(s=="$(1)"){print $$i;exit}};\
83 if(index(m,$$i)==1||index(s,$$i)==1)\
84 {t=s;sub("-.*","",t);\
85 if(t=="$(1)"){print $$i;exit}}}}')
88 TARGET_SYSTEMS := $(sort $(foreach sys,$(sort \
89 $(shell echo $(BUILD_SYSTEMS)|$(SED) -e 's/_[^- ]*\(-\{0,1\}\)/\1/g')), \
90 $(call FILTER_SYSTEM,$(sys),$(SYSTEMS))))
92 TARGET_SYSTEMS := $(sort $(foreach sys,$(BUILD_SYSTEMS),\
93 $(call FILTER_SYSTEM,$(sys),$(SYSTEMS))))
96 DIR_FROM_SUB = $(firstword $(addprefix ../,$(patsubst /%,,$(1))) $(1))
97 SYSTEM_TO_ARCH = $(shell echo $(1)|$(SED) -e 's/[_-].*//')
98 SYSTEM_TO_CPU = $(shell echo $(1)|$(SED) -ne 's/[^-_]*_\([^-]*\).*/\1/p')
99 SYSTEM_TO_L4API = $(shell echo $(1)|$(SED) -ne 's/.*-\(.*\)/\1/p')
101 $(foreach sys,$(TARGET_SYSTEMS),$(OBJ_DIR)/OBJ-$(sys)/$(BID_OBJ_Makefile)):$(OBJ_DIR)/OBJ-%/$(BID_OBJ_Makefile):$(OBJ_DIR)/.general.d
102 @install -d $(dir $@)
103 @echo 'L4DIR=$(L4DIR_ABS)'>$@
104 @echo 'OBJ_BASE=$(OBJ_BASE)'>>$@
105 @echo 'OBJ_DIR=$(OBJ_DIR)'>>$@
106 @echo 'SRC_DIR=$(SRC_DIR)'>>$@
107 @echo 'PKGDIR=$(PKGDIR_ABS)'>>$@
108 @echo 'PKGDIR_ABS=$(PKGDIR_ABS)'>>$@
109 @echo 'PKGDIR_OBJ=$(PKGDIR_OBJ)'>>$@
110 @echo 'MAKECONFLOCAL=$(SRC_DIR)/Makeconf.local'>>$@
111 @echo 'OSYSTEM=$(call BID_ORIG_SYSTEM,$*,$(SYSTEMS))'>>$@
112 @echo 'SYSTEM=$*'>>$@
113 @echo 'ARCH=$(call SYSTEM_TO_ARCH,$*)'>>$@
114 @echo 'CPU=$(call SYSTEM_TO_CPU,$*)'>>$@
115 @echo 'L4API=$(call SYSTEM_TO_L4API,$*)'>>$@
116 @echo 'vpath %.c $(VPATH_SRC_BASE)'>>$@
117 @echo 'vpath %.cc $(VPATH_SRC_BASE)'>>$@
118 @echo 'vpath %.cpp $(VPATH_SRC_BASE)'>>$@
119 @echo 'vpath %.S $(VPATH_SRC_BASE)'>>$@
120 @echo 'vpath %.y $(VPATH_SRC_BASE)'>>$@
121 @echo 'vpath %.l $(VPATH_SRC_BASE)'>>$@
122 @echo 'vpath %.ld $(VPATH_SRC_BASE)'>>$@
123 @echo 'vpath %.dpe $(VPATH_SRC_BASE)'>>$@
124 @echo '.general.d: $(SRC_DIR)/$(if $(wildcard Make.rules),Make.rules,Makefile)'>>$@
125 @echo 'include $(SRC_DIR)/$(if $(wildcard Make.rules),Make.rules,Makefile)'>>$@
126 @echo 'include $$(L4DIR)/mk/$(ROLE)'>>$@
128 install relink scrub:: $(foreach arch,$(TARGET_SYSTEMS),\
129 $(OBJ_DIR)/OBJ-$(arch)/$(BID_OBJ_Makefile))
130 $(if $(TARGET_SYSTEMS), $(VERBOSE)set -e ; \
131 for d in $(TARGET_SYSTEMS) ; do \
132 PWD=$OBJ-$$d $(MAKE) -C $(OBJ_DIR)/OBJ-$$d -f $(BID_OBJ_Makefile) \
138 all:: $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch))
139 .PHONY: $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch))
140 $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch)):%:%/$(BID_OBJ_Makefile) pre-obj
141 $(VERBOSE)PWD=$@ $(MAKE) $(PL_j) -C $@ -f $(BID_OBJ_Makefile)
144 foreach_objdir = $(if $(wildcard $(OBJ_DIR)/OBJ-*), $(VERBOSE)set -e ; \
145 for d in $(wildcard $(OBJ_DIR)/OBJ-*) ; do \
146 PWD=$$d $(MAKE) -C $$d -f $(BID_OBJ_Makefile) $(1); \
149 %.i %.s.i:: export DO_SHOW_RESULT_FILE=y
151 $(call foreach_objdir,$@)
154 $(call foreach_objdir,$@)
157 $(VERBOSE)$(RM) -r $(wildcard $(OBJ_DIR))
159 .PHONY: $(TARGET_SYSTEMS)
162 ###############################################################
164 # we have a system defined in $(SYSTEM), we are in an OBJ- dir
166 ###############################################################
171 $(call DISASM_CMD,$(if $(DABIN),$(DABIN),$<))
173 ifneq ($(CONFIG_USE_DROPS_STDDIR),)
174 L4INCDIR ?= $(addprefix $(OBJ_BASE)/include/$(ARCH)/,$(L4API)) \
175 $(addprefix $(OBJ_BASE)/include/,$(L4API)) \
176 $(OBJ_BASE)/include/$(ARCH) \
177 $(OBJ_BASE)/include \
178 $(if $(USE_DICE),$(DICE_INCDIR),) \
179 $(addprefix $(DROPS_STDDIR)/include/$(ARCH)/,$(L4API)) \
180 $(addprefix $(DROPS_STDDIR)/include/,$(L4API)) \
181 $(DROPS_STDDIR)/include/$(ARCH) \
182 $(DROPS_STDDIR)/include
184 L4LIBDIR ?= $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
185 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
187 $(addprefix $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
188 $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU) \
193 L4INCDIR ?= $(addprefix $(OBJ_BASE)/include/$(ARCH)/,$(L4API)) \
194 $(addprefix $(OBJ_BASE)/include/,$(L4API)) \
195 $(OBJ_BASE)/include/$(ARCH) \
196 $(OBJ_BASE)/include \
197 $(if $(USE_DICE),$(DICE_INCDIR),)
199 L4LIBDIR ?= $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
200 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
207 # There is a hierarchy on defining variables depending on the targets they
208 # refer to: Most standard-Make Variables are supported. This includes
209 # LDFLAGS - options for ld, defined in prog.mk and lib.mk
210 # CPPFLAGS - options for the c preprocessor, included in CFLAGS
211 # CFLAGS - options for the c compiler
212 # CXXFLAGS - options for the c++ compiler
213 # ASFLAGS - options for the assembler
215 # Addtitionally, the following varibales are supported:
216 # SRC_C, SRC_CC, SRC_S - .c, .cc, .S source files
217 # CRT0, CRTN - startup and finish code
218 # LIBS - additional libs to link (with -l), including paths (-L)
219 # IDL - interface definition files
220 # TARGET - targets to ge built
222 # These variables will be used for all operations with the corresponding
223 # file types. More specific description is possible by using variables with
224 # added specifications. These specifications include a referred element and
225 # the architecture, both optional but in this order, separated by
226 # underscores. The referred element for CPPFLAGS, CFLAGS, CXXFLAGS and
227 # ASFLAGS is the source file. For the other variables, it is one of the
228 # target files. The TARGET variable can only be postfixed by an
230 # The specific variables will be used for the target and the referred element
231 # given in the name, additionally to the more general ones.
233 # Example for a valid specifications:
234 # SRC_C_libxverbose.a = verbose.c - ar's verbose.o into libxverbose.a, but
235 # not in other libs in the TARGET var.
237 include $(L4DIR)/mk/modes.inc
239 # select the variable specified in $(1) from the current architecture and
240 # mode. Fall back to "all" architecture if no specific version exists.
241 BID_mode_var= $(if $($(1)_$(ARCH)_$(MODE)),$($(1)_$(ARCH)_$(MODE)),$($(1)_all_$(MODE)))
243 BID_SUPPORTED ?= $(call BID_mode_var,BID_SUPPORTED)
244 ifneq ($(BID_SUPPORTED),y)
245 $(error Mode "$(MODE)" is not supported for CPU architecture "$(ARCH)")
248 LIBCINCDIR ?= $(call BID_mode_var,LIBCINCDIR)
249 LIBCLIBDIR ?= $(call BID_mode_var,LIBCLIBDIR)
250 L4_LIBS ?= $(call BID_mode_var,L4_LIBS)
251 CRT0 ?= $(call BID_mode_var,CRT0)
252 CRTP ?= $(if $(filter $(CRT0_DEFAULT),$(CRT0)),$(CRTP_DEFAULT),$(CRT0))
253 CRTN ?= $(call BID_mode_var,CRTN)
254 LDSCRIPT ?= $(call BID_mode_var,LDSCRIPT)
255 LDFLAGS += $(call BID_mode_var,LDFLAGS)
256 REQUIRES_LIBS += $(REQUIRES_LIBS_$(ARCH)) $(call BID_mode_var,REQUIRES_LIBS)
258 # we do not need to put our FLAG-definitions into a special file if we can
259 # use the target to parameterize it and if it needs not to appear in the deps
260 #CRT0 = $(word 1, $(CRT0_$@_$(OSYSTEM)) $(CRT0_$@) $(CRT0_$(OSYSTEM)))
261 #CRTN = $(word 1, $(CRTN_$@_$(OSYSTEM)) $(CRTN_$@) $(CRTN_$(OSYSTEM)))
262 LIBS += $(strip $(LIBS_$(OSYSTEM)) $(LIBS_$@) $(LIBS_$@_$(OSYSTEM)))
264 LDFLAGS += $(strip $(LDFLAGS_$(OSYSTEM)) $(LDFLAGS_$@) $(LDFLAGS_$@_$(OSYSTEM)))
265 CARCHFLAGS += $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU))
267 # ---------------------------------
271 # call pkg-config, returns __PKGCONFIG_FAILED__ if the call failed
273 # 2: parameters to pkg-config
274 # 3: list of packages
275 # use L4_BID_PKG_CONFIG because of export-defs, the function is copied
276 L4_BID_PKG_CONFIG = $(PKG_CONFIG)
277 BID_PKG_CONFIG = $(if $(strip $(3)), \
278 $(shell PKG_CONFIG_LIBDIR=$(1)/pc \
279 PKG_CONFIG_PATH= $(L4_BID_PKG_CONFIG) \
280 --define-variable=incdir=$(1)/include/contrib \
281 $(if $(VERBOSE),--silence-errors) \
282 $(2) $(3) || echo __PKGCONFIG_FAILED__))
284 BID_PKG_CONFIG_MISSING = \
285 $(if $(strip $(3)), \
286 $(shell PKG_CONFIG_LIBDIR=$(1)/pc \
287 PKG_CONFIG_PATH= LANG=C $(L4_BID_PKG_CONFIG) \
288 --errors-to-stdout --print-errors $(2) $(3) \
289 | LANG=C grep ", not found"))
291 BID_PKG_CONFIG_FAILED = $(findstring __PKGCONFIG_FAILED__,$(1))
293 ifeq ($(BID_MISSING_PCS),)
295 ifneq ($(REQUIRES_LIBS),)
296 REQUIRES_LIBS_LIST := $(strip $(call BID_PKG_CONFIG,$(OBJ_BASE),--libs,$(REQUIRES_LIBS)))
298 ifneq ($(call BID_PKG_CONFIG_FAILED,$(REQUIRES_LIBS_LIST)),)
299 BID_MISSING_PCS := $(strip $(foreach i,$(REQUIRES_LIBS), \
300 $(if $(filter __PKGCONFIG_FAILED__,$(call BID_PKG_CONFIG,$(OBJ_BASE),--libs --print-errors,$(i))),$(i))))
301 text := $(shell echo -e "\033[31mLibrary dependencies missing: \033[1m$(BID_MISSING_PCS)\033[22m in directory '$(SRC_DIR)'; aborting.\033[0m")
302 text2 := $(strip $(foreach i,$(REQUIRES_LIBS), $(call BID_PKG_CONFIG_MISSING,$(OBJ_BASE),--libs,$(i))))
303 $(if $(text2),$(info $(shell echo -e "\033[31m$(text2)\033[0m")))
304 $(if $(BID_MISSING_PCS),$(info $(text)),$(error $(text)))
308 ifneq ($(filter libl4re-vfs,$(REQUIRES_LIBS)),)
309 $(error Never include 'libl4re-vfs'!)
313 BID_PKG_CONFIG_CFLAGS := $(call BID_PKG_CONFIG,$(OBJ_BASE),--cflags, $(REQUIRES_CFLAGS) $(REQUIRES_LIBS))
316 ifneq ($(call BID_PKG_CONFIG_FAILED,$(BID_PKG_CONFIG_CFLAGS)),)
317 BID_MISSING_PCS := $(strip $(foreach i,$(REQUIRES_CFLAGS) $(REQUIRES_LIBS), \
318 $(if $(filter __PKGCONFIG_FAILED__,$(call BID_PKG_CONFIG,$(OBJ_BASE),--cflags --print-errors,$(i))),$(i))))
319 text := $(shell echo -e "\033[31mCflags dependencies missing: \033[1m$(BID_MISSING_PCS)\033[22m in directory '$(SRC_DIR)'; aborting.\033[0m")
320 text2 := $(strip $(foreach i,$(REQUIRES_LIBS), $(call BID_PKG_CONFIG_MISSING,$(OBJ_BASE),--cflags,$(i))))
321 $(if $(text2),$(info $(shell echo -e "\033[31m$(text2)\033[0m")))
327 # -----------------------
329 # May 2007: force somewhat old hash-style as some(!, independant of the
330 # actual version) ld now use an other format, no uclibc upstream fix
331 # available yet, until available, we need:
332 ifeq ($(LD_HAS_HASH_STYLE_OPTION),y)
333 ifneq ($(HOST_LINK),1)
334 LDFLAGS += --hash-style=sysv
338 OPTS ?= -g -O2 -fno-strict-aliasing
339 WARNINGS?= -Wextra -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(WARNINGS_$@)
342 # never cross compile in host mode
346 LIBS += $(REQUIRES_LIBS_LIST)
348 # no architecture specific flags in host mode
349 LDFLAGS += $(LDFLAGS_$(ARCH))
350 L4_LIBS += $(REQUIRES_LIBS_LIST)
353 # no link address if build a lib or we're compiling a host program and using
354 # the host linker scripts
355 ifeq ($(ROLE),lib.mk)
356 NO_DEFAULT_RELOC := y
358 ifneq ($(HOST_LINK),)
359 NO_DEFAULT_RELOC := y
362 default_reloc_base = $(firstword $(DEFAULT_RELOC_$(1)) \
363 $(DEFAULT_RELOC_$(ARCH)) \
365 $(if $(NO_DEFAULT_RELOC),,0x01000000))
366 default_reloc = $(if $(call default_reloc_base,$(1)),\
367 $(if $(RELOC_PHYS), \
368 $(shell printf "0x%x" $$(($(RAM_BASE) + $(call default_reloc_base,$(1))))), \
369 $(call default_reloc_base,$(1))))
371 # can be overwritten to get the old mode
372 CFLAGS_C99 ?= -std=gnu99
375 CFLAGS_L4_GENERIC += $(CCXX_FLAGS) $(CARCHFLAGS) $(GCCNOSTACKPROTOPT)
378 $(CLIENTIDL:.idl=-client.o): CFLAGS += -ffunction-sections
379 CFLAGS += $(if $(CONFIG_BID_GCC_OMIT_FP),-fomit-frame-pointer,)
380 CFLAGS += $(CFLAGS_$(OSYSTEM)) $(CFLAGS_$<) $(CFLAGS_$(<F)) $(CFLAGS_$(<D)) $(CFLAGS_$(<F)_$(OSYSTEM))
381 CFLAGS += $(CFLAGS_$(L4API))
382 CFLAGS += $(OPTS) $(WARNINGS)
383 CFLAGS += -fno-common
384 CFLAGS += $(CFLAGS_C99)
385 CFLAGS += $(CFLAGS_L4_GENERIC)
386 DEFINES += $(DEFINES_$(OSYSTEM)) $(DEFINES_$<) $(DEFINES_$(<F)) $(DEFINES_$(<D)) $(DEFINES_$(<F)_$(OSYSTEM))
387 DEFINES += -DSYSTEM_$(subst -,_,$(SYSTEM)) -DARCH_$(ARCH) -DCPUTYPE_$(CPU) -DL4API_$(L4API)
388 DEFINES += $(DEFINES-y)
389 DEFINES += -D_GNU_SOURCE $(if $(L4API),,-DL4_MINIMAL_LIBC)
391 ifeq (,$(filter 0 n N, $(DEBUG)))
396 CPPFLAGS-DEBUG_MODE = \
397 $(addprefix -include, $(OBJ_BASE)/include/$(ARCH)/l4/sys/kdebug.h) \
398 $(addprefix -include, $(wildcard $(if $(L4API),$(OBJ_BASE)/include/$(ARCH)/$(L4API)/l4/sys/ktrace.h) \
399 $(OBJ_BASE)/include/$(ARCH)/l4/sys/ktrace.h)) \
400 -include $(OBJ_BASE)/include/l4/util/kprintf.h \
401 $(if $(L4API),-include $(OBJ_BASE)/include/l4/sys/debugger.h)
403 CPPFLAGS+= $(CPPFLAGS_$(OSYSTEM)) $(CPPFLAGS_$<) $(CPPFLAGS_$(<F)) $(CPPFLAGS_$(<D)) $(CPPFLAGS_$(<F)_$(OSYSTEM))
404 CPPFLAGS+= $(DEFINES)
405 CPPFLAGS+= $(addprefix -I, $(PRIVATE_INCDIR) $(PRIVATE_INCDIR_$(OSYSTEM)) $(PRIVATE_INCDIR_$@) $(PRIVATE_INCDIR_$@_$(OSYSTEM)))
406 CPPFLAGS+= $(if $(CONTRIB_INCDIR),$(addprefix -I$(OBJ_BASE)/include/contrib/,$(CONTRIB_INCDIR)))
407 CPPFLAGS+= $(BID_PKG_CONFIG_CFLAGS)
408 CPPFLAGS+= $(if $(CLIENTIDL)$(SERVERIDL)$(addprefix CLIENTIDL_,$(TARGET))$(addprefix SERVERIDL_,$(TARGET)),$(addprefix -I, $(IDL_PATH)))
410 CPPFLAGS+= $(addprefix -I, $(L4INCDIR))
412 CPPFLAGS+= $(if $(DEBUG_MODE),$(CPPFLAGS-DEBUG_MODE))
413 CPPFLAGS+= $(LIBCINCDIR)
416 CXXFLAGS_L4_GENERIC += $(CARCHFLAGS) $(CCXX_FLAGS)
417 CXXFLAGS_L4_GENERIC += $(if $(GCC_HAS_ATOMICS),-DL4_GCC_HAS_ATOMICS)
418 CXXFLAGS_L4_GENERIC += $(GCCNOSTACKPROTOPT)
419 CXXFLAGS_L4_GENERIC += -fuse-cxa-atexit
422 CXXFLAGS+= $(if $(CONFIG_BID_GCC_OMIT_FP),-fomit-frame-pointer,)
423 CXXFLAGS+= $(CXXFLAGS_$(OSYSTEM)) $(CXXFLAGS_$@) $(CXXFLAGS_$(@D)) $(CXXFLAGS_$<) $(CXXFLAGS_$(<F)) $(CXXFLAGS_$(<D)) $(CXXFLAGS_$(<F)_$(OSYSTEM))
424 CXXFLAGS+= $(OPTS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wno-pointer-sign,$(WARNINGS))
425 CXXFLAGS+= $(CXXFLAGS-y)
426 CXXFLAGS+= -fno-common
427 CXXFLAGS+= $(CXXFLAGS_L4_GENERIC)
429 PICFLAGS += -fPIC -U__PIC__ -D__PIC__=1
432 ASFLAGS_L4_GENERIC += $(CARCHFLAGS) $(CCXX_FLAGS)
435 ASFLAGS += $(OPTS) $(ASFLAGS_L4_GENERIC)
436 ASFLAGS += $(ASFLAGS_$(ARCH)) $(ASFLAGS_$(@:.o=.S)) $(ASFLAGS_$(@:.o=.S)_$(OSYSTEM))
437 OBJS += $(strip $(OBJS_$(OSYSTEM)) $(OBJS_$@) $(OBJS_$@_$(OSYSTEM)))
438 ALLOBJS = $(OBJS) $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)),\
439 $(OBJS_$(target)) $(OBJS_$(target)_$(OSYSTEM)))
440 ALLDPI = $(sort $(foreach obj,$(ALLOBJS),$(patsubst %.dpe,%.dpi,\
441 $(DPE_$(obj:.o=.c)))))
443 # implementation of $(CLIENTIDL) and $(SERVERIDL)
445 IDL_PKGDIR ?= $(PKGDIR_OBJ)
446 IDL_PATH ?= $(addsuffix /idl/OBJ-$(ARCH)-$(L4API),$(IDL_PKGDIR))
447 ifneq ($(IDL_TYPE), dice)
448 ifneq ($(IDL_TYPE), corba)
449 $(error IDL_TYPE "$(IDL_TYPE)" not supported.)
453 # A function to deliver the source files generated from IDL-files and
454 # that should be linked to a given target. Used by "targetobjs" to write
455 # the target-objects and in the "Makefile.inc:"-rule to write the IDL_SRC_C-
458 IDL_SRC_Cfn = $(CLIENTIDL:.idl=-client.c) $(SERVERIDL:.idl=-server.c) \
459 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
460 $(CLIENTIDL_$(inter):.idl=-client.c) \
461 $(SERVERIDL_$(inter):.idl=-server.c))
462 IDL_SRC_CCfn = $(CLIENTIDL:.idl=-client.cc) $(SERVERIDL:.idl=-server.cc) \
463 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
464 $(CLIENTIDL_$(inter):.idl=-client.cc) \
465 $(SERVERIDL_$(inter):.idl=-server.cc))
467 # *all* CLIENTIDLs/SERVERIDLs
468 # needed for the test if we should include the IDL-Path into vpath
469 IDL_ALLCLIENTIDL = $(CLIENTIDL) $(CLIENTIDL_$(OSYSTEM)) \
470 $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)), \
471 $(CLIENTIDL_$(target)) $(CLIENTIDL_$(target)_$(OSYSTEM)))
472 IDL_ALLSERVERIDL = $(SERVERIDL) $(SERVERIDL_$(OSYSTEM)) \
473 $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)), \
474 $(SERVERIDL_$(target)) $(SERVERIDL_$(target)_$(OSYSTEM)))
476 ifneq ($(IDL_ALLCLIENTIDL),)
477 vpath %-client.c $(IDL_PATH)
478 vpath %-client.cc $(IDL_PATH)
480 ifneq ($(IDL_ALLSERVERIDL),)
481 vpath %-server.c $(IDL_PATH)
482 vpath %-server.cc $(IDL_PATH)
485 # convert list of c++ files names to .o files
486 # arg: 1 - list of files
487 # 2 - infix between the basename and the .o
488 convert_cc_to_o_file = $(patsubst %.cc,%$(2).o, $(filter %.cc,$(1))) \
489 $(if $(BID_ALLOW_CPP_AS_CPLUSPLUS_FILE), \
490 $(patsubst %.cpp,%$(2).o,$(filter %.cpp,$(1))))
494 # 2 - infix between the basename and the .o
495 # 3 - additional infix before .o in case of .cc files
496 targetobjs_gen = $(SRC_C:.c=$(2).o) $(SRC_S:.S=$(2).o) \
497 $(call convert_cc_to_o_file,$(SRC_CC),$(2)$(3)) \
498 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
499 $(SRC_C_$(inter):.c=$(2).o) \
500 $(SRC_S_$(inter):.S=$(2).o) \
501 $(call convert_cc_to_o_file,$(SRC_CC_$(inter)),$(2)$(3))) \
502 $(patsubst %.c,%$(2).o,$(call IDL_SRC_Cfn,$(1)))
504 # a helper function to generate the object-files for a given target
506 # 2 - infix between the basename and the .o
507 targetobjs = $(call targetobjs_gen,$(1),$(2),)
509 # special version of targetobjs that shares objects between exception and
510 # non-exception cases, we just need two versions for C++ files
512 # 2 - infix between the basename and the .o or .ne.o
513 targetobjs_ne = $(call targetobjs_gen,$(1),$(2),.ne)
515 # The directories our object files will go into. These dirs will be created
516 # on generation of Makefile.inc in the OBJ- dirs.
517 OBJDIRS = $(strip $(sort $(filter-out ./,$(dir \
518 $(foreach t,$(TARGET_STANDARD), \
519 $(call targetobjs,$(t),)) \
520 $(foreach t,$(TARGET_STANDARD_NE), \
521 $(call targetobjs,$(t),.ne)) \
522 $(foreach t,$(TARGET_SHARED), \
523 $(call targetobjs,$(t),)) \
524 $(foreach t,$(TARGET_SHARED_NE), \
525 $(call targetobjs,$(t),.ne)) \
526 $(foreach t,$(PROFILE), \
527 $(call targetobjs,$(t),.pr)) \
528 $(foreach t,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED),\
529 $(call targetobjs,$(t),.pr.s))))))
531 # The include file for the Makefile. This file contains definitions and
532 # dependencies which are dynamically generated. Unfortunately, make does
533 # not support variable declarations using the foreach function. Same
535 $(BID_OBJ_Makefile).inc: .general.d $(BID_RAM_BASE_DEP)
537 @$(ECHO) "# automatically generated, do not edit!" >$@_
538 # write helper variables containing the IDL-C-Sources
539 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
540 \nIDL_SRC_C_$(target)=$(call IDL_SRC_Cfn,$(target))))'>>$@_
541 # and add them to SRC_C
542 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
543 \nSRC_C_$(target) += $$(IDL_SRC_C_$(target))))'>>$@_
544 # but set the variables empty for the current rule
545 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
546 \n$(BID_OBJ_Makefile).inc: IDL_SRC_C_$(target)=))'>>$@_
547 # write helper variables containing the IDL-C++-Sources
548 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
549 \nIDL_SRC_CC_$(target)=$(call IDL_SRC_CCfn,$(target))))'>>$@_
550 # and add them to SRC_CC
551 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
552 \nSRC_CC_$(target) += $$(IDL_SRC_CC_$(target))))'>>$@_
553 # but set the variables empty for the current rule
554 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
555 \n$(BID_OBJ_Makefile).inc: IDL_SRC_CC_$(target)=))'>>$@_
556 # write the object declaration variables
557 # TARGET_{STANDARD, PIC, SHARED, STANDARD_NE, SHARED_NE}
558 # contain the appropriate targets
559 # TARGET_PROFILE_{STANDARD, PIC, SHARED} as well
560 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_STANDARD), \
561 \nOBJS_$(target) += $(call targetobjs,$(target),)))' >>$@_
562 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_STANDARD_NE), \
563 \nOBJS_$(target) += $(call targetobjs_ne,$(target),)))' >>$@_
564 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PIC) $(TARGET_SHARED), \
565 \nOBJS_$(target) += $(call targetobjs,$(target),.s)))' >>$@_
566 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PIC_NE) $(TARGET_SHARED_NE), \
567 \nOBJS_$(target) += $(call targetobjs_ne,$(target),.s) \
568 \nLINK_WITH_NOEXC_LIBS_$(target) = y))' >>$@_
569 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PROFILE), \
570 \nOBJS_$(target) += $(call targetobjs,$(target),.pr)))' >>$@_
571 @$(ECHO) -e '$(strip $(foreach target,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED), \
572 \nOBJS_$(target) += $(call targetobjs,$(target),.pr.s)))' >>$@_
574 # write the dpe-dependencies
575 @$(ECHO) -e '$(foreach obj,$(sort \
576 $(foreach t,$(TARGET_STANDARD),$(call targetobjs,$t)) \
577 $(foreach t,$(TARGET_PIC) $(TARGET_SHARED), \
578 $(call targetobjs,$t,.s)) \
579 $(foreach t,$(TARGET_PROFILE),$(call targetobjs,$t,.pr)) \
580 $(foreach t,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED),\
581 $(call targetobjs,$t,.pr.s))),$(strip \
582 $(addprefix \n$(obj): ,$(patsubst %.dpe,%.dpi, \
583 $(DPE_$(obj:.o=.c)) $(DPE_$(obj:.o=.cc)) \
584 $(DPE_$(obj:.s.o=.c)) $(DPE_$(obj:.s.o=.cc)) \
585 $(DPE_$(obj:.pr.o=.c)) $(DPE_$(obj:.pr.o=.cc)) \
586 $(DPE_$(obj:.pr.s.o=.c)) $(DPE_$(obj:.pr.s.o=.cc)) \
589 # create the object-dirs
590 @$(if $(OBJDIRS), $(VERBOSE)set -e; for d in $(OBJDIRS); do \
591 [ -d "$$d" ] || $(MKDIR) $$d; done )
594 # write the object-dependencies for the targets
595 @$(ECHO) -e '$(foreach target,$(TARGET),$(strip\
596 \n$(target): $$(OBJS_$(target)) ))' >> $@_
597 # make the target dependent on '.general.d'
598 @$(ECHO) -e '$(foreach target,$(TARGET),$(strip \
599 \n$$(OBJS_$(target)): .general.d))' \
601 # Using LDSO does not need a RELOC address, so omit the following in
603 ifneq ($(MODE),shared)
604 # in case of a binary, write the link address
605 # the dependency to the static file: If DEFAULT_RELOC is set,
606 # all targets are made dependent on the STATIC file
607 # (defined in Makeconf).
608 # If DEFAULT_RELOC_xxx is set, xxx is made dependent on the
610 ifneq ($(strip $(foreach target,$(TARGET), $(call default_reloc,$(target)))),)
611 ifneq ($(filter l4linux host,$(MODE)),)
612 $(error DEFAULT_RELOC must not be set if MODE is l4linux or host)
614 # the relocatable binaries depend on Makefile.inc
615 @$(ECHO) -e '\n$(strip \
616 $(foreach target, $(TARGET), \
617 $(if $(call default_reloc,$(target)),$(target))) \
619 # we find out the relocation address here.
620 @$(ECHO) -e '$(foreach target, $(TARGET),$(strip \
621 \nLDFLAGS_$(target)+= --defsym=__executable_start=$(firstword \
622 $(call default_reloc,$(target)))))' \
625 endif # MODE != shared
628 ifeq ($(filter scrub help,$(MAKECMDGOALS)),)
629 -include $(BID_OBJ_Makefile).inc
636 # the default target "all" ensures building of the targets. When multiple
637 # architectures are used, the targets are build in subdirs.
639 # the relink-rule: make the TARGETs phony. Specification of build-targets
640 # in MAKECMDGOALS is not allowed. Possibility: TARGET=
642 ifneq ($(filter relink,$(MAKECMDGOALS)),)
651 # Compilation rules with dependency-generation
653 # If we have ld.so, we use it to create our dependencies (see MAKEDEP
654 # definition). Otherwise, we fall back to whatever we need. For
655 # compilation with gcc, this is using "-MD" and postprocessing the
658 ifeq ($(CONFIG_HAVE_LDSO),)
659 LIBDEPS = $(foreach file, \
660 $(patsubst -l%,lib%.a,$(filter-out -L%,$(LDFLAGS))) \
661 $(patsubst -l%,lib%.so,$(filter-out -L%,$(LDFLAGS))),\
662 $(word 1, $(foreach dir, \
664 $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
665 $(wildcard $(dir)/$(file)))))
667 DEPEND_EXTEND_CMD = $(AWKP) ' \
669 while(sub("\\\\$$","")){ \
671 $$0=$$0 " " nextline \
673 split($$0,field,": "); \
674 sub("^$(*F).o","$*.s $*.i $@",field[1]); \
675 nr=split(field[2],deps) ; \
677 printf("ifeq ($$(shell test y \\\n"); \
678 for(j=0; j<100 && i+j<=nr; j++){ \
679 printf("-a -r %s \\\n", deps[i+j]); \
681 printf("&& echo y),)"); \
682 printf("\n%s: FORCE\nelse\n%s: $(BID_OBJ_Makefile) \\\n", \
683 field[1],field[1]); \
684 for(j=0; j<100 && i+j<=nr; j++){ \
685 printf("%s \\\n",deps[i+j]); \
687 printf("\nendif\n"); \
691 DEPEND_EXTEND_FUNC = ( $(DEPEND_EXTEND_CMD) < $(1) > $(2).new && rm -f $(1) && mv $(2).new $(2) ) || ( rm -f $(1) $(2).new $(2) ; $(DEPEND_IGNORE_ERRORS) )
695 endif # CONFIG_HAVE_LDSO empty
696 DEPFLAGS = -MD -MF $(@D)/.$(@F).d
698 include $(L4DIR)/mk/rules.inc
700 # generate rules to compile %.cc files to %.o, %.s.o etc
701 $(eval $(call BID_GENERATE_CXX_MAKE_RULES,cc))
702 # generate rules to compile %.cpp files to %.o, %.s.o etc
703 $(if $(BID_ALLOW_CPP_AS_CPLUSPLUS_FILE),$(eval $(call BID_GENERATE_CXX_MAKE_RULES,cpp)))
704 # generate rules to compile %.c files to %.o, %.s.o etc
705 $(eval $(call BID_GENERATE_C_MAKE_RULES,c))
706 # generate rules to compile %.S files to %.o, %.s.o etc
707 $(eval $(call BID_GENERATE_DEFAULT_MAKE_RULES,%,%.S,AS))
709 # Reset implicit rules, mind the TAB.
722 $(eval $(call BID_GENERATE_I_MAKE_RULE,%.i,%.c,$(CC),$(CFLAGS)))
723 $(eval $(call BID_GENERATE_I_MAKE_RULE,%.s.i,%.c,$(CC),$(CFLAGS) $(PICFLAGS)))
724 $(eval $(call BID_GENERATE_I_MAKE_RULE,%.i,%.cc,$(CXX),$(CXXFLAGS)))
725 $(eval $(call BID_GENERATE_I_MAKE_RULE,%.s.i,%.cc,$(CXX),$(CXXFLAGS) $(PICFLAGS)))
726 $(if $(BID_ALLOW_CPP_AS_CPLUSPLUS_FILE),$(eval $(call BID_GENERATE_I_MAKE_RULE,%.i,%.cpp,$(CXX),$(CXXFLAGS))))
727 $(if $(BID_ALLOW_CPP_AS_CPLUSPLUS_FILE),$(eval $(call BID_GENERATE_I_MAKE_RULE,%.s.i,%.cpp,$(CXX),$(CXXFLAGS) $(PICFLAGS))))
728 $(eval $(call BID_GENERATE_I_MAKE_RULE,%.i,%.S,$(CC),$(ASFLAGS)))
730 $(eval $(call BID_GENERATE_S_MAKE_RULE,%.c,$(CC),$(CFLAGS)))
731 $(eval $(call BID_GENERATE_S_MAKE_RULE,%.cc,$(CC),$(CXXFLAGS)))
732 $(if $(BID_ALLOW_CPP_AS_CPLUSPLUS_FILE),$(eval $(call BID_GENERATE_S_MAKE_RULE,%.cpp,$(CC),$(CXXFLAGS))))
736 $(VERBOSE)$(CONFIG_YACC) $(YFLAGS) $(call absfilename,$<)
737 $(VERBOSE)mv -f y.tab.c $@
738 $(VERBOSE)if [ -f y.tab.h ]; then mv -f y.tab.h $(@:.c=.h); fi
742 $(VERBOSE)$(CONFIG_LEX) -o$@ $(call absfilename,$<)
746 $(VERBOSE)$(call MAKEDEP,perl) $(GEN_DOPECODE) $< >$@
748 DEPS += $(foreach file,$(ALLOBJS), $(dir $(file)).$(notdir $(file)).d)
749 DEPS += $(foreach file,$(ALLDPI), $(dir $(file)).$(notdir $(file)).d)
754 $(VERBOSE)$(RM) $(strip $(filter-out $(KEEP_ON_CLEAN),\
755 $(wildcard *.dpi) $(wildcard *.o) $(wildcard *.i) \
756 $(wildcard *.S) $(ALLOBJS) $(DEL_ON_CLEAN)))
758 # clean: delete all temporary editor files, objects, binaries
759 # and most generated files
761 $(VERBOSE)$(RM) $(TARGET) $(wildcard .*.d) $(wildcard $(BID_OBJ_Makefile).inc)
763 .PHONY: scrub clean cleanall disasm
765 endif # $(SYSTEM) is defined
769 # scrub: delete temporary editor files and stuff like this
770 # can be extended by lokals