]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-omk-template/Makefile.rules
97409ce148dd8bc9d54e091913a963fbb8b9a957
[rtems-devel.git] / rtems-omk-template / Makefile.rules
1 #  Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
2 #
3 #  (C) Copyright 2003, 2006, 2007, 2008, 2009  by Pavel Pisa - OCERA team member
4 #  (C) Copyright 2006, 2007, 2008, 2009 by Michal Sojka - Czech Technical University, FEE, DCE
5 #
6 #  Homepage: http://rtime.felk.cvut.cz/omk/
7 #  Version:  0.1-95-g0919d5c
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 # We need to ensure definition of sources directory first
46 ifndef SOURCES_DIR
47 # Only shell built-in pwd understands -L
48 SOURCES_DIR := $(shell ( pwd -L ) )
49 endif
50
51 # If we are not called by OMK leaf Makefile...
52 ifndef MAKERULES_DIR
53 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
54 endif
55
56 # OUTPUT_DIR is the place where _compiled, _build and possible other
57 # files/directories are created. By default is the same as
58 # $(MAKERULES_DIR).
59 ifndef OUTPUT_DIR
60 OUTPUT_DIR := $(MAKERULES_DIR)
61 endif
62
63 .PHONY: all default check-make-ver omkize
64
65 ifdef W
66   ifeq ("$(origin W)", "command line")
67     OMK_WHOLE_TREE:=$(W)
68   endif
69 endif
70 ifndef OMK_WHOLE_TREE
71   OMK_WHOLE_TREE:=0
72 endif
73
74 ifneq ($(OMK_WHOLE_TREE),1)
75 all: check-make-ver default
76         @echo "Compilation finished"
77 else
78 # Run make in the top-level directory
79 all:
80         @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
81 endif
82
83 ifdef OMK_TESTSROOT
84 # Usage: $(call canttest,<error message>)
85 define canttest
86         ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
87 endef
88 else
89 define canttest
90         echo "$(1)"
91 endef
92 endif
93
94 #=========================
95 # Include the config file
96
97 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
98 # config files and it is not clearly defined to which file is this
99 # variable related.
100 ifneq ($(CONFIG_FILE_OK),y)
101 ifndef CONFIG_FILE
102 CONFIG_FILE      := $(OUTPUT_DIR)/config.omk
103 endif
104 ifneq ($(wildcard $(CONFIG_FILE)-default),)
105 -include $(CONFIG_FILE)-default
106 else
107 ifneq ($(MAKECMDGOALS),default-config)
108 $(warning Please, run "make default-config" first)
109 endif
110 endif
111
112 -include $(OUTPUT_DIR)/config.target
113
114 ifneq ($(wildcard $(CONFIG_FILE)),)
115 -include $(CONFIG_FILE)
116 CONFIG_FILE_OK = y
117 endif
118 endif #$(CONFIG_FILE_OK)
119
120
121 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
122
123
124 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
125 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
126 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
127 # must to be serialized only in the toplevel make.
128
129 ifndef RELATIVE_DIR
130 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
131 endif
132 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
133 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
134 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
135 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
136 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
137 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
138
139 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
140 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
141 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
142
143 # We have to use RELATIVE_PREFIX because of mingw
144 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
145 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
146
147 #vpath %.c $(SOURCES_DIR)
148 #vpath %.cc $(SOURCES_DIR)
149 #vpath %.cxx $(SOURCES_DIR)
150
151 # Define srcdir for Automake compatibility
152 srcdir = $(SOURCES_DIR)
153
154 # Defines for quiet compilation
155 ifdef V
156   ifeq ("$(origin V)", "command line")
157     OMK_VERBOSE = $(V)
158   endif
159 endif
160 ifndef OMK_VERBOSE
161   OMK_VERBOSE = 0
162 endif
163 ifneq ($(OMK_VERBOSE),0)
164   Q =
165 else
166   Q = @
167 endif
168 ifneq ($(findstring s,$(MAKEFLAGS)),)
169   QUIET_CMD_ECHO = true
170   OMK_SILENT = 1
171 else
172   QUIET_CMD_ECHO = echo
173 endif
174
175 MAKEFILE_OMK=Makefile.omk
176 # All subdirectories (even linked ones) containing Makefile.omk
177 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
178 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
179
180 # ===================================================================
181 # We have set up all important variables, so we can check and include
182 # real OCERA style Makefile.omk now
183 ifndef OMK_INCLUDED
184 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
185 ifeq ($(AUTOMATIC_SUBDIRS),y)
186 SUBDIRS?=$(ALL_OMK_SUBDIRS)
187 endif
188 OMK_INCLUDED := 1
189 endif
190
191 check-make-ver:
192         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
193         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
194                 echo "Your make program version is too old and does not support OMK system." ; \
195                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
196         fi
197
198 distclean dist-clean:
199         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
200         @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)  $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
201
202 # Common OMK templates
203 # ====================
204
205 # Syntax: $(call mkdir,<dir name>)
206 define mkdir_def
207         [ -d $(1) ] || mkdir -p $(1) || exit 1
208 endef
209
210 ifneq ($(OMK_VERBOSE),2)
211 NO_PRINT_DIRECTORY := --no-print-directory
212 endif
213
214 ifeq ($(USE_LEAF_MAKEFILES),n)
215 export USE_LEAF_MAKEFILES
216 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
217 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
218 else
219 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
220 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
221 endif
222
223 pass = $(strip $(1))
224
225 # Call a pass in a subdirectory
226 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
227 define omk_pass_subdir_template
228 .PHONY: $(pass)-$(3)-subdir
229 $(pass)-submakes: $(pass)-$(3)-subdir
230 $(pass)-$(3)-subdir:
231         @$(call mkdir_def,$(2)/$(3))
232         +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
233                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
234                 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
235 # In subdirectories we can call submakes directly since passes are
236 # already serialized on the toplevel make.
237 endef
238
239 ifdef OMK_TESTSROOT
240 check-target = $(1:%=%-check)
241 endif
242
243 # Call a pass in a subdirectory
244 # Usage: $(call extra_rules_subdir_template,<subdir>)
245 define extra_rules_subdir_template
246 extra-rules-subdirs: extra-rules-$(1)
247 extra-rules-$(1):
248         +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
249                 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
250 endef
251
252 .PHONY: extra-rules-subdirs
253 extra-rules-subdirs:
254
255 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
256
257 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
258 define omk_pass_template
259 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
260 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
261 $(pass):
262 # Submakes have to be called this way and not as dependecies for pass
263 # serialization to work
264         +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
265                 RELATIVE_DIR=$(RELATIVE_DIR) \
266                 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
267 $(pass)-submakes:
268         @true                   # Do not emit "nothing to be done" messages
269
270 ifneq ($(4)$($(pass)_HOOKS),)
271 $(pass)-submakes: $(pass)-this-dir
272 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
273         +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
274         @$(call mkdir_def,$(2))
275         +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
276                 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
277 $(pass)-local: $($(pass)_HOOKS)
278 endif
279 endef
280
281 # =======================
282 # DEFAULT CONFIG PASS
283
284 default-config:
285         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
286         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
287         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
288         @echo >> "$(CONFIG_FILE)-default"
289         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
290                 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
291                 -f $(OUTPUT_DIR)/Makefile default-config-pass
292
293 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
294
295 default-config-pass-local:
296 #       @echo Default config for $(RELATIVE_DIR)
297         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
298         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
299                 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
300
301
302 omkize:
303         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
304            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
305         fi
306         $(Q)for i in `find -L . -name Makefile.omk` ; do \
307            d=`dirname $${i}`; \
308            if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \
309               rm -f "$${d}/Makefile"; \
310               cp -v Makefile "$${d}/Makefile"; \
311            fi \
312         done
313 ifeq ($(OMK_VERBOSE),1)                                                          #OMK:include.omk@Makefile.rules.rtems
314 CPHEADER_FLAGS += -v
315 LNHEADER_FLAGS += -v
316 endif
317
318 ifneq ($(LN_HEADERS),y)
319 define cp_cmd
320 ( echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
321 endef
322 else
323 define cp_cmd
324 ( echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
325 endef
326 endif
327
328 # TODO: Check modification date of changed header files. If it is
329 # newer that in source dir, show a warning.
330
331 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
332 define include-pass-template
333 include-pass-local: include-pass-local-$(2)
334 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'))
335         @$$(foreach f, $$($(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(notdir $$(f)) \
336            || $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; )
337         @$$(foreach f, $$($(2)_GEN_HEADERS), cmp --quiet $$(f) $(1)/$$(notdir $$(f)) \
338            || $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; ) # FIXME: Use correct build dir, then document it
339         @$$(foreach f, $$(nobase_$(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(f) \
340            || ( mkdir -p $(1)/$$(dir $$(f)) && $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)) ) || exit 1 ; )
341         @$$(foreach f, $$(renamed_$(2)_HEADERS), \
342            srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
343            cmp --quiet $$(SOURCES_DIR)/$$$${srcfname} $(1)/$$$${destfname} \
344            || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
345         @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
346            srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
347            cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
348            || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
349 endef
350                                                                                  #OMK:rtems.omk@Makefile.rules.rtems
351 ifdef OMK_TESTSROOT
352 ifeq ($(RTEMS_MAKEFILE_PATH),)
353 $(error $(shell $(call canttest,RTEMS_MAKEFILE_PATH not defined)))
354 endif
355 endif
356
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 >$$@ '/* Automatically generated from $$< */'
512         $(Q)echo >>$$@ '/* Conditionals to control compilation */'
513         $(Q)set -o pipefail ; $(NM) $$< \
514                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
515                 | sort >>$$@
516         $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
517         $(Q)set -o pipefail ; $(NM) $$< \
518                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
519                 | sort >>$$@
520 endef
521
522 # Syntax: $(call PROGRAM_template,<dir>,<executable-name>,<link-variant>)
523 define PROGRAM_template
524 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
525 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
526 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
527 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
528 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
529 $(1)_OBJS := $$(sort $$($(1)_OBJS))
530
531 USER_OBJS  += $$($(1)_OBJS)
532 USER_SOURCES += $$($(1)_SOURCES)
533 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
534
535 $(2)/$(1): $(USER_LIB_DIR)/timestamp
536
537 $(2)/$(1): $$($(1)_OBJS)
538         @$(QUIET_CMD_ECHO) "  LINK    $$@"
539         $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
540           then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
541           else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
542           $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
543           -o $(2)/$(1)
544 #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d
545 #@sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(USER_OBJS_DIR)/$(1).exe.map  >>$(USER_OBJS_DIR)/$(1).exe.d
546 #@echo >>$(USER_OBJS_DIR)/$(1).exe.d
547 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map
548 # FIXME: Why the map file was commented out?
549 endef
550
551
552
553 # Syntax: $(call LIBRARY_template,<library-name>)
554 define LIBRARY_template
555 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
556 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
557 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
558 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
559 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
560 $(1)_OBJS := $$(sort $$($(1)_OBJS))
561
562 USER_OBJS  += $$($(1)_OBJS)
563 USER_SOURCES += $$($(1)_SOURCES)
564 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
565
566 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
567         @$(QUIET_CMD_ECHO) "  AR      $$@"
568         $(Q) $(AR) rcs $$@ $$^
569         @touch $(USER_LIB_DIR)/timestamp
570 endef
571
572
573
574 # Syntax: $(call SOLIB_template,<library-name>)
575 define SOLIB_template
576 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
577 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
578 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
579 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
580 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
581 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
582
583 SOLIB_OBJS  += $$($(1)_OBJSLO)
584 SOLIB_SOURCES += $$($(1)_SOURCES)
585 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
586
587 $(USER_LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
588         @$(QUIET_CMD_ECHO) "  LINK    $$@"
589         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
590 endef
591
592
593
594 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
595                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
596
597 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/% $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%)
598
599 # Special rules for CMETRIC generated headers
600
601 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
602                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
603                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
604 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
605                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
606                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
607
608 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
609
610 # Generate rules for compilation of programs and libraries
611
612 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
613
614 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
615
616 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
617
618 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
619
620 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
621
622 -include $(USER_OBJS_DIR)/*.d
623
624 endif
625
626 #=====================================================================
627
628
629 $(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
630 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
631 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
632
633 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
634
635 check-dir::
636         @$(call mkdir_def,$(USER_INCLUDE_DIR))
637         @$(call mkdir_def,$(USER_LIB_DIR))
638         @$(call mkdir_def,$(USER_BIN_DIR))
639         @$(call mkdir_def,$(USER_UTILS_DIR))
640         @$(call mkdir_def,$(USER_TESTS_DIR))
641
642 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
643
644 ifdef USER_RULE_TEMPLATES
645
646 # User-space static libraries and applications object files
647
648 USER_SOURCES := $(sort $(USER_SOURCES))
649
650 #$(warning USER_SOURCES = $(USER_SOURCES))
651
652 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
653
654 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
655
656 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
657
658 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
659
660 # User-space shared libraries object files
661
662 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
663
664 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
665
666 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
667
668 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
669
670 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
671
672 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
673
674 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
675
676 endif
677
678
679 clean-local:
680         @echo Cleaning in $(USER_OBJS_DIR)
681         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
682                $(USER_OBJS_DIR)/*.d \
683                $(USER_OBJS_DIR)/*.map \
684                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
685                $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile)
686
687
688 default: include-pass library-pass binary-pass
689                                                                                  #OMK:config_h.omk@Makefile.rules.rtems
690 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
691 define BUILD_CONFIG_H_template
692
693 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
694         @$(QUIET_CMD_ECHO) "  CONFGEN $(notdir $(2))"
695         @if [ ! -d `dirname $(2).tmp` ] ; then \
696                 mkdir -p `dirname $(2).tmp` ; fi
697         @echo "/* Automatically generated from */" > "$(2).tmp"
698         @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
699         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
700         @echo "#ifndef $(4)" >> "$(2).tmp"
701         @echo "#define $(4)" >> "$(2).tmp"
702         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
703                 echo '$(x).$($(x))' ; ) echo ; ) | \
704                 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
705                 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
706                   >> "$(2).tmp"
707         @echo "#endif /*$(4)*/" >> "$(2).tmp"
708         @touch "$$@"
709         @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
710         else mv "$(2).tmp" "$(2)" ; \
711         echo "Updated configuration $(2)" ; fi
712
713 endef
714
715 ifdef LOCAL_CONFIG_H
716
717 # This must be declared after the default cflags are assigned!
718 # Override is used to override command line assignemnt.
719 override CFLAGS += -I $(USER_OBJS_DIR)
720 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
721 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
722
723 endif
724
725 # Special rules for configuration exported headers
726
727 #FIXME: The directory for headers should not be specified here.
728 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
729 _$(basename $(notdir $(confh)))_H \
730 )))
731
732 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
733
734 # Add some hooks to standard passes
735 include-pass-local: $(config_h_stamp_files)
736
737 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
738
739 ifdef LOCAL_CONFIG_H
740 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
741 endif
742
743 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
744 _$(basename $(notdir $(confh)))_H \
745 )))
746
747 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
748
749 # Add some hooks to standard passes
750 include-pass-local: $(kern_config_h_stamp_files)
751
752 endif
753
754 clean-local: clean-local-config-h
755
756 clean-local-config-h:
757         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
758             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
759         )
760                                                                                  #OMK:sources-list.omk@Makefile.rules.rtems
761 # Rules that creates the list of files which are used during
762 # compilation. The list reflects conditional compilation depending on
763 # config.omk and other variables.
764
765 SOURCES_LIST_FN=sources.txt
766 ifndef SOURCES_LIST
767 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
768 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
769 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
770 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
771 endif
772
773 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
774 NEED_SOURCES_LIST=y
775 endif
776
777 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
778 .PHONY: sources-list
779 sources-list: $(SOURCES_LIST)
780
781 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
782         @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
783         @echo -n "" > "$(SOURCES_LIST).tmp"
784         @echo -n "" > "$(SOURCES_LIST_D).tmp"
785         @$(MAKE) --no-print-directory sources-list-pass
786         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
787         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
788         @rm "$(SOURCES_LIST).tmp"
789         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
790         @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
791         @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
792                 sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
793         @rm "$(SOURCES_LIST_D).tmp"
794         @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
795 endif
796
797 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
798
799 sources-list-pass-local:
800         @$(foreach m,$(MAKEFILE_LIST),echo '  $(m)' >> "$(SOURCES_LIST_D).tmp";)
801         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
802           echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
803         @$(foreach ch,$(config_include_HEADERS), \
804           echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
805         @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
806         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
807           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
808           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
809
810 ############ TAGS ###########
811
812 ifeq ($(MAKECMDGOALS),TAGS)
813 ETAGS=etags
814 TAGS_CMD = $(ETAGS)
815 TAGS: $(SOURCES_LIST)
816         @$(MAKE) --no-print-directory do-tags
817 endif
818 ifeq ($(MAKECMDGOALS),tags) 
819 CTAGS=ctags -N
820 TAGS_CMD = $(CTAGS)
821 tags: $(SOURCES_LIST)
822         @$(MAKE) --no-print-directory do-tags
823 endif
824 export TAGS_CMD
825
826 ifeq ($(MAKECMDGOALS),do-tags)
827 .PHONY: do-tags
828 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
829         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
830         $(Q)$(TAGS_CMD) $^
831 endif
832
833 ############ CSCOPE ###########
834
835 cscope: $(SOURCES_LIST)
836         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
837         $(Q)sed -e '/^#/d' $(SOURCES_LIST) > cscope.files
838         $(Q)cscope -b -icscope.files
839 #FIXME: see doc to -i in cscope(1)