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