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