]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-omk-template/Makefile.rules
00510cc9b9448c4ecf14328ded4b93b045f62f76
[rtems-devel.git] / rtems-omk-template / Makefile.rules
1 #  Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
2 #
3 #  (C) Copyright 2003, 2006, 2007, 2008, 2009  by Pavel Pisa - OCERA team member
4 #  (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015 by Michal Sojka - Czech Technical University, FEE, DCE
5 #
6 #  Homepage: http://rtime.felk.cvut.cz/omk/
7 #  Version:  0.2-174-g15f6d83
8 #
9 # The OMK build system is distributed under the GNU General Public
10 # License.  See file COPYING for details.
11 #
12 #
13 #                   This version is adapted for RTEMS build                      #OMK:rtems.omk
14 #
15 #
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 # lib_LIBRARIES    .. list of the user-space libraries                           #OMK:rtems.omk
23 # shared_LIBRARIES .. list of the user-space shared libraries
24 # include_HEADERS  .. list of the user-space public header files
25 # nobase_include_HEADERS .. public headers copied even with directory part
26 # renamed_include_HEADERS .. public headers copied to the different target name
27 # bin_PROGRAMS     .. list of the require binary programs
28 # utils_PROGRAMS   .. list of the development utility programs
29 # test_PROGRAMS    .. list of the test programs
30 # xxx_SOURCES      .. list of specific target sources
31 # xxx_LIBS         .. list of specific target libraries
32 # INCLUDES         .. additional include directories and defines for user-space
33 # xxx_EMBEDTARFILES .. list of source subdirectories which are embedded as tar files to the application
34 # xxx_EXPORTSYMBOLS .. if "y" then include symbol table in the application for dlopen functionality
35 # cmetric_include_HEADERS    .. generate header file with offsets and sizes of structure fields #OMK:cmetric.omk
36 # xxx_CMETRIC_SOURCES        .. the source cmetric generation
37 # LOCAL_CONFIG_H   .. name of local config.h file generated from values          #OMK:config_h.omk
38 #                     of options defined in the current directory
39 # config_include_HEADERS .. names of global config files (possibly
40 #                     with subdirectories)
41 # xxx_DEFINES      .. list of config directives to be included in
42 #                     config header file of the name <somedir>/xxx.h
43 # DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
44 #                     command, so it is possible to document config
45 #                     variables.
46 OMK_RULES_TYPE=rtems                                                             #OMK:Makefile.rules.rtems@
47                                                                                  #OMK:base.omk@Makefile.rules.rtems
48 # If we are not called by OMK leaf Makefile...
49 ifndef MAKERULES_DIR
50 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
51 endif
52
53 # The $(SED4OMK) command for BSD based systems requires -E option to allow
54 # extended regular expressions
55
56 SED4OMK ?= sed
57 ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
58   SED4OMK := $(SED4OMK) -E
59   ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
60     SED4OMK := gsed
61   endif
62   ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
63     SED4OMK := gsed -E
64   endif
65   ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
66     $(error No SED program suitable for OMK found)
67   endif
68 endif
69
70 # OUTPUT_DIR is the place where _compiled, _build and possible other
71 # files/directories are created. By default is the same as
72 # $(MAKERULES_DIR).
73 ifndef OUTPUT_DIR
74 OUTPUT_DIR := $(MAKERULES_DIR)
75 endif
76
77 # We need to ensure definition of sources directory first
78 ifndef SOURCES_DIR
79 # Only shell built-in pwd understands -L
80 SOURCES_DIR := $(shell ( pwd -L ) )
81 INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
82 INVOCATION_DIR := $(INVOCATION_DIR:/%=%)
83 INVOCATION_DIR := $(INVOCATION_DIR:\\%=%)
84 endif
85
86 .PHONY: all default check-make-ver print-hints omkize
87
88 ifdef W
89   ifeq ("$(origin W)", "command line")
90     OMK_WHOLE_TREE:=$(W)
91   endif
92 endif
93 ifndef OMK_WHOLE_TREE
94   OMK_WHOLE_TREE:=0
95 endif
96
97 ifneq ($(OMK_WHOLE_TREE),1)
98 all: check-make-ver print-hints default
99         @echo "Compilation finished"
100 else
101 # Run make in the top-level directory
102 all:
103         @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
104 endif
105
106 # omk-get-var target allows external scripts/programs to determine the
107 # values of OMK variables such as RELATIVE_DIR etc.
108 .PHONY: omk-get-var
109 omk-get-var:
110         @$(foreach var,$(VAR),echo $(var)=$($(var));)
111
112 #=========================
113 # Include the config file
114
115 ifndef CONFIG_FILE
116 CONFIG_FILE      := $(OUTPUT_DIR)/config.omk
117 endif
118
119 $(CONFIG_FILE)-default:
120         $(MAKE) default-config 
121
122 ifeq ($(MAKECMDGOALS),default-config)
123 export DEFAULT_CONFIG_PASS=1
124 endif
125
126 ifneq ($(DEFAULT_CONFIG_PASS),1)
127 include $(CONFIG_FILE)-default
128 endif
129
130 -include $(OUTPUT_DIR)/config.target
131
132 ifneq ($(wildcard $(CONFIG_FILE)),)
133 -include $(CONFIG_FILE)
134 endif
135
136
137 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
138
139
140 export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
141 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
142 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
143 # must to be serialized only in the toplevel make.
144
145 ifndef RELATIVE_DIR
146 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
147 endif
148 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
149 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
150 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
151 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
152 #override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
153 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
154
155 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
156 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
157 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
158
159 # We have to use RELATIVE_PREFIX because of mingw
160 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
161 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
162
163 #vpath %.c $(SOURCES_DIR)
164 #vpath %.cc $(SOURCES_DIR)
165 #vpath %.cxx $(SOURCES_DIR)
166
167 # Define srcdir for Automake compatibility
168 srcdir = $(SOURCES_DIR)
169
170 # Defines for quiet compilation
171 ifdef V
172   ifeq ("$(origin V)", "command line")
173     OMK_VERBOSE = $(V)
174   endif
175 endif
176 ifndef OMK_VERBOSE
177   OMK_VERBOSE = 0
178 endif
179 ifneq ($(OMK_VERBOSE),0)
180   Q =
181 else
182   Q = @
183 endif
184 ifneq ($(findstring s,$(MAKEFLAGS)),)
185   QUIET_CMD_ECHO = true
186   OMK_SILENT = 1
187 else
188   QUIET_CMD_ECHO = echo
189 endif
190
191 MAKEFILE_OMK=Makefile.omk
192 # All subdirectories (even linked ones) containing Makefile.omk
193 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
194 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
195
196 # ===================================================================
197 # We have set up all important variables, so we can check and include
198 # real OCERA style Makefile.omk now
199 ifndef OMK_INCLUDED
200 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
201 ifeq ($(AUTOMATIC_SUBDIRS),y)
202 SUBDIRS?=$(ALL_OMK_SUBDIRS)
203 endif
204 OMK_INCLUDED := 1
205 endif
206
207 print-hints:
208         @echo 'Use "make V=1" to see the verbose compile lines.'
209
210 check-make-ver:
211         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
212         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
213                 echo "Your make program version ($(MAKE_VERSION)) is too old and does not support OMK system." ; \
214                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
215         fi
216
217 distclean dist-clean:
218         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
219         @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)  $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
220
221 # Common OMK templates
222 # ====================
223
224 # Syntax: $(call mkdir,<dir name>)
225 define mkdir_def
226         [ -d $(1) ] || mkdir -p $(1) || exit 1
227 endef
228
229 ifneq ($(OMK_VERBOSE),2)
230 NO_PRINT_DIRECTORY := --no-print-directory
231 endif
232
233 ifeq ($(USE_LEAF_MAKEFILES),n)
234 export USE_LEAF_MAKEFILES
235 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
236 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
237 else
238 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
239 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
240 endif
241
242 pass = $(strip $(1))
243
244 unexport SUBDIRS
245
246 # Call a pass in a subdirectory
247 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
248 define omk_pass_subdir_template
249 .PHONY: $(pass)-$(3)-subdir
250 $(pass)-submakes: $(pass)-$(3)-subdir
251 $(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
252 $(pass)-$(3)-subdir:
253         @$(call mkdir_def,$(2)/$(3))
254         +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
255                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
256                 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
257 # In subdirectories we can call submakes directly since passes are
258 # already serialized on the toplevel make.
259 endef
260
261 ifdef OMK_TESTSROOT
262 check-target = $(1:%=%-check)
263 endif
264
265 # Call a pass in a subdirectory
266 # Usage: $(call extra_rules_subdir_template,<subdir>)
267 define extra_rules_subdir_template
268 extra-rules-subdirs: extra-rules-$(1)
269 extra-rules-$(1):
270         +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
271                 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
272 endef
273
274 .PHONY: extra-rules-subdirs
275 extra-rules-subdirs:
276
277 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
278
279 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
280 define omk_pass_template
281 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
282 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
283 $(pass):
284 # Submakes have to be called this way and not as dependecies for pass
285 # serialization to work
286         +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
287                 RELATIVE_DIR=$(RELATIVE_DIR) \
288                 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
289 $(pass)-submakes:
290         @true                   # Do not emit "nothing to be done" messages
291
292 ifneq ($(4)$($(pass)_HOOKS),)
293 $(pass)-submakes: $(pass)-this-dir
294 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
295         +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
296         @$(call mkdir_def,$(2))
297         +@$(MAKE) --no-builtin-rules $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
298                 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
299 ifneq ($(pass),clean)
300 $(pass)-local: $($(pass)_HOOKS)
301 endif
302 endif
303 endef
304
305 # =======================
306 # DEFAULT CONFIG PASS
307
308 default-config:
309         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
310         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
311         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
312         @echo >> "$(CONFIG_FILE)-default"
313         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
314                 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
315                 -f $(OUTPUT_DIR)/Makefile default-config-pass
316
317 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
318
319 default-config-pass-local:
320 #       @echo Default config for $(RELATIVE_DIR)
321         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
322         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
323                 $(SED4OMK) -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
324
325
326 omkize:
327         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
328            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
329         fi
330         $(Q)for i in `find -L . -name Makefile.omk` ; do \
331            d=`dirname $${i}`; \
332            if ! test -f "$${d}/Makefile.rules" && ! cmp -s Makefile "$${d}/Makefile"; then \
333               rm -f "$${d}/Makefile"; \
334               cp -v Makefile "$${d}/Makefile"; \
335            fi \
336         done
337 ifeq ($(OMK_VERBOSE),1)                                                          #OMK:include.omk@Makefile.rules.rtems
338 CPHEADER_FLAGS += -v
339 LNHEADER_FLAGS += -v
340 endif
341
342 ifneq ($(LN_HEADERS),y)
343 define cp_cmd
344 if ! cmp -s $(1) $(2); then \
345     echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
346     install -d $(CPHEADER_FLAGS) `dirname $(2)` && \
347     install $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
348 fi
349 endef
350 else
351 define cp_cmd
352 if ! cmp -s $(1) $(2); then \
353     echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
354     if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \
355 fi
356 endef
357 endif
358
359 # TODO: Check modification date of changed header files. If it is
360 # newer that in source dir, show a warning.
361
362 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
363 define include-pass-template
364 include-pass-local: include-pass-local-$(2)
365 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell f='$$(f)'; echo $$$${f%->*}))
366         @$$(foreach f, $$($(2)_HEADERS),$$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
367 # FIXME: Use correct build dir, then document it (in the line bellow)
368         @$$(foreach f, $$($(2)_GEN_HEADERS),$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
369         @$$(foreach f, $$(nobase_$(2)_HEADERS), $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)); )
370         @$$(foreach f, $$(renamed_$(2)_HEADERS), \
371            f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
372            $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
373         @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
374            f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
375            $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
376 # Suppress "Nothing to be done for `include-pass-local'" message if no headers are defined in Makefile.omk
377         @$$(if $$($(2)_HEADERS)$$($(2)_GEN_HEADERS)$$(nobase_$(2)_HEADERS)$$(renamed_$(2)_HEADERS)$$(renamed_$(2)_GEN_HEADERS),,true)
378 endef
379                                                                                  #OMK:rtems.omk@Makefile.rules.rtems
380 include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
381 include $(RTEMS_CUSTOM)
382 include $(CONFIG.CC)
383
384 BUILD_DIR_NAME = _build/$(RTEMS_BSP)
385 COMPILED_DIR_NAME = _compiled/$(RTEMS_BSP)
386 GROUP_DIR_NAME =
387
388
389 USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
390 USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
391 USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
392 USER_TESTS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-tests
393 USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
394 USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
395
396 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
397
398
399 DEFAULT_INCLUDES = -I $(PROJECT_INCLUDE)
400
401 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
402
403 CPPFLAGS  += $(CONFIG_OMK_DEFINES)
404
405 #CPPFLAGS  += $(OMK_CPPFLAGS)
406 #CFLAGS    += $(OMK_CFLAGS)
407 #CXXFLAGS  += $(OMK_CXXFLAGS)
408 #LDFLAGS   += $(CFLAGS) $(OMK_CFLAGS) $(LD_PATHS:%=-L%)
409
410 LOADLIBES += -L$(USER_LIB_DIR)
411
412 LOADLIBES += $(lib_LOADLIBES:%=-l%)
413
414 SOLIB_PICFLAGS += -shared -fpic
415
416 ifndef RELATIVE_DIR
417 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
418 endif
419 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
420 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
421 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
422
423 #$(warning SOURCES_DIR = $(SOURCES_DIR))
424 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
425 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
426
427 #vpath %.c $(SOURCES_DIR)
428 #vpath %.cc $(SOURCES_DIR)
429 #vpath %.cxx $(SOURCES_DIR)
430
431 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
432
433 .PHONY: check-dir
434
435 # Some support to serialize some targets for parallel make
436 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
437 include-pass: check-dir
438 library-pass: include-pass
439 binary-pass: library-pass
440
441 override OMK_SERIALIZE_INCLUDED = y
442 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
443 endif
444
445 #=====================================================================
446 # Special rules for target filesystem and data preparation
447
448 # Syntax: $(call TARFILE_template,<filename>,<filename2>,<directory>) FIXME: Is this correct?
449 define TARFILE_template
450
451 .PHONY: $(2)
452
453 $(2):
454         $(Q) ABSOLUTETARFILE=`cd $$(dir $$@) ; pwd`/$$@ ; \
455              ( test -e $$$$ABSOLUTETARFILE && ( cd  $(3) && tar $$(TARFLAGS) -df $$$$ABSOLUTETARFILE ) ) || \
456              ( cd  $(3) && tar $$(TARFLAGS) -cf $$$$ABSOLUTETARFILE . )
457
458 $(2).o: $(2)
459         @$(QUIET_CMD_ECHO) "  TARFILE $$@"
460         $(Q) $(LD) -r --accept-unknown-input-arch -b binary -o $$@.tmp $$^
461         $(Q) $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents $$@.tmp $$@
462
463 endef
464
465 #=====================================================================
466 # User-space rules and templates to compile programs, libraries etc.
467
468 ifdef USER_RULE_TEMPLATES
469
470
471 #%.lo: %.c
472 #       $(CC) -o $@ $(LCFLAGS) -c $<
473
474 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(OMK_CPPFLAGS) \
475         $(CPPFLAGS) $(OMK_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
476
477 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(OMK_CPPFLAGS) \
478         $(CPPFLAGS) $(OMK_CXXFLAGS) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) -DOMK_FOR_USER
479
480 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OMK_CPPFLAGS) \
481         $(CPPFLAGS) $(OMK_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
482
483 # Check GCC version for user build
484 ifndef CC_MAJOR_VERSION
485 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
486 endif
487 # Prepare suitable define for dependency building
488 ifeq ($(CC_MAJOR_VERSION),2)
489 CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
490 else
491 CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
492 endif
493
494
495 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
496 define COMPILE_c_o_template
497 $(2): $(1) $$(GEN_HEADERS)
498         @$(QUIET_CMD_ECHO) "  CC      $$@"
499         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
500         then mv -f "$$@.d.tmp" "$$@.d" ; \
501         else rm -f "$$@.d.tmp" ; exit 1; \
502         fi
503 endef
504
505
506 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
507 define COMPILE_cc_o_template
508 $(2): $(1) $$(GEN_HEADERS)
509         @$(QUIET_CMD_ECHO) "  CXX     $$@"
510         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
511         then mv -f "$$@.d.tmp" "$$@.d" ; \
512         else rm -f "$$@.d.tmp" ; exit 1; \
513         fi
514 endef
515
516
517 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
518 define COMPILE_S_o_template
519 $(2): $(1) $$(GEN_HEADERS)
520         @$(QUIET_CMD_ECHO) "  AS      $$@"
521         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
522         then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
523         else rm -f "$$@.d.tmp" ; exit 1; \
524         fi
525 endef
526
527 idl_COMPILE = $(IDL_COMPILER)
528
529 define COMPILE_idl_template
530 $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE)))
531         @$(QUIET_CMD_ECHO) "  IDL     $$@"
532         $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
533 endef
534
535 RTEMS_SYSM?=rtems-syms
536
537 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
538 define PROGRAM_template
539 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
540 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
541 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
542 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
543 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
544 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
545 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
546
547 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
548 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
549 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
550 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
551 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
552 $(1)_OBJS := $$(sort $$($(1)_OBJS))
553
554 USER_OBJS  += $$($(1)_OBJS)
555 USER_SOURCES += $$($(1)_SOURCES)
556 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
557
558 $(1)_LDFLAGS += $$(if $$(filter COMPLETE,$$($(1)_EXPORTSYMBOLS)),-Xlinker --whole-archive,)
559
560 $(1)_LDCOMMAND += $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
561           then echo $$(CC)  $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS) ; \
562           else echo $$(CXX) $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CXXFLAGS) $$(CXXFLAGS) ; fi) \
563           $$($(1)_LDFLAGS) $$(OMK_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS)
564
565 $(2)/$(1): $(USER_LIB_DIR)/timestamp
566 $(2)/$(1): $$($(1)_OBJS)
567         @$(QUIET_CMD_ECHO) "  LINK    $$@"
568         $(Q) if [ -z "$$($(1)_EXPORTSYMBOLS)" ] ; then \
569           $$($(1)_LDCOMMAND) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -o $(2)/$(1) || exit 1; \
570         else \
571           rm -f $(1).prelink ; \
572           $$($(1)_LDCOMMAND) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -o $(1).prelink || exit 1 ; \
573           $(RTEMS_SYSM) -e -c "$$(CC)  $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS)" \
574                 -S $(1)-symbol-table.c -o $(1)-symbol-table.o $(1).prelink || exit 1 ; \
575           $$($(1)_LDCOMMAND) $(1)-symbol-table.o $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -o $(2)/$(1) || exit 1 ; \
576         fi
577
578 #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d
579 #@$(SED4OMK) -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(USER_OBJS_DIR)/$(1).exe.map  >>$(USER_OBJS_DIR)/$(1).exe.d
580 #@echo >>$(USER_OBJS_DIR)/$(1).exe.d
581 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map
582 # FIXME: Why the map file was commented out?
583 endef
584
585
586
587 # Syntax: $(call LIBRARY_template,<library-name>)
588 define LIBRARY_template
589 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
590 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
591 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
592 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
593 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
594 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
595 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
596
597 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
598 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
599 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
600 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
601 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
602 $(1)_OBJS := $$(sort $$($(1)_OBJS))
603
604 USER_OBJS  += $$($(1)_OBJS)
605 USER_SOURCES += $$($(1)_SOURCES)
606 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
607
608 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
609         @$(QUIET_CMD_ECHO) "  AR      $$@"
610         $(Q) $(AR) rcs $$@ $$^
611         @touch $(USER_LIB_DIR)/timestamp
612 endef
613
614 $(USER_LIB_DIR)/timestamp:
615         $(Q)touch $@
616
617 # Syntax: $(call SOLIB_template,<library-name>)
618 define SOLIB_template
619 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
620 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
621 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
622 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
623 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
624 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
625 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
626
627 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
628 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
629 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
630 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
631 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
632 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
633
634 SOLIB_OBJS  += $$($(1)_OBJSLO)
635 SOLIB_SOURCES += $$($(1)_SOURCES)
636 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
637
638 $(USER_LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
639         @$(QUIET_CMD_ECHO) "  LINK    $$@"
640         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
641 endef
642
643
644
645 library-pass-local: $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
646
647 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%)
648
649 GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h))
650
651 # Generate rules for compilation of programs and libraries
652
653 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
654
655 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
656
657 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
658
659 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
660
661 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
662
663 # Create _build directories for sources in subdirectories i.e. *_SOURCES=dir/file.c
664 _dirs_to_create=$(filter-out ./,$(sort $(dir $(USER_SOURCES) $(SOLIB_SOURCES))))
665 ifneq ($(_dirs_to_create),)
666 $(shell mkdir -p $(addprefix $(LOCAL_BUILD_DIR)/,$(_dirs_to_create)))
667 endif
668
669 # IDL compilation
670 USER_IDLS := $(sort $(USER_IDLS))
671 $(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%))))
672
673
674 -include $(USER_OBJS_DIR)/*.d
675
676 endif
677
678 #=====================================================================
679
680
681 $(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
682 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
683 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
684
685 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
686
687 check-dir::
688         @$(call mkdir_def,$(USER_INCLUDE_DIR))
689         @$(call mkdir_def,$(USER_LIB_DIR))
690         @$(call mkdir_def,$(USER_BIN_DIR))
691         @$(call mkdir_def,$(USER_UTILS_DIR))
692         @$(call mkdir_def,$(USER_TESTS_DIR))
693
694 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
695
696 ifdef USER_RULE_TEMPLATES
697
698 # User-space static libraries and applications object files
699
700 USER_SOURCES := $(sort $(USER_SOURCES))
701 USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES))
702
703 #$(warning USER_SOURCES = $(USER_SOURCES))
704
705 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
706
707 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
708
709 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
710
711 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
712
713 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
714
715 # User-space shared libraries object files
716
717 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
718
719 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
720
721 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
722
723 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
724
725 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
726
727 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
728
729 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
730
731 endif
732
733
734 clean-local::
735         @echo Cleaning in $(USER_OBJS_DIR)
736         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
737                $(USER_OBJS_DIR)/*.d \
738                $(USER_OBJS_DIR)/*.map \
739                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
740                $(USER_OBJS_DIR)/*_tarfile \
741                $(USER_OBJS_DIR)/*.prelink \
742                $(USER_OBJS_DIR)/*.tmp
743
744
745 default: include-pass library-pass binary-pass
746
747 include-pass-submakes: extra-rules-subdirs
748
749 # We must go to EXTRA_RULES_SUBDIRS before going to any other
750 # directory, since the executables compiled in EXTRA_RULES_SUBDIRS
751 # might be needed there.
752 include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs
753                                                                                  #OMK:cmetric.omk@Makefile.rules.rtems
754 NM ?= nm
755
756 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
757 define CMETRIC_o_h_template
758 $(2): $(1)
759         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
760         $(Q)if [ -n `dirname $$@` ] ; then \
761               if [ ! -e `dirname $$@` ] ; then \
762                 mkdir -p `dirname $$@` ; fi ; fi
763         $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
764         $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
765 # Bellow, the tricks with redirection are for shells without set -o pipefail
766 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
767         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
768                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
769                 | sort >>$$@.tmp` && exit $$$$status
770         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
771         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
772                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
773                 | sort >>$$@.tmp` && exit $$$$status
774         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
775         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
776                 | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
777                 | sort >>$$@.tmp` && exit $$$$status
778         $(Q)mv $$@.tmp $$@
779 endef
780
781 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS))
782
783 # Special rules for CMETRIC generated headers
784
785 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
786                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
787                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
788 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
789                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
790                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
791
792 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
793                                                                                  #OMK:config_h.omk@Makefile.rules.rtems
794 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
795 define BUILD_CONFIG_H_template
796
797 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
798         @$(QUIET_CMD_ECHO) "  CONFGEN $(notdir $(2))"
799         @if [ ! -d `dirname $(2).tmp` ] ; then \
800                 mkdir -p `dirname $(2).tmp` ; fi
801         @echo "/* Automatically generated from */" > "$(2).tmp"
802         @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
803         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
804         @echo "#ifndef $(4)" >> "$(2).tmp"
805         @echo "#define $(4)" >> "$(2).tmp"
806         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | $(SED4OMK) -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
807                 echo '$(x).$($(x))' ; ) echo ; ) | \
808                 $(SED4OMK) -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
809                 $(SED4OMK) -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
810                   >> "$(2).tmp"
811         @echo "#endif /*$(4)*/" >> "$(2).tmp"
812         @touch "$$@"
813         @if cmp -s "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
814         else mv "$(2).tmp" "$(2)" ; \
815         echo "Updated configuration $(2)" ; fi
816
817 endef
818
819 ifdef LOCAL_CONFIG_H
820
821 # This must be declared after the default cflags are assigned!
822 # Override is used to override command line assignemnt.
823 override CFLAGS += -I $(USER_OBJS_DIR)
824 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
825 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
826
827 endif
828
829 # Special rules for configuration exported headers
830
831 #FIXME: The directory for headers should not be specified here.
832 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
833 _$(basename $(notdir $(confh)))_H \
834 )))
835
836 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
837
838 # Add some hooks to standard passes
839 include-pass-local: $(config_h_stamp_files)
840
841 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
842
843 ifdef LOCAL_CONFIG_H
844 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
845 endif
846
847 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
848 _$(basename $(notdir $(confh)))_H \
849 )))
850
851 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
852
853 # Add some hooks to standard passes
854 include-pass-local: $(kern_config_h_stamp_files)
855
856 endif
857
858 clean-local::
859         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
860             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
861         )
862                                                                                  #OMK:sources-list.omk@Makefile.rules.rtems
863 # Rules that creates the list of files which are used during
864 # compilation. The list reflects conditional compilation depending on
865 # config.omk and other variables.
866
867 SOURCES_LIST_FN=sources.txt
868 ifndef SOURCES_LIST
869 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
870 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
871 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
872 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
873 endif
874
875 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
876 NEED_SOURCES_LIST=y
877 endif
878
879 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
880 .PHONY: sources-list
881 sources-list: $(SOURCES_LIST)
882
883 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
884         @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
885         @echo -n "" > "$(SOURCES_LIST).tmp"
886         @echo -n "" > "$(SOURCES_LIST_D).tmp"
887         @$(MAKE) --no-print-directory sources-list-pass
888         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
889         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
890         @rm "$(SOURCES_LIST).tmp"
891         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
892         @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
893         @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
894                 $(SED4OMK) -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
895         @rm "$(SOURCES_LIST_D).tmp"
896         @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
897 endif
898
899 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
900
901 sources-list-pass-local:
902         @$(foreach m,$(MAKEFILE_LIST),echo '  $(m)' >> "$(SOURCES_LIST_D).tmp";)
903         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
904           echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
905         @$(foreach ch,$(config_include_HEADERS), \
906           echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
907         @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|$(SED4OMK) -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
908         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
909           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
910           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
911
912 ############ TAGS ###########
913
914 ifeq ($(MAKECMDGOALS),TAGS)
915 ETAGS=etags
916 TAGS_CMD = $(ETAGS)
917 TAGS: $(SOURCES_LIST)
918         @$(MAKE) --no-print-directory do-tags
919 endif
920 ifeq ($(MAKECMDGOALS),tags) 
921 CTAGS=ctags -N
922 TAGS_CMD = $(CTAGS)
923 tags: $(SOURCES_LIST)
924         @$(MAKE) --no-print-directory do-tags
925 endif
926 export TAGS_CMD
927
928 ifeq ($(MAKECMDGOALS),do-tags)
929 .PHONY: do-tags
930 do-tags: $(shell $(SED4OMK) -e '/^\#/d' $(SOURCES_LIST))
931         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
932         $(Q)$(TAGS_CMD) $^
933 endif
934
935 ############ CSCOPE ###########
936
937 cscope: $(SOURCES_LIST)
938         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
939         $(Q)$(SED4OMK) -e '/^#/d' $(SOURCES_LIST) > cscope.files
940         $(Q)cscope -b -icscope.files
941 #FIXME: see doc to -i in cscope(1)