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