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