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