]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - rtems/gw/Makefile.rules
Adds a library with pair of functions to put load on CPU.
[can-benchmark.git] / rtems / gw / 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-97-g532aeb1
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 --silent 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 --quiet $(1) $(2); then \
340     echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
341     install -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
342 fi
343 endef
344 else
345 define cp_cmd
346 if ! cmp --quiet $(1) $(2); then \
347     echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
348     if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \
349 fi
350 endef
351 endif
352
353 # TODO: Check modification date of changed header files. If it is
354 # newer that in source dir, show a warning.
355
356 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
357 define include-pass-template
358 include-pass-local: include-pass-local-$(2)
359 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell f='$$(f)'; echo $$$${f%->*}))
360         @$$(foreach f, $$($(2)_HEADERS),$$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
361 # FIXME: Use correct build dir, then document it (in the line bellow)
362         @$$(foreach f, $$($(2)_GEN_HEADERS),$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
363         @$$(foreach f, $$(nobase_$(2)_HEADERS), $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)); )
364         @$$(foreach f, $$(renamed_$(2)_HEADERS), \
365            f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
366            $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
367         @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
368            f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
369            $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
370 # Suppress "Nothing to be done for `include-pass-local'" message if no headers are defined in Makefile.omk
371         @$$(if $$($(2)_HEADERS)$$($(2)_GEN_HEADERS)$$(nobase_$(2)_HEADERS)$$(renamed_$(2)_HEADERS)$$(renamed_$(2)_GEN_HEADERS),,true)
372 endef
373                                                                                  #OMK:rtems.omk@Makefile.rules.rtems
374 include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
375 include $(RTEMS_CUSTOM)
376 include $(CONFIG.CC)
377
378 BUILD_DIR_NAME = _build/$(RTEMS_BSP)
379 COMPILED_DIR_NAME = _compiled/$(RTEMS_BSP)
380 GROUP_DIR_NAME =
381
382
383 USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
384 USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
385 USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
386 USER_TESTS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-tests
387 USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
388 USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
389
390 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
391
392
393 DEFAULT_INCLUDES = -I $(PROJECT_INCLUDE)
394
395 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
396
397 CPPFLAGS  += $(CONFIG_OMK_DEFINES)
398
399 #CPPFLAGS  += $(AM_CPPFLAGS)
400 #CFLAGS    += $(AM_CFLAGS)
401 #CXXFLAGS  += $(AM_CXXFLAGS)
402 #LDFLAGS   += $(CFLAGS) $(AM_CFLAGS) $(LD_PATHS:%=-L%)
403
404 LOADLIBES += -L$(USER_LIB_DIR)
405
406 LOADLIBES += $(lib_LOADLIBES:%=-l%)
407
408 SOLIB_PICFLAGS += -shared -fpic
409
410 ifndef RELATIVE_DIR
411 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
412 endif
413 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
414 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
415 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
416
417 #$(warning SOURCES_DIR = $(SOURCES_DIR))
418 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
419 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
420
421 #vpath %.c $(SOURCES_DIR)
422 #vpath %.cc $(SOURCES_DIR)
423 #vpath %.cxx $(SOURCES_DIR)
424
425 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
426
427 .PHONY: check-dir
428
429 # Some support to serialize some targets for parallel make
430 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
431 include-pass: check-dir
432 library-pass: include-pass
433 binary-pass: library-pass
434
435 override OMK_SERIALIZE_INCLUDED = y
436 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
437 endif
438
439 #=====================================================================
440 # Special rules for target filesystem and data preparation
441
442 # Syntax: $(call TARFILE_template,<filename>,<filename2>,<directory>) FIXME: Is this correct?
443 define TARFILE_template
444
445 .PHONY: $(2)
446
447 $(2):
448         $(Q) ABSOLUTETARFILE=`cd $$(dir $$@) ; pwd`/$$@ ; \
449              ( test -e $$$$ABSOLUTETARFILE && ( cd  $(3) && tar $$(TARFLAGS) -df $$$$ABSOLUTETARFILE ) ) || \
450              ( cd  $(3) && tar $$(TARFLAGS) -cf $$$$ABSOLUTETARFILE . )
451
452 $(2).o: $(2)
453         @$(QUIET_CMD_ECHO) "  TARFILE $$@"
454         $(Q) $(LD) -r --accept-unknown-input-arch -b binary -o $$@.tmp $$^
455         $(Q) $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents $$@.tmp $$@
456
457 endef
458
459 #=====================================================================
460 # User-space rules and templates to compile programs, libraries etc.
461
462 ifdef USER_RULE_TEMPLATES
463
464
465 #%.lo: %.c
466 #       $(CC) -o $@ $(LCFLAGS) -c $<
467
468 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
469         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
470
471 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
472         $(CPPFLAGS) $(AM_CXXFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
473
474 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
475         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
476
477 # Check GCC version for user build
478 ifndef CC_MAJOR_VERSION
479 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
480 endif
481 # Prepare suitable define for dependency building
482 ifeq ($(CC_MAJOR_VERSION),2)
483 CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
484 else
485 CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
486 endif
487
488
489 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
490 define COMPILE_c_o_template
491 $(2): $(1) $$(GEN_HEADERS)
492         @$(QUIET_CMD_ECHO) "  CC      $$@"
493         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
494         then mv -f "$$@.d.tmp" "$$@.d" ; \
495         else rm -f "$$@.d.tmp" ; exit 1; \
496         fi
497 endef
498
499
500 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
501 define COMPILE_cc_o_template
502 $(2): $(1) $$(GEN_HEADERS)
503         @$(QUIET_CMD_ECHO) "  CXX     $$@"
504         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
505         then mv -f "$$@.d.tmp" "$$@.d" ; \
506         else rm -f "$$@.d.tmp" ; exit 1; \
507         fi
508 endef
509
510
511 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
512 define COMPILE_S_o_template
513 $(2): $(1) $$(GEN_HEADERS)
514         @$(QUIET_CMD_ECHO) "  AS      $$@"
515         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
516         then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
517         else rm -f "$$@.d.tmp" ; exit 1; \
518         fi
519 endef
520
521 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
522 define CMETRIC_o_h_template
523 $(2): $(1)
524         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
525         $(Q)if [ -n `dirname $$@` ] ; then \
526               if [ ! -e `dirname $$@` ] ; then \
527                 mkdir -p `dirname $$@` ; fi ; fi
528         $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
529         $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
530 # Bellow, the tricks with redirection are for shells without set -o pipefail
531 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
532         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
533                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
534                 | sort >>$$@.tmp` && exit $$$$status
535         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
536         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
537                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
538                 | sort >>$$@.tmp` && exit $$$$status
539         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
540         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
541                 | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
542                 | sort >>$$@.tmp` && exit $$$$status
543         $(Q)mv $$@.tmp $$@
544 endef
545
546 idl_COMPILE = $(IDL_COMPILER)
547
548 define COMPILE_idl_template
549 $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE)))
550         @$(QUIET_CMD_ECHO) "  IDL     $$@"
551         $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
552 endef
553
554 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
555 define PROGRAM_template
556 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
557 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
558 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
559 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
560 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
561 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
562 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
563
564 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
565 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
566 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
567 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
568 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
569 $(1)_OBJS := $$(sort $$($(1)_OBJS))
570
571 USER_OBJS  += $$($(1)_OBJS)
572 USER_SOURCES += $$($(1)_SOURCES)
573 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
574
575 $(2)/$(1): $(USER_LIB_DIR)/timestamp
576 $(2)/$(1): $$($(1)_OBJS)
577         @$(QUIET_CMD_ECHO) "  LINK    $$@"
578         $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
579           then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
580           else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
581           $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
582           -o $(2)/$(1)
583 #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d
584 #@$(SED4OMK) -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(USER_OBJS_DIR)/$(1).exe.map  >>$(USER_OBJS_DIR)/$(1).exe.d
585 #@echo >>$(USER_OBJS_DIR)/$(1).exe.d
586 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map
587 # FIXME: Why the map file was commented out?
588 endef
589
590
591
592 # Syntax: $(call LIBRARY_template,<library-name>)
593 define LIBRARY_template
594 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
595 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
596 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
597 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
598 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
599 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
600 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
601
602 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
603 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
604 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
605 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o))
606 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
607 $(1)_OBJS := $$(sort $$($(1)_OBJS))
608
609 USER_OBJS  += $$($(1)_OBJS)
610 USER_SOURCES += $$($(1)_SOURCES)
611 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
612
613 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
614         @$(QUIET_CMD_ECHO) "  AR      $$@"
615         $(Q) $(AR) rcs $$@ $$^
616         @touch $(USER_LIB_DIR)/timestamp
617 endef
618
619 $(USER_LIB_DIR)/timestamp:
620         $(Q)touch $@
621
622 # Syntax: $(call SOLIB_template,<library-name>)
623 define SOLIB_template
624 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
625 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
626 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
627 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
628 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
629 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
630 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
631
632 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
633 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
634 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
635 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo))
636 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
637 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
638
639 SOLIB_OBJS  += $$($(1)_OBJSLO)
640 SOLIB_SOURCES += $$($(1)_SOURCES)
641 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
642
643 $(USER_LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
644         @$(QUIET_CMD_ECHO) "  LINK    $$@"
645         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
646 endef
647
648
649
650 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
651                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
652
653 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%)
654
655 # Special rules for CMETRIC generated headers
656
657 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
658                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
659                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
660 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
661                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
662                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
663
664 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
665 GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h))
666
667 # Generate rules for compilation of programs and libraries
668
669 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
670
671 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
672
673 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
674
675 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
676
677 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
678
679 # IDL compilation
680 USER_IDLS := $(sort $(USER_IDLS))
681 $(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%))))
682
683
684 -include $(USER_OBJS_DIR)/*.d
685
686 endif
687
688 #=====================================================================
689
690
691 $(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)))
692 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
693 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
694
695 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
696
697 check-dir::
698         @$(call mkdir_def,$(USER_INCLUDE_DIR))
699         @$(call mkdir_def,$(USER_LIB_DIR))
700         @$(call mkdir_def,$(USER_BIN_DIR))
701         @$(call mkdir_def,$(USER_UTILS_DIR))
702         @$(call mkdir_def,$(USER_TESTS_DIR))
703
704 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
705
706 ifdef USER_RULE_TEMPLATES
707
708 # User-space static libraries and applications object files
709
710 USER_SOURCES := $(sort $(USER_SOURCES))
711 USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES))
712
713 #$(warning USER_SOURCES = $(USER_SOURCES))
714
715 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
716
717 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
718
719 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
720
721 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
722
723 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
724
725 # User-space shared libraries object files
726
727 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
728
729 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
730
731 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
732
733 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
734
735 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
736
737 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
738
739 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
740
741 endif
742
743
744 clean-local:
745         @echo Cleaning in $(USER_OBJS_DIR)
746         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
747                $(USER_OBJS_DIR)/*.d \
748                $(USER_OBJS_DIR)/*.map \
749                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
750                $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile)
751
752
753 default: include-pass library-pass binary-pass
754
755 include-pass-submakes: extra-rules-subdirs
756
757 # We must go to EXTRA_RULES_SUBDIRS before going to any other
758 # directory, since the executables compiled in EXTRA_RULES_SUBDIRS
759 # might be needed there.
760 include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs
761                                                                                  #OMK:config_h.omk@Makefile.rules.rtems
762 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
763 define BUILD_CONFIG_H_template
764
765 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
766         @$(QUIET_CMD_ECHO) "  CONFGEN $(notdir $(2))"
767         @if [ ! -d `dirname $(2).tmp` ] ; then \
768                 mkdir -p `dirname $(2).tmp` ; fi
769         @echo "/* Automatically generated from */" > "$(2).tmp"
770         @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
771         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
772         @echo "#ifndef $(4)" >> "$(2).tmp"
773         @echo "#define $(4)" >> "$(2).tmp"
774         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | $(SED4OMK) -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
775                 echo '$(x).$($(x))' ; ) echo ; ) | \
776                 $(SED4OMK) -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
777                 $(SED4OMK) -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
778                   >> "$(2).tmp"
779         @echo "#endif /*$(4)*/" >> "$(2).tmp"
780         @touch "$$@"
781         @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
782         else mv "$(2).tmp" "$(2)" ; \
783         echo "Updated configuration $(2)" ; fi
784
785 endef
786
787 ifdef LOCAL_CONFIG_H
788
789 # This must be declared after the default cflags are assigned!
790 # Override is used to override command line assignemnt.
791 override CFLAGS += -I $(USER_OBJS_DIR)
792 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
793 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
794
795 endif
796
797 # Special rules for configuration exported headers
798
799 #FIXME: The directory for headers should not be specified here.
800 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
801 _$(basename $(notdir $(confh)))_H \
802 )))
803
804 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
805
806 # Add some hooks to standard passes
807 include-pass-local: $(config_h_stamp_files)
808
809 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
810
811 ifdef LOCAL_CONFIG_H
812 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
813 endif
814
815 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
816 _$(basename $(notdir $(confh)))_H \
817 )))
818
819 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
820
821 # Add some hooks to standard passes
822 include-pass-local: $(kern_config_h_stamp_files)
823
824 endif
825
826 clean-local: clean-local-config-h
827
828 clean-local-config-h:
829         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
830             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
831         )
832                                                                                  #OMK:sources-list.omk@Makefile.rules.rtems
833 # Rules that creates the list of files which are used during
834 # compilation. The list reflects conditional compilation depending on
835 # config.omk and other variables.
836
837 SOURCES_LIST_FN=sources.txt
838 ifndef SOURCES_LIST
839 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
840 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
841 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
842 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
843 endif
844
845 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
846 NEED_SOURCES_LIST=y
847 endif
848
849 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
850 .PHONY: sources-list
851 sources-list: $(SOURCES_LIST)
852
853 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
854         @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
855         @echo -n "" > "$(SOURCES_LIST).tmp"
856         @echo -n "" > "$(SOURCES_LIST_D).tmp"
857         @$(MAKE) --no-print-directory sources-list-pass
858         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
859         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
860         @rm "$(SOURCES_LIST).tmp"
861         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
862         @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
863         @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
864                 $(SED4OMK) -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
865         @rm "$(SOURCES_LIST_D).tmp"
866         @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
867 endif
868
869 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
870
871 sources-list-pass-local:
872         @$(foreach m,$(MAKEFILE_LIST),echo '  $(m)' >> "$(SOURCES_LIST_D).tmp";)
873         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
874           echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
875         @$(foreach ch,$(config_include_HEADERS), \
876           echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
877         @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|$(SED4OMK) -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
878         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
879           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
880           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
881
882 ############ TAGS ###########
883
884 ifeq ($(MAKECMDGOALS),TAGS)
885 ETAGS=etags
886 TAGS_CMD = $(ETAGS)
887 TAGS: $(SOURCES_LIST)
888         @$(MAKE) --no-print-directory do-tags
889 endif
890 ifeq ($(MAKECMDGOALS),tags) 
891 CTAGS=ctags -N
892 TAGS_CMD = $(CTAGS)
893 tags: $(SOURCES_LIST)
894         @$(MAKE) --no-print-directory do-tags
895 endif
896 export TAGS_CMD
897
898 ifeq ($(MAKECMDGOALS),do-tags)
899 .PHONY: do-tags
900 do-tags: $(shell $(SED4OMK) -e '/^\#/d' $(SOURCES_LIST))
901         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
902         $(Q)$(TAGS_CMD) $^
903 endif
904
905 ############ CSCOPE ###########
906
907 cscope: $(SOURCES_LIST)
908         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
909         $(Q)$(SED4OMK) -e '/^#/d' $(SOURCES_LIST) > cscope.files
910         $(Q)cscope -b -icscope.files
911 #FIXME: see doc to -i in cscope(1)