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