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