1 # Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
3 # (C) Copyright 2003, 2006, 2007, 2008, 2009 by Pavel Pisa - OCERA team member
4 # (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE
6 # Homepage: http://rtime.felk.cvut.cz/omk/
7 # Version: 0.2-91-gaac4278
9 # The OMK build system is distributed under the GNU General Public
10 # License. See file COPYING for details.
13 # Version for system-less builds. #OMK:sysless.omk
16 # input variables #OMK:base.omk
17 # V .. if set to 1, full command text is shown else short form is used
18 # W .. whole tree - if set to 1, make is always called from the top-level directory
19 # SUBDIRS .. list of subdirectories intended for make from actual directory
20 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
21 # LN_HEADERS .. if "y", header files are symbolicaly linked instead of copied. #OMK:include.omk
22 # bin_PROGRAMS .. list of the require binary programs #OMK:sysless.omk
23 # test_PROGRAMS .. list of the test programs
24 # include_HEADERS .. list of the user-space public header files
25 # lib_LIBRARIES .. list of the user-space libraries
26 # lib_LDSCRIPTS .. list of LD scripts that should be copied to the lib direcotry
27 # lib_obj_SOURCES .. list of source files which should be compiled and
28 # the produced object file placed to the lib directory (e.g. crt0.S)
29 # shared_LIBRARIES .. list of the user-space shared libraries
30 # nobase_include_HEADERS .. public headers copied even with directory part
31 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
32 # utils_PROGRAMS .. list of the development utility programs (compiled for host computer, this might change in future)
33 # xxx_SOURCES .. list of specific target sources
34 # xxx_LIBS .. list of specific target libraries
35 # INCLUDES .. additional include directories and defines for user-space
36 # lib_LOADLIBES .. list of libraries linked to each executable
37 # link_VARIANTS .. list of ld script suffixes (after hypen `-') that
38 # should be used for linking (e.g. ram flash). If this is not
39 # specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
40 # PREFIX_DIR .. Prefix to directories in _compiled and _build. Used in config.omk.
41 # TARGET_STDSTARTFILES .. if left unset or set to `n', startup file provided
42 # by compiler is supressed
43 # LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK:config_h.omk
44 # of options defined in the current directory
45 # config_include_HEADERS .. names of global config files (possibly
46 # with subdirectories)
47 # xxx_DEFINES .. list of config directives to be included in
48 # config header file of the name <somedir>/xxx.h
49 # DOXYGEN .. if non-empty, generated headers includes Doxygen's @file
50 # command, so it is possible to document config
52 # local_EVALUATE .. Makefile hook, which is executed at the end of #OMK:localeval.omk
53 # the Makefile.rules. Used only for dirty hacks.
54 OMK_RULES_TYPE=sysless #OMK:Makefile.rules.sysless@
55 #OMK:base.omk@Makefile.rules.sysless
56 # If we are not called by OMK leaf Makefile...
58 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
61 # The $(SED4OMK) command for BSD based systems requires -E option to allow
62 # extended regular expressions
65 ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
66 SED4OMK := $(SED4OMK) -E
67 ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
70 ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
73 ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
74 $(error No SED program suitable for OMK found)
78 # OUTPUT_DIR is the place where _compiled, _build and possible other
79 # files/directories are created. By default is the same as
82 OUTPUT_DIR := $(MAKERULES_DIR)
85 # We need to ensure definition of sources directory first
87 # Only shell built-in pwd understands -L
88 SOURCES_DIR := $(shell ( pwd -L ) )
89 INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
90 INVOCATION_DIR := $(INVOCATION_DIR:/%=%)
91 INVOCATION_DIR := $(INVOCATION_DIR:\\%=%)
94 .PHONY: all default check-make-ver print-hints omkize
97 ifeq ("$(origin W)", "command line")
101 ifndef OMK_WHOLE_TREE
105 ifneq ($(OMK_WHOLE_TREE),1)
106 all: check-make-ver print-hints default
107 @echo "Compilation finished"
109 # Run make in the top-level directory
111 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
114 # omk-get-var target allows external scripts/programs to determine the
115 # values of OMK variables such as RELATIVE_DIR etc.
118 @$(foreach var,$(VAR),echo $(var)=$($(var));)
120 #=========================
121 # Include the config file
124 CONFIG_FILE := $(OUTPUT_DIR)/config.omk
127 $(CONFIG_FILE)-default:
128 $(MAKE) default-config
130 ifeq ($(MAKECMDGOALS),default-config)
131 export DEFAULT_CONFIG_PASS=1
134 ifneq ($(DEFAULT_CONFIG_PASS),1)
135 include $(CONFIG_FILE)-default
138 -include $(OUTPUT_DIR)/config.target
140 ifneq ($(wildcard $(CONFIG_FILE)),)
141 -include $(CONFIG_FILE)
145 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
148 export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
149 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
150 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
151 # must to be serialized only in the toplevel make.
154 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
156 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
157 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
158 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
159 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
160 #override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
161 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
163 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
164 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
165 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
167 # We have to use RELATIVE_PREFIX because of mingw
168 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
169 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
171 #vpath %.c $(SOURCES_DIR)
172 #vpath %.cc $(SOURCES_DIR)
173 #vpath %.cxx $(SOURCES_DIR)
175 # Define srcdir for Automake compatibility
176 srcdir = $(SOURCES_DIR)
178 # Defines for quiet compilation
180 ifeq ("$(origin V)", "command line")
187 ifneq ($(OMK_VERBOSE),0)
192 ifneq ($(findstring s,$(MAKEFLAGS)),)
193 QUIET_CMD_ECHO = true
196 QUIET_CMD_ECHO = echo
199 MAKEFILE_OMK=Makefile.omk
200 # All subdirectories (even linked ones) containing Makefile.omk
201 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
202 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
204 # ===================================================================
205 # We have set up all important variables, so we can check and include
206 # real OCERA style Makefile.omk now
208 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
209 ifeq ($(AUTOMATIC_SUBDIRS),y)
210 SUBDIRS?=$(ALL_OMK_SUBDIRS)
216 @echo 'Use "make V=1" to see the verbose compile lines.'
219 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
220 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
221 echo "Your make program version is too old and does not support OMK system." ; \
222 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
225 distclean dist-clean:
226 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
227 @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
229 # Common OMK templates
230 # ====================
232 # Syntax: $(call mkdir,<dir name>)
234 [ -d $(1) ] || mkdir -p $(1) || exit 1
237 ifneq ($(OMK_VERBOSE),2)
238 NO_PRINT_DIRECTORY := --no-print-directory
241 ifeq ($(USE_LEAF_MAKEFILES),n)
242 export USE_LEAF_MAKEFILES
243 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
244 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
246 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
247 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
254 # Call a pass in a subdirectory
255 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
256 define omk_pass_subdir_template
257 .PHONY: $(pass)-$(3)-subdir
258 $(pass)-submakes: $(pass)-$(3)-subdir
259 $(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
261 @$(call mkdir_def,$(2)/$(3))
262 +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
263 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
264 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
265 # In subdirectories we can call submakes directly since passes are
266 # already serialized on the toplevel make.
270 check-target = $(1:%=%-check)
273 # Call a pass in a subdirectory
274 # Usage: $(call extra_rules_subdir_template,<subdir>)
275 define extra_rules_subdir_template
276 extra-rules-subdirs: extra-rules-$(1)
278 +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
279 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
282 .PHONY: extra-rules-subdirs
285 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
287 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
288 define omk_pass_template
289 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
290 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
292 # Submakes have to be called this way and not as dependecies for pass
293 # serialization to work
294 +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
295 RELATIVE_DIR=$(RELATIVE_DIR) \
296 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
298 @true # Do not emit "nothing to be done" messages
300 ifneq ($(4)$($(pass)_HOOKS),)
301 $(pass)-submakes: $(pass)-this-dir
302 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
303 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
304 @$(call mkdir_def,$(2))
305 +@$(MAKE) --no-builtin-rules $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
306 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
307 $(pass)-local: $($(pass)_HOOKS)
311 # =======================
312 # DEFAULT CONFIG PASS
315 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
316 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
317 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
318 @echo >> "$(CONFIG_FILE)-default"
319 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
320 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
321 -f $(OUTPUT_DIR)/Makefile default-config-pass
323 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
325 default-config-pass-local:
326 # @echo Default config for $(RELATIVE_DIR)
327 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
328 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
329 $(SED4OMK) -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
333 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
334 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
336 $(Q)for i in `find -L . -name Makefile.omk` ; do \
338 if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \
339 rm -f "$${d}/Makefile"; \
340 cp -v Makefile "$${d}/Makefile"; \
343 #OMK:gcc.omk@Makefile.rules.sysless
344 # Rules for compilation of C, C++ and assembler sources using GNU
347 # Interface to other rules:
350 # LIB_DIR - directory where compiled libraries are stored
351 # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
352 # INCLUDE_DIR - where includes can be found
353 # from config.omk or Makefile.omk
355 # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
356 # from base: SOURCES_DIR
357 # from Makefile.omk: lib_LOADLIBES
360 # SOURCES - all the source files that needs to be compiled (except for shared library sources)
361 # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
362 # OBJ_EXT - extension of object files
363 # LIB_EXT - extension of library files
364 # LIB_PREF - prefix for library files
365 # ASM_EXT - extension of assembler sources
368 # COMPILER_DEFS_template - definitions that should be defined before
369 # the following templates can be used. The input variables needs to be
370 # defined before evaluating this template
372 # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
373 # templates that create rules for compilation of sources
375 # CMETRIC_o_h_template - FIXME
377 # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
378 # create rules for compilation of a program, library and shared
379 # library. The rules can use rules produced by COMPILE_xxx_template.
381 define COMPILER_DEFS_template
387 CC = $(CROSS_COMPILE)gcc
388 LINK = $(CROSS_COMPILE)ld
389 AR = $(CROSS_COMPILE)ar
390 OBJCOPY = $(CROSS_COMPILE)objcopy
391 NM = $(CROSS_COMPILE)nm
393 CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE)
395 CFLAGS += -I$(SOURCES_DIR)
396 CFLAGS += -I$(INCLUDE_DIR)
398 LOADLIBES += -L$(LIB_DIR)
399 LOADLIBES += $(lib_LOADLIBES:%=-l%)
402 -include $(OBJS_DIR)/*.d
404 SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.S .o/.o
406 SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.lo
409 # $(CC) -o $@ $(LCFLAGS) -c $<
411 c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
412 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
414 cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
415 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
417 S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
418 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS)
421 # Check GCC version for user build
422 ifndef CC_MAJOR_VERSION
423 CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
425 # Prepare suitable define for dependency building
426 ifeq ($$(CC_MAJOR_VERSION),2)
427 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
429 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
432 endef # COMPILER_DEFS_template
435 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
436 define COMPILE_c_o_template
437 $(2): $(1) $$(GEN_HEADERS)
438 @$(QUIET_CMD_ECHO) " CC $$@"
439 $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
440 then mv -f "$$@.d.tmp" "$$@.d" ; \
441 else rm -f "$$@.d.tmp" ; exit 1; \
447 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
448 define COMPILE_cc_o_template
449 $(2): $(1) $$(GEN_HEADERS)
450 @$(QUIET_CMD_ECHO) " CXX $$@"
451 $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
452 then mv -f "$$@.d.tmp" "$$@.d" ; \
453 else rm -f "$$@.d.tmp" ; exit 1; \
457 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
458 define COMPILE_S_o_template
459 $(2): $(1) $$(GEN_HEADERS)
460 @$(QUIET_CMD_ECHO) " AS $$@"
461 $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
462 then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
463 else rm -f "$$@.d.tmp" ; exit 1; \
467 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
468 define CMETRIC_o_h_template
470 @$(QUIET_CMD_ECHO) " CMETRIC $$@"
471 $(Q)if [ -n `dirname $$@` ] ; then \
472 if [ ! -e `dirname $$@` ] ; then \
473 mkdir -p `dirname $$@` ; fi ; fi
474 $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
475 $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
476 # Bellow, the tricks with redirection are for shells without set -o pipefail
477 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
478 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
479 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
480 | sort >>$$@.tmp` && exit $$$$status
481 $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
482 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
483 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
484 | sort >>$$@.tmp` && exit $$$$status
485 $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
486 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
487 | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
488 | sort >>$$@.tmp` && exit $$$$status
492 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
493 define PROGRAM_template
495 GEN_SOURCES += $$($(1)_GEN_SOURCES)
497 $(foreach x, $(SOURCES2OBJS),
498 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
499 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
501 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
503 SOURCES += $$($(1)_SOURCES)
505 ifneq ($(LD_SCRIPT),)
506 $(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%)
509 $(2)/$(1)$(3:%=-%): $$($(1)_OBJS)
510 @$(QUIET_CMD_ECHO) " LINK $$@"
511 $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
512 then echo $$(CC) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
513 else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
514 $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \
515 $$($(1)_OBJS) $$($(1)_MOREOBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
517 @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
518 @if [ -n "$(LD_SCRIPT)" ]; then \
519 echo " $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi
520 @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(OBJS_DIR)/$(1)$(3:%=-%).map|tr '&' '\134' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
521 @echo >>$(OBJS_DIR)/$(1).exe.d
524 # Rules for other output formats (can be specified by OUTPUT_FORMATS)
526 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
527 $(Q) $(OBJCOPY) --output-target=binary -S $< $@
530 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
531 $(Q) $(OBJCOPY) --output-target=ihex -S $< $@
534 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
535 $(Q) $(OBJCOPY) --output-target=srec -S $< $@
537 # Syntax: $(call LIBRARY_template,<library-name>)
538 define LIBRARY_template
540 GEN_SOURCES += $$($(1)_GEN_SOURCES)
542 $(foreach x, $(SOURCES2OBJS),
543 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
544 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
546 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
548 SOURCES += $$($(1)_SOURCES)
550 $(LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
551 @$(QUIET_CMD_ECHO) " AR $$@"
552 $(Q) $(AR) rcs $$@ $$^
556 # Syntax: $(call SOLIB_template,<library-name>)
557 define SOLIB_template
559 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
561 $(foreach x, $(SOURCES2OBJSLO),
562 $(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
563 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
565 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
567 SOLIB_OBJS += $$($(1)_OBJSLO)
568 SOLIB_SOURCES += $$($(1)_SOURCES)
570 $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
571 @$(QUIET_CMD_ECHO) " LINK $$@"
572 $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
574 ifeq ($(OMK_VERBOSE),1) #OMK:include.omk@Makefile.rules.sysless
579 ifneq ($(LN_HEADERS),y)
581 if ! cmp --quiet $(1) $(2); then \
582 echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
583 install -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
588 if ! cmp --quiet $(1) $(2); then \
589 echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
590 if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \
595 # TODO: Check modification date of changed header files. If it is
596 # newer that in source dir, show a warning.
598 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
599 define include-pass-template
600 include-pass-local: include-pass-local-$(2)
601 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell f='$$(f)'; echo $$$${f%->*}))
602 @$$(foreach f, $$($(2)_HEADERS),$$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
603 # FIXME: Use correct build dir, then document it (in the line bellow)
604 @$$(foreach f, $$($(2)_GEN_HEADERS),$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
605 @$$(foreach f, $$(nobase_$(2)_HEADERS), $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)); )
606 @$$(foreach f, $$(renamed_$(2)_HEADERS), \
607 f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
608 $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
609 @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
610 f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
611 $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
612 # Suppress "Nothing to be done for `include-pass-local'" message if no headers are defined in Makefile.omk
613 @$$(if $$($(2)_HEADERS)$$($(2)_GEN_HEADERS)$$(nobase_$(2)_HEADERS)$$(renamed_$(2)_HEADERS)$$(renamed_$(2)_GEN_HEADERS),,true)
615 #OMK:sysless.omk@Makefile.rules.sysless
616 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
617 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
619 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
620 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
622 #=====================================================================
623 # Common utility rules
625 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
628 #=====================================================================
629 # Include correct rules for just running pass
631 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
633 USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
634 USER_LIB_DIR = $(USER_COMPILED_DIR_NAME)/lib
635 USER_UTILS_DIR = $(USER_COMPILED_DIR_NAME)/bin-utils
636 USER_TESTS_DIR = $(USER_COMPILED_DIR_NAME)/bin-tests
637 USER_BIN_DIR = $(USER_COMPILED_DIR_NAME)/bin
638 USER_OBJS_DIR = $(LOCAL_BUILD_DIR)
642 # Some support to serialize some targets for parallel make
643 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
644 include-pass: check-dir
645 library-pass: include-pass
646 binary-pass utils-pass: library-pass
648 override OMK_SERIALIZE_INCLUDED = y
649 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
652 # -------------------------------------
653 # Rules for compilation for target
654 ifdef TARGET_RULE_TEMPLATES
656 ifeq ($(TARGET_STDSTARTFILES),)
657 TARGET_STDSTARTFILES=n
660 ifneq ($(TARGET_STDSTARTFILES),y)
661 LDFLAGS += -nostartfiles
662 ifneq ($(TARGET_STDSTARTFILES),n)
663 LDFLAGS += $(TARGET_STDSTARTFILES)
667 # FIXME: These are not used. What they are good for?
668 LIB_CPPFLAGS += $(CPPFLAGS)
669 LIB_CFLAGS += $(CFLAGS)
671 SOLIB_PICFLAGS += -shared -fpic
673 CFLAGS += -DOMK_FOR_TARGET
675 INCLUDE_DIR := $(USER_INCLUDE_DIR)
676 LIB_DIR := $(USER_LIB_DIR)
677 OBJS_DIR := $(USER_OBJS_DIR)
679 $(eval $(COMPILER_DEFS_template))
681 # Special rules for CMETRIC generated headers
683 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
684 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
685 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
686 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
687 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
688 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
690 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
692 # Generate rules for compilation of programs and libraries
693 ifneq ($(link_VARIANTS),)
694 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
695 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
697 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
698 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
701 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
702 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
703 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
706 # lib_obj_SOURCES handling
707 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
708 #$(warning lib_OBJS = $(lib_OBJS))
709 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
711 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
712 @echo " CP $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
713 $(Q)cp $(CP_FLAGS) $< $@
716 # User-space static libraries and applications object files
717 SOURCES := $(sort $(SOURCES))
718 #$(warning SOURCES = $(SOURCES))
719 GEN_SOURCES := $(sort $(GEN_SOURCES))
721 # User-space shared libraries object files
722 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
723 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
724 SOLIB_GEN_SOURCES := $(sort $(SOLIB_GEN_SOURCES))
726 # Create _build directories for sources in subdirectories i.e. *_SOURCES=dir/file.c
727 _dirs_to_create=$(filter-out ./,$(sort $(dir $(SOURCES) $(SOLIB_SOURCES))))
728 ifneq ($(_dirs_to_create),)
729 $(shell mkdir -p $(addprefix $(LOCAL_BUILD_DIR)/,$(_dirs_to_create)))
732 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
733 # variables. Now generate rules for compilation of theese sources
734 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
735 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
736 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
737 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
738 $(foreach src,$(filter %.c,$(GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
740 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
741 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
742 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
743 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
744 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
746 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
747 $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
748 $(addprefix $(LIB_DIR)/,$(lib_OBJS))
750 ifneq ($(link_VARIANTS),)
751 binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
752 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
754 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
755 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
758 endif # TARGET_RULE_TEMPLATES
761 # -------------------------------------
762 # Rules for compilation utilities for host (user space)
763 ifdef HOST_RULE_TEMPLATES
768 SOLIB_PICFLAGS += -shared -fpic
770 # For host compilation, we don't use a specfic ld script
773 # TODO: It is probably better to use different directories for host
774 # includes, libraries and objects
775 INCLUDE_DIR := $(USER_INCLUDE_DIR)
776 LIB_DIR := $(USER_LIB_DIR)
777 OBJS_DIR := $(USER_OBJS_DIR)
779 $(eval $(COMPILER_DEFS_template))
781 #User-space static libraries and applications object files
782 #SOURCES := $(sort $(SOURCES))
783 #$(warning SOURCES = $(SOURCES))
785 # Generate rules for compilation of utility programs
786 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
788 # The above generated rule produced $(SOURCES) variable. Now generate
789 # rules for compilation of theese sources
790 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
791 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
792 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
793 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
795 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
797 endif # HOST_RULE_TEMPLATES
799 #=====================================================================
800 # Automatic loading of compiled program by issuing "make load"
802 ifneq ($(OUTPUT_FORMATS),)
803 # Select a file extension (e.g. .bin) for "make load" command to load.
804 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
807 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
808 # Used to load program to the target hardware
809 define LOAD_PROGRAM_template
810 .PHONY: load-$(1)$(3:%=-%)
811 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(if $(LOAD_EXTENSION-$(3)),$(LOAD_EXTENSION-$(3)),$(LOAD_EXTENSION))
812 @$(QUIET_CMD_ECHO) " LOAD $$<"
813 @if [ -z '$$(LOAD_CMD$(3:%=-%))' ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
814 $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
817 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
818 # Used to load and/or run non-default variant of the default program
819 define LOAD_RUN_VARIANT_template
820 .PHONY: load-$(1) run-$(1)
822 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
825 @$(QUIET_CMD_ECHO) " RUN $(1)"
826 @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
831 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
832 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
833 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
836 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
838 run: run-$(firstword $(link_VARIANTS))
842 #=====================================================================
843 # Generate pass rules from generic templates
845 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
846 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
847 $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
848 $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
849 $(eval $(call omk_pass_template, dep, $(LOCAL_BUILD_DIR),,always))
850 $(eval $(call omk_pass_template, clean, $(LOCAL_BUILD_DIR),,always))
851 $(eval $(call omk_pass_template, install,$(LOCAL_BUILD_DIR),,always))
858 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
861 @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
862 || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
866 clean-local: clean-custom
867 $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
868 $(USER_OBJS_DIR)/*.d \
869 $(USER_OBJS_DIR)/*.map \
870 $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
873 @$(call mkdir_def,$(USER_INCLUDE_DIR))
874 @$(call mkdir_def,$(USER_LIB_DIR))
875 @$(call mkdir_def,$(USER_BIN_DIR))
876 @$(call mkdir_def,$(USER_UTILS_DIR))
877 @$(call mkdir_def,$(USER_TESTS_DIR))
879 include-pass-submakes: extra-rules-subdirs
880 # Which passes to pass
881 default: include-pass library-pass binary-pass utils-pass
882 #OMK:config_h.omk@Makefile.rules.sysless
883 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
884 define BUILD_CONFIG_H_template
886 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
887 @$(QUIET_CMD_ECHO) " CONFGEN $(notdir $(2))"
888 @if [ ! -d `dirname $(2).tmp` ] ; then \
889 mkdir -p `dirname $(2).tmp` ; fi
890 @echo "/* Automatically generated from */" > "$(2).tmp"
891 @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
892 $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
893 @echo "#ifndef $(4)" >> "$(2).tmp"
894 @echo "#define $(4)" >> "$(2).tmp"
895 @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | $(SED4OMK) -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
896 echo '$(x).$($(x))' ; ) echo ; ) | \
897 $(SED4OMK) -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
898 $(SED4OMK) -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
900 @echo "#endif /*$(4)*/" >> "$(2).tmp"
902 @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
903 else mv "$(2).tmp" "$(2)" ; \
904 echo "Updated configuration $(2)" ; fi
910 # This must be declared after the default cflags are assigned!
911 # Override is used to override command line assignemnt.
912 override CFLAGS += -I $(USER_OBJS_DIR)
913 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
914 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
918 # Special rules for configuration exported headers
920 #FIXME: The directory for headers should not be specified here.
921 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
922 _$(basename $(notdir $(confh)))_H \
925 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
927 # Add some hooks to standard passes
928 include-pass-local: $(config_h_stamp_files)
930 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
933 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
936 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
937 _$(basename $(notdir $(confh)))_H \
940 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
942 # Add some hooks to standard passes
943 include-pass-local: $(kern_config_h_stamp_files)
947 clean-local: clean-local-config-h
949 clean-local-config-h:
950 @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
951 if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
953 #OMK:sources-list.omk@Makefile.rules.sysless
954 # Rules that creates the list of files which are used during
955 # compilation. The list reflects conditional compilation depending on
956 # config.omk and other variables.
958 SOURCES_LIST_FN=sources.txt
960 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
961 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
962 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
963 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
966 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
970 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
972 sources-list: $(SOURCES_LIST)
974 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
975 @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
976 @echo -n "" > "$(SOURCES_LIST).tmp"
977 @echo -n "" > "$(SOURCES_LIST_D).tmp"
978 @$(MAKE) --no-print-directory sources-list-pass
979 @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
980 @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
981 @rm "$(SOURCES_LIST).tmp"
982 @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
983 @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
984 @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
985 $(SED4OMK) -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
986 @rm "$(SOURCES_LIST_D).tmp"
987 @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
990 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
992 sources-list-pass-local:
993 @$(foreach m,$(MAKEFILE_LIST),echo ' $(m)' >> "$(SOURCES_LIST_D).tmp";)
994 @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
995 echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
996 @$(foreach ch,$(config_include_HEADERS), \
997 echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
998 @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|$(SED4OMK) -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
999 @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
1000 $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
1001 $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
1003 ############ TAGS ###########
1005 ifeq ($(MAKECMDGOALS),TAGS)
1008 TAGS: $(SOURCES_LIST)
1009 @$(MAKE) --no-print-directory do-tags
1011 ifeq ($(MAKECMDGOALS),tags)
1014 tags: $(SOURCES_LIST)
1015 @$(MAKE) --no-print-directory do-tags
1019 ifeq ($(MAKECMDGOALS),do-tags)
1021 do-tags: $(shell $(SED4OMK) -e '/^\#/d' $(SOURCES_LIST))
1022 @$(QUIET_CMD_ECHO) " TAGS $(SOURCES_LIST_FN)"
1026 ############ CSCOPE ###########
1028 cscope: $(SOURCES_LIST)
1029 @$(QUIET_CMD_ECHO) " CSCOPE < $(SOURCES_LIST_FN)"
1030 $(Q)$(SED4OMK) -e '/^#/d' $(SOURCES_LIST) > cscope.files
1031 $(Q)cscope -b -icscope.files
1032 #FIXME: see doc to -i in cscope(1)
1033 #OMK:localeval.omk@Makefile.rules.sysless
1034 ifneq ($(local_EVALUATE),)
1035 #$(warning $(local_EVALUATE))
1036 $(eval $(local_EVALUATE))