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