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