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