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