]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - marte/Makefile.rules
First import based on FRESCOR omk-build repository
[frescor/frsh-forb.git] / marte / Makefile.rules
1 #                   Version for Linux/RTLinux builds.        #OMK@linux
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@linux
20 # input variables
21 # lib_LIBRARIES    .. list of the user-space libraries
22 # shared_LIBRARIES .. list of the user-space shared libraries
23 # kernel_LIBRARIES .. list of the kernel-space libraries
24 # rtlinux_LIBRARIES.. list of the RT-Linux kernel-space libraries
25 # include_HEADERS  .. list of the user-space public header files
26 # nobase_include_HEADERS .. public headers copied even with directory part
27 # renamed_include_HEADERS .. public headers copied to the different target name
28 # kernel_HEADERS   .. list of the kernel-space public header files
29 # rtlinux_HEADERS  .. list of the RT-Linux kernel-space public header files
30 # bin_PROGRAMS     .. list of the require binary programs
31 # utils_PROGRAMS   .. list of the development utility programs
32 # test_PROGRAMS    .. list of the testing programs
33 # kernel_MODULES   .. list of the kernel side modules/applications
34 # rtlinux_MODULES  .. list of RT-Linux the kernel side modules/applications
35 # xxx_SOURCES      .. list of specific target sources
36 # xxx_LIBS         .. list of specific target libraries
37 # INCLUDES         .. additional include directories and defines for user-space
38 # kernel_INCLUDES  .. additional include directories and defines for kernel-space
39 # rtlinux_INCLUDES .. additional include directories and defines for RT-Linux
40 # OMIT_KERNEL_PASSES  if defined, all kernel passes are omited
41 #
42 # LINUX_DIR        .. location of Linux kernel sources
43 # RTL_DIR          .. location of RT-Linux sources
44 # CFLAGS           .. C compiler flags
45 # CXXFLAGS         .. C++ compiler flags
46 # CPPFLAGS         .. C preprocessor flags
47 # LDFLAGS          .. linker flags for programs linking
48 # LOCAL_CONFIG_H   .. name of local config.h file generated from values #OMK@config_h
49 #                     of options defined in the current directory
50 # config_include_HEADERS .. names of global config files (possibly
51 #                     with subdirectories)
52 # xxx_DEFINES      .. list of config directives to be included in
53 #                     config header file of the name <somedir>/xxx.h
54 # DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
55 #                     command, so it is possible to document config
56 #                     variables.
57 # QT_SUBDIRS       .. subdirectories where to build QT applications using qmake #OMK@qt
58 # QTDIR            .. where QT resides
59 OMK_RULES_TYPE=linux                                         #OMK@__type
60                                                              #OMK@base
61 # We need to ensure definition of sources directory first
62 ifndef SOURCES_DIR
63 # Only shell built-in pwd understands -L
64 SOURCES_DIR := $(shell ( pwd -L ) )
65 endif
66
67 # If we are not called by OMK leaf Makefile...
68 ifndef MAKERULES_DIR
69 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
70 endif
71
72 # OUTPUT_DIR is the place where _compiled, _build and possible other
73 # files/directories are created. By default is the same as
74 # $(MAKERULES_DIR).
75 ifndef OUTPUT_DIR
76 OUTPUT_DIR := $(MAKERULES_DIR)
77 endif
78
79 .PHONY: all default check-make-ver omkize
80
81 ifdef W
82   ifeq ("$(origin W)", "command line")
83     OMK_WHOLE_TREE:=$(W)
84   endif
85 endif
86 ifndef OMK_WHOLE_TREE
87   OMK_WHOLE_TREE:=0
88 endif
89
90 ifneq ($(OMK_WHOLE_TREE),1)
91 all: check-make-ver default
92         @echo "Compilation finished"
93 else
94 # Run make in the top-level directory
95 all:
96         @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
97 endif
98
99 ifdef OMK_TESTSROOT
100 # Usage: $(call canttest,<error message>)
101 define canttest
102         ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
103 endef
104 else
105 define canttest
106         echo "$(1)"
107 endef
108 endif
109
110 #=========================
111 # Include the config file
112
113 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
114 # config files and it is not clearly defined to which file is this
115 # variable related.
116 ifneq ($(CONFIG_FILE_OK),y)
117 ifndef CONFIG_FILE
118 CONFIG_FILE      := $(OUTPUT_DIR)/config.omk
119 endif
120 ifneq ($(wildcard $(CONFIG_FILE)-default),)
121 -include $(CONFIG_FILE)-default
122 else
123 ifneq ($(MAKECMDGOALS),default-config)
124 $(warning Please, run "make default-config" first)
125 endif
126 endif
127
128 -include $(OUTPUT_DIR)/config.target
129
130 ifneq ($(wildcard $(CONFIG_FILE)),)
131 -include $(CONFIG_FILE)
132 CONFIG_FILE_OK = y
133 endif
134 endif #$(CONFIG_FILE_OK)
135
136
137 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
138
139
140 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
141 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
142 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
143 # must to be serialized only in the toplevel make.
144
145 ifndef RELATIVE_DIR
146 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
147 endif
148 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
149 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
150 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
151 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
152 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
153 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
154
155 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
156 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
157 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
158
159 # We have to use RELATIVE_PREFIX because of mingw
160 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
161 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
162
163 #vpath %.c $(SOURCES_DIR)
164 #vpath %.cc $(SOURCES_DIR)
165 #vpath %.cxx $(SOURCES_DIR)
166
167 # Define srcdir for Automake compatibility
168 srcdir = $(SOURCES_DIR)
169
170 # Defines for quiet compilation
171 ifdef V
172   ifeq ("$(origin V)", "command line")
173     OMK_VERBOSE = $(V)
174   endif
175 endif
176 ifndef OMK_VERBOSE
177   OMK_VERBOSE = 0
178 endif
179 ifneq ($(OMK_VERBOSE),0)
180   Q =
181 else
182   Q = @
183 endif
184 ifneq ($(findstring s,$(MAKEFLAGS)),)
185   QUIET_CMD_ECHO = true
186   OMK_SILENT = 1
187 else
188   QUIET_CMD_ECHO = echo
189 endif
190
191 MAKEFILE_OMK=Makefile.omk
192 # All subdirectories (even linked ones) containing Makefile.omk
193 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
194 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
195
196 # ===================================================================
197 # We have set up all important variables, so we can check and include
198 # real OCERA style Makefile.omk now
199 ifndef OMK_INCLUDED
200 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
201 ifeq ($(AUTOMATIC_SUBDIRS),y)
202 SUBDIRS?=$(ALL_OMK_SUBDIRS)
203 endif
204 OMK_INCLUDED := 1
205 endif
206
207 check-make-ver:
208         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
209         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
210                 echo "Your make program version is too old and does not support OMK system." ; \
211                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
212         fi
213
214 distclean dist-clean:
215         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
216         @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)  $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
217
218 # Common OMK templates
219 # ====================
220
221 # Syntax: $(call mkdir,<dir name>)
222 define mkdir_def
223         [ -d $(1) ] || mkdir -p $(1) || exit 1
224 endef
225
226 ifneq ($(OMK_VERBOSE),2)
227 NO_PRINT_DIRECTORY := --no-print-directory
228 endif
229
230 ifeq ($(USE_LEAF_MAKEFILES),n)
231 export USE_LEAF_MAKEFILES
232 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
233 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
234 else
235 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
236 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
237 endif
238
239 pass = $(strip $(1))
240
241 # Call a pass in a subdirectory
242 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
243 define omk_pass_subdir_template
244 .PHONY: $(pass)-$(3)-subdir
245 $(pass)-submakes: $(pass)-$(3)-subdir
246 $(pass)-$(3)-subdir:
247         @$(call mkdir_def,$(2)/$(3))
248         +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
249                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
250                 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
251 # In subdirectories we can call submakes directly since passes are
252 # already searialized on the toplevel make.
253 endef
254
255 ifdef OMK_TESTSROOT
256 check-target = $(1:%=%-check)
257 endif
258
259 # Call a pass in a subdirectory
260 # Usage: $(call extra_rules_subdir_template,<subdir>)
261 define extra_rules_subdir_template
262 extra-rules-subdirs: extra-rules-$(1)
263 extra-rules-$(1):
264         +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
265                 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
266 endef
267
268 .PHONY: extra-rules-subdirs
269 extra-rules-subdirs:
270
271 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
272
273 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
274 define omk_pass_template
275 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
276 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
277 $(pass):
278 # Submakes have to be called this way and not as dependecies for pass
279 # serialization to work
280         +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
281                 RELATIVE_DIR=$(RELATIVE_DIR) \
282                 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
283 $(pass)-submakes:
284         @true                   # Do not emit "nothing to be done" messages
285
286 ifneq ($(4)$($(pass)_HOOKS),)
287 $(pass)-submakes: $(pass)-this-dir
288 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
289         +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
290         @$(call mkdir_def,$(2))
291         +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
292                 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
293 $(pass)-local: $($(pass)_HOOKS)
294 endif
295 endef
296
297 # =======================
298 # DEFAULT CONFIG PASS
299
300 default-config:
301         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
302         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
303         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
304         @echo >> "$(CONFIG_FILE)-default"
305         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
306                 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
307                 -f $(OUTPUT_DIR)/Makefile default-config-pass
308
309 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
310
311 default-config-pass-local:
312 #       @echo Default config for $(RELATIVE_DIR)
313         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
314         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
315                 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
316
317
318 omkize:
319         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
320            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
321         fi
322         $(Q)for i in `find -L . -name Makefile.omk` ; do \
323            d=`dirname $${i}`; \
324            if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
325               rm -f "$${d}/Makefile"; \
326               cp -v Makefile "$${d}/Makefile"; \
327            fi \
328         done
329 ifeq ($(OMK_VERBOSE),1)                                      #OMK@include
330 CPHEADER_FLAGS += -v
331 LNHEADER_FLAGS += -v
332 endif
333
334 ifneq ($(LN_HEADERS),y)
335 define cp_cmd
336 ( echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
337 endef
338 else
339 define cp_cmd
340 ( echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
341 endef
342 endif
343
344 # TODO: Check modification date of changed header files. If it is
345 # newer that in source dir, show a warning.
346
347 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
348 define include-pass-template
349 include-pass-local: include-pass-local-$(2)
350 include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'))
351         @$$(foreach f, $$($(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(notdir $$(f)) \
352            || $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; )
353         @$$(foreach f, $$($(2)_GEN_HEADERS), cmp --quiet $$(f) $(1)/$$(notdir $$(f)) \
354            || $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; ) # FIXME: Use correct build dir, then document it
355         @$$(foreach f, $$(nobase_$(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(f) \
356            || ( mkdir -p $(1)/$$(dir $$(f)) && $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)) ) || exit 1 ; )
357         @$$(foreach f, $$(renamed_$(2)_HEADERS), \
358            srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
359            cmp --quiet $$(SOURCES_DIR)/$$$${srcfname} $(1)/$$$${destfname} \
360            || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
361         @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
362            srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
363            cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
364            || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
365 endef
366
367 # Local Variables:
368 # mode:makefile
369 # End:
370                                                              #OMK@linux
371 # Hack to check RT-Linux rules
372 #LINUX_DIR := /home/cvs/ocera/ocera-build/kernel/linux
373 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
374 #CONFIG_RTLINUX = y
375 #OCERA_DIR := $(shell ( cd -L $(OUTPUT_DIR)/../../.. ; pwd -L ) )
376
377 -include $(OUTPUT_DIR)/OCERA_TOP_DIR
378
379 BUILD_DIR_NAME = _build
380 COMPILED_DIR_NAME = _compiled
381 ifndef GROUP_DIR_NAME
382 GROUP_DIR_NAME = nogroup
383 endif
384
385 ifdef OCERA_DIR
386 ifeq ($(wildcard $(OCERA_DIR)/ocera.mk),)
387 $(warning "ocera.mk" file does not exist. Adapt Makefile.rules for standalone compilation)
388 $(warning (comment out definition of OCERA_DIR line and optionally select RTL_DIR) )
389 $(error or go to the ocera/ directory and do 'make' to generate the "ocera.mk" file first, please)
390 endif
391 include $(OCERA_DIR)/ocera.mk
392 KERN_INCLUDE_DIR := $(OCERA_KERNEL_INCLUDES_DIR)
393 KERN_LIB_DIR     := $(OCERA_KERNEL_LIBRARIES_DIR)
394 KERN_MODULES_DIR := $(OCERA_MODULES_DIR)
395 KERN_BUILD_DIR   := $(BUILD_DIR)/kern/$(GROUP_DIR_NAME)
396 KERN_MODPOST_DIR := $(BUILD_DIR)/kern-modpost
397 USER_INCLUDE_DIR := $(OCERA_USER_INCLUDES_DIR)
398 USER_LIB_DIR     := $(OCERA_USER_LIBRARIES_DIR)
399 USER_UTILS_DIR   := $(TARGET_DIR)/usr/bin
400 USER_TESTS_DIR   := $(TARGET_DIR)/usr/bin
401 USER_BIN_DIR     := $(TARGET_DIR)/usr/bin
402 USER_BUILD_DIR   := $(BUILD_DIR)/user/$(GROUP_DIR_NAME)
403 #LINUX_DIR        := $(OCERA_DIR)/kernel/linux
404 #RTL_DIR          := $(OCERA_DIR)/kernel/rtlinux
405 #CONFIG_FILE      := $(OCERA_DIR)/emdebsys/.config 
406 ifneq ($(wildcard $(CONFIG_FILE)),)
407 CONFIG_FILE_OK = y
408 endif
409 else # OCERA_DIR
410 KERN_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include-kern
411 KERN_LIB_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib-kern
412 KERN_MODULES_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/modules
413 KERN_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern
414 KERN_MODPOST_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern-modpost
415 USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include
416 USER_LIB_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib
417 USER_UTILS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils
418 USER_TESTS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests
419 USER_BIN_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin
420 USER_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user
421
422 ifndef LINUX_VERSION
423 LINUX_VERSION=$(shell uname -r)
424 endif
425 ifndef LINUX_DIR
426 LINUX_DIR=/lib/modules/$(LINUX_VERSION)/build
427 endif
428 endif # OCERA_DIR
429
430 ifeq ($(BUILD_OS),)
431   # Check for target
432   ifeq ($(OS),Windows_NT)
433     BUILD_OS := win32
434   else
435     BUILD_OS := $(shell uname | tr '[A-Z]' '[a-z]' )
436     #$(warning BUILD_OS=$(BUILD_OS))
437   endif
438 endif
439
440 ifeq ($(TARGET_OS),)
441   TARGET_OS := $(BUILD_OS)
442 endif
443
444 export TARGET_OS
445 export BUILD_OS
446
447 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
448
449 # Assign default values to CFLAGS variable. If the variable is defined
450 # earlier (i.g. in config.omk), it is not overriden here.
451 CFLAGS ?= -O2 -Wall
452 CXXFLAGS ?= -O2 -Wall
453
454
455 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
456
457 LOADLIBES += -L$(USER_LIB_DIR) 
458
459 LOADLIBES += $(lib_LOADLIBES:%=-l%)
460
461 LIB_CPPFLAGS += $(CPPFLAGS)
462 LIB_CFLAGS   += $(CFLAGS)
463
464 ifeq ($(TARGET_OS),win32)
465   SOLIB_EXT = dll
466 else
467   SOLIB_EXT = so
468   SOLIB_PICFLAGS += -fpic
469 endif
470
471 #vpath %.c $(SOURCES_DIR)
472 #vpath %.cc $(SOURCES_DIR)
473 #vpath %.cxx $(SOURCES_DIR)
474
475 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
476 KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR)
477
478 .PHONY: dep subdirs clean clean-custom cleandepend check-dir
479
480 # Some support to serialize some targets for parallel make
481 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
482 include-pass: check-dir
483 library-pass: include-pass
484 binary-pass: library-pass
485 kernel-lib-pass: include-pass
486 kernel-mod-pass: kernel-lib-pass
487 kernel-modpost-pass: kernel-mod-pass
488 kernel-pass: kernel-mod-pass kernel-modpost-pass
489
490 override OMK_SERIALIZE_INCLUDED = y
491 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
492 endif
493
494 # Checks for OMK tester
495 ifdef OMK_TESTSROOT
496 default-config-pass-check include-pass-check:
497 library-pass-check binary-pass-check:
498         @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
499 endif
500
501 #=====================================================================
502 # User-space rules and templates to compile programs, libraries etc.
503
504 ifdef USER_RULE_TEMPLATES
505
506 USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.S .o/.o
507
508 USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.lo
509
510 #%.lo: %.c
511 #       $(CC) -o $@ $(LCFLAGS) -c $<
512
513 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
514         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
515
516 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
517         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
518
519 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
520         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
521
522 idl_COMPILE = $(IDL_COMPILER)
523
524 # Check GCC version for user build
525 ifndef CC_MAJOR_VERSION
526 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
527 endif
528 # Prepare suitable define for dependency building
529 ifeq ($(CC_MAJOR_VERSION),2)
530 CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
531 else
532 CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
533 endif
534
535
536 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
537 define COMPILE_c_o_template
538 $(2): $(1) $$(GEN_HEADERS)
539         @$(QUIET_CMD_ECHO) "  CC      $$@"
540         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
541         then mv -f "$$@.d.tmp" "$$@.d" ; \
542         else rm -f "$$@.d.tmp" ; exit 1; \
543         fi
544 endef
545
546
547 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
548 define COMPILE_cc_o_template
549 $(2): $(1) $$(GEN_HEADERS)
550         @$(QUIET_CMD_ECHO) "  CXX     $$@"
551         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
552         then mv -f "$$@.d.tmp" "$$@.d" ; \
553         else rm -f "$$@.d.tmp" ; exit 1; \
554         fi
555 endef
556
557
558 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
559 define COMPILE_S_o_template
560 $(2): $(1) $$(GEN_HEADERS)
561         @$(QUIET_CMD_ECHO) "  AS      $$@"
562         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
563         then mv -f "$$@.d.tmp" "$$@.d" ; \
564         else rm -f "$$@.d.tmp" ; exit 1; \
565         fi
566 endef
567
568
569 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
570 define CMETRIC_o_h_template
571 $(2): $(1)
572         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
573         $(Q)if [ -n `dirname $$@` ] ; then \
574               if [ ! -e `dirname $$@` ] ; then \
575                 mkdir -p `dirname $$@` ; fi ; fi
576         $(Q)echo >$$@ '/* Automatically generated from $$< */'
577         $(Q)echo >>$$@ '/* Conditionals to control compilation */'
578         $(Q)set -o pipefail ; $(NM) $$< \
579                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
580                 | sort >>$$@
581         $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
582         $(Q)set -o pipefail ; $(NM) $$< \
583                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
584                 | sort >>$$@
585 endef
586
587
588
589 define COMPILE_idl_template
590 $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1)
591         @$(QUIET_CMD_ECHO) "  IDL     $$@"
592         $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
593 endef
594
595
596 # Syntax: $(call PROGRAM_template,<dir>,<executable-name>,<executable-suffix>,<linker-sript>)
597 # FIXME: ???????? asi je tu blbej komentar
598 define PROGRAM_template
599
600 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
601 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
602 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
603 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
604 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
605 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
606 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
607
608 $(foreach x, $(USER_SOURCES2OBJS),
609 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
610                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
611 )
612 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
613
614 USER_OBJS  += $$($(1)_OBJS)
615 USER_SOURCES += $$($(1)_SOURCES)
616
617 $(2)/$(1)$(3): $$($(1)_OBJS)
618         @$(QUIET_CMD_ECHO) "  LINK    $$@"
619         $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES:%.cxx=%.cc)),$$(CXX),$$(CC)) \
620           $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
621         @echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
622         @sed -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134'  >>$(USER_OBJS_DIR)/$(1).exe.d
623         @echo >>$(USER_OBJS_DIR)/$(1).exe.d
624 endef
625
626
627 # Syntax: $(call LIBRARY_template,<library-name>)
628 define LIBRARY_template
629
630 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
631 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
632 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
633 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
634 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
635 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
636 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
637
638 $(foreach x, $(USER_SOURCES2OBJS),
639 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
640                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
641 )
642 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
643
644 USER_OBJS  += $$($(1)_OBJS)
645 USER_SOURCES += $$($(1)_SOURCES)
646
647 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
648         @$(QUIET_CMD_ECHO) "  AR      $$@"
649         $(Q) $(AR) rcs $$@ $$^
650 endef
651
652
653 # Syntax: $(call SOLIB_template,<library-name>)
654 define SOLIB_template
655
656 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
657 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
658 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
659 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
660 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
661 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
662 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
663
664 $(foreach x, $(USER_SOURCES2OBJSLO),
665 $(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
666                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
667 )
668 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
669
670 SOLIB_OBJS  += $$($(1)_OBJSLO)
671 SOLIB_SOURCES += $$($(1)_SOURCES)
672
673 $(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_OBJSLO)
674         @$(QUIET_CMD_ECHO) "  LINK    $$@"
675         $(Q) $(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -o $$@ $$^ $$(LOADLIBES) $$($(1)_LIBS:%=-l%)
676 endef
677
678
679
680 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
681                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT))
682
683 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX))
684
685 # Special rules for CMETRIC generated headers
686
687 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
688                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
689                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
690 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
691                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
692                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
693
694 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
695
696 GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h))
697
698 # Generate rules for compilation of programs and libraries
699
700 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),$(EXE_SUFFIX))))
701
702 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(EXE_SUFFIX))))
703
704 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(EXE_SUFFIX))))
705
706 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
707
708 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
709
710 -include $(USER_OBJS_DIR)/*.d
711
712 endif
713
714 #=====================================================================
715 # Kernel-space rules and templates to compile modules, libraries etc.
716
717 ifdef KERN_RULE_TEMPLATES
718
719 $(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(MAKERULES_DIR)/kernelcfg2mk
720         @$(QUIET_CMD_ECHO) "  KCFG2MK $$@"
721         $(Q) $(MAKERULES_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR)
722
723 ifeq ($(CONFIG_RTLINUX),y)
724 include $(RTL_DIR)/rtl.mk
725
726 KERN_CC = $(CC)
727 kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' )
728 INCLUDES := -I $(KERN_INCLUDE_DIR) $(INCLUDE) $(rtlinux_INCLUDES) $(kernel_INCLUDES)
729 #-DEXPORT_NO_SYMBOLS
730 c_o_kern_COMPILE = $(KERN_CC) -idirafter $(kern_GCCLIB_DIR)/include $(INCLUDES)  $(CFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
731 cc_o_kern_COMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
732 KERN_EXE_SUFFIX := .o
733 KERN_ARCH = $(ARCH)
734 KERN_LD = $(LD)
735 KERN_AR = $(AR)
736
737 else # CONFIG_RTLINUX
738
739 include $(KERN_LIB_DIR)/kernel.mk
740
741 ifeq ($(LINUX_SRC),)
742 LINUX_SRC = $(LINUX_DIR)
743 endif
744 kernel_INCLUDES += -I $(LINUX_DIR) -idirafter $(LINUX_SRC)/include/linux
745
746 ifdef LINUX_CC
747 KERN_CC = $(LINUX_CC)
748 kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(LINUX_CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' )
749 else
750 KERN_CC = echo KERN_CC not defined - compilation skipped
751 endif
752 c_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
753 cc_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
754 S_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_AFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
755 KERN_EXE_SUFFIX := $(LINUX_MODULE_EXT)
756 KERN_LDFLAGS = $(LINUX_LDFLAGS)
757 ifdef LINUX_ARCH
758 KERN_ARCH = $(LINUX_ARCH)
759 else
760 KERN_ARCH = echo KERN_ARCH not defined - skipped
761 endif
762 ifdef LINUX_LD
763 KERN_LD = $(LINUX_LD)
764 else
765 KERN_LD = echo KERN_LD  not defined - skipped
766 endif
767 ifneq ($(LINUX_AR),)
768 KERN_AR = $(LINUX_AR)
769 else
770 KERN_AR = $(AR)
771 endif
772 ifeq ($(LINUX_QUOTE_MODNAME),y)
773 KERN_MQ=\"
774 KERN_KBUILD_MODNAME=-D"KBUILD_MODNAME=((THIS_MODULE)!=NULL?(THIS_MODULE)->name:NULL)"
775 endif
776 endif # CONFIG_RTLINUX
777
778 KERN_LOADLIBES += -L$(KERN_LIB_DIR) 
779
780 KERN_LOADLIBES += $(rtlinux_LOADLIBES:%=-l%)
781 KERN_LOADLIBES += $(kernel_LOADLIBES:%=-l%)
782
783
784
785 # Check GCC version for kernel part of build
786 ifndef kern_CC_MAJOR_VERSION
787 kern_CC_MAJOR_VERSION := $(shell $(KERN_CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
788 endif
789 # Prepare suitable define for dependency building
790 ifeq ($(kern_CC_MAJOR_VERSION),2)
791 kern_CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
792 else
793 kern_CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
794 endif
795
796 ifeq ($(KERN_EXE_SUFFIX),.ko)
797 ifeq ($(wildcard $(LINUX_DIR)/scripts/mod/modpost),)
798 KERN_MODPOST = $(LINUX_DIR)/scripts/modpost
799 else
800 KERN_MODPOST = $(LINUX_DIR)/scripts/mod/modpost
801 endif
802 KERN_MODULES_LINK_DIR = $(KERN_MODPOST_DIR)
803 KERN_LINK_SUFFIX = .o
804 else
805 KERN_MODULES_LINK_DIR = $(KERN_MODULES_DIR)
806 KERN_LINK_SUFFIX = $(KERN_EXE_SUFFIX)
807 endif
808
809 ifeq ($(LINUX_CONFIG_MODVERSIONS),y)
810 MODPOST_OPTS += -m
811 MODPOST_OPTS += -i $(LINUX_DIR)/Module.symvers
812 ifneq ($(LINUX_BUILDHOST),) # this is not correct point, it should look for 2.6.17 kernel
813 MODPOST_OPTS += -I $(KERN_LIB_DIR)/Module.symvers
814 endif
815 MODPOST_OPTS += -o $(KERN_LIB_DIR)/Module.symvers
816 endif
817
818 ifeq ($(LINUX_CONFIG_DEBUG_SECTION_MISMATCH),y)
819 MODPOST_OPTS += -S
820 endif
821
822 ifeq ($(LINUX_CONFIG_MARKERS),y)
823 MODPOST_OPTS += -K $(LINUX_DIR)/Module.markers
824 MODPOST_OPTS += -M $(KERN_LIB_DIR)/Module.markers
825 endif
826
827 ifeq ($(LINUX_KBUILD_MODPOST_WARN),y)
828 MODPOST_OPTS += -w
829 endif
830
831 ifneq ($(LINUX_BUILDHOST),)
832 ifneq ($(LINUX_BUILDHOST),$(LINUX_ARCH))
833 MODPOST_OPTS += -c
834 endif
835 endif
836
837 define COMPILE_c_o_kern_template
838
839 $(2): $(1)
840         @$(QUIET_CMD_ECHO) "  CC [K]  $$@"
841         $(Q) if $$(c_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
842         -D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
843         -o $$@ -c $$< ; \
844         then mv -f "$$@.d.tmp" "$$@.d" ; \
845         else rm -f "$$@.d.tmp" ; exit 1; \
846         fi
847 endef
848
849
850
851 define COMPILE_cc_o_kern_template
852
853 $(2): $(1)
854         @$(QUIET_CMD_ECHO) "  CXX [K] $$@"
855         $(Q) if $$(cc_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
856         -D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
857         -o $$@ -c $$< ; \
858         then mv -f "$$@.d.tmp" "$$@.d" ; \
859         else rm -f "$$@.d.tmp" ; exit 1; \
860         fi
861 endef
862
863
864
865 define COMPILE_S_o_kern_template
866
867 $(2): $(1)
868         @$(QUIET_CMD_ECHO) "  AS [K]  $$@"
869         $(Q) if $$(S_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
870         -D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
871         -o $$@ -c $$< ; \
872         then mv -f "$$@.d.tmp" "$$@.d" ; \
873         else rm -f "$$@.d.tmp" ; exit 1; \
874         fi
875 endef
876
877
878
879 define MODULE_kern_template
880 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
881 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
882 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
883 $(1)_OBJS := $$(sort $$($(1)_OBJS))
884
885 KERN_OBJS  += $$($(1)_OBJS)
886 KERN_SOURCES += $$($(1)_SOURCES)
887
888 # this is hack to build "__this_module" structure for 2.6.x kernels
889 # modpost is used for that purpose now
890
891 #$(1).mod.c:
892 #       echo  "\
893 #       #include <linux/version.h>@\
894 #       #include <linux/module.h>@\
895 #       #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,5))@\
896 #       #include <linux/vermagic.h>@\
897 #       #include <linux/compiler.h>@\
898 #       @\
899 #       MODULE_INFO(vermagic, VERMAGIC_STRING);@\
900 #       @\
901 #       #undef unix@\
902 #       struct module __this_module@\
903 #       __attribute__((section(\".gnu.linkonce.this_module\"))) = {@\
904 #        .name = __stringify(KBUILD_MODNAME),@\
905 #        .init = init_module,@\
906 #       #ifdef CONFIG_MODULE_UNLOAD@\
907 #        .exit = cleanup_module,@\
908 #       #endif@\
909 #       };@\
910 #       #endif@\
911 #       " | tr @ \\n >$$@ 
912
913
914 #$(eval $(call COMPILE_c_o_kern_template,$(1).mod.c,$(1).mod.o,-DKBUILD_MODNAME=$(1)))
915
916 $(2)/$(1)$(KERN_LINK_SUFFIX): $$($(1)_OBJS)
917         @$(QUIET_CMD_ECHO) "  LD [K]  $$@"
918         $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) -r $$($(1)_OBJS) -L$$(kern_GCCLIB_DIR) $$($(1)_LIBS:%=-l%) $$(KERN_LOADLIBES) -Map $(KERN_OBJS_DIR)/$(1).mod.map -o $$@
919         @echo "$(2)/$(1)$(KERN_LINK_SUFFIX): \\" >$(KERN_OBJS_DIR)/$(1).mod.d
920         @sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(KERN_OBJS_DIR)/$(1).mod.map  >>$(KERN_OBJS_DIR)/$(1).mod.d
921         @echo >>$(KERN_OBJS_DIR)/$(1).mod.d
922         @if [ "$(KERN_EXE_SUFFIX)" = ".ko" ] ; then \
923           echo $(1) >>$(KERN_MODPOST_DIR)/module-changes ; \
924           echo $(1) >$(KERN_MODPOST_DIR)/$(1).mod.stamp ; \
925         fi
926
927 endef
928
929
930
931 define LIBRARY_kern_template
932 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
933 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
934 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
935 $(1)_OBJS := $$(sort $$($(1)_OBJS))
936
937 KERN_OBJS  += $$($(1)_OBJS)
938 KERN_SOURCES += $$($(1)_SOURCES)
939
940 $(KERN_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
941         @$(QUIET_CMD_ECHO) "  AR [K]  $$@"
942         $(Q) $(KERN_AR) rcs $$@ $$^
943 endef
944
945
946 ifdef LINUX_DIR
947
948 kernel-lib-pass-local: $(kernel_LIBRARIES:%=$(KERN_LIB_DIR)/lib%.a)
949
950 kernel-mod-pass-local: $(kernel_MODULES:%=$(KERN_MODULES_LINK_DIR)/%$(KERN_LINK_SUFFIX))
951
952 $(foreach module,$(kernel_MODULES),$(eval $(call MODULE_kern_template,$(module),$(KERN_MODULES_LINK_DIR))))
953
954 $(foreach lib,$(kernel_LIBRARIES),$(eval $(call LIBRARY_kern_template,$(lib))))
955
956 endif
957
958
959 ifeq ($(CONFIG_RTLINUX),y)
960
961 kernel-mod-pass-local: $(rtlinux_MODULES:%=$(KERN_MODULES_LINK_DIR)/%$(KERN_LINK_SUFFIX))
962
963 kernel-lib-pass-local: $(rtlinux_LIBRARIES:%=$(KERN_LIB_DIR)/lib%.a)
964
965 $(foreach module,$(rtlinux_MODULES),$(eval $(call MODULE_kern_template,$(module),$(KERN_MODULES_LINK_DIR))))
966
967 $(foreach lib,$(rtlinux_LIBRARIES),$(eval $(call LIBRARY_kern_template,$(lib))))
968
969 endif
970
971 ifeq ($(KERN_MODPOST_PASS),y)
972
973 MODULES_LIST := $(wildcard *.mod.stamp)
974 MODULES_LIST := $(MODULES_LIST:%.mod.stamp=%)
975
976 define MODPOST_kern_template
977 $(2) : $(1)$(KERN_LINK_SUFFIX) $(1).mod.c
978         @$(QUIET_CMD_ECHO) "  LD [M]  $$@"
979         $(Q) $$(cc_o_kern_COMPILE) -D"KBUILD_BASENAME=$(KERN_MQ)$(1)$(KERN_MQ)" \
980                 -D"KBUILD_MODNAME=$(KERN_MQ)$(1)$(KERN_MQ)" \
981                 -o $(1).mod.o -c $(1).mod.c
982         $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) $(1)$(KERN_LINK_SUFFIX) $(1).mod.o -r -o $$@
983 endef
984
985 kernel-modpost-versions: $(wildcard $(LINUX_DIR)/Module.symvers)
986         @$(QUIET_CMD_ECHO) "  MODPOST    $(KERN_MODPOST_DIR)"
987         @echo  >$(KERN_MODPOST_DIR)/modpost-running
988         @rm -f $(KERN_MODPOST_DIR)/module-changes
989         $(Q) $(KERN_MODPOST) $(MODPOST_OPTS) $(MODULES_LIST:%=%$(KERN_LINK_SUFFIX))
990
991 $(MODULES_LIST:%=%.mod.c) : kernel-modpost-versions
992
993 kernel-modpost-pass-local: $(MODULES_LIST:%=$(KERN_MODULES_DIR)/%$(KERN_EXE_SUFFIX))
994         @rm -f $(KERN_MODPOST_DIR)/modpost-running
995
996 $(foreach module,$(MODULES_LIST),$(eval $(call MODPOST_kern_template,$(module),$(module:%=$(KERN_MODULES_DIR)/%$(KERN_EXE_SUFFIX)))))
997
998 endif
999
1000 -include $(KERN_OBJS_DIR)/*.d
1001
1002 endif
1003
1004 #=====================================================================
1005
1006 # Kernel requires its own set of configuration header-files
1007 ifneq ($(kernel_LIBRARIES)$(rtlinux_LIBRARIES)$(kernel_MODULES)$(rtlinux_MODULES)$(kernel_HEADERS)$(rtlinux_HEADERS)$(kernel_HEADERS)$(rtlinux_HEADERS)$(nobase_kernel_HEADERS)$(nobase_rtlinux_HEADERS)$(renamed_kernel_HEADERS)$(renamed_rtlinux_HEADERS),)
1008 KERN_CONFIG_HEADERS_REQUIRED = y
1009 endif
1010
1011 $(eval $(call omk_pass_template, kernel-lib-pass,$(KERN_OBJS_DIR),KERN_RULE_TEMPLATES=y,$(kernel_LIBRARIES)$(rtlinux_LIBRARIES)))
1012 $(eval $(call omk_pass_template, kernel-mod-pass,$(KERN_OBJS_DIR),KERN_RULE_TEMPLATES=y,$(kernel_MODULES)$(rtlinux_MODULES)))
1013
1014 kernel-modpost-pass:
1015         +@if [ -e "$(KERN_MODPOST_DIR)/module-changes" -o -e "$(KERN_MODPOST_DIR)/modpost-running" ] ; \
1016         then \
1017             $(MAKE) --no-print-directory -C $(KERN_MODPOST_DIR) \
1018                -f $(SOURCES_DIR)/Makefile KERN_RULE_TEMPLATES=y KERN_MODPOST_PASS=y $(@:%=%-local) ; \
1019         fi
1020
1021 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
1022 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
1023
1024 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
1025 $(eval $(call omk_pass_template,install,$(USER_OBJS_DIR),,always))
1026 $(eval $(call omk_pass_template,include-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,always))
1027
1028 check-dir:
1029         @$(call mkdir_def,$(USER_BUILD_DIR))
1030         @$(call mkdir_def,$(KERN_BUILD_DIR))
1031         @$(call mkdir_def,$(USER_INCLUDE_DIR))
1032         @$(call mkdir_def,$(KERN_INCLUDE_DIR))
1033         @$(call mkdir_def,$(USER_LIB_DIR))
1034         @$(call mkdir_def,$(KERN_LIB_DIR))
1035         @$(call mkdir_def,$(USER_BIN_DIR))
1036         @$(call mkdir_def,$(USER_UTILS_DIR))
1037         @$(call mkdir_def,$(USER_TESTS_DIR))
1038         @$(call mkdir_def,$(KERN_MODULES_DIR))
1039         @$(call mkdir_def,$(KERN_MODPOST_DIR))
1040
1041 install-local:                  # TODO
1042
1043 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
1044 $(eval $(call include-pass-template,$(KERN_INCLUDE_DIR),kernel))
1045 ifeq ($(CONFIG_RTLINUX),y)
1046 $(eval $(call include-pass-template,$(KERN_INCLUDE_DIR),rtlinux))
1047 endif
1048
1049
1050 ifdef USER_RULE_TEMPLATES
1051
1052 # User-space static libraries and applications object files
1053
1054 USER_SOURCES := $(sort $(USER_SOURCES))
1055
1056 USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES))
1057
1058 #$(warning USER_SOURCES = $(USER_SOURCES))
1059
1060 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
1061
1062 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
1063
1064 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
1065
1066 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
1067
1068 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
1069
1070 # User-space shared libraries object files
1071
1072 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
1073
1074 SOLIB_GEN_SOURCES := $(sort $(SOLIB_GEN_SOURCES))
1075
1076 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
1077 #$(warning SOLIB_GEN_SOURCES = $(SOLIB_GEN_SOURCES))
1078
1079 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
1080
1081 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
1082
1083 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
1084
1085 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
1086
1087 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
1088
1089 # IDL compilation
1090
1091 USER_IDLS := $(sort $(USER_IDLS))
1092
1093 $(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%))))
1094
1095 endif
1096
1097 ifdef KERN_RULE_TEMPLATES
1098
1099 KERN_SOURCES := $(sort $(KERN_SOURCES))
1100
1101 #$(warning KERN_SOURCES = $(KERN_SOURCES))
1102
1103 $(foreach src,$(filter %.c,$(KERN_SOURCES)),$(eval $(call COMPILE_c_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
1104
1105 $(foreach src,$(filter %.cc,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
1106
1107 $(foreach src,$(filter %.cxx,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
1108
1109 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
1110 endif
1111
1112 clean-local: clean-custom
1113         @echo Cleaning in $(KERN_OBJS_DIR) and $(USER_OBJS_DIR)
1114         @rm -f $(KERN_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.[och] $(USER_OBJS_DIR)/*.lo\
1115                $(KERN_OBJS_DIR)/*.d $(USER_OBJS_DIR)/*.d \
1116                $(KERN_OBJS_DIR)/*.map $(USER_OBJS_DIR)/*.map \
1117                $(KERN_OBJS_DIR)/*.mod.c \
1118                $(kernel_MODULES:%=$(KERN_MODPOST_DIR)/%.*) \
1119                $(LOCAL_CONFIG_H:%=$(KERN_OBJS_DIR)/%) \
1120                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
1121         @if [ -e $(KERN_LIB_DIR)/kernel.mk ] ; then \
1122             touch -t 200001010101 $(KERN_LIB_DIR)/kernel.mk ; \
1123         fi
1124
1125 include-pass-submakes: extra-rules-subdirs
1126
1127 # We must go to EXTRA_RULES_SUBDIRS beofre going to any other
1128 # directory, since the executables compiled in EXTRA_RULES_SUBDIRS
1129 # might be needed there.
1130 include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs
1131
1132 default: include-pass library-pass binary-pass
1133 ifndef OMIT_KERNEL_PASSES
1134 # Also make kernel passes if not disabled
1135 default: kernel-lib-pass kernel-pass
1136 endif
1137
1138 # Local Variables:
1139 # mode:makefile
1140 # End:
1141                                                              #OMK@config_h
1142 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
1143 define BUILD_CONFIG_H_template
1144
1145 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
1146         @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:%.stamp=%)"
1147         @if [ ! -d `dirname $(2).tmp` ] ; then \
1148                 mkdir -p `dirname $(2).tmp` ; fi
1149         @echo "/* Automatically generated from */" > "$(2).tmp"
1150         @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp"
1151         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
1152         @echo "#ifndef $(4)" >> "$(2).tmp"
1153         @echo "#define $(4)" >> "$(2).tmp"
1154         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
1155                 echo '$(x).$($(x))' ; ) echo ; ) | \
1156                 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
1157                 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
1158                   >> "$(2).tmp"
1159         @echo "#endif /*$(4)*/" >> "$(2).tmp"
1160         @touch "$$@"
1161         @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
1162         else mv "$(2).tmp" "$(2)" ; \
1163         echo "Updated configuration $(2)" ; fi
1164
1165 endef
1166
1167 ifdef LOCAL_CONFIG_H
1168
1169 # This must be declared after the default cflags are assigned!
1170 # Override is used to override command line assignemnt.
1171 override CFLAGS += -I $(USER_OBJS_DIR)
1172 override kernel_INCLUDES += -I $(KERN_OBJS_DIR)
1173 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
1174
1175 endif
1176
1177 # Special rules for configuration exported headers
1178
1179 #FIXME: The directory for headers should not be specified here.
1180 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
1181 _$(basename $(notdir $(confh)))_H \
1182 )))
1183
1184 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
1185
1186 # Add some hooks to standard passes
1187 include-pass-local: $(config_h_stamp_files)
1188
1189 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
1190
1191 ifdef LOCAL_CONFIG_H
1192 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
1193 endif
1194
1195 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
1196 _$(basename $(notdir $(confh)))_H \
1197 )))
1198
1199 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
1200
1201 # Add some hooks to standard passes
1202 include-pass-local: $(kern_config_h_stamp_files)
1203
1204 endif
1205
1206 clean-local: clean-local-config-h
1207
1208 clean-local-config-h:
1209         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
1210             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
1211         )
1212
1213
1214 # Local Variables:
1215 # mode:makefile
1216 # End:
1217                                                              #OMK@qt
1218 ifneq ($(QT_SUBDIRS),)
1219
1220 .PHONY: qt-subpass clean-qt distclean-qt
1221
1222 # Usage: $(call qt_makefile_template,<qt-subdir>)
1223 define qt_makefile_template
1224 $(SOURCES_DIR)/$(1)/Makefile: $(wildcard $(SOURCES_DIR)/$(1)/*.pro)
1225         cd $(SOURCES_DIR)/$(1); $(QTDIR:%=%/bin/)qmake TOP_DIR=$(OUTPUT_DIR) \
1226              RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) $(QTDIR:%=QTDIR=%) CC=$(CC) \
1227              CXX=$(CXX) LIBS+="-L$(USER_LIB_DIR)" INCLUDEPATH+="$(USER_INCLUDE_DIR)"
1228 endef
1229 $(foreach dir,$(QT_SUBDIRS), $(eval $(call qt_makefile_template,$(dir))))
1230
1231 qt-subpass: $(foreach dir,$(QT_SUBDIRS), $(SOURCES_DIR)/$(dir)/Makefile)
1232         $(foreach dir,$(QT_SUBDIRS),\
1233                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
1234                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
1235                 -f $(SOURCES_DIR)/$(dir)/Makefile || exit 1 ;)
1236
1237 # Hook to binary pass
1238 binary-pass-submakes: qt-subpass
1239
1240 # Hook to clean pass
1241 clean-local: clean-qt
1242 clean-qt:
1243         +@$(foreach dir, $(QT_SUBDIRS), \
1244                 $(if $(wildcard $(SOURCES_DIR)/$(dir)/Makefile), \
1245                 @$(QUIET_CMD_ECHO) "  CLEAN   $(dir)"; \
1246                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
1247                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
1248                 -f $(SOURCES_DIR)/$(dir)/Makefile clean|| exit 1 ;))
1249
1250
1251 # Hook to distclean
1252 distclean: distclean-qt
1253
1254 # TODO: Add distclean-qt-pass to handle QT_SUBDIRS in the whole
1255 # tree. This way we only distclean toplevel subdirs.
1256 distclean-qt:
1257         +@$(foreach dir, $(QT_SUBDIRS), \
1258                 $(if $(wildcard $(SOURCES_DIR)/$(dir)/Makefile), \
1259                 @$(QUIET_CMD_ECHO) "  DISTCLEAN $(dir)"; \
1260                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
1261                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
1262                 -f $(SOURCES_DIR)/$(dir)/Makefile distclean|| exit 1 ;))
1263 endif
1264
1265 # Local Variables:
1266 # mode:makefile
1267 # End:
1268                                                              #OMK@sources-list
1269 # Rules that creates the list of files which are used during
1270 # compilation. The list reflects conditional compilation depending on
1271 # config.omk and other variables.
1272
1273 SOURCES_LIST_FN=sources.txt
1274 ifndef SOURCES_LIST
1275 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
1276 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
1277 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
1278 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
1279 endif
1280
1281 ifeq ($(MAKECMDGOALS),sources-list)
1282 NEED_SOURCES_LIST=y
1283 endif
1284 ifeq ($(MAKECMDGOALS),TAGS)
1285 NEED_SOURCES_LIST=y
1286 endif
1287 ifeq ($(MAKECMDGOALS),tags)
1288 NEED_SOURCES_LIST=y
1289 endif
1290
1291 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
1292 .PHONY: sources-list
1293 sources-list: $(SOURCES_LIST)
1294
1295 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
1296         @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
1297         @echo -n "" > "$(SOURCES_LIST).tmp"
1298         @echo -n "" > "$(SOURCES_LIST_D).tmp"
1299         @$(MAKE) --no-print-directory sources-list-pass
1300         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
1301         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
1302         @rm "$(SOURCES_LIST).tmp"
1303         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
1304         @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
1305         @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
1306                 sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
1307         @rm "$(SOURCES_LIST_D).tmp"
1308         @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
1309 endif
1310
1311 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
1312
1313 sources-list-pass-local:
1314         @$(foreach m,$(MAKEFILE_LIST),echo '  $(m)' >> "$(SOURCES_LIST_D).tmp";)
1315         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
1316           echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
1317         @$(foreach ch,$(config_include_HEADERS), \
1318           echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
1319         @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
1320         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
1321           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
1322           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
1323
1324 ############ TAGS ###########
1325
1326 ifeq ($(MAKECMDGOALS),TAGS)
1327 ETAGS=etags
1328 TAGS_CMD = $(ETAGS)
1329 TAGS: $(SOURCES_LIST)
1330         @$(MAKE) --no-print-directory do-tags
1331 endif
1332 ifeq ($(MAKECMDGOALS),tags) 
1333 CTAGS=ctags -N
1334 TAGS_CMD = $(CTAGS)
1335 tags: $(SOURCES_LIST)
1336         @$(MAKE) --no-print-directory do-tags
1337 endif
1338 export TAGS_CMD
1339
1340 ifeq ($(MAKECMDGOALS),do-tags)
1341 .PHONY: do-tags
1342 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
1343         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
1344         $(Q)$(TAGS_CMD) $^
1345 endif
1346
1347 ############ CSCOPE ###########
1348
1349 cscope: $(SOURCES_LIST)
1350         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
1351         $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
1352 #FIXME: see doc to -i in cscope(1)
1353
1354 # Local Variables:
1355 # mode:makefile
1356 # End: