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