]> rtime.felk.cvut.cz Git - sysless.git/blob - Makefile.rules
Makefile.rules updated to the newest version.
[sysless.git] / Makefile.rules
1 #                   Version for system-less builds.          #OMK@sysless
2 #
3 #  Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base
4 #
5 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
6 #  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
7 #
8 #  Homepage: http://rtime.felk.cvut.cz/omk/
9 #
10 # The OMK build system is distributed under the GNU General Public
11 # License.  See file COPYING for details.
12 #
13 # input variables
14 # V                .. if set to 1, full command text is shown else short form is used
15 # W                .. whole tree - if set to 1, make is always called from the top-level directory
16 # SUBDIRS          .. list of subdirectories intended for make from actual directory
17 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
18 # LN_HEADERS       .. if "y", header files are symbolicaly linked instead of copied. #OMK@include
19 #                                                            #OMK@sysless
20 # bin_PROGRAMS     .. list of the require binary programs
21 # test_PROGRAMS    .. list of the test programs
22 # include_HEADERS  .. list of the user-space public header files
23 # lib_LIBRARIES    .. list of the user-space libraries
24 # lib_LDSCRIPTS    .. list of LD scripts that should be copied to the lib direcotry
25 # lib_obj_SOURCES  .. list of source files which should be compiled and
26 #                     the produced object file placed to the lib directory (e.g. crt0.S)
27 # shared_LIBRARIES .. list of the user-space shared libraries
28 # nobase_include_HEADERS .. public headers copied even with directory part
29 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
30 # utils_PROGRAMS   .. list of the development utility programs (compiled for host computer, this might change in future)
31 # xxx_SOURCES      .. list of specific target sources
32 # xxx_LIBS         .. list of specific target libraries
33 # INCLUDES         .. additional include directories and defines for user-space
34 # lib_LOADLIBES    .. list of libraries linked to each executable
35 # link_VARIANTS    .. list of ld script suffixes (after hypen `-') that
36 #                     should be used for linking (e.g. ram flash). If this is not
37 #                     specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
38 # PREFIX_DIR       .. Prefix to  directories in _compiled and _build. Used in config.omk.
39 # LOCAL_CONFIG_H   .. name of local config.h file generated from values #OMK@config_h
40 #                     of options defined in the current directory
41 # config_include_HEADERS .. names of global config files (possibly
42 #                     with subdirectories)
43 # xxx_DEFINES      .. list of config directives to be included in
44 #                     config header file of the name <somedir>/xxx.h
45 # DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
46 #                     command, so it is possible to document config
47 #                     variables.
48 # local_EVALUATE   .. Makefile hook, which is executed at the end of #OMK@localeval
49 #                     the Makefile.rules. Used only for dirty hacks.
50                                                              #OMK@sysless-setup
51 -include $(MAKERULES_DIR)/config.target
52
53 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
54 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
55
56 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
57 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
58
59 #=====================================================================
60 # Common utility rules
61
62 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
63
64
65 #=====================================================================
66 # Include correct rules for just running pass
67
68 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
69
70 USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
71 USER_LIB_DIR     = $(USER_COMPILED_DIR_NAME)/lib
72 USER_UTILS_DIR   = $(USER_COMPILED_DIR_NAME)/bin-utils
73 USER_TESTS_DIR   = $(USER_COMPILED_DIR_NAME)/bin-tests
74 USER_BIN_DIR     = $(USER_COMPILED_DIR_NAME)/bin
75 USER_OBJS_DIR    = $(LOCAL_BUILD_DIR)
76
77 # Local Variables:
78 # mode:makefile
79 # End:
80                                                              #OMK@base
81 # We need to ensure definition of sources directory first
82 ifndef SOURCES_DIR
83 SOURCES_DIR := $(shell ( pwd -L ) )
84 endif
85
86 .PHONY: all default check-make-ver omkize
87
88 ifdef W
89   ifeq ("$(origin W)", "command line")
90     OMK_WHOLE_TREE:=$(W)
91   endif
92 endif
93 ifndef OMK_WHOLE_TREE
94   OMK_WHOLE_TREE:=0
95 endif
96
97 ifneq ($(OMK_WHOLE_TREE),1)
98 all: check-make-ver default
99         @echo "Compilation finished"
100 else
101 # Run make in the top-level directory
102 all:
103         @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
104 endif
105
106 #=========================
107 # Include the config file
108
109 ifneq ($(CONFIG_FILE_OK),y)
110 ifndef CONFIG_FILE
111 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
112 endif
113 ifneq ($(wildcard $(CONFIG_FILE)-default),)
114 -include $(CONFIG_FILE)-default
115 else
116 ifneq ($(MAKECMDGOALS),default-config)
117 $(warning Please, run "make default-config" first)
118 endif
119 endif
120
121 ifneq ($(wildcard $(CONFIG_FILE)),)
122 include $(CONFIG_FILE)
123 CONFIG_FILE_OK = y
124 endif
125 endif #$(CONFIG_FILE_OK)
126
127 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
128 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
129 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
130 # must to be serialized only in the toplevel make.
131
132 ifndef RELATIVE_DIR
133 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
134 endif
135 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
136 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
137 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
138 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
139 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
140 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
141
142 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
143 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
144 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
145
146 # We have to use RELATIVE_PREFIX because of mingw
147 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
148 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
149
150 #vpath %.c $(SOURCES_DIR)
151 #vpath %.cc $(SOURCES_DIR)
152 #vpath %.cxx $(SOURCES_DIR)
153
154 VPATH = $(SOURCES_DIR)
155 srcdir = $(SOURCES_DIR)
156
157 # Defines for quiet compilation
158 ifdef V
159   ifeq ("$(origin V)", "command line")
160     OMK_VERBOSE = $(V)
161   endif
162 endif
163 ifndef OMK_VERBOSE
164   OMK_VERBOSE = 0
165 endif
166 ifneq ($(OMK_VERBOSE),0)
167   Q =
168 else
169   Q = @
170 endif
171 ifneq ($(findstring s,$(MAKEFLAGS)),)
172   QUIET_CMD_ECHO = true
173   OMK_SILENT = 1
174 else
175   QUIET_CMD_ECHO = echo
176 endif
177
178 MAKEFILE_OMK=Makefile.omk
179 # All subdirectories (even linked ones) containing Makefile.omk
180 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
181 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
182
183 # ===================================================================
184 # We have set up all important variables, so we can check and include
185 # real OCERA style Makefile.omk now
186 ifndef OMK_INCLUDED
187 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
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 $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_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 ($(V),2)
211 NO_PRINT_DIRECTORY := --no-print-directory
212 endif
213
214 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
215 define omk_pass_template
216 .PHNOY: $(1) $(1)-local
217 $(1):
218         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
219                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
220                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
221                 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
222 ifneq ($(4),)
223         @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
224         $(call mkdir_def,$(2)); \
225         $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
226                 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
227 endif
228 endef
229
230 # =======================
231 # DEFAULT CONFIG PASS
232
233 default-config:
234         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
235         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
236         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
237         @echo >> "$(CONFIG_FILE)-default"
238         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
239                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
240                 -f $(MAKERULES_DIR)/Makefile default-config-pass
241
242 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
243
244 default-config-pass-local:
245 #       @echo Default config for $(RELATIVE_DIR)
246         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
247         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
248                 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
249
250
251 omkize:
252         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
253            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
254         fi
255         $(Q)for i in `find -L . -name Makefile.omk` ; do \
256            i=`dirname $${i}`; \
257            if [ x"$$i" != x"." ]; then \
258               rm -f $${i}/Makefile; \
259               cp Makefile $${i}/Makefile; \
260            fi \
261         done
262                                                              #OMK@gcc
263 # Rules for compilation of C, C++ and assembler sources using GNU
264 # toolchain.
265
266 # Interface to other rules:
267
268 # Input variables:
269 # LIB_DIR - directory where compiled libraries are stored
270 # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
271 # INCLUDE_DIR - where includes can be found
272 # from config.omk or Makefile.omk
273 # CROSS_COMPILE - 
274 # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
275 # from base: SOURCES_DIR
276 # from Makefile.omk: lib_LOADLIBES
277
278 # Output variables:
279 # SOURCES - all the source files that needs to be compiled (except for shared library sources)
280 # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
281 # OBJ_EXT - extension of object files
282 # LIB_EXT - extension of library files
283 # LIB_PREF - prefix for library files
284 # ASM_EXT - extension of assembler sources
285
286 # Templates:
287 # COMPILER_DEFS_template - definitions that should be defined before
288 # the following templates can be used. The input variables needs to be
289 # defined before evaluating this template
290
291 # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
292 # templates that create rules for compilation of sources
293
294 # CMETRIC_o_h_template - FIXME
295
296 # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
297 # create rules for compilation of a program, library and shared
298 # library. The rules can use rules produced by COMPILE_xxx_template.
299
300 define COMPILER_DEFS_template
301 OBJ_EXT = .o
302 LIB_EXT = .a
303 LIB_PREF = lib
304 ASM_EXT = .S
305
306 CC = $(CROSS_COMPILE)gcc
307 LINK = $(CROSS_COMPILE)ld
308 AR = $(CROSS_COMPILE)ar
309 OBJCOPY = $(CROSS_COMPILE)objcopy
310 NM = $(CROSS_COMPILE)nm
311
312 CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE)
313 CFLAGS  += -Wall
314 CFLAGS += -I$(SOURCES_DIR)
315 CFLAGS += -I$(INCLUDE_DIR)
316
317 LOADLIBES += -L$(LIB_DIR)
318 LOADLIBES += $(lib_LOADLIBES:%=-l%)
319
320
321 -include $(OBJS_DIR)/*.d
322
323 #%.lo: %.c
324 #       $(CC) -o $@ $(LCFLAGS) -c $<
325
326 c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
327         $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
328
329 cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
330         $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
331
332 S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
333         $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS)
334
335
336 # Check GCC version for user build
337 ifndef CC_MAJOR_VERSION
338 CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
339 endif
340 # Prepare suitable define for dependency building
341 ifeq ($$(CC_MAJOR_VERSION),2)
342 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
343 else
344 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
345 endif
346
347 endef # COMPILER_DEFS_template
348
349
350 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
351 define COMPILE_c_o_template
352 $(2): $(1) $$(GEN_HEADERS)
353         @$(QUIET_CMD_ECHO) "  CC      $$@"
354         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
355         then mv -f "$$@.d.tmp" "$$@.d" ; \
356         else rm -f "$$@.d.tmp" ; exit 1; \
357         fi
358 endef
359
360
361
362 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
363 define COMPILE_cc_o_template
364 $(2): $(1) $$(GEN_HEADERS)
365         @$(QUIET_CMD_ECHO) "  CXX     $$@"
366         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
367         then mv -f "$$@.d.tmp" "$$@.d" ; \
368         else rm -f "$$@.d.tmp" ; exit 1; \
369         fi
370 endef
371
372 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
373 define COMPILE_S_o_template
374 $(2): $(1) $$(GEN_HEADERS)
375         @$(QUIET_CMD_ECHO) "  AS      $$@"
376         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
377         then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
378         else rm -f "$$@.d.tmp" ; exit 1; \
379         fi
380 endef
381
382 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
383 define CMETRIC_o_h_template
384 $(2): $(1)
385         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
386         $(Q)if [ -n `dirname $$@` ] ; then \
387               if [ ! -e `dirname $$@` ] ; then \
388                 mkdir -p `dirname $$@` ; fi ; fi
389         $(Q)echo >$$@ '/* Automatically generated from $$< */'
390         $(Q)echo >>$$@ '/* Conditionals to control compilation */'
391         $(Q)set -o pipefail ; $(NM) $$< \
392                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
393                 | sort >>$$@
394         $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
395         $(Q)set -o pipefail ; $(NM) $$< \
396                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
397                 | sort >>$$@
398 endef
399
400 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
401 define PROGRAM_template
402 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
403 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
404 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
405 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
406 $(1)_OBJS += $$(filter %.o,$(1)_SOURCES)
407 $(1)_OBJS := $$(sort $$($(1)_OBJS))
408
409 SOURCES += $$($(1)_SOURCES)
410
411 ifneq ($(LD_SCRIPT),)
412 $(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%)
413 endif
414
415 $(2)/$(1)$(3:%=-%): $$($(1)_OBJS)
416         @$(QUIET_CMD_ECHO) "  LINK    $$@"
417         $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
418           then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS)   $$(CFLAGS) ; \
419           else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
420           $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \
421           $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \
422           -o $$@
423         @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
424         @if [ -n "$(LD_SCRIPT)" ]; then \
425           echo "  $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi
426         @sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(OBJS_DIR)/$(1)$(3:%=-%).map  >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
427         @echo >>$(OBJS_DIR)/$(1).exe.d
428 endef
429
430 # Rules for other output formats (can be specified by OUTPUT_FORMATS)
431 %.bin: %
432         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
433         $(Q) $(OBJCOPY)  --output-target=binary -S $< $@
434
435 %.hex: %
436         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
437         $(Q) $(OBJCOPY)  --output-target=ihex -S $< $@
438
439 %.srec: %
440         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
441         $(Q) $(OBJCOPY)  --output-target=srec -S $< $@
442
443 # Syntax: $(call LIBRARY_template,<library-name>)
444 define LIBRARY_template
445 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
446 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
447 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
448 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
449 $(1)_OBJS := $$(sort $$($(1)_OBJS))
450
451 SOURCES += $$($(1)_SOURCES)
452
453 $(LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
454         @$(QUIET_CMD_ECHO) "  AR      $$@"
455         $(Q) $(AR) rcs $$@ $$^
456 endef
457
458
459 # Syntax: $(call SOLIB_template,<library-name>)
460 define SOLIB_template
461 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
462 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
463 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
464 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
465 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
466
467 SOLIB_OBJS  += $$($(1)_OBJSLO)
468 SOLIB_SOURCES += $$($(1)_SOURCES)
469
470 $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
471         @$(QUIET_CMD_ECHO) "  LINK    $$@"
472         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
473 endef
474
475 # Local Variables:
476 # mode:makefile
477 # End:
478 ifeq ($(OMK_VERBOSE),1)                                      #OMK@include
479 CPHEADER_FLAGS += -v
480 LNHEADER_FLAGS += -v
481 endif
482
483 ifneq ($(LN_HEADERS),y)
484 define cp_cmd
485 ( echo "  CP      $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
486 endef
487 else
488 define cp_cmd
489 ( echo "  LN      $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
490 endef
491 endif
492
493 # TODO: Check modification date of changed header files. If it is
494 # newer that in source dir, show a warning.
495
496 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
497 define include-pass-template
498         @$(foreach f, $($(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(notdir $(f)) \
499            || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(notdir $(f))) || exit 1 ; )
500         @$(foreach f, $(nobase_$(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(f) \
501            || ( mkdir -p $(1)/$(dir $(f)) && $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(f)) ) || exit 1 ; )
502         @$(foreach f, $(renamed_$(2)_HEADERS), \
503            srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \
504            cmp --quiet $(SOURCES_DIR)/$${srcfname} $(1)/$${destfname} \
505            || ( mkdir -p `dirname $(1)/$${destfname}` && $(call cp_cmd,$(SOURCES_DIR)/$${srcfname},$(1)/$${destfname}) ) || exit 1 ; )
506 endef
507
508 # Local Variables:
509 # mode:makefile
510 # End:
511                                                              #OMK@sysless
512 .PHONY: check-dir
513
514 # Some support to serialize some targets for parallel make
515 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
516 include-pass: check-dir
517 library-pass: include-pass
518 binary-pass utils-pass: library-pass
519
520 override OMK_SERIALIZE_INCLUDED = y
521 endif
522
523 # -------------------------------------
524 # Rules for compilation for target
525 ifdef TARGET_RULE_TEMPLATES
526
527 LDFLAGS += -nostartfiles
528
529  # FIXME: These are not used. What they are good for?
530 LIB_CPPFLAGS += $(CPPFLAGS)
531 LIB_CFLAGS   += $(CFLAGS)
532
533 SOLIB_PICFLAGS += -shared -fpic
534
535 CFLAGS += -DOMK_FOR_TARGET
536
537 INCLUDE_DIR := $(USER_INCLUDE_DIR)
538 LIB_DIR     := $(USER_LIB_DIR)
539 OBJS_DIR    := $(USER_OBJS_DIR)
540
541 $(eval $(COMPILER_DEFS_template))
542
543 # Special rules for CMETRIC generated headers
544
545 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
546                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
547                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
548 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
549                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
550                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
551
552 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
553
554 # Generate rules for compilation of programs and libraries
555 ifneq ($(link_VARIANTS),)
556 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
557 $(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
558 else
559 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
560 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
561 endif
562
563 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
564 $(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
565 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
566
567
568 # lib_obj_SOURCES handling
569 lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
570 #$(warning lib_OBJS = $(lib_OBJS))
571 SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
572
573 $(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
574         @echo "  CP      $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
575         $(Q)cp $(CP_FLAGS) $< $@
576
577
578 # User-space static libraries and applications object files
579 SOURCES := $(sort $(SOURCES))
580 #$(warning SOURCES = $(SOURCES))
581
582 # User-space shared libraries object files
583 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
584 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
585
586
587 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
588 # variables. Now generate rules for compilation of theese sources
589 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
590 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
591 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
592 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
593
594 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
595 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
596 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
597 $(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
598
599 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
600                     $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
601                     $(addprefix $(LIB_DIR)/,$(lib_OBJS))
602
603 ifneq ($(link_VARIANTS),)
604 binary-pass-local:  $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
605                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
606 else
607 binary-pass-local:  $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
608                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
609 endif
610
611 endif # TARGET_RULE_TEMPLATES
612
613
614 # -------------------------------------
615 # Rules for compilation utilities for host (user space)
616 ifdef HOST_RULE_TEMPLATES
617
618 CROSS_COMPILE =
619 TARGET_ARCH =
620
621 SOLIB_PICFLAGS += -shared -fpic
622
623 # For host compilation, we don't use a specfic ld script
624 LD_SCRIPT =
625
626 # TODO: It is probably better to use different directories for host
627 # includes, libraries and objects
628 INCLUDE_DIR := $(USER_INCLUDE_DIR)
629 LIB_DIR     := $(USER_LIB_DIR)
630 OBJS_DIR    := $(USER_OBJS_DIR)
631
632 $(eval $(COMPILER_DEFS_template))
633
634  #User-space static libraries and applications object files
635 #SOURCES := $(sort $(SOURCES))
636 #$(warning SOURCES = $(SOURCES))
637
638 # Generate rules for compilation of utility programs
639 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
640
641 # The above generated rule produced $(SOURCES) variable. Now generate
642 # rules for compilation of theese sources
643 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
644 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
645 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
646 $(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
647
648 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
649
650 endif # HOST_RULE_TEMPLATES
651
652
653 #=====================================================================
654 # Automatic loading of compiled program by issuing "make load"
655
656 ifneq ($(OUTPUT_FORMATS),)
657 # Select a file extension (e.g. .bin) for "make load" command to load.
658 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
659 endif
660
661 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
662 # Used to load program to the target hardware
663 define LOAD_PROGRAM_template
664 .PHONY: load-$(1)$(3:%=-%)
665 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
666         @$(QUIET_CMD_ECHO) "  LOAD    $$<"
667         @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
668         $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
669 endef
670
671 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
672 # Used to load and/or run non-default variant of the default program
673 define LOAD_RUN_VARIANT_template
674 .PHONY: load-$(1) run-$(1)
675
676 load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
677
678 run-$(1):
679         @$(QUIET_CMD_ECHO) "  RUN     $(1)"
680         @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
681         $(Q) $(RUN_CMD-$(1))
682
683 endef
684
685 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
686 $(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TEST_DIR),$(link)))))
687 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
688
689 .PHONY: load run
690 load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
691
692 run: run-$(firstword $(link_VARIANTS))
693
694
695
696 #=====================================================================
697 # Generate pass rules from generic templates
698 OTHER_PASSES = dep clean install
699
700 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
701 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
702 $(eval $(call omk_pass_template, binary-pass,  $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
703 $(eval $(call omk_pass_template, utils-pass,   $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
704
705
706 $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR),,always))
707
708
709 dep-local:
710
711 install-local:
712
713 include-pass-local:
714         $(call include-pass-template,$(USER_INCLUDE_DIR),include)
715         @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
716            || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
717
718
719 .PHONY: clean-custom
720 clean-local: clean-custom
721         $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
722                $(USER_OBJS_DIR)/*.d \
723                $(USER_OBJS_DIR)/*.map \
724                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
725
726 check-dir:
727         @$(call mkdir_def,$(USER_INCLUDE_DIR))
728         @$(call mkdir_def,$(USER_LIB_DIR))
729         @$(call mkdir_def,$(USER_BIN_DIR))
730         @$(call mkdir_def,$(USER_UTILS_DIR))
731         @$(call mkdir_def,$(USER_TESTS_DIR))
732
733 # Which passes to pass
734 default: include-pass library-pass binary-pass utils-pass
735
736 # Local Variables:
737 # mode:makefile
738 # End:
739                                                              #OMK@config_h
740 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
741 define BUILD_CONFIG_H_template
742
743 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default)
744         @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:%.stamp=%)"
745         @if [ ! -d `dirname $(2).tmp` ] ; then \
746                 mkdir -p `dirname $(2).tmp` ; fi
747         @echo "/* Automatically generated from */" > "$(2).tmp"
748         @echo "/* config file: $$< */" >> "$(2).tmp"
749         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
750         @echo "#ifndef $(4)" >> "$(2).tmp"
751         @echo "#define $(4)" >> "$(2).tmp"
752         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
753                 echo '$(x).$($(x))' ; ) echo ; ) | \
754                 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
755                 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
756                   >> "$(2).tmp"
757         @echo "#endif /*$(4)*/" >> "$(2).tmp"
758         @touch "$$@"
759         @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
760         else mv "$(2).tmp" "$(2)" ; \
761         echo "Updated configuration $(2)" ; fi
762
763 endef
764
765 ifdef LOCAL_CONFIG_H
766
767 # This must be declared after the default cflags are assigned!
768 # Override is used to override command line assignemnt.
769 override CFLAGS += -I.
770 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
771
772 endif
773
774 # Special rules for configuration exported headers
775
776 #FIXME: The directory for headers should not be specified here.
777 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
778 _$(basename $(notdir $(confh)))_H \
779 )))
780
781 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
782
783 # Add some hooks to standard passes
784 include-pass-local: $(config_h_stamp_files)
785
786 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
787
788 ifdef LOCAL_CONFIG_H
789 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
790 endif
791
792 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
793 _$(basename $(notdir $(confh)))_H \
794 )))
795
796 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
797
798 # Add some hooks to standard passes
799 include-pass-local: $(kern_config_h_stamp_files)
800
801 endif
802
803 clean-local: clean-local-config-h
804
805 clean-local-config-h:
806         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
807             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
808         )
809
810
811 # Local Variables:
812 # mode:makefile
813 # End:
814                                                              #OMK@sources-list
815 # Rules that creates the list of files which are used during
816 # compilation. The list reflects conditional compilation depending on
817 # config.omk and other variables.
818
819 SOURCES_LIST_FN=sources.txt
820 ifndef SOURCES_LIST
821 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
822 SOURCES_LIST:=$(MAKERULES_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
823 export SOURCES_LIST SOURCES_LIST_DIR
824 endif
825
826 ifeq ($(MAKECMDGOALS),sources-list)
827 NEED_SOURCES_LIST=y
828 endif
829 ifeq ($(MAKECMDGOALS),TAGS)
830 NEED_SOURCES_LIST=y
831 endif
832 ifeq ($(MAKECMDGOALS),tags)
833 NEED_SOURCES_LIST=y
834 endif
835
836 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
837 .PHONY: sources-list
838 sources-list: $(SOURCES_LIST)
839
840 $(SOURCES_LIST): $(CONFIG_FILE) $(CONFIG_FILE)-default $(shell find -name $(MAKEFILE_OMK))
841         @echo -n "" > "$(SOURCES_LIST).tmp"
842         @$(MAKE) --no-print-directory sources-list-pass
843         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
844         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
845         @rm "$(SOURCES_LIST).tmp"
846         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
847 endif
848
849 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
850
851 sources-list-pass-local:
852         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
853           echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)" >> "$(SOURCES_LIST).tmp";)
854         @$(foreach ch,$(config_include_HEADERS), \
855           echo "$(USER_INCLUDE_DIR:$(MAKERULES_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
856         @$(foreach h,$(renamed_include_HEADERS),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)"|sed -e 's/\(.*\)->.*/\1/' >> "$(SOURCES_LIST).tmp";)
857         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
858           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
859           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(src)" >> "$(SOURCES_LIST).tmp";))
860
861 ############ TAGS ###########
862
863 ifeq ($(MAKECMDGOALS),TAGS)
864 ETAGS=etags
865 TAGS_CMD = $(ETAGS)
866 TAGS: $(SOURCES_LIST)
867         @$(MAKE) --no-print-directory do-tags
868 endif
869 ifeq ($(MAKECMDGOALS),tags) 
870 CTAGS=ctags -N
871 TAGS_CMD = $(CTAGS)
872 tags: $(SOURCES_LIST)
873         @$(MAKE) --no-print-directory do-tags
874 endif
875 export TAGS_CMD
876
877 ifeq ($(MAKECMDGOALS),do-tags)
878 .PHONY: do-tags
879 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
880         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
881         $(Q)$(TAGS_CMD) $^
882 endif
883
884 ############ CSCOPE ###########
885
886 cscope: $(SOURCES_LIST)
887         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
888         $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
889 #FIXME: see doc to -i in cscope(1)
890
891 # Local Variables:
892 # mode:makefile
893 # End:
894                                                              #OMK@localeval
895 ifneq ($(local_EVALUATE),)
896 #$(warning $(local_EVALUATE))
897 $(eval $(local_EVALUATE))
898 endif
899
900 # Local Variables:
901 # mode:makefile
902 # End: