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