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