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 $(L4DIR)/pkg/$(i)) \
49 $(wildcard $(OBJ_BASE)/pc/$(i).pc)),,$(i))))))
51 ifneq ($(BID_MISSING_PKGS),)
52 # clear SYSTEMS to prevent building anything
54 text := $(shell echo -e "\033[32mPackage dependencies missing: \033[1m$(BID_MISSING_PKGS)\033[22m; skipping directory '$(SRC_DIR)'.\033[0m")
55 $(if $(BID_FAIL_ON_MISSING),$(error $(text)), $(info $(text)))
58 # intersection with BUILD_SYSTEMS
60 # filter the systems from the local SYSTEMS variable ($2), that match
61 # the build-architecture.
62 # args: $(1) - build architecture (one from BUILD_SYSTEMS)
64 # 1. check, if both systems are the same (optionally reduced by the CPU)
65 # 2. check, if at least the arch matches (and optionally the cpu)
66 FILTER_SYSTEM = $(shell echo $(2)|$(AWKP) '\
67 BEGIN{m=s="$(1)";sub("_[^-]*","",m)}\
69 if(m==$$i||s==$$i){print s}else\
70 if(index(m,$$i)==1||index(s,$$i)==1)\
71 {t=s;sub("-.*","",t);print t}}}')
73 # print that system of the SYSTEMS variable that actually matched with
74 # $(BUILD_SYSTEMS) to the given system
75 # args: $(1) - build architecture (SYSTEM)
77 # + do nearly the same as in FILTER_SYSTEM, but additionally check if
78 # the resulting system matches $(1). If so, print the according pattern from
80 BID_ORIG_SYSTEM = $(shell echo $(2)|$(AWKP) '\
81 BEGIN{m=s="$(1)";sub("_[^-]*","",m)}\
83 if(m==$$i||s==$$i){if(s=="$(1)"){print $$i;exit}};\
84 if(index(m,$$i)==1||index(s,$$i)==1)\
85 {t=s;sub("-.*","",t);\
86 if(t=="$(1)"){print $$i;exit}}}}')
89 TARGET_SYSTEMS := $(sort $(foreach sys,$(sort \
90 $(shell echo $(BUILD_SYSTEMS)|$(SED) -e 's/_[^- ]*\(-\{0,1\}\)/\1/g')), \
91 $(call FILTER_SYSTEM,$(sys),$(SYSTEMS))))
93 TARGET_SYSTEMS := $(sort $(foreach sys,$(BUILD_SYSTEMS),\
94 $(call FILTER_SYSTEM,$(sys),$(SYSTEMS))))
97 DIR_FROM_SUB = $(firstword $(addprefix ../,$(patsubst /%,,$(1))) $(1))
98 SYSTEM_TO_ARCH = $(shell echo $(1)|$(SED) -e 's/[_-].*//')
99 SYSTEM_TO_CPU = $(shell echo $(1)|$(SED) -ne 's/[^-_]*_\([^-]*\).*/\1/p')
100 SYSTEM_TO_L4API = $(shell echo $(1)|$(SED) -ne 's/.*-\(.*\)/\1/p')
102 $(foreach sys,$(TARGET_SYSTEMS),$(OBJ_DIR)/OBJ-$(sys)/$(BID_OBJ_Makefile)):$(OBJ_DIR)/OBJ-%/$(BID_OBJ_Makefile):$(OBJ_DIR)/.general.d
103 @install -d $(dir $@)
104 @echo 'L4DIR=$(L4DIR_ABS)'>$@
105 @echo 'OBJ_BASE=$(OBJ_BASE)'>>$@
106 @echo 'OBJ_DIR=$(OBJ_DIR)'>>$@
107 @echo 'SRC_DIR=$(SRC_DIR)'>>$@
108 @echo 'PKGDIR=$(PKGDIR_ABS)'>>$@
109 @echo 'PKGDIR_ABS=$(PKGDIR_ABS)'>>$@
110 @echo 'PKGDIR_OBJ=$(PKGDIR_OBJ)'>>$@
111 @echo 'MAKECONFLOCAL=$(SRC_DIR)/Makeconf.local'>>$@
112 @echo 'OSYSTEM=$(call BID_ORIG_SYSTEM,$*,$(SYSTEMS))'>>$@
113 @echo 'SYSTEM=$*'>>$@
114 @echo 'ARCH=$(call SYSTEM_TO_ARCH,$*)'>>$@
115 @echo 'CPU=$(call SYSTEM_TO_CPU,$*)'>>$@
116 @echo 'L4API=$(call SYSTEM_TO_L4API,$*)'>>$@
117 @echo 'vpath %.c $(VPATH_SRC_BASE)'>>$@
118 @echo 'vpath %.cc $(VPATH_SRC_BASE)'>>$@
119 @echo 'vpath %.cpp $(VPATH_SRC_BASE)'>>$@
120 @echo 'vpath %.S $(VPATH_SRC_BASE)'>>$@
121 @echo 'vpath %.y $(VPATH_SRC_BASE)'>>$@
122 @echo 'vpath %.l $(VPATH_SRC_BASE)'>>$@
123 @echo 'vpath %.ld $(VPATH_SRC_BASE)'>>$@
124 @echo 'vpath %.dpe $(VPATH_SRC_BASE)'>>$@
125 @echo '.general.d: $(SRC_DIR)/$(if $(wildcard Make.rules),Make.rules,Makefile)'>>$@
126 @echo 'include $(SRC_DIR)/$(if $(wildcard Make.rules),Make.rules,Makefile)'>>$@
127 @echo 'include $$(L4DIR)/mk/$(ROLE)'>>$@
129 install relink scrub:: $(foreach arch,$(TARGET_SYSTEMS),\
130 $(OBJ_DIR)/OBJ-$(arch)/$(BID_OBJ_Makefile))
131 $(if $(TARGET_SYSTEMS), $(VERBOSE)set -e ; \
132 for d in $(TARGET_SYSTEMS) ; do \
133 PWD=$OBJ-$$d $(MAKE) -C $(OBJ_DIR)/OBJ-$$d -f $(BID_OBJ_Makefile) \
139 all:: $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch))
140 .PHONY: $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch))
141 $(foreach arch,$(TARGET_SYSTEMS), $(OBJ_DIR)/OBJ-$(arch)):%:%/$(BID_OBJ_Makefile) pre-obj
142 $(VERBOSE)PWD=$@ $(MAKE) $(PL_j) -C $@ -f $(BID_OBJ_Makefile)
145 foreach_objdir = $(if $(wildcard $(OBJ_DIR)/OBJ-*), $(VERBOSE)set -e ; \
146 for d in $(wildcard $(OBJ_DIR)/OBJ-*) ; do \
147 PWD=$$d $(MAKE) -C $$d -f $(BID_OBJ_Makefile) $(1); \
150 %.i %.s.i:: export DO_SHOW_RESULT_FILE=y
152 $(call foreach_objdir,$@)
155 $(call foreach_objdir,$@)
158 $(VERBOSE)$(RM) -r $(wildcard $(OBJ_DIR))
160 .PHONY: $(TARGET_SYSTEMS)
163 ###############################################################
165 # we have a system defined in $(SYSTEM), we are in an OBJ- dir
167 ###############################################################
172 $(call DISASM_CMD,$(if $(DABIN),$(DABIN),$<))
174 ifneq ($(CONFIG_USE_DROPS_STDDIR),)
175 L4INCDIR ?= $(addprefix $(OBJ_BASE)/include/$(ARCH)/,$(L4API)) \
176 $(addprefix $(OBJ_BASE)/include/,$(L4API)) \
177 $(OBJ_BASE)/include/$(ARCH) \
178 $(OBJ_BASE)/include \
179 $(if $(USE_DICE),$(DICE_INCDIR),) \
180 $(addprefix $(DROPS_STDDIR)/include/$(ARCH)/,$(L4API)) \
181 $(addprefix $(DROPS_STDDIR)/include/,$(L4API)) \
182 $(DROPS_STDDIR)/include/$(ARCH) \
183 $(DROPS_STDDIR)/include
185 L4LIBDIR ?= $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
186 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
188 $(addprefix $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
189 $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU) \
194 L4INCDIR ?= $(addprefix $(OBJ_BASE)/include/$(ARCH)/,$(L4API)) \
195 $(addprefix $(OBJ_BASE)/include/,$(L4API)) \
196 $(OBJ_BASE)/include/$(ARCH) \
197 $(OBJ_BASE)/include \
198 $(if $(USE_DICE),$(DICE_INCDIR),)
200 L4LIBDIR ?= $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
201 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
208 # There is a hierarchy on defining variables depending on the targets they
209 # refer to: Most standard-Make Variables are supported. This includes
210 # LDFLAGS - options for ld, defined in prog.mk and lib.mk
211 # CPPFLAGS - options for the c preprocessor, included in CFLAGS
212 # CFLAGS - options for the c compiler
213 # CXXFLAGS - options for the c++ compiler
214 # ASFLAGS - options for the assembler
216 # Addtitionally, the following varibales are supported:
217 # SRC_C, SRC_CC, SRC_S - .c, .cc, .S source files
218 # CRT0, CRTN - startup and finish code
219 # LIBS - additional libs to link (with -l), including paths (-L)
220 # IDL - interface definition files
221 # TARGET - targets to ge built
223 # These variables will be used for all operations with the corresponding
224 # file types. More specific description is possible by using variables with
225 # added specifications. These specifications include a referred element and
226 # the architecture, both optional but in this order, separated by
227 # underscores. The referred element for CPPFLAGS, CFLAGS, CXXFLAGS and
228 # ASFLAGS is the source file. For the other variables, it is one of the
229 # target files. The TARGET variable can only be postfixed by an
231 # The specific variables will be used for the target and the referred element
232 # given in the name, additionally to the more general ones.
234 # Example for a valid specifications:
235 # SRC_C_libxverbose.a = verbose.c - ar's verbose.o into libxverbose.a, but
236 # not in other libs in the TARGET var.
238 include $(L4DIR)/mk/modes.inc
240 # select the variable specified in $(1) from the current architecture and
241 # mode. Fall back to "all" architecture if no specific version exists.
242 BID_mode_var= $(if $($(1)_$(ARCH)_$(MODE)),$($(1)_$(ARCH)_$(MODE)),$($(1)_all_$(MODE)))
244 BID_SUPPORTED ?= $(call BID_mode_var,BID_SUPPORTED)
245 ifneq ($(BID_SUPPORTED),y)
246 $(error Mode "$(MODE)" is not supported for CPU architecture "$(ARCH)")
249 LIBCINCDIR ?= $(call BID_mode_var,LIBCINCDIR)
250 LIBCLIBDIR ?= $(call BID_mode_var,LIBCLIBDIR)
251 L4_LIBS ?= $(call BID_mode_var,L4_LIBS)
252 CRT0 ?= $(call BID_mode_var,CRT0)
253 CRTP ?= $(if $(filter $(CRT0_DEFAULT),$(CRT0)),$(CRTP_DEFAULT),$(CRT0))
254 CRTN ?= $(call BID_mode_var,CRTN)
255 LDSCRIPT ?= $(call BID_mode_var,LDSCRIPT)
256 LDFLAGS += $(call BID_mode_var,LDFLAGS)
257 REQUIRES_LIBS += $(REQUIRES_LIBS_$(ARCH)) $(call BID_mode_var,REQUIRES_LIBS)
259 # we do not need to put our FLAG-definitions into a special file if we can
260 # use the target to parameterize it and if it needs not to appear in the deps
261 #CRT0 = $(word 1, $(CRT0_$@_$(OSYSTEM)) $(CRT0_$@) $(CRT0_$(OSYSTEM)))
262 #CRTN = $(word 1, $(CRTN_$@_$(OSYSTEM)) $(CRTN_$@) $(CRTN_$(OSYSTEM)))
263 LIBS += $(strip $(LIBS_$(OSYSTEM)) $(LIBS_$@) $(LIBS_$@_$(OSYSTEM)))
265 LDFLAGS += $(strip $(LDFLAGS_$(OSYSTEM)) $(LDFLAGS_$@) $(LDFLAGS_$@_$(OSYSTEM)))
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_PKGS),)
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_PKGS := $(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_PKGS)\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_PKGS),$(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_PKGS := $(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_PKGS)\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 OPTS += $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU))
351 L4_LIBS += $(REQUIRES_LIBS_LIST)
354 # no link address if build a lib or we're compiling a host program and using
355 # the host linker scripts
356 ifeq ($(ROLE),lib.mk)
357 NO_DEFAULT_RELOC := y
359 ifneq ($(HOST_LINK),)
360 NO_DEFAULT_RELOC := y
363 default_reloc_base = $(firstword $(DEFAULT_RELOC_$(1)) \
364 $(DEFAULT_RELOC_$(ARCH)) \
366 $(if $(NO_DEFAULT_RELOC),,0x01000000))
367 default_reloc = $(if $(call default_reloc_base,$(1)),\
368 $(if $(RELOC_PHYS), \
369 $(shell printf "0x%x" $$(($(RAM_BASE) + $(call default_reloc_base,$(1))))), \
370 $(call default_reloc_base,$(1))))
372 # can be overwritten to get the old mode
373 CFLAGS_C99 ?= -std=gnu99
375 $(CLIENTIDL:.idl=-client.o): CFLAGS += -ffunction-sections
376 CFLAGS += $(if $(CONFIG_BID_GCC_OMIT_FP),-fomit-frame-pointer,)
377 CFLAGS += $(CFLAGS_$(OSYSTEM)) $(CFLAGS_$(<F)) $(CFLAGS_$(<D)) $(CFLAGS_$(<F)_$(OSYSTEM))
378 CFLAGS += $(CFLAGS_$(L4API))
379 CFLAGS += $(OPTS) $(WARNINGS)
380 CFLAGS += -fno-common
381 CFLAGS += $(CFLAGS_C99)
383 CFLAGS += $(GCCNOSTACKPROTOPT)
385 DEFINES += $(DEFINES_$(OSYSTEM)) $(DEFINES_$(<F)) $(DEFINES_$(<D)) $(DEFINES_$(<F)_$(OSYSTEM))
386 DEFINES += -DSYSTEM_$(subst -,_,$(SYSTEM)) -DARCH_$(ARCH) -DCPUTYPE_$(CPU) -DL4API_$(L4API)
387 DEFINES += $(DEFINES-y)
388 DEFINES += -D_GNU_SOURCE
390 ifeq (,$(filter 0 n N, $(DEBUG)))
395 CPPFLAGS-DEBUG_MODE = \
396 $(addprefix -include, $(OBJ_BASE)/include/$(ARCH)/l4/sys/kdebug.h) \
397 $(addprefix -include, $(wildcard $(if $(L4API),$(OBJ_BASE)/include/$(ARCH)/$(L4API)/l4/sys/ktrace.h) \
398 $(OBJ_BASE)/include/$(ARCH)/l4/sys/ktrace.h)) \
399 -include $(OBJ_BASE)/include/l4/util/kprintf.h \
400 $(if $(L4API),-include $(OBJ_BASE)/include/l4/sys/debugger.h)
402 CPPFLAGS+= $(CPPFLAGS_$(OSYSTEM)) $(CPPFLAGS_$(<F)) $(CPPFLAGS_$(<D)) $(CPPFLAGS_$(<F)_$(OSYSTEM))
403 CPPFLAGS+= $(DEFINES)
404 CPPFLAGS+= $(addprefix -I, $(PRIVATE_INCDIR) $(PRIVATE_INCDIR_$(OSYSTEM)) $(PRIVATE_INCDIR_$@) $(PRIVATE_INCDIR_$@_$(OSYSTEM)))
405 CPPFLAGS+= $(if $(CONTRIB_INCDIR),$(addprefix -I$(OBJ_BASE)/include/contrib/,$(CONTRIB_INCDIR)))
406 CPPFLAGS+= $(BID_PKG_CONFIG_CFLAGS)
407 CPPFLAGS+= $(if $(CLIENTIDL)$(SERVERIDL)$(addprefix CLIENTIDL_,$(TARGET))$(addprefix SERVERIDL_,$(TARGET)),$(addprefix -I, $(IDL_PATH)))
409 CPPFLAGS+= $(addprefix -I, $(L4INCDIR))
411 CPPFLAGS+= $(if $(DEBUG_MODE),$(CPPFLAGS-DEBUG_MODE))
412 CPPFLAGS+= $(LIBCINCDIR)
414 CXXFLAGS+= $(if $(CONFIG_BID_GCC_OMIT_FP),-fomit-frame-pointer,)
415 CXXFLAGS+= $(CXXFLAGS_$(OSYSTEM))
416 CXXFLAGS+= $(CXXFLAGS_$(@:.o=.cc)) $(CXXFLAGS_$(@:.o=.cc)_$(OSYSTEM))
417 CXXFLAGS+= $(CXXFLAGS_$(@:.o=.cpp)) $(CXXFLAGS_$(@:.o=.cpp)_$(OSYSTEM))
418 CXXFLAGS+= $(OPTS) $(filter-out -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wno-pointer-sign,$(WARNINGS))
419 CXXFLAGS+= $(CXXFLAGS-y)
420 CXXFLAGS+= -fno-common
422 CXXFLAGS+= $(GCCNOSTACKPROTOPT)
425 PICFLAGS += -fPIC -U__PIC__ -D__PIC__=1
427 ASFLAGS += $(OPTS) $(ASFLAGS_$(ARCH)) $(ASFLAGS_$(@:.o=.S)) $(ASFLAGS_$(@:.o=.S)_$(OSYSTEM))
428 OBJS += $(strip $(OBJS_$(OSYSTEM)) $(OBJS_$@) $(OBJS_$@_$(OSYSTEM)))
429 ALLOBJS = $(OBJS) $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)),\
430 $(OBJS_$(target)) $(OBJS_$(target)_$(OSYSTEM)))
431 ALLDPI = $(sort $(foreach obj,$(ALLOBJS),$(patsubst %.dpe,%.dpi,\
432 $(DPE_$(obj:.o=.c)))))
434 # implementation of $(CLIENTIDL) and $(SERVERIDL)
436 IDL_PKGDIR ?= $(PKGDIR_OBJ)
437 IDL_PATH ?= $(addsuffix /idl/OBJ-$(ARCH)-$(L4API),$(IDL_PKGDIR))
438 ifneq ($(IDL_TYPE), dice)
439 ifneq ($(IDL_TYPE), corba)
440 $(error IDL_TYPE "$(IDL_TYPE)" not supported.)
444 # A function to deliver the source files generated from IDL-files and
445 # that should be linked to a given target. Used by "targetobjs" to write
446 # the target-objects and in the "Makefile.inc:"-rule to write the IDL_SRC_C-
449 IDL_SRC_Cfn = $(CLIENTIDL:.idl=-client.c) $(SERVERIDL:.idl=-server.c) \
450 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
451 $(CLIENTIDL_$(inter):.idl=-client.c) \
452 $(SERVERIDL_$(inter):.idl=-server.c))
453 IDL_SRC_CCfn = $(CLIENTIDL:.idl=-client.cc) $(SERVERIDL:.idl=-server.cc) \
454 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
455 $(CLIENTIDL_$(inter):.idl=-client.cc) \
456 $(SERVERIDL_$(inter):.idl=-server.cc))
458 # *all* CLIENTIDLs/SERVERIDLs
459 # needed for the test if we should include the IDL-Path into vpath
460 IDL_ALLCLIENTIDL = $(CLIENTIDL) $(CLIENTIDL_$(OSYSTEM)) \
461 $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)), \
462 $(CLIENTIDL_$(target)) $(CLIENTIDL_$(target)_$(OSYSTEM)))
463 IDL_ALLSERVERIDL = $(SERVERIDL) $(SERVERIDL_$(OSYSTEM)) \
464 $(foreach target,$(TARGET) $(TARGET_$(OSYSTEM)), \
465 $(SERVERIDL_$(target)) $(SERVERIDL_$(target)_$(OSYSTEM)))
467 ifneq ($(IDL_ALLCLIENTIDL),)
468 vpath %-client.c $(IDL_PATH)
469 vpath %-client.cc $(IDL_PATH)
471 ifneq ($(IDL_ALLSERVERIDL),)
472 vpath %-server.c $(IDL_PATH)
473 vpath %-server.cc $(IDL_PATH)
478 # 2 - infix between the basename and the .o
479 # 3 - additional infix before .o in case of .cc files
480 targetobjs_gen = $(SRC_C:.c=$(2).o) $(SRC_S:.S=$(2).o) \
481 $(SRC_CC:.cc=$(2)$(3).o) \
482 $(foreach inter, $(OSYSTEM) $(1) $(1)_$(OSYSTEM), \
483 $(SRC_C_$(inter):.c=$(2).o) \
484 $(SRC_S_$(inter):.S=$(2).o) \
485 $(SRC_CC_$(inter):.cc=$(2)$(3).o)) \
486 $(patsubst %.c,%$(2).o,$(call IDL_SRC_Cfn,$(1)))
488 # a helper function to generate the object-files for a given target
490 # 2 - infix between the basename and the .o
491 targetobjs = $(call targetobjs_gen,$(1),$(2),)
493 # special version of targetobjs that shares objects between exception and
494 # non-exception cases, we just need two versions for C++ files
496 # 2 - infix between the basename and the .o or .ne.o
497 targetobjs_ne = $(call targetobjs_gen,$(1),$(2),.ne)
499 # The directories our object files will go into. These dirs will be created
500 # on generation of Makefile.inc in the OBJ- dirs.
501 OBJDIRS = $(strip $(sort $(filter-out ./,$(dir \
502 $(foreach t,$(TARGET_STANDARD), \
503 $(call targetobjs,$(t),)) \
504 $(foreach t,$(TARGET_STANDARD_NE), \
505 $(call targetobjs,$(t),.ne)) \
506 $(foreach t,$(TARGET_SHARED), \
507 $(call targetobjs,$(t),)) \
508 $(foreach t,$(TARGET_SHARED_NE), \
509 $(call targetobjs,$(t),.ne)) \
510 $(foreach t,$(PROFILE), \
511 $(call targetobjs,$(t),.pr)) \
512 $(foreach t,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED),\
513 $(call targetobjs,$(t),.pr.s))))))
515 # The include file for the Makefile. This file contains definitions and
516 # dependencies which are dynamically generated. Unfortunately, make does
517 # not support variable declarations using the foreach function. Same
519 $(BID_OBJ_Makefile).inc: .general.d $(BID_RAM_BASE_DEP)
521 @$(ECHO) "# automatically generated, do not edit!" >$@_
522 # write helper variables containing the IDL-C-Sources
523 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
524 \nIDL_SRC_C_$(target)=$(call IDL_SRC_Cfn,$(target))))'>>$@_
525 # and add them to SRC_C
526 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
527 \nSRC_C_$(target) += $$(IDL_SRC_C_$(target))))'>>$@_
528 # but set the variables empty for the current rule
529 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
530 \n$(BID_OBJ_Makefile).inc: IDL_SRC_C_$(target)=))'>>$@_
531 # write helper variables containing the IDL-C++-Sources
532 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
533 \nIDL_SRC_CC_$(target)=$(call IDL_SRC_CCfn,$(target))))'>>$@_
534 # and add them to SRC_CC
535 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
536 \nSRC_CC_$(target) += $$(IDL_SRC_CC_$(target))))'>>$@_
537 # but set the variables empty for the current rule
538 @$(ECHO) -en '$(strip $(foreach target,$(TARGET), \
539 \n$(BID_OBJ_Makefile).inc: IDL_SRC_CC_$(target)=))'>>$@_
540 # write the object declaration variables
541 # TARGET_{STANDARD, PIC, SHARED, STANDARD_NE, SHARED_NE}
542 # contain the appropriate targets
543 # TARGET_PROFILE_{STANDARD, PIC, SHARED} as well
544 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_STANDARD), \
545 \nOBJS_$(target) += $(call targetobjs,$(target),)))' >>$@_
546 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_STANDARD_NE), \
547 \nOBJS_$(target) += $(call targetobjs_ne,$(target),)))' >>$@_
548 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PIC) $(TARGET_SHARED), \
549 \nOBJS_$(target) += $(call targetobjs,$(target),.s)))' >>$@_
550 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PIC_NE) $(TARGET_SHARED_NE), \
551 \nOBJS_$(target) += $(call targetobjs_ne,$(target),.s) \
552 \nLINK_WITH_NOEXC_LIBS_$(target) = y))' >>$@_
553 @$(ECHO) -en '$(strip $(foreach target,$(TARGET_PROFILE), \
554 \nOBJS_$(target) += $(call targetobjs,$(target),.pr)))' >>$@_
555 @$(ECHO) -e '$(strip $(foreach target,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED), \
556 \nOBJS_$(target) += $(call targetobjs,$(target),.pr.s)))' >>$@_
558 # write the dpe-dependencies
559 @$(ECHO) -e '$(foreach obj,$(sort \
560 $(foreach t,$(TARGET_STANDARD),$(call targetobjs,$t)) \
561 $(foreach t,$(TARGET_PIC) $(TARGET_SHARED), \
562 $(call targetobjs,$t,.s)) \
563 $(foreach t,$(TARGET_PROFILE),$(call targetobjs,$t,.pr)) \
564 $(foreach t,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED),\
565 $(call targetobjs,$t,.pr.s))),$(strip \
566 $(addprefix \n$(obj): ,$(patsubst %.dpe,%.dpi, \
567 $(DPE_$(obj:.o=.c)) $(DPE_$(obj:.o=.cc)) \
568 $(DPE_$(obj:.s.o=.c)) $(DPE_$(obj:.s.o=.cc)) \
569 $(DPE_$(obj:.pr.o=.c)) $(DPE_$(obj:.pr.o=.cc)) \
570 $(DPE_$(obj:.pr.s.o=.c)) $(DPE_$(obj:.pr.s.o=.cc)) \
573 # create the object-dirs
574 @$(if $(OBJDIRS), $(VERBOSE)set -e; for d in $(OBJDIRS); do \
575 [ -d "$$d" ] || $(MKDIR) $$d; done )
578 # write the object-dependencies for the targets
579 @$(ECHO) -e '$(foreach target,$(TARGET),$(strip\
580 \n$(target): $$(OBJS_$(target)) ))' >> $@_
581 # make the target dependent on '.general.d'
582 @$(ECHO) -e '$(foreach target,$(TARGET),$(strip \
583 \n$$(OBJS_$(target)): .general.d))' \
585 # Using LDSO does not need a RELOC address, so omit the following in
587 ifneq ($(MODE),shared)
588 # in case of a binary, write the link address
589 # the dependency to the static file: If DEFAULT_RELOC is set,
590 # all targets are made dependent on the STATIC file
591 # (defined in Makeconf).
592 # If DEFAULT_RELOC_xxx is set, xxx is made dependent on the
594 ifneq ($(strip $(foreach target,$(TARGET), $(call default_reloc,$(target)))),)
595 ifneq ($(filter l4linux host,$(MODE)),)
596 $(error DEFAULT_RELOC must not be set if MODE is l4linux or host)
598 # the relocatable binaries depend on Makefile.inc
599 @$(ECHO) -e '\n$(strip \
600 $(foreach target, $(TARGET), \
601 $(if $(call default_reloc,$(target)),$(target))) \
603 ifneq ($(wildcard $(STATICFILE)),)
604 # Makefile.inc depends on STATIC
605 @$(ECHO) -e '\n$@: $(firstword $(wildcard $(STATICFILE)))' >>$@_
606 # we find out the relocation address here.
607 @$(ECHO) -e '$(foreach target, $(TARGET),$(strip \
608 \nLDFLAGS_$(target)+= -Ttext=__executable_start=$(firstword \
609 $(shell $(AWKP) -v prog=$(target) \
610 "/^[^\#]/{if(\$$2==prog){print $$1; exit}}" \
611 < $(firstword $(wildcard $(STATICFILE)))) \
612 $(call default_reloc,$(target)))))' \
614 # and the dummy-rule to rebuild myself if STATIC disappears
615 @$(ECHO) -e '\n$(firstword $(wildcard $(STATICFILE))): ' >>$@_
617 # STATIC does not exist. rebuild myself if STATIC appears
618 @$(ECHO) -e '\n$$(if $$(wildcard $(STATICFILE)), $@: FORCE)' \
620 # we find out the relocation address here.
621 @$(ECHO) -e '$(foreach target, $(TARGET),$(strip \
622 \nLDFLAGS_$(target)+= --defsym=__executable_start=$(firstword \
623 $(call default_reloc,$(target)))))' \
627 endif # MODE != shared
630 ifeq ($(filter scrub help,$(MAKECMDGOALS)),)
631 -include $(BID_OBJ_Makefile).inc
638 # the default target "all" ensures building of the targets. When multiple
639 # architectures are used, the targets are build in subdirs.
641 # the relink-rule: make the TARGETs phony. Specification of build-targets
642 # in MAKECMDGOALS is not allowed. Possibility: TARGET=
644 ifneq ($(filter relink,$(MAKECMDGOALS)),)
653 # Compilation rules with dependency-generation
655 # If we have ld.so, we use it to create our dependencies (see MAKEDEP
656 # definition). Otherwise, we fall back to whatever we need. For
657 # compilation with gcc, this is using "-MD" and postprocessing the
660 ifeq ($(CONFIG_HAVE_LDSO),)
661 LIBDEPS = $(foreach file, \
662 $(patsubst -l%,lib%.a,$(filter-out -L%,$(LDFLAGS))) \
663 $(patsubst -l%,lib%.so,$(filter-out -L%,$(LDFLAGS))),\
664 $(word 1, $(foreach dir, \
666 $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
667 $(wildcard $(dir)/$(file)))))
669 DEPEND_EXTEND_CMD = $(AWKP) ' \
671 while(sub("\\\\$$","")){ \
673 $$0=$$0 " " nextline \
675 split($$0,field,": "); \
676 sub("^$(*F).o","$*.s $*.i $@",field[1]); \
677 nr=split(field[2],deps) ; \
679 printf("ifeq ($$(shell test y \\\n"); \
680 for(j=0; j<100 && i+j<=nr; j++){ \
681 printf("-a -r %s \\\n", deps[i+j]); \
683 printf("&& echo y),)"); \
684 printf("\n%s: FORCE\nelse\n%s: $(BID_OBJ_Makefile) \\\n", \
685 field[1],field[1]); \
686 for(j=0; j<100 && i+j<=nr; j++){ \
687 printf("%s \\\n",deps[i+j]); \
689 printf("\nendif\n"); \
693 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) )
697 endif # CONFIG_HAVE_LDSO empty
698 DEPFLAGS = -MD -MF $(@D)/.$(@F).d
700 include $(L4DIR)/mk/rules.inc
702 # generate rules to compile %.cc files to %.o, %.s.o etc
703 $(eval $(call BID_GENERATE_CXX_MAKE_RULES,cc))
704 # generate rules to compile %.cpp files to %.o, %.s.o etc
705 $(eval $(call BID_GENERATE_CXX_MAKE_RULES,cpp))
706 # generate rules to compile %.c files to %.o, %.s.o etc
707 $(eval $(call BID_GENERATE_C_MAKE_RULES,c))
708 # generate rules to compile %.S files to %.o, %.s.o etc
709 $(eval $(call BID_GENERATE_DEFAULT_MAKE_RULES,%,%.S,AS))
711 # Reset implicit rules, mind the TAB.
723 $(VERBOSE)$(CONFIG_YACC) $(YFLAGS) $(call absfilename,$<)
724 $(VERBOSE)mv -f y.tab.c $@
725 $(VERBOSE)if [ -f y.tab.h ]; then mv -f y.tab.h $(@:.c=.h); fi
729 $(VERBOSE)$(CONFIG_LEX) -o$@ $(call absfilename,$<)
733 $(VERBOSE)$(CC) -E -H -dD $(CPPFLAGS) $(CFLAGS) $(call absfilename,$<) -o $@
734 $(VERBOSE)$(INDENT) -o $@ $@
735 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
739 $(VERBOSE)$(CC) -E -H -dD $(CPPFLAGS) $(CFLAGS) $(PICFLAGS) $(call absfilename,$<) -o $@
740 $(VERBOSE)$(INDENT) -o $@ $@
741 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
745 $(VERBOSE)$(CXX) -E -H -dD $(CPPFLAGS) $(CXXFLAGS) $(call absfilename,$<) -o $@
746 $(VERBOSE)$(INDENT) -sob -o $@ $@
747 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
751 $(VERBOSE)$(CXX) -E -H -dD $(CPPFLAGS) $(CXXFLAGS) $(PICFLAGS) $(call absfilename,$<) -o $@
752 $(VERBOSE)$(INDENT) -sob -o $@ $@
753 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
757 $(VERBOSE)$(CXX) -E -H -dD $(CPPFLAGS) $(CXXFLAGS) $(call absfilename,$<) -o $@
758 $(VERBOSE)$(INDENT) -sob -o $@ $@
759 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
763 $(VERBOSE)$(CC) -E -H -dD $(CPPFLAGS) $(ASFLAGS) $(call absfilename,$<) -o $@
764 $(VERBOSE)$(INDENT) -sob -o $@ $@
765 $(VERBOSE)$(if $(DO_SHOW_RESULT_FILE),$(PAGER) $@)
769 $(VERBOSE)$(CC) -S $(CFLAGS) $(CPPFLAGS) $(call absfilename,$<) -fverbose-asm -o $@
773 $(VERBOSE)$(CXX) -S $(CXXFLAGS) $(CPPFLAGS) $(call absfilename,$<) -fverbose-asm -o $@
777 $(VERBOSE)$(CXX) -S $(CXXFLAGS) $(CPPFLAGS) $(call absfilename,$<) -fverbose-asm -o $@
781 $(VERBOSE)$(call MAKEDEP,perl) $(GEN_DOPECODE) $< >$@
783 DEPS += $(foreach file,$(ALLOBJS), $(dir $(file)).$(notdir $(file)).d)
784 DEPS += $(foreach file,$(ALLDPI), $(dir $(file)).$(notdir $(file)).d)
789 $(VERBOSE)$(RM) $(strip $(filter-out $(KEEP_ON_CLEAN),\
790 $(wildcard *.dpi) $(wildcard *.o) $(wildcard *.i) \
791 $(wildcard *.S) $(ALLOBJS) $(DEL_ON_CLEAN)))
793 # clean: delete all temporary editor files, objects, binaries
794 # and most generated files
796 $(VERBOSE)$(RM) $(TARGET) $(wildcard .*.d) $(wildcard $(BID_OBJ_Makefile).inc)
798 .PHONY: scrub clean cleanall disasm
800 endif # $(SYSTEM) is defined
804 # scrub: delete temporary editor files and stuff like this
805 # can be extended by lokals