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 by Michal Sojka - Czech Technical University, FEE, DCE
6 # Homepage: http://rtime.felk.cvut.cz/omk/
7 # Version: 0.2-6-g3d689d6
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 # LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK:config_h.omk
42 # of options defined in the current directory
43 # config_include_HEADERS .. names of global config files (possibly
44 # with subdirectories)
45 # xxx_DEFINES .. list of config directives to be included in
46 # config header file of the name <somedir>/xxx.h
47 # DOXYGEN .. if non-empty, generated headers includes Doxygen's @file
48 # command, so it is possible to document config
50 # local_EVALUATE .. Makefile hook, which is executed at the end of #OMK:localeval.omk
51 # the Makefile.rules. Used only for dirty hacks.
52 OMK_RULES_TYPE=sysless #OMK:Makefile.rules.sysless@
53 #OMK:base.omk@Makefile.rules.sysless
54 # If we are not called by OMK leaf Makefile...
56 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
59 # OUTPUT_DIR is the place where _compiled, _build and possible other
60 # files/directories are created. By default is the same as
63 OUTPUT_DIR := $(MAKERULES_DIR)
66 # We need to ensure definition of sources directory first
68 # Only shell built-in pwd understands -L
69 SOURCES_DIR := $(shell ( pwd -L ) )
70 INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
71 INVOCATION_DIR := $(INVOCATION_DIR:/%=%)
72 INVOCATION_DIR := $(INVOCATION_DIR:\\%=%)
75 .PHONY: all default check-make-ver omkize
78 ifeq ("$(origin W)", "command line")
86 ifneq ($(OMK_WHOLE_TREE),1)
87 all: check-make-ver default
88 @echo "Compilation finished"
90 # Run make in the top-level directory
92 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
96 # Usage: $(call canttest,<error message>)
98 ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
106 #=========================
107 # Include the config file
109 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
110 # config files and it is not clearly defined to which file is this
112 ifneq ($(CONFIG_FILE_OK),y)
114 CONFIG_FILE := $(OUTPUT_DIR)/config.omk
116 ifneq ($(wildcard $(CONFIG_FILE)-default),)
117 -include $(CONFIG_FILE)-default
119 ifneq ($(MAKECMDGOALS),default-config)
120 $(warning Please, run "make default-config" first)
124 -include $(OUTPUT_DIR)/config.target
126 ifneq ($(wildcard $(CONFIG_FILE)),)
127 -include $(CONFIG_FILE)
130 endif #$(CONFIG_FILE_OK)
133 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
136 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
137 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
138 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
139 # must to be serialized only in the toplevel make.
142 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
144 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
145 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
146 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
147 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
148 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
149 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
151 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
152 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
153 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
155 # We have to use RELATIVE_PREFIX because of mingw
156 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
157 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
159 #vpath %.c $(SOURCES_DIR)
160 #vpath %.cc $(SOURCES_DIR)
161 #vpath %.cxx $(SOURCES_DIR)
163 # Define srcdir for Automake compatibility
164 srcdir = $(SOURCES_DIR)
166 # Defines for quiet compilation
168 ifeq ("$(origin V)", "command line")
175 ifneq ($(OMK_VERBOSE),0)
180 ifneq ($(findstring s,$(MAKEFLAGS)),)
181 QUIET_CMD_ECHO = true
184 QUIET_CMD_ECHO = echo
187 MAKEFILE_OMK=Makefile.omk
188 # All subdirectories (even linked ones) containing Makefile.omk
189 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
190 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
192 # ===================================================================
193 # We have set up all important variables, so we can check and include
194 # real OCERA style Makefile.omk now
196 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
197 ifeq ($(AUTOMATIC_SUBDIRS),y)
198 SUBDIRS?=$(ALL_OMK_SUBDIRS)
204 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
205 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
206 echo "Your make program version is too old and does not support OMK system." ; \
207 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
210 distclean dist-clean:
211 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
212 @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
214 # Common OMK templates
215 # ====================
217 # Syntax: $(call mkdir,<dir name>)
219 [ -d $(1) ] || mkdir -p $(1) || exit 1
222 ifneq ($(OMK_VERBOSE),2)
223 NO_PRINT_DIRECTORY := --no-print-directory
226 ifeq ($(USE_LEAF_MAKEFILES),n)
227 export USE_LEAF_MAKEFILES
228 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
229 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
231 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
232 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
239 # Call a pass in a subdirectory
240 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
241 define omk_pass_subdir_template
242 .PHONY: $(pass)-$(3)-subdir
243 $(pass)-submakes: $(pass)-$(3)-subdir
244 $(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
246 @$(call mkdir_def,$(2)/$(3))
247 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
248 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
249 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
250 # In subdirectories we can call submakes directly since passes are
251 # already serialized on the toplevel make.
255 check-target = $(1:%=%-check)
258 # Call a pass in a subdirectory
259 # Usage: $(call extra_rules_subdir_template,<subdir>)
260 define extra_rules_subdir_template
261 extra-rules-subdirs: extra-rules-$(1)
263 +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
264 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
267 .PHONY: extra-rules-subdirs
270 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
272 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
273 define omk_pass_template
274 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
275 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
277 # Submakes have to be called this way and not as dependecies for pass
278 # serialization to work
279 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
280 RELATIVE_DIR=$(RELATIVE_DIR) \
281 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
283 @true # Do not emit "nothing to be done" messages
285 ifneq ($(4)$($(pass)_HOOKS),)
286 $(pass)-submakes: $(pass)-this-dir
287 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
288 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
289 @$(call mkdir_def,$(2))
290 +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
291 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
292 $(pass)-local: $($(pass)_HOOKS)
296 # =======================
297 # DEFAULT CONFIG PASS
300 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
301 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
302 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
303 @echo >> "$(CONFIG_FILE)-default"
304 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
305 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
306 -f $(OUTPUT_DIR)/Makefile default-config-pass
308 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
310 default-config-pass-local:
311 # @echo Default config for $(RELATIVE_DIR)
312 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
313 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
314 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
318 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
319 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
321 $(Q)for i in `find -L . -name Makefile.omk` ; do \
323 if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \
324 rm -f "$${d}/Makefile"; \
325 cp -v Makefile "$${d}/Makefile"; \
328 #OMK:gcc.omk@Makefile.rules.sysless
329 # Rules for compilation of C, C++ and assembler sources using GNU
332 # Interface to other rules:
335 # LIB_DIR - directory where compiled libraries are stored
336 # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
337 # INCLUDE_DIR - where includes can be found
338 # from config.omk or Makefile.omk
340 # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
341 # from base: SOURCES_DIR
342 # from Makefile.omk: lib_LOADLIBES
345 # SOURCES - all the source files that needs to be compiled (except for shared library sources)
346 # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
347 # OBJ_EXT - extension of object files
348 # LIB_EXT - extension of library files
349 # LIB_PREF - prefix for library files
350 # ASM_EXT - extension of assembler sources
353 # COMPILER_DEFS_template - definitions that should be defined before
354 # the following templates can be used. The input variables needs to be
355 # defined before evaluating this template
357 # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
358 # templates that create rules for compilation of sources
360 # CMETRIC_o_h_template - FIXME
362 # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
363 # create rules for compilation of a program, library and shared
364 # library. The rules can use rules produced by COMPILE_xxx_template.
366 define COMPILER_DEFS_template
372 CC = $(CROSS_COMPILE)gcc
373 LINK = $(CROSS_COMPILE)ld
374 AR = $(CROSS_COMPILE)ar
375 OBJCOPY = $(CROSS_COMPILE)objcopy
376 NM = $(CROSS_COMPILE)nm
378 CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE)
380 CFLAGS += -I$(SOURCES_DIR)
381 CFLAGS += -I$(INCLUDE_DIR)
383 LOADLIBES += -L$(LIB_DIR)
384 LOADLIBES += $(lib_LOADLIBES:%=-l%)
387 -include $(OBJS_DIR)/*.d
389 SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.S .o/.o
391 SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.lo
394 # $(CC) -o $@ $(LCFLAGS) -c $<
396 c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
397 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
399 cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
400 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
402 S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
403 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS)
406 # Check GCC version for user build
407 ifndef CC_MAJOR_VERSION
408 CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
410 # Prepare suitable define for dependency building
411 ifeq ($$(CC_MAJOR_VERSION),2)
412 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
414 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
417 endef # COMPILER_DEFS_template
420 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
421 define COMPILE_c_o_template
422 $(2): $(1) $$(GEN_HEADERS)
423 @$(QUIET_CMD_ECHO) " CC $$@"
424 $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
425 then mv -f "$$@.d.tmp" "$$@.d" ; \
426 else rm -f "$$@.d.tmp" ; exit 1; \
432 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
433 define COMPILE_cc_o_template
434 $(2): $(1) $$(GEN_HEADERS)
435 @$(QUIET_CMD_ECHO) " CXX $$@"
436 $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
437 then mv -f "$$@.d.tmp" "$$@.d" ; \
438 else rm -f "$$@.d.tmp" ; exit 1; \
442 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
443 define COMPILE_S_o_template
444 $(2): $(1) $$(GEN_HEADERS)
445 @$(QUIET_CMD_ECHO) " AS $$@"
446 $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
447 then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
448 else rm -f "$$@.d.tmp" ; exit 1; \
452 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
453 define CMETRIC_o_h_template
455 @$(QUIET_CMD_ECHO) " CMETRIC $$@"
456 $(Q)if [ -n `dirname $$@` ] ; then \
457 if [ ! -e `dirname $$@` ] ; then \
458 mkdir -p `dirname $$@` ; fi ; fi
459 $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
460 $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
461 # Bellow, the tricks with redirection are for shells without set -o pipefail
462 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
463 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
464 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
465 | sort >>$$@.tmp` && exit $$$$status
466 $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
467 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
468 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
469 | sort >>$$@.tmp` && exit $$$$status
470 $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
471 $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
472 | sed -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
473 | sort >>$$@.tmp` && exit $$$$status
477 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
478 define PROGRAM_template
480 GEN_SOURCES += $$($(1)_GEN_SOURCES)
482 $(foreach x, $(SOURCES2OBJS),
483 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
484 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
486 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
488 SOURCES += $$($(1)_SOURCES)
490 ifneq ($(LD_SCRIPT),)
491 $(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%)
494 $(2)/$(1)$(3:%=-%): $$($(1)_OBJS)
495 @$(QUIET_CMD_ECHO) " LINK $$@"
496 $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
497 then echo $$(CC) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
498 else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
499 $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \
500 $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \
502 @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
503 @if [ -n "$(LD_SCRIPT)" ]; then \
504 echo " $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi
505 @sed -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(OBJS_DIR)/$(1)$(3:%=-%).map|tr '&' '\134' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
506 @echo >>$(OBJS_DIR)/$(1).exe.d
509 # Rules for other output formats (can be specified by OUTPUT_FORMATS)
511 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
512 $(Q) $(OBJCOPY) --output-target=binary -S $< $@
515 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
516 $(Q) $(OBJCOPY) --output-target=ihex -S $< $@
519 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
520 $(Q) $(OBJCOPY) --output-target=srec -S $< $@
522 # Syntax: $(call LIBRARY_template,<library-name>)
523 define LIBRARY_template
525 GEN_SOURCES += $$($(1)_GEN_SOURCES)
527 $(foreach x, $(SOURCES2OBJS),
528 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
529 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
531 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
533 SOURCES += $$($(1)_SOURCES)
535 $(LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
536 @$(QUIET_CMD_ECHO) " AR $$@"
537 $(Q) $(AR) rcs $$@ $$^
541 # Syntax: $(call SOLIB_template,<library-name>)
542 define SOLIB_template
544 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
546 $(foreach x, $(SOURCES2OBJSLO),
547 $(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
548 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
550 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
552 SOLIB_OBJS += $$($(1)_OBJSLO)
553 SOLIB_SOURCES += $$($(1)_SOURCES)
555 $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
556 @$(QUIET_CMD_ECHO) " LINK $$@"
557 $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
559 ifeq ($(OMK_VERBOSE),1) #OMK:include.omk@Makefile.rules.sysless
564 ifneq ($(LN_HEADERS),y)
566 ( echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
570 ( echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
574 # TODO: Check modification date of changed header files. If it is
575 # newer that in source dir, show a warning.
577 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
578 define include-pass-template
579 include-pass-local: include-pass-local-$(2)
580 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'))
581 @$$(foreach f, $$($(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(notdir $$(f)) \
582 || $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; )
583 @$$(foreach f, $$($(2)_GEN_HEADERS), cmp --quiet $$(f) $(1)/$$(notdir $$(f)) \
584 || $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; ) # FIXME: Use correct build dir, then document it
585 @$$(foreach f, $$(nobase_$(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(f) \
586 || ( mkdir -p $(1)/$$(dir $$(f)) && $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)) ) || exit 1 ; )
587 @$$(foreach f, $$(renamed_$(2)_HEADERS), \
588 srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
589 cmp --quiet $$(SOURCES_DIR)/$$$${srcfname} $(1)/$$$${destfname} \
590 || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
591 @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
592 srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
593 cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
594 || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
596 #OMK:sysless.omk@Makefile.rules.sysless
597 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
598 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
600 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
601 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
603 #=====================================================================
604 # Common utility rules
606 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
609 #=====================================================================
610 # Include correct rules for just running pass
612 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
614 USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
615 USER_LIB_DIR = $(USER_COMPILED_DIR_NAME)/lib
616 USER_UTILS_DIR = $(USER_COMPILED_DIR_NAME)/bin-utils
617 USER_TESTS_DIR = $(USER_COMPILED_DIR_NAME)/bin-tests
618 USER_BIN_DIR = $(USER_COMPILED_DIR_NAME)/bin
619 USER_OBJS_DIR = $(LOCAL_BUILD_DIR)
623 # Some support to serialize some targets for parallel make
624 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
625 include-pass: check-dir
626 library-pass: include-pass
627 binary-pass utils-pass: library-pass
629 override OMK_SERIALIZE_INCLUDED = y
630 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
633 # -------------------------------------
634 # Rules for compilation for target
635 ifdef TARGET_RULE_TEMPLATES
637 LDFLAGS += -nostartfiles
639 # FIXME: These are not used. What they are good for?
640 LIB_CPPFLAGS += $(CPPFLAGS)
641 LIB_CFLAGS += $(CFLAGS)
643 SOLIB_PICFLAGS += -shared -fpic
645 CFLAGS += -DOMK_FOR_TARGET
647 INCLUDE_DIR := $(USER_INCLUDE_DIR)
648 LIB_DIR := $(USER_LIB_DIR)
649 OBJS_DIR := $(USER_OBJS_DIR)
651 $(eval $(COMPILER_DEFS_template))
653 # Special rules for CMETRIC generated headers
655 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
656 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
657 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
658 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
659 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
660 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
662 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
664 # Generate rules for compilation of programs and libraries
665 ifneq ($(link_VARIANTS),)
666 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
667 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
669 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
670 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
673 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
674 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
675 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
678 # lib_obj_SOURCES handling
679 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
680 #$(warning lib_OBJS = $(lib_OBJS))
681 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
683 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
684 @echo " CP $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
685 $(Q)cp $(CP_FLAGS) $< $@
688 # User-space static libraries and applications object files
689 SOURCES := $(sort $(SOURCES))
690 #$(warning SOURCES = $(SOURCES))
691 GEN_SOURCES := $(sort $(GEN_SOURCES))
693 # User-space shared libraries object files
694 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
695 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
696 SOLIB_GEN_SOURCES := $(sort $(SOLIB_GEN_SOURCES))
698 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
699 # variables. Now generate rules for compilation of theese sources
700 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
701 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
702 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
703 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
704 $(foreach src,$(filter %.c,$(GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
706 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
707 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
708 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
709 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
710 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
712 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
713 $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
714 $(addprefix $(LIB_DIR)/,$(lib_OBJS))
716 ifneq ($(link_VARIANTS),)
717 binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
718 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
720 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
721 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
724 endif # TARGET_RULE_TEMPLATES
727 # -------------------------------------
728 # Rules for compilation utilities for host (user space)
729 ifdef HOST_RULE_TEMPLATES
734 SOLIB_PICFLAGS += -shared -fpic
736 # For host compilation, we don't use a specfic ld script
739 # TODO: It is probably better to use different directories for host
740 # includes, libraries and objects
741 INCLUDE_DIR := $(USER_INCLUDE_DIR)
742 LIB_DIR := $(USER_LIB_DIR)
743 OBJS_DIR := $(USER_OBJS_DIR)
745 $(eval $(COMPILER_DEFS_template))
747 #User-space static libraries and applications object files
748 #SOURCES := $(sort $(SOURCES))
749 #$(warning SOURCES = $(SOURCES))
751 # Generate rules for compilation of utility programs
752 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
754 # The above generated rule produced $(SOURCES) variable. Now generate
755 # rules for compilation of theese sources
756 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
757 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
758 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
759 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
761 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
763 endif # HOST_RULE_TEMPLATES
765 # Checks for OMK tester
767 default-config-pass-check include-pass-check:
768 library-pass-check binary-pass-check:
769 @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
772 #=====================================================================
773 # Automatic loading of compiled program by issuing "make load"
775 ifneq ($(OUTPUT_FORMATS),)
776 # Select a file extension (e.g. .bin) for "make load" command to load.
777 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
780 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
781 # Used to load program to the target hardware
782 define LOAD_PROGRAM_template
783 .PHONY: load-$(1)$(3:%=-%)
784 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(if $(LOAD_EXTENSION-$(3)),$(LOAD_EXTENSION-$(3)),$(LOAD_EXTENSION))
785 @$(QUIET_CMD_ECHO) " LOAD $$<"
786 @if [ -z '$$(LOAD_CMD$(3:%=-%))' ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
787 $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
790 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
791 # Used to load and/or run non-default variant of the default program
792 define LOAD_RUN_VARIANT_template
793 .PHONY: load-$(1) run-$(1)
795 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
798 @$(QUIET_CMD_ECHO) " RUN $(1)"
799 @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
804 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
805 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
806 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
809 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
811 run: run-$(firstword $(link_VARIANTS))
815 #=====================================================================
816 # Generate pass rules from generic templates
818 $(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)))
819 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
820 $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
821 $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
822 $(eval $(call omk_pass_template, dep, $(LOCAL_BUILD_DIR),,always))
823 $(eval $(call omk_pass_template, clean, $(LOCAL_BUILD_DIR),,always))
824 $(eval $(call omk_pass_template, install,$(LOCAL_BUILD_DIR),,always))
831 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
834 @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
835 || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
839 clean-local: clean-custom
840 $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
841 $(USER_OBJS_DIR)/*.d \
842 $(USER_OBJS_DIR)/*.map \
843 $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
846 @$(call mkdir_def,$(USER_INCLUDE_DIR))
847 @$(call mkdir_def,$(USER_LIB_DIR))
848 @$(call mkdir_def,$(USER_BIN_DIR))
849 @$(call mkdir_def,$(USER_UTILS_DIR))
850 @$(call mkdir_def,$(USER_TESTS_DIR))
852 include-pass-submakes: extra-rules-subdirs
853 # Which passes to pass
854 default: include-pass library-pass binary-pass utils-pass
855 #OMK:config_h.omk@Makefile.rules.sysless
856 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
857 define BUILD_CONFIG_H_template
859 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
860 @$(QUIET_CMD_ECHO) " CONFGEN $(notdir $(2))"
861 @if [ ! -d `dirname $(2).tmp` ] ; then \
862 mkdir -p `dirname $(2).tmp` ; fi
863 @echo "/* Automatically generated from */" > "$(2).tmp"
864 @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
865 $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
866 @echo "#ifndef $(4)" >> "$(2).tmp"
867 @echo "#define $(4)" >> "$(2).tmp"
868 @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
869 echo '$(x).$($(x))' ; ) echo ; ) | \
870 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
871 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
873 @echo "#endif /*$(4)*/" >> "$(2).tmp"
875 @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
876 else mv "$(2).tmp" "$(2)" ; \
877 echo "Updated configuration $(2)" ; fi
883 # This must be declared after the default cflags are assigned!
884 # Override is used to override command line assignemnt.
885 override CFLAGS += -I $(USER_OBJS_DIR)
886 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
887 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
891 # Special rules for configuration exported headers
893 #FIXME: The directory for headers should not be specified here.
894 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
895 _$(basename $(notdir $(confh)))_H \
898 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
900 # Add some hooks to standard passes
901 include-pass-local: $(config_h_stamp_files)
903 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
906 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
909 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
910 _$(basename $(notdir $(confh)))_H \
913 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
915 # Add some hooks to standard passes
916 include-pass-local: $(kern_config_h_stamp_files)
920 clean-local: clean-local-config-h
922 clean-local-config-h:
923 @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
924 if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
926 #OMK:sources-list.omk@Makefile.rules.sysless
927 # Rules that creates the list of files which are used during
928 # compilation. The list reflects conditional compilation depending on
929 # config.omk and other variables.
931 SOURCES_LIST_FN=sources.txt
933 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
934 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
935 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
936 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
939 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
943 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
945 sources-list: $(SOURCES_LIST)
947 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
948 @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
949 @echo -n "" > "$(SOURCES_LIST).tmp"
950 @echo -n "" > "$(SOURCES_LIST_D).tmp"
951 @$(MAKE) --no-print-directory sources-list-pass
952 @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
953 @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
954 @rm "$(SOURCES_LIST).tmp"
955 @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
956 @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
957 @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
958 sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
959 @rm "$(SOURCES_LIST_D).tmp"
960 @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
963 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
965 sources-list-pass-local:
966 @$(foreach m,$(MAKEFILE_LIST),echo ' $(m)' >> "$(SOURCES_LIST_D).tmp";)
967 @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
968 echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
969 @$(foreach ch,$(config_include_HEADERS), \
970 echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
971 @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
972 @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
973 $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
974 $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
976 ############ TAGS ###########
978 ifeq ($(MAKECMDGOALS),TAGS)
981 TAGS: $(SOURCES_LIST)
982 @$(MAKE) --no-print-directory do-tags
984 ifeq ($(MAKECMDGOALS),tags)
987 tags: $(SOURCES_LIST)
988 @$(MAKE) --no-print-directory do-tags
992 ifeq ($(MAKECMDGOALS),do-tags)
994 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
995 @$(QUIET_CMD_ECHO) " TAGS $(SOURCES_LIST_FN)"
999 ############ CSCOPE ###########
1001 cscope: $(SOURCES_LIST)
1002 @$(QUIET_CMD_ECHO) " CSCOPE < $(SOURCES_LIST_FN)"
1003 $(Q)sed -e '/^#/d' $(SOURCES_LIST) > cscope.files
1004 $(Q)cscope -b -icscope.files
1005 #FIXME: see doc to -i in cscope(1)
1006 #OMK:localeval.omk@Makefile.rules.sysless
1007 ifneq ($(local_EVALUATE),)
1008 #$(warning $(local_EVALUATE))
1009 $(eval $(local_EVALUATE))