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