]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/rtems.omk
Removed emacs modelines
[omk.git] / snippets / rtems.omk
1 #                   This version is adapted for RTEMS build
2 #
3 #
4 # lib_LIBRARIES    .. list of the user-space libraries
5 # shared_LIBRARIES .. list of the user-space shared libraries
6 # include_HEADERS  .. list of the user-space public header files
7 # nobase_include_HEADERS .. public headers copied even with directory part
8 # renamed_include_HEADERS .. public headers copied to the different target name
9 # bin_PROGRAMS     .. list of the require binary programs
10 # utils_PROGRAMS   .. list of the development utility programs
11 # test_PROGRAMS    .. list of the test programs
12 # xxx_SOURCES      .. list of specific target sources
13 # xxx_LIBS         .. list of specific target libraries
14 # INCLUDES         .. additional include directories and defines for user-space
15 # tar_EMBEDFILES   .. list of tars with embedded files
16
17 ifdef OMK_TESTSROOT
18 ifeq ($(RTEMS_MAKEFILE_PATH),)
19 $(error $(shell $(call canttest,RTEMS_MAKEFILE_PATH not defined)))
20 endif
21 endif
22
23 include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
24 include $(RTEMS_CUSTOM)
25 include $(CONFIG.CC)
26
27 BUILD_DIR_NAME = _build/$(RTEMS_BSP)
28 COMPILED_DIR_NAME = _compiled/$(RTEMS_BSP)
29 GROUP_DIR_NAME =
30
31
32 USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
33 USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
34 USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
35 USER_TESTS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-tests
36 USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
37 USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
38
39 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
40
41
42 DEFAULT_INCLUDES = -I $(PROJECT_INCLUDE)
43
44 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
45
46 CPPFLAGS  += $(CONFIG_OMK_DEFINES)
47
48 #CPPFLAGS  += $(AM_CPPFLAGS)
49 #CFLAGS    += $(AM_CFLAGS)
50 #CXXFLAGS  += $(AM_CXXFLAGS)
51 #LDFLAGS   += $(CFLAGS) $(AM_CFLAGS) $(LD_PATHS:%=-L%)
52
53 LOADLIBES += -L$(USER_LIB_DIR)
54
55 LOADLIBES += $(lib_LOADLIBES:%=-l%)
56
57 SOLIB_PICFLAGS += -shared -fpic
58
59 ifndef RELATIVE_DIR
60 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
61 endif
62 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
63 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
64 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
65
66 #$(warning SOURCES_DIR = $(SOURCES_DIR))
67 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
68 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
69
70 #vpath %.c $(SOURCES_DIR)
71 #vpath %.cc $(SOURCES_DIR)
72 #vpath %.cxx $(SOURCES_DIR)
73
74 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
75
76 .PHONY: check-dir
77
78 # Some support to serialize some targets for parallel make
79 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
80 include-pass: check-dir
81 library-pass: include-pass
82 binary-pass: library-pass
83
84 override OMK_SERIALIZE_INCLUDED = y
85 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
86 endif
87
88 #=====================================================================
89 # Special rules for target filesystem and data preparation
90
91 # Syntax: $(call TARFILE_template,<filename>,<filename2>,<directory>) FIXME: Is this correct?
92 define TARFILE_template
93
94 .PHONY: $(2)
95
96 $(2):
97         $(Q) ABSOLUTETARFILE=`cd $$(dir $$@) ; pwd`/$$@ ; \
98              ( test -e $$$$ABSOLUTETARFILE && ( cd  $(3) && tar $$(TARFLAGS) -df $$$$ABSOLUTETARFILE ) ) || \
99              ( cd  $(3) && tar $$(TARFLAGS) -cf $$$$ABSOLUTETARFILE . )
100
101 $(2).o: $(2)
102         @$(QUIET_CMD_ECHO) "  TARFILE $$@"
103         $(Q) $(OBJCOPY) -I binary -O elf32-littlearm  $$^ $$@
104
105 endef
106
107 #=====================================================================
108 # User-space rules and templates to compile programs, libraries etc.
109
110 ifdef USER_RULE_TEMPLATES
111
112
113 #%.lo: %.c
114 #       $(CC) -o $@ $(LCFLAGS) -c $<
115
116 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
117         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
118
119 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
120         $(CPPFLAGS) $(AM_CXXFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
121
122 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
123         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
124
125 # Check GCC version for user build
126 ifndef CC_MAJOR_VERSION
127 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
128 endif
129 # Prepare suitable define for dependency building
130 ifeq ($(CC_MAJOR_VERSION),2)
131 CC_DEPFLAGS = -Wp,-MD,"$@.d.tmp"
132 else
133 CC_DEPFLAGS = -MT $@ -MD -MP -MF "$@.d.tmp"
134 endif
135
136
137 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
138 define COMPILE_c_o_template
139 $(2): $(1) $$(GEN_HEADERS)
140         @$(QUIET_CMD_ECHO) "  CC      $$@"
141         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
142         then mv -f "$$@.d.tmp" "$$@.d" ; \
143         else rm -f "$$@.d.tmp" ; exit 1; \
144         fi
145 endef
146
147
148 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
149 define COMPILE_cc_o_template
150 $(2): $(1) $$(GEN_HEADERS)
151         @$(QUIET_CMD_ECHO) "  CXX     $$@"
152         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
153         then mv -f "$$@.d.tmp" "$$@.d" ; \
154         else rm -f "$$@.d.tmp" ; exit 1; \
155         fi
156 endef
157
158
159 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
160 define COMPILE_S_o_template
161 $(2): $(1) $$(GEN_HEADERS)
162         @$(QUIET_CMD_ECHO) "  AS      $$@"
163         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
164         then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
165         else rm -f "$$@.d.tmp" ; exit 1; \
166         fi
167 endef
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 >$$@ '/* Automatically generated from $$< */'
177         $(Q)echo >>$$@ '/* Conditionals to control compilation */'
178         $(Q)set -o pipefail ; $(NM) $$< \
179                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
180                 | sort >>$$@
181         $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
182         $(Q)set -o pipefail ; $(NM) $$< \
183                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
184                 | sort >>$$@
185 endef
186
187 # Syntax: $(call PROGRAM_template,<dir>,<executable-name>,<link-variant>)
188 define PROGRAM_template
189 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
190 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
191 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
192 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
193 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
194 $(1)_OBJS := $$(sort $$($(1)_OBJS))
195
196 USER_OBJS  += $$($(1)_OBJS)
197 USER_SOURCES += $$($(1)_SOURCES)
198 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
199
200 $(2)/$(1): $(USER_LIB_DIR)/timestamp
201
202 $(2)/$(1): $$($(1)_OBJS)
203         @$(QUIET_CMD_ECHO) "  LINK    $$@"
204         $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
205           then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
206           else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
207           $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
208           -o $(2)/$(1)
209 #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d
210 #@sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(USER_OBJS_DIR)/$(1).exe.map  >>$(USER_OBJS_DIR)/$(1).exe.d
211 #@echo >>$(USER_OBJS_DIR)/$(1).exe.d
212 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map
213 # FIXME: Why the map file was commented out?
214 endef
215
216
217
218 # Syntax: $(call LIBRARY_template,<library-name>)
219 define LIBRARY_template
220 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
221 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
222 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
223 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
224 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
225 $(1)_OBJS := $$(sort $$($(1)_OBJS))
226
227 USER_OBJS  += $$($(1)_OBJS)
228 USER_SOURCES += $$($(1)_SOURCES)
229 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
230
231 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
232         @$(QUIET_CMD_ECHO) "  AR      $$@"
233         $(Q) $(AR) rcs $$@ $$^
234         @touch $(USER_LIB_DIR)/timestamp
235 endef
236
237
238
239 # Syntax: $(call SOLIB_template,<library-name>)
240 define SOLIB_template
241 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
242 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
243 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
244 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
245 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
246 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
247
248 SOLIB_OBJS  += $$($(1)_OBJSLO)
249 SOLIB_SOURCES += $$($(1)_SOURCES)
250 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
251
252 $(USER_LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
253         @$(QUIET_CMD_ECHO) "  LINK    $$@"
254         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
255 endef
256
257
258
259 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
260                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
261
262 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/% $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%)
263
264 # Special rules for CMETRIC generated headers
265
266 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
267                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
268                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
269 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
270                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
271                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
272
273 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
274
275 # Generate rules for compilation of programs and libraries
276
277 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
278
279 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
280
281 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
282
283 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
284
285 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
286
287 -include $(USER_OBJS_DIR)/*.d
288
289 endif
290
291 #=====================================================================
292
293
294 $(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
295 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
296 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
297
298 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
299
300 check-dir::
301         @$(call mkdir_def,$(USER_INCLUDE_DIR))
302         @$(call mkdir_def,$(USER_LIB_DIR))
303         @$(call mkdir_def,$(USER_BIN_DIR))
304         @$(call mkdir_def,$(USER_UTILS_DIR))
305         @$(call mkdir_def,$(USER_TESTS_DIR))
306
307 $(eval $(call include-pass-template,$(USER_INCLUDE_DIR),include))
308
309 ifdef USER_RULE_TEMPLATES
310
311 # User-space static libraries and applications object files
312
313 USER_SOURCES := $(sort $(USER_SOURCES))
314
315 #$(warning USER_SOURCES = $(USER_SOURCES))
316
317 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
318
319 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
320
321 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
322
323 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
324
325 # User-space shared libraries object files
326
327 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
328
329 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
330
331 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
332
333 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
334
335 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
336
337 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
338
339 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
340
341 endif
342
343
344 clean-local:
345         @echo Cleaning in $(USER_OBJS_DIR)
346         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
347                $(USER_OBJS_DIR)/*.d \
348                $(USER_OBJS_DIR)/*.map \
349                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
350                $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile)
351
352
353 default: include-pass library-pass binary-pass