]> rtime.felk.cvut.cz Git - l4.git/blob - l4/mk/binary.inc
39b22a8b413080ea4419e10de46a516e834164b0
[l4.git] / l4 / mk / binary.inc
1 # -*- Makefile -*-
2 # vim:set ft=make:
3 #
4 # DROPS (Dresden Realtime OPerating System) Component
5 #
6 # Makefile-Include for compiling templates (prog.mk, lib.mk)
7
8 # Makefile-Include for binary and lib directories
9 # Definitions for building the Makefile.inc, building dependencies,
10 # compiler configuration.
11 #
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.
17 #
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.
21 #
22 # The relink-rule is defined in this file.
23 #
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.
26 #
27 # Clean-rules are defined here.
28 #
29
30 $(GENERAL_D_LOC): $(L4DIR)/mk/binary.inc $(L4DIR)/mk/modes.inc
31
32 # our default Makefile-name in the OBJ-Subdirs
33 BID_OBJ_Makefile ?= Makefile
34
35 ifeq ($(SYSTEM),) # if we have no system yet, build the subdirs
36 #################################################################
37 #
38 # we have NO system defined in $(SYSTEM), we are in the src/ dir
39 #
40 #################################################################
41
42 # our default systems
43 SYSTEMS ?= $(SYSTEMS_ABI)
44
45 BID_MISSING_PCS := \
46    $(strip $(if $(DEPENDS_PKGS), \
47              $(strip $(foreach i,$(DEPENDS_PKGS),            \
48                        $(if $(strip $(wildcard $(OBJ_BASE)/pc/$(i).pc)),,$(i))))))
49
50 ifneq ($(BID_MISSING_PCS),)
51   # clear SYSTEMS to prevent building anything
52   SYSTEMS =
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)))
55 endif
56
57 # intersection with BUILD_SYSTEMS
58
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)
62 #       $(2) - 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)}\
67                         {for(i=1;i<=NF;i++){\
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}}}')
71
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)
75 #       $(2) - SYSTEMS
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
78 #   SYSTEMS and exit
79 BID_ORIG_SYSTEM = $(shell echo $(2)|$(AWKP) '\
80                     BEGIN{m=s="$(1)";sub("_[^-]*","",m)}\
81                     {for(i=1;i<=NF;i++){\
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}}}}')
86
87 ifeq ($(ROLE),idl.mk)
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))))
91 else
92 TARGET_SYSTEMS := $(sort $(foreach sys,$(BUILD_SYSTEMS),\
93                         $(call FILTER_SYSTEM,$(sys),$(SYSTEMS))))
94 endif
95
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')
100
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)'>>$@
127
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) \
133                         $@ ; done )
134
135 .PHONY: pre-obj
136 pre-obj::
137
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)
142
143
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); \
147                      done, @true)
148
149 %.i %.s.i:: export DO_SHOW_RESULT_FILE=y
150 %.i %.s.i::
151         $(call foreach_objdir,$@)
152
153 clean disasm::
154         $(call foreach_objdir,$@)
155
156 cleanall::
157         $(VERBOSE)$(RM) -r $(wildcard $(OBJ_DIR))
158
159 .PHONY: $(TARGET_SYSTEMS)
160
161 else
162 ###############################################################
163 #
164 # we have a system defined in $(SYSTEM), we are in an OBJ- dir
165 #
166 ###############################################################
167
168 all::           $(TARGET)
169
170 disasm: $(TARGET)
171         $(call DISASM_CMD,$(if $(DABIN),$(DABIN),$<))
172
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
183
184 L4LIBDIR ?=     $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
185                 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
186                 $(OBJ_BASE)/lib \
187                 $(addprefix $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
188                 $(DROPS_STDDIR)/lib/$(ARCH)_$(CPU) \
189                 $(DROPS_STDDIR)/lib
190
191 else
192
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),)
198
199 L4LIBDIR ?=     $(addprefix $(OBJ_BASE)/lib/$(ARCH)_$(CPU)/,$(L4API)) \
200                 $(OBJ_BASE)/lib/$(ARCH)_$(CPU) \
201                 $(OBJ_BASE)/lib
202 endif
203
204 #
205 # Variables Section
206 #
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
214 #
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
221 #
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
229 # architecture.
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.
232 #
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.
236
237 include $(L4DIR)/mk/modes.inc
238
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)))
242
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)")
246 endif
247
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)
257
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)))
263
264 LDFLAGS += $(strip $(LDFLAGS_$(OSYSTEM)) $(LDFLAGS_$@) $(LDFLAGS_$@_$(OSYSTEM)))
265 CARCHFLAGS += $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU))
266
267 # ---------------------------------
268
269 BID_MISSING_LIBS :=
270
271 # call pkg-config, returns __PKGCONFIG_FAILED__ if the call failed
272 # 1: OBJ_BASE
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__))
283
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"))
290
291 BID_PKG_CONFIG_FAILED = $(findstring __PKGCONFIG_FAILED__,$(1))
292
293 ifeq ($(BID_MISSING_PCS),)
294  ifneq ($(SYSTEM),)
295   ifneq ($(REQUIRES_LIBS),)
296    REQUIRES_LIBS_LIST := $(strip $(call BID_PKG_CONFIG,$(OBJ_BASE),--libs,$(REQUIRES_LIBS)))
297    # error handling
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)))
305    endif
306
307    # some sanity check
308    ifneq ($(filter libl4re-vfs,$(REQUIRES_LIBS)),)
309      $(error Never include 'libl4re-vfs'!)
310    endif
311   endif
312
313   BID_PKG_CONFIG_CFLAGS := $(call BID_PKG_CONFIG,$(OBJ_BASE),--cflags, $(REQUIRES_CFLAGS) $(REQUIRES_LIBS))
314
315   # error handling
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")))
322    $(error $(text))
323   endif
324  endif # SYSTEM
325 endif
326
327 # -----------------------
328
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
335 endif
336 endif
337
338 OPTS    ?= -g -O2 -fno-strict-aliasing
339 WARNINGS?= -Wextra -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(WARNINGS_$@)
340
341 ifeq ($(MODE),host)
342 # never cross compile in host mode
343 SYSTEM_TARGET = 
344 CC            = $(HOST_CC)
345 CXX           = $(HOST_CXX)
346 LIBS         += $(REQUIRES_LIBS_LIST)
347 else
348 # no architecture specific flags in host mode
349 LDFLAGS      += $(LDFLAGS_$(ARCH))
350 L4_LIBS      += $(REQUIRES_LIBS_LIST)
351 endif
352
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
357 endif
358 ifneq ($(HOST_LINK),)
359 NO_DEFAULT_RELOC := y
360 endif
361
362 default_reloc_base = $(firstword $(DEFAULT_RELOC_$(1)) \
363                                  $(DEFAULT_RELOC_$(ARCH)) \
364                                  $(DEFAULT_RELOC) \
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))))
370
371 # can be overwritten to get the old mode
372 CFLAGS_C99 ?= -std=gnu99
373
374 ifneq ($(MODE),host)
375 CFLAGS_L4_GENERIC += $(CCXX_FLAGS) $(CARCHFLAGS) $(GCCNOSTACKPROTOPT)
376 endif
377
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)
390 ifdef DEBUG
391 ifeq (,$(filter 0 n N, $(DEBUG)))
392 DEFINES += -DDEBUG
393 endif
394 endif
395
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)
402
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)))
409 ifneq ($(MODE),host)
410 CPPFLAGS+= $(addprefix -I, $(L4INCDIR))
411 endif
412 CPPFLAGS+= $(if $(DEBUG_MODE),$(CPPFLAGS-DEBUG_MODE))
413 CPPFLAGS+= $(LIBCINCDIR)
414
415 ifneq ($(MODE),host)
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
420 endif
421
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)
428
429 PICFLAGS += -fPIC -U__PIC__ -D__PIC__=1
430
431 ifneq ($(MODE),host)
432 ASFLAGS_L4_GENERIC += $(CARCHFLAGS) $(CCXX_FLAGS)
433 endif
434
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)))))
442
443 # implementation of $(CLIENTIDL) and $(SERVERIDL)
444 IDL_TYPE   ?= dice
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.)
450 endif
451 endif
452
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-
456 # variables
457 # arg: 1 - target
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))
466
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)))
475
476 ifneq ($(IDL_ALLCLIENTIDL),)
477 vpath %-client.c $(IDL_PATH)
478 vpath %-client.cc $(IDL_PATH)
479 endif
480 ifneq ($(IDL_ALLSERVERIDL),)
481 vpath %-server.c $(IDL_PATH)
482 vpath %-server.cc $(IDL_PATH)
483 endif
484
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))))
491
492 # generic targetobjs
493 # arg: 1 - target
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)))
503
504 # a helper function to generate the object-files for a given target
505 # arg: 1 - target
506 #      2 - infix between the basename and the .o
507 targetobjs   = $(call targetobjs_gen,$(1),$(2),)
508
509 # special version of targetobjs that shares objects between exception and
510 # non-exception cases, we just need two versions for C++ files
511 # arg: 1 - target
512 #      2 - infix between the basename and the .o or .ne.o
513 targetobjs_ne = $(call targetobjs_gen,$(1),$(2),.ne)
514
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))))))
530
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
534 # for rules.
535 $(BID_OBJ_Makefile).inc: .general.d $(BID_RAM_BASE_DEP)
536         @$(BUILD_MESSAGE)
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)))' >>$@_
573         #
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))      \
587                 ))))' >>$@_
588         #
589         # create the object-dirs
590         @$(if $(OBJDIRS), $(VERBOSE)set -e; for d in $(OBJDIRS); do     \
591                 [ -d "$$d" ] || $(MKDIR) $$d; done )
592
593         #
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))'                   \
600                 >> $@_
601         # Using LDSO does not need a RELOC address, so omit the following in
602         # this case
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
609         # STATIC file.
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)
613 endif
614         # the relocatable binaries depend on Makefile.inc
615         @$(ECHO) -e '\n$(strip                                           \
616                 $(foreach target, $(TARGET),                             \
617                         $(if $(call default_reloc,$(target)),$(target))) \
618                 : $@)' >>$@_
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)))))'     \
623                 >>$@_
624 endif
625 endif # MODE != shared
626         @mv $@_ $@
627
628 ifeq ($(filter scrub help,$(MAKECMDGOALS)),)
629 -include $(BID_OBJ_Makefile).inc
630 endif
631
632 #
633 # Rules Section
634 #
635
636 # the default target "all" ensures building of the targets. When multiple
637 # architectures are used, the targets are build in subdirs.
638
639 # the relink-rule: make the TARGETs phony. Specification of build-targets 
640 # in MAKECMDGOALS is not allowed. Possibility: TARGET=
641 #
642 ifneq ($(filter relink,$(MAKECMDGOALS)),)
643 .PHONY: $(TARGET)
644 relink: all
645 endif
646
647
648
649 ###
650 #
651 # Compilation rules with dependency-generation
652 #
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
656 # generated files.
657
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, \
663                            $(patsubst -L%,%,\
664                            $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
665                       $(wildcard $(dir)/$(file)))))
666
667 DEPEND_EXTEND_CMD = $(AWKP) '                   \
668 /^[^:]*: ..*/{                                  \
669         while(sub("\\\\$$","")){                \
670                 getline nextline ;              \
671                 $$0=$$0 " " nextline            \
672         }                                       \
673         split($$0,field,": ");                  \
674         sub("^$(*F).o","$*.s $*.i $@",field[1]);        \
675         nr=split(field[2],deps) ;               \
676         for(i=1;i<=nr;){                        \
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]); \
680           }                                     \
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]);        \
686           }                                     \
687           printf("\nendif\n");                  \
688           i+=j;                                 \
689         }                                       \
690 }'
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) )
692 DEPEND_FLAG = -MD
693
694 .PHONY: FORCE
695 endif # CONFIG_HAVE_LDSO empty
696 DEPFLAGS = -MD -MF $(@D)/.$(@F).d
697
698 include $(L4DIR)/mk/rules.inc
699
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))
708
709 # Reset implicit rules, mind the TAB.
710 %:      %.c
711         
712
713 %:      %.cc
714         
715
716 %:      %.cpp
717         
718
719 %:      %.S
720         
721
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)))
729
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))))
733
734 %.c:    %.y
735         @$(GEN_MESSAGE)
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
739
740 %.c:    %.l
741         @$(COMP_MESSAGE)
742         $(VERBOSE)$(CONFIG_LEX) -o$@ $(call absfilename,$<)
743
744 %.dpi:  %.dpe
745         @$(GEN_MESSAGE)
746         $(VERBOSE)$(call MAKEDEP,perl) $(GEN_DOPECODE) $< >$@
747
748 DEPS    += $(foreach file,$(ALLOBJS), $(dir $(file)).$(notdir $(file)).d)
749 DEPS    += $(foreach file,$(ALLDPI), $(dir $(file)).$(notdir $(file)).d)
750
751 # Common clean Rules
752
753 clean cleanall::
754         $(VERBOSE)$(RM) $(strip $(filter-out $(KEEP_ON_CLEAN),\
755                 $(wildcard *.dpi) $(wildcard *.o) $(wildcard *.i) \
756                 $(wildcard *.S) $(ALLOBJS) $(DEL_ON_CLEAN)))
757
758 # clean: delete all temporary editor files, objects, binaries
759 #        and most generated files
760 cleanall::
761         $(VERBOSE)$(RM) $(TARGET) $(wildcard .*.d) $(wildcard $(BID_OBJ_Makefile).inc)
762
763 .PHONY: scrub clean cleanall disasm
764
765 endif   # $(SYSTEM) is defined
766
767 # General rules
768
769 # scrub: delete temporary editor files and stuff like this
770 #        can be extended by lokals
771 scrub cleanall::
772         $(VERBOSE)$(SCRUB)
773