]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/linux.omk
Document AM_ variables instead of user variables
[omk.git] / snippets / linux.omk
1 #                   Version for Linux/RTLinux builds.
2 #
3 #
4 # input variables
5 # lib_LIBRARIES    .. list of the user-space libraries
6 # shared_LIBRARIES .. list of the user-space shared libraries
7 # include_HEADERS  .. list of the user-space public header files
8 # nobase_include_HEADERS .. public headers copied even with directory part
9 # renamed_include_HEADERS .. public headers copied to the different target name
10 # bin_PROGRAMS     .. list of the require binary programs
11 # utils_PROGRAMS   .. list of the development utility programs
12 # test_PROGRAMS    .. list of the testing programs
13 # bin_SCRIPTS      .. list of scripts to be copied to _compiled/bin
14 # xxx_SOURCES      .. list of specific target sources
15 # xxx_LIBS         .. list of specific target libraries (-l prefix is automatically added)
16 # xxx_LDFLAGS      .. list of specific target LDFLAGS
17 # lib_LOADLIBES    .. list of libraries linked to each executable
18 # INCLUDES         .. additional include directories and defines for user-space
19 #
20 # AM_CFLAGS        .. C compiler flags
21 # AM_CXXFLAGS      .. C++ compiler flags
22 # AM_CPPFLAGS      .. C preprocessor flags
23 # LDFLAGS          .. linker flags for programs linking
24
25 BUILD_DIR_NAME = _build
26 COMPILED_DIR_NAME = _compiled
27 ifndef GROUP_DIR_NAME
28 GROUP_DIR_NAME = nogroup
29 endif
30
31 USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include
32 USER_LIB_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib
33 USER_UTILS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils
34 USER_TESTS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests
35 USER_BIN_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin
36 USER_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user
37
38 ifeq ($(BUILD_OS),)
39   # Check for target
40   ifeq ($(OS),Windows_NT)
41     BUILD_OS := win32
42   else
43     BUILD_OS := $(shell uname | tr '[A-Z]' '[a-z]' )
44     #$(warning BUILD_OS=$(BUILD_OS))
45   endif
46 endif
47
48 ifeq ($(TARGET_OS),)
49   TARGET_OS := $(BUILD_OS)
50 endif
51
52 export TARGET_OS
53 export BUILD_OS
54
55 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
56
57 # Assign default values to CFLAGS variable. If the variable is defined
58 # earlier (i.g. in config.omk), it is not overriden here.
59 CFLAGS ?= -O2 -Wall
60 CXXFLAGS ?= -O2 -Wall
61
62
63 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
64
65 LOADLIBES += -L$(USER_LIB_DIR) 
66
67 LOADLIBES += $(lib_LOADLIBES:%=-l%)
68
69 LIB_CPPFLAGS += $(CPPFLAGS)
70 LIB_CFLAGS   += $(CFLAGS)
71
72 ifeq ($(TARGET_OS),win32)
73   EXE_SUFFIX = .exe
74   SOLIB_EXT = dll
75 else
76   SOLIB_EXT = so
77   SOLIB_PICFLAGS += -fpic
78 endif
79
80 #vpath %.c $(SOURCES_DIR)
81 #vpath %.cc $(SOURCES_DIR)
82 #vpath %.cxx $(SOURCES_DIR)
83
84 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
85 OMK_WORK_DIR  = $(USER_OBJS_DIR)
86
87 .PHONY: dep subdirs clean clean-custom cleandepend check-dir
88
89 # Some support to serialize some targets for parallel make
90 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
91 include-pass: check-dir
92 library-pass: include-pass
93 link-pseudo-pass: library-pass
94 binary-pass: link-pseudo-pass
95
96 override OMK_SERIALIZE_INCLUDED = y
97 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
98 endif
99
100 #=====================================================================
101 # User-space rules and templates to compile programs, libraries etc.
102
103 ifdef USER_RULE_TEMPLATES
104
105 USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.cpp .o/.S .o/.o
106
107 USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.cpp .lo/.S .lo/.lo
108
109 #%.lo: %.c
110 #       $(CC) -o $@ $(LCFLAGS) -c $<
111
112 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
113         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
114
115 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
116         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -DOMK_FOR_USER
117
118 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
119         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
120
121 idl_COMPILE = $(IDL_COMPILER)
122
123 # Check GCC version for user build
124 ifndef CC_MAJOR_VERSION
125 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
126 endif
127 # Prepare suitable define for dependency building
128 ifeq ($(CC_MAJOR_VERSION),2)
129 CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
130 else
131 CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
132 endif
133
134
135 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
136 define COMPILE_c_o_template
137 $(2): $(1) $$(GEN_HEADERS)
138         @$(QUIET_CMD_ECHO) "  CC      $$@"
139         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
140         then mv -f "$$@.d.tmp" "$$@.d" ; \
141         else rm -f "$$@.d.tmp" ; exit 1; \
142         fi
143 endef
144
145
146 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
147 define COMPILE_cc_o_template
148 $(2): $(1) $$(GEN_HEADERS)
149         @$(QUIET_CMD_ECHO) "  CXX     $$@"
150         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
151         then mv -f "$$@.d.tmp" "$$@.d" ; \
152         else rm -f "$$@.d.tmp" ; exit 1; \
153         fi
154 endef
155
156
157 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
158 define COMPILE_S_o_template
159 $(2): $(1) $$(GEN_HEADERS)
160         @$(QUIET_CMD_ECHO) "  AS      $$@"
161         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
162         then mv -f "$$@.d.tmp" "$$@.d" ; \
163         else rm -f "$$@.d.tmp" ; exit 1; \
164         fi
165 endef
166
167 NM ?= nm
168
169 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
170 define CMETRIC_o_h_template
171 $(2): $(1)
172         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
173         $(Q)if [ -n `dirname $$@` ] ; then \
174               if [ ! -e `dirname $$@` ] ; then \
175                 mkdir -p `dirname $$@` ; fi ; fi
176         $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
177         $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
178 # Bellow, the tricks with redirection are for shells without set -o pipefail
179 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
180         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
181                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
182                 | sort >>$$@.tmp` && exit $$$$status
183         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
184         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
185                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
186                 | sort >>$$@.tmp` && exit $$$$status
187         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
188         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
189                 | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
190                 | sort >>$$@.tmp` && exit $$$$status
191         $(Q)mv $$@.tmp $$@
192 endef
193
194
195
196 define COMPILE_idl_template
197 $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE)))
198         @$(QUIET_CMD_ECHO) "  IDL     $$@"
199         $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
200 endef
201
202
203 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<executable-suffix>,<linker-sript>)
204 define PROGRAM_template
205
206 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
207 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
208 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
209 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
210 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
211 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
212 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
213
214 $(foreach x, $(USER_SOURCES2OBJS),
215 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
216                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
217 )
218 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
219
220 USER_OBJS  += $$($(1)_OBJS)
221 USER_SOURCES += $$($(1)_SOURCES)
222
223 $(2)/$(1)$(3): $$($(1)_OBJS)
224         @$(QUIET_CMD_ECHO) "  LINK    $$@"
225         $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES))$$(filter %.cxx,$$($(1)_SOURCES))$$(filter %.cpp,$$($(1)_SOURCES)),$$(CXX),$$(CC)) \
226           $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) $$($(1)_LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
227         @echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
228         @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134'  >>$(USER_OBJS_DIR)/$(1).exe.d
229         @echo >>$(USER_OBJS_DIR)/$(1).exe.d
230 endef
231
232 # Usage: $(call SCRIPT_template,<target-directory>,<script-name>)
233 define SCRIPT_template
234 $(2)/$(1): $$(SOURCES_DIR)/$(1)
235         @$(QUIET_CMD_ECHO) "  CP      $$@"
236         $(Q)cp $$^ $$@
237 endef
238
239
240 # Syntax: $(call LIBRARY_template,<library-name>)
241 define LIBRARY_template
242
243 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
244 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
245 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
246 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
247 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
248 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
249 USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
250
251 $(foreach x, $(USER_SOURCES2OBJS),
252 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
253                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
254 )
255 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
256
257 USER_OBJS  += $$($(1)_OBJS)
258 USER_SOURCES += $$($(1)_SOURCES)
259
260 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
261         @$(QUIET_CMD_ECHO) "  AR      $$@"
262         $(Q) $(AR) rcs $$@ $$^
263 endef
264
265 .PHONY: FORCE
266
267 # Syntax: $(call SOLIB_template,<library-name>)
268 define SOLIB_template
269
270 USER_IDLS  += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
271 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
272 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
273 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
274 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
275 $(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
276 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
277
278 $(foreach x, $(USER_SOURCES2OBJSLO),
279 $(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
280                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
281 )
282 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
283
284 SOLIB_OBJS  += $$($(1)_OBJSLO)
285 SOLIB_SOURCES += $$($(1)_SOURCES)
286
287 $(OMK_WORK_DIR)/lib$(1).$(SOLIB_EXT).omkvar: $$($(1)_OBJSLO) FORCE
288         $(Q)echo '$(1)_objslo += $$$$(addprefix $(USER_OBJS_DIR)/,$$($(1)_OBJSLO))' > $$@.tmp; \
289             echo '$(1)_libs += $$($(1)_LIBS) $$(lib_LOADLIBES)' >> $$@.tmp; \
290             echo '$(1)_ldflags += $$($(1)_LDFLAGS) $$(lib_LDFLAGS)' >> $$@.tmp; \
291             echo 'shared_libs := $$$$(sort $(1) $$$$(shared_libs))' >> $$@.tmp; \
292             if cmp -s $$@.tmp $$@; then rm $$@.tmp; else mv $$@.tmp $$@; fi
293 endef
294
295 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
296                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(OMK_WORK_DIR)/lib%.$(SOLIB_EXT).omkvar)
297
298 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) \
299                    $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) \
300                    $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX)) \
301                    $(bin_SCRIPTS:%=$(USER_BIN_DIR)/%)
302
303 # Special rules for CMETRIC generated headers
304
305 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
306                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
307                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
308 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
309                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
310                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
311
312 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
313
314 GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h))
315
316 # Generate rules for compilation of programs and libraries
317
318 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),$(EXE_SUFFIX))))
319
320 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(EXE_SUFFIX))))
321
322 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(EXE_SUFFIX))))
323
324 $(foreach script,$(bin_SCRIPTS),$(eval $(call SCRIPT_template,$(script),$(USER_BIN_DIR))))
325
326
327 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
328
329 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
330
331 -include $(USER_OBJS_DIR)/*.d
332 #FIXME: This doesn't include dependencies of source files from
333 #subdirectories (i.s. *_SOURCES=dir/file.c. I'm currently not sure,
334 #how to handle this.
335
336 endif # USER_RULE_TEMPLATES
337
338 .PHONY: link-pseudo-pass
339 link-pseudo-pass:
340         $(Q)$(MAKE) $(NO_PRINT_DIRECTORY) -C $(USER_BUILD_DIR) -f $(SOURCESDIR_MAKEFILE) link-shared-libs
341
342 ifeq ($(MAKECMDGOALS),link-shared-libs)
343
344 # Syntax: $(call solib_link_template,<library-name>)
345 define solib_link_template
346 $(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(shared_libs),$$($(1)_libs)))
347 #$$(warning $(1)_shared_libs = $$($(1)_shared_libs))
348 $(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_shared_libs) $$($(1)_objslo)
349         @$(QUIET_CMD_ECHO) "  LINK    $$@"
350         $(Q)$(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -Wl,-Map,$(USER_OBJS_DIR)/lib$(1).$(SOLIB_EXT).map -o $$@ $$($(1)_objslo) $$(LOADLIBES) $$($(1)_libs:%=-l%) $$(lib_ldflags) $$($(1)_ldflags)
351 endef
352
353 -include $(shell true; find $(USER_BUILD_DIR) -name 'lib*.omkvar') # `true' is a hack for MinGW
354 #$(warning $(shared_libs))
355 $(foreach lib,$(shared_libs),$(eval $(call solib_link_template,$(lib))))
356
357 .PHONY: link-shared-libs
358 link-shared-libs: $(shared_libs:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT))
359 endif # link-shared-libs
360
361 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
362 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)$(bin_SCRIPTS)))
363
364 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
365 $(eval $(call omk_pass_template,install,$(USER_OBJS_DIR),,always))
366 $(eval $(call omk_pass_template,include-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,always))
367
368 check-dir::
369         @$(call mkdir_def,$(USER_BUILD_DIR))
370         @$(call mkdir_def,$(USER_INCLUDE_DIR))
371         @$(call mkdir_def,$(USER_LIB_DIR))
372         @$(call mkdir_def,$(USER_BIN_DIR))
373         @$(call mkdir_def,$(USER_UTILS_DIR))
374         @$(call mkdir_def,$(USER_TESTS_DIR))
375
376 install-local:                  # TODO
377
378 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
379
380 ifdef USER_RULE_TEMPLATES
381
382 # User-space static libraries and applications object files
383
384 USER_SOURCES := $(sort $(USER_SOURCES))
385
386 USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES))
387
388 #$(warning USER_SOURCES = $(USER_SOURCES))
389
390 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
391
392 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
393
394 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
395
396 $(foreach src,$(filter %.cpp,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.o),)))
397
398 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
399
400 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
401
402 # User-space shared libraries object files
403
404 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
405
406 SOLIB_GEN_SOURCES := $(sort $(SOLIB_GEN_SOURCES))
407
408 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
409 #$(warning SOLIB_GEN_SOURCES = $(SOLIB_GEN_SOURCES))
410
411 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
412
413 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
414
415 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
416
417 $(foreach src,$(filter %.cpp,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.lo),$(SOLIB_PICFLAGS))))
418
419 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
420
421 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
422
423 # Create _build directories for sources in subdirectories i.e. *_SOURCES=dir/file.c
424 _dirs_to_create=$(filter-out ./,$(sort $(dir $(USER_SOURCES) $(SOLIB_SOURCES))))
425 ifneq ($(_dirs_to_create),)
426 $(shell mkdir -p $(addprefix $(LOCAL_BUILD_DIR)/,$(_dirs_to_create)))
427 endif
428
429 # IDL compilation
430
431 USER_IDLS := $(sort $(USER_IDLS))
432
433 $(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%))))
434
435 endif
436
437 clean-local::
438         @echo Cleaning in $(USER_OBJS_DIR)
439         @rm -f $(USER_OBJS_DIR)/*.[och] \
440                $(USER_OBJS_DIR)/*.lo \
441                $(USER_OBJS_DIR)/*.d \
442                $(USER_OBJS_DIR)/*.map \
443                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
444
445 include-pass-submakes: extra-rules-subdirs
446
447 # We must go to EXTRA_RULES_SUBDIRS before going to any other
448 # directory, since the executables compiled in EXTRA_RULES_SUBDIRS
449 # might be needed there.
450 include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs
451
452 default: include-pass library-pass binary-pass