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