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