1 # Version for system-less builds. #OMK@sysless
3 # Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base
5 # (C) Copyright 2003 by Pavel Pisa - OCERA team member
6 # (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
8 # Homepage: http://rtime.felk.cvut.cz/omk/
10 # The OMK build system is distributed under the GNU General Public
11 # License. See file COPYING for details.
14 # V .. if set to 1, full command text is shown else short form is used
15 # W .. whole tree - if set to 1, make is always called from the top-level directory
16 # SUBDIRS .. list of subdirectories intended for make from actual directory
17 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
18 # LN_HEADERS .. if "y", header files are symbolicaly linked instead of copied. #OMK@include
20 # bin_PROGRAMS .. list of the require binary programs
21 # test_PROGRAMS .. list of the test programs
22 # include_HEADERS .. list of the user-space public header files
23 # lib_LIBRARIES .. list of the user-space libraries
24 # lib_LDSCRIPTS .. list of LD scripts that should be copied to the lib direcotry
25 # lib_obj_SOURCES .. list of source files which should be compiled and
26 # the produced object file placed to the lib directory (e.g. crt0.S)
27 # shared_LIBRARIES .. list of the user-space shared libraries
28 # nobase_include_HEADERS .. public headers copied even with directory part
29 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
30 # utils_PROGRAMS .. list of the development utility programs (compiled for host computer, this might change in future)
31 # xxx_SOURCES .. list of specific target sources
32 # xxx_LIBS .. list of specific target libraries
33 # INCLUDES .. additional include directories and defines for user-space
34 # lib_LOADLIBES .. list of libraries linked to each executable
35 # link_VARIANTS .. list of ld script suffixes (after hypen `-') that
36 # should be used for linking (e.g. ram flash). If this is not
37 # specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
38 # PREFIX_DIR .. Prefix to directories in _compiled and _build. Used in config.omk.
39 # LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK@config_h
40 # of options defined in the current directory
41 # config_include_HEADERS .. names of global config files (possibly
42 # with subdirectories)
43 # xxx_DEFINES .. list of config directives to be included in
44 # config header file of the name <somedir>/xxx.h
45 # DOXYGEN .. if non-empty, generated headers includes Doxygen's @file
46 # command, so it is possible to document config
48 # local_EVALUATE .. Makefile hook, which is executed at the end of #OMK@localeval
49 # the Makefile.rules. Used only for dirty hacks.
50 OMK_RULES_TYPE=sysless #OMK@__type
52 # We need to ensure definition of sources directory first
54 # Only shell built-in pwd understands -L
55 SOURCES_DIR := $(shell ( pwd -L ) )
58 # If we are not called by OMK leaf Makefile...
60 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
63 # OUTPUT_DIR is the place where _compiled, _build and possible other
64 # files/directories are created. By default is the same as
67 OUTPUT_DIR := $(MAKERULES_DIR)
70 .PHONY: all default check-make-ver omkize
73 ifeq ("$(origin W)", "command line")
81 ifneq ($(OMK_WHOLE_TREE),1)
82 all: check-make-ver default
83 @echo "Compilation finished"
85 # Run make in the top-level directory
87 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
91 # Usage: $(call canttest,<error message>)
93 ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
101 #=========================
102 # Include the config file
104 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
105 # config files and it is not clearly defined to which file is this
107 ifneq ($(CONFIG_FILE_OK),y)
109 CONFIG_FILE := $(OUTPUT_DIR)/config.omk
111 ifneq ($(wildcard $(CONFIG_FILE)-default),)
112 -include $(CONFIG_FILE)-default
114 ifneq ($(MAKECMDGOALS),default-config)
115 $(warning Please, run "make default-config" first)
119 -include $(OUTPUT_DIR)/config.target
121 ifneq ($(wildcard $(CONFIG_FILE)),)
122 -include $(CONFIG_FILE)
125 endif #$(CONFIG_FILE_OK)
128 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
131 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
132 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
133 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
134 # must to be serialized only in the toplevel make.
137 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
139 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
140 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
141 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
142 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
143 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
144 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
146 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
147 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
148 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
150 # We have to use RELATIVE_PREFIX because of mingw
151 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
152 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
154 #vpath %.c $(SOURCES_DIR)
155 #vpath %.cc $(SOURCES_DIR)
156 #vpath %.cxx $(SOURCES_DIR)
158 # Define srcdir for Automake compatibility
159 srcdir = $(SOURCES_DIR)
161 # Defines for quiet compilation
163 ifeq ("$(origin V)", "command line")
170 ifneq ($(OMK_VERBOSE),0)
175 ifneq ($(findstring s,$(MAKEFLAGS)),)
176 QUIET_CMD_ECHO = true
179 QUIET_CMD_ECHO = echo
182 MAKEFILE_OMK=Makefile.omk
183 # All subdirectories (even linked ones) containing Makefile.omk
184 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
185 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
187 # ===================================================================
188 # We have set up all important variables, so we can check and include
189 # real OCERA style Makefile.omk now
191 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
192 ifeq ($(AUTOMATIC_SUBDIRS),y)
193 SUBDIRS?=$(ALL_OMK_SUBDIRS)
199 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
200 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
201 echo "Your make program version is too old and does not support OMK system." ; \
202 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
205 distclean dist-clean:
206 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
207 @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
209 # Common OMK templates
210 # ====================
212 # Syntax: $(call mkdir,<dir name>)
214 [ -d $(1) ] || mkdir -p $(1) || exit 1
217 ifneq ($(OMK_VERBOSE),2)
218 NO_PRINT_DIRECTORY := --no-print-directory
221 ifeq ($(USE_LEAF_MAKEFILES),n)
222 export USE_LEAF_MAKEFILES
223 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
224 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
226 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
227 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
232 # Call a pass in a subdirectory
233 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
234 define omk_pass_subdir_template
235 .PHONY: $(pass)-$(3)-subdir
236 $(pass)-submakes: $(pass)-$(3)-subdir
238 @$(call mkdir_def,$(2)/$(3))
239 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
240 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
241 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
242 # In subdirectories we can call submakes directly since passes are
243 # already searialized on the toplevel make.
247 check-target = $(1:%=%-check)
250 # Call a pass in a subdirectory
251 # Usage: $(call extra_rules_subdir_template,<subdir>)
252 define extra_rules_subdir_template
253 extra-rules-subdirs: extra-rules-$(1)
255 +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
256 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
259 .PHONY: extra-rules-subdirs
262 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
264 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
265 define omk_pass_template
266 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
267 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
269 # Submakes have to be called this way and not as dependecies for pass
270 # serialization to work
271 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
272 RELATIVE_DIR=$(RELATIVE_DIR) \
273 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
275 @true # Do not emit "nothing to be done" messages
277 ifneq ($(4)$($(pass)_HOOKS),)
278 $(pass)-submakes: $(pass)-this-dir
279 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
280 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
281 @$(call mkdir_def,$(2))
282 +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
283 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
284 $(pass)-local: $($(pass)_HOOKS)
288 # =======================
289 # DEFAULT CONFIG PASS
292 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
293 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
294 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
295 @echo >> "$(CONFIG_FILE)-default"
296 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
297 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
298 -f $(OUTPUT_DIR)/Makefile default-config-pass
300 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
302 default-config-pass-local:
303 # @echo Default config for $(RELATIVE_DIR)
304 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
305 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
306 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
310 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
311 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
313 $(Q)for i in `find -L . -name Makefile.omk` ; do \
315 if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
316 rm -f "$${d}/Makefile"; \
317 cp -v Makefile "$${d}/Makefile"; \
321 # Rules for compilation of C, C++ and assembler sources using GNU
324 # Interface to other rules:
327 # LIB_DIR - directory where compiled libraries are stored
328 # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
329 # INCLUDE_DIR - where includes can be found
330 # from config.omk or Makefile.omk
332 # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
333 # from base: SOURCES_DIR
334 # from Makefile.omk: lib_LOADLIBES
337 # SOURCES - all the source files that needs to be compiled (except for shared library sources)
338 # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
339 # OBJ_EXT - extension of object files
340 # LIB_EXT - extension of library files
341 # LIB_PREF - prefix for library files
342 # ASM_EXT - extension of assembler sources
345 # COMPILER_DEFS_template - definitions that should be defined before
346 # the following templates can be used. The input variables needs to be
347 # defined before evaluating this template
349 # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
350 # templates that create rules for compilation of sources
352 # CMETRIC_o_h_template - FIXME
354 # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
355 # create rules for compilation of a program, library and shared
356 # library. The rules can use rules produced by COMPILE_xxx_template.
358 define COMPILER_DEFS_template
364 CC = $(CROSS_COMPILE)gcc
365 LINK = $(CROSS_COMPILE)ld
366 AR = $(CROSS_COMPILE)ar
367 OBJCOPY = $(CROSS_COMPILE)objcopy
368 NM = $(CROSS_COMPILE)nm
370 CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE)
372 CFLAGS += -I$(SOURCES_DIR)
373 CFLAGS += -I$(INCLUDE_DIR)
375 LOADLIBES += -L$(LIB_DIR)
376 LOADLIBES += $(lib_LOADLIBES:%=-l%)
379 -include $(OBJS_DIR)/*.d
382 # $(CC) -o $@ $(LCFLAGS) -c $<
384 c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
385 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
387 cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
388 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
390 S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
391 $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS)
394 # Check GCC version for user build
395 ifndef CC_MAJOR_VERSION
396 CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
398 # Prepare suitable define for dependency building
399 ifeq ($$(CC_MAJOR_VERSION),2)
400 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
402 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
405 endef # COMPILER_DEFS_template
408 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
409 define COMPILE_c_o_template
410 $(2): $(1) $$(GEN_HEADERS)
411 @$(QUIET_CMD_ECHO) " CC $$@"
412 $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
413 then mv -f "$$@.d.tmp" "$$@.d" ; \
414 else rm -f "$$@.d.tmp" ; exit 1; \
420 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
421 define COMPILE_cc_o_template
422 $(2): $(1) $$(GEN_HEADERS)
423 @$(QUIET_CMD_ECHO) " CXX $$@"
424 $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
425 then mv -f "$$@.d.tmp" "$$@.d" ; \
426 else rm -f "$$@.d.tmp" ; exit 1; \
430 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
431 define COMPILE_S_o_template
432 $(2): $(1) $$(GEN_HEADERS)
433 @$(QUIET_CMD_ECHO) " AS $$@"
434 $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
435 then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
436 else rm -f "$$@.d.tmp" ; exit 1; \
440 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
441 define CMETRIC_o_h_template
443 @$(QUIET_CMD_ECHO) " CMETRIC $$@"
444 $(Q)if [ -n `dirname $$@` ] ; then \
445 if [ ! -e `dirname $$@` ] ; then \
446 mkdir -p `dirname $$@` ; fi ; fi
447 $(Q)echo >$$@ '/* Automatically generated from $$< */'
448 $(Q)echo >>$$@ '/* Conditionals to control compilation */'
449 $(Q)set -o pipefail ; $(NM) $$< \
450 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
452 $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
453 $(Q)set -o pipefail ; $(NM) $$< \
454 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
458 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
459 define PROGRAM_template
460 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
461 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
462 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
463 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
464 $(1)_OBJS += $$(filter %.o,$(1)_SOURCES)
465 $(1)_OBJS := $$(sort $$($(1)_OBJS))
467 SOURCES += $$($(1)_SOURCES)
469 ifneq ($(LD_SCRIPT),)
470 $(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%)
473 $(2)/$(1)$(3:%=-%): $$($(1)_OBJS)
474 @$(QUIET_CMD_ECHO) " LINK $$@"
475 $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
476 then echo $$(CC) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
477 else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
478 $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \
479 $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \
481 @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
482 @if [ -n "$(LD_SCRIPT)" ]; then \
483 echo " $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi
484 @sed -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(OBJS_DIR)/$(1)$(3:%=-%).map|tr '&' '\134' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
485 @echo >>$(OBJS_DIR)/$(1).exe.d
488 # Rules for other output formats (can be specified by OUTPUT_FORMATS)
490 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
491 $(Q) $(OBJCOPY) --output-target=binary -S $< $@
494 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
495 $(Q) $(OBJCOPY) --output-target=ihex -S $< $@
498 @$(QUIET_CMD_ECHO) " OBJCOPY $@"
499 $(Q) $(OBJCOPY) --output-target=srec -S $< $@
501 # Syntax: $(call LIBRARY_template,<library-name>)
502 define LIBRARY_template
503 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
504 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
505 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
506 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
507 $(1)_OBJS := $$(sort $$($(1)_OBJS))
509 SOURCES += $$($(1)_SOURCES)
511 $(LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
512 @$(QUIET_CMD_ECHO) " AR $$@"
513 $(Q) $(AR) rcs $$@ $$^
517 # Syntax: $(call SOLIB_template,<library-name>)
518 define SOLIB_template
519 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
520 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
521 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
522 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
523 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
525 SOLIB_OBJS += $$($(1)_OBJSLO)
526 SOLIB_SOURCES += $$($(1)_SOURCES)
528 $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
529 @$(QUIET_CMD_ECHO) " LINK $$@"
530 $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
536 ifeq ($(OMK_VERBOSE),1) #OMK@include
541 ifneq ($(LN_HEADERS),y)
543 ( echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
547 ( echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
551 # TODO: Check modification date of changed header files. If it is
552 # newer that in source dir, show a warning.
554 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
555 define include-pass-template
556 include-pass-local: include-pass-local-$(2)
557 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'))
558 @$$(foreach f, $$($(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(notdir $$(f)) \
559 || $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; )
560 @$$(foreach f, $$($(2)_GEN_HEADERS), cmp --quiet $$(f) $(1)/$$(notdir $$(f)) \
561 || $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; ) # FIXME: Use correct build dir, then document it
562 @$$(foreach f, $$(nobase_$(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(f) \
563 || ( mkdir -p $(1)/$$(dir $$(f)) && $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)) ) || exit 1 ; )
564 @$$(foreach f, $$(renamed_$(2)_HEADERS), \
565 srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
566 cmp --quiet $$(SOURCES_DIR)/$$$${srcfname} $(1)/$$$${destfname} \
567 || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
568 @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
569 srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
570 cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
571 || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
578 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
579 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
581 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
582 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
584 #=====================================================================
585 # Common utility rules
587 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
590 #=====================================================================
591 # Include correct rules for just running pass
593 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
595 USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
596 USER_LIB_DIR = $(USER_COMPILED_DIR_NAME)/lib
597 USER_UTILS_DIR = $(USER_COMPILED_DIR_NAME)/bin-utils
598 USER_TESTS_DIR = $(USER_COMPILED_DIR_NAME)/bin-tests
599 USER_BIN_DIR = $(USER_COMPILED_DIR_NAME)/bin
600 USER_OBJS_DIR = $(LOCAL_BUILD_DIR)
604 # Some support to serialize some targets for parallel make
605 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
606 include-pass: check-dir
607 library-pass: include-pass
608 binary-pass utils-pass: library-pass
610 override OMK_SERIALIZE_INCLUDED = y
611 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
614 # -------------------------------------
615 # Rules for compilation for target
616 ifdef TARGET_RULE_TEMPLATES
618 LDFLAGS += -nostartfiles
620 # FIXME: These are not used. What they are good for?
621 LIB_CPPFLAGS += $(CPPFLAGS)
622 LIB_CFLAGS += $(CFLAGS)
624 SOLIB_PICFLAGS += -shared -fpic
626 CFLAGS += -DOMK_FOR_TARGET
628 INCLUDE_DIR := $(USER_INCLUDE_DIR)
629 LIB_DIR := $(USER_LIB_DIR)
630 OBJS_DIR := $(USER_OBJS_DIR)
632 $(eval $(COMPILER_DEFS_template))
634 # Special rules for CMETRIC generated headers
636 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
637 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
638 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
639 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
640 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
641 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
643 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
645 # Generate rules for compilation of programs and libraries
646 ifneq ($(link_VARIANTS),)
647 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
648 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
650 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
651 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
654 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
655 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
656 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
659 # lib_obj_SOURCES handling
660 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
661 #$(warning lib_OBJS = $(lib_OBJS))
662 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
664 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
665 @echo " CP $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
666 $(Q)cp $(CP_FLAGS) $< $@
669 # User-space static libraries and applications object files
670 SOURCES := $(sort $(SOURCES))
671 #$(warning SOURCES = $(SOURCES))
673 # User-space shared libraries object files
674 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
675 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
678 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
679 # variables. Now generate rules for compilation of theese sources
680 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
681 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
682 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
683 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
685 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
686 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
687 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
688 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
690 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
691 $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
692 $(addprefix $(LIB_DIR)/,$(lib_OBJS))
694 ifneq ($(link_VARIANTS),)
695 binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
696 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
698 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
699 $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
702 endif # TARGET_RULE_TEMPLATES
705 # -------------------------------------
706 # Rules for compilation utilities for host (user space)
707 ifdef HOST_RULE_TEMPLATES
712 SOLIB_PICFLAGS += -shared -fpic
714 # For host compilation, we don't use a specfic ld script
717 # TODO: It is probably better to use different directories for host
718 # includes, libraries and objects
719 INCLUDE_DIR := $(USER_INCLUDE_DIR)
720 LIB_DIR := $(USER_LIB_DIR)
721 OBJS_DIR := $(USER_OBJS_DIR)
723 $(eval $(COMPILER_DEFS_template))
725 #User-space static libraries and applications object files
726 #SOURCES := $(sort $(SOURCES))
727 #$(warning SOURCES = $(SOURCES))
729 # Generate rules for compilation of utility programs
730 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
732 # The above generated rule produced $(SOURCES) variable. Now generate
733 # 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)),)))
739 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
741 endif # HOST_RULE_TEMPLATES
743 # Checks for OMK tester
745 default-config-pass-check include-pass-check:
746 library-pass-check binary-pass-check:
747 @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
750 #=====================================================================
751 # Automatic loading of compiled program by issuing "make load"
753 ifneq ($(OUTPUT_FORMATS),)
754 # Select a file extension (e.g. .bin) for "make load" command to load.
755 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
758 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
759 # Used to load program to the target hardware
760 define LOAD_PROGRAM_template
761 .PHONY: load-$(1)$(3:%=-%)
762 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
763 @$(QUIET_CMD_ECHO) " LOAD $$<"
764 @if [ -z '$$(LOAD_CMD$(3:%=-%))' ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
765 $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
768 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
769 # Used to load and/or run non-default variant of the default program
770 define LOAD_RUN_VARIANT_template
771 .PHONY: load-$(1) run-$(1)
773 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
776 @$(QUIET_CMD_ECHO) " RUN $(1)"
777 @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
782 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
783 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
784 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
787 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
789 run: run-$(firstword $(link_VARIANTS))
793 #=====================================================================
794 # Generate pass rules from generic templates
796 $(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)))
797 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
798 $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
799 $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
800 $(eval $(call omk_pass_template, dep, $(LOCAL_BUILD_DIR),,always))
801 $(eval $(call omk_pass_template, clean, $(LOCAL_BUILD_DIR),,always))
802 $(eval $(call omk_pass_template, install,$(LOCAL_BUILD_DIR),,always))
809 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
812 @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
813 || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
817 clean-local: clean-custom
818 $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
819 $(USER_OBJS_DIR)/*.d \
820 $(USER_OBJS_DIR)/*.map \
821 $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
824 @$(call mkdir_def,$(USER_INCLUDE_DIR))
825 @$(call mkdir_def,$(USER_LIB_DIR))
826 @$(call mkdir_def,$(USER_BIN_DIR))
827 @$(call mkdir_def,$(USER_UTILS_DIR))
828 @$(call mkdir_def,$(USER_TESTS_DIR))
830 include-pass-submakes: extra-rules-subdirs
831 # Which passes to pass
832 default: include-pass library-pass binary-pass utils-pass
838 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
839 define BUILD_CONFIG_H_template
841 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
842 @$(QUIET_CMD_ECHO) " CONFGEN $$(@:%.stamp=%)"
843 @if [ ! -d `dirname $(2).tmp` ] ; then \
844 mkdir -p `dirname $(2).tmp` ; fi
845 @echo "/* Automatically generated from */" > "$(2).tmp"
846 @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
847 $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
848 @echo "#ifndef $(4)" >> "$(2).tmp"
849 @echo "#define $(4)" >> "$(2).tmp"
850 @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
851 echo '$(x).$($(x))' ; ) echo ; ) | \
852 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
853 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
855 @echo "#endif /*$(4)*/" >> "$(2).tmp"
857 @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
858 else mv "$(2).tmp" "$(2)" ; \
859 echo "Updated configuration $(2)" ; fi
865 # This must be declared after the default cflags are assigned!
866 # Override is used to override command line assignemnt.
867 override CFLAGS += -I $(USER_OBJS_DIR)
868 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
869 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
873 # Special rules for configuration exported headers
875 #FIXME: The directory for headers should not be specified here.
876 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
877 _$(basename $(notdir $(confh)))_H \
880 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
882 # Add some hooks to standard passes
883 include-pass-local: $(config_h_stamp_files)
885 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
888 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
891 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
892 _$(basename $(notdir $(confh)))_H \
895 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
897 # Add some hooks to standard passes
898 include-pass-local: $(kern_config_h_stamp_files)
902 clean-local: clean-local-config-h
904 clean-local-config-h:
905 @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
906 if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
914 # Rules that creates the list of files which are used during
915 # compilation. The list reflects conditional compilation depending on
916 # config.omk and other variables.
918 SOURCES_LIST_FN=sources.txt
920 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
921 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
922 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
923 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
926 ifeq ($(MAKECMDGOALS),sources-list)
929 ifeq ($(MAKECMDGOALS),TAGS)
932 ifeq ($(MAKECMDGOALS),tags)
936 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
938 sources-list: $(SOURCES_LIST)
940 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
941 @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
942 @echo -n "" > "$(SOURCES_LIST).tmp"
943 @echo -n "" > "$(SOURCES_LIST_D).tmp"
944 @$(MAKE) --no-print-directory sources-list-pass
945 @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
946 @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
947 @rm "$(SOURCES_LIST).tmp"
948 @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
949 @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
950 @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
951 sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
952 @rm "$(SOURCES_LIST_D).tmp"
953 @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
956 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
958 sources-list-pass-local:
959 @$(foreach m,$(MAKEFILE_LIST),echo ' $(m)' >> "$(SOURCES_LIST_D).tmp";)
960 @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
961 echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
962 @$(foreach ch,$(config_include_HEADERS), \
963 echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
964 @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
965 @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
966 $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
967 $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
969 ############ TAGS ###########
971 ifeq ($(MAKECMDGOALS),TAGS)
974 TAGS: $(SOURCES_LIST)
975 @$(MAKE) --no-print-directory do-tags
977 ifeq ($(MAKECMDGOALS),tags)
980 tags: $(SOURCES_LIST)
981 @$(MAKE) --no-print-directory do-tags
985 ifeq ($(MAKECMDGOALS),do-tags)
987 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
988 @$(QUIET_CMD_ECHO) " TAGS $(SOURCES_LIST_FN)"
992 ############ CSCOPE ###########
994 cscope: $(SOURCES_LIST)
995 @$(QUIET_CMD_ECHO) " CSCOPE < $(SOURCES_LIST_FN)"
996 $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
997 #FIXME: see doc to -i in cscope(1)
1003 ifneq ($(local_EVALUATE),)
1004 #$(warning $(local_EVALUATE))
1005 $(eval $(local_EVALUATE))