]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - snippets/rtems
Propagated correction of MinGW madness workaround to Sysless rules.
[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 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 endif
85
86 #=====================================================================
87 # Special rules for target filesystem and data preparation
88
89 # Syntax: $(call TARFILE_template,<filename>,<filename2>,<directory>) FIXME: Is this correct?
90 define TARFILE_template
91
92 .PHONY: $(2)
93
94 $(2):
95         $(Q) ABSOLUTETARFILE=`cd $$(dir $$@) ; pwd`/$$@ ; \
96              ( test -e $$$$ABSOLUTETARFILE && ( cd  $(3) && tar -df $$$$ABSOLUTETARFILE ) ) || \
97              ( cd  $(3) && tar -cf $$$$ABSOLUTETARFILE . )
98
99 $(2).o: $(2)
100         @$(QUIET_CMD_ECHO) "  TARFILE $$@"
101         $(Q) $(OBJCOPY) -I binary -O elf32-littlearm  $$^ $$@
102
103 endef
104
105 #=====================================================================
106 # User-space rules and templates to compile programs, libraries etc.
107
108 ifdef USER_RULE_TEMPLATES
109
110
111 #%.lo: %.c
112 #       $(CC) -o $@ $(LCFLAGS) -c $<
113
114 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
115         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
116
117 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \
118         $(CPPFLAGS) $(AM_CXXFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER
119
120 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
121         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
122
123 # Check GCC version for user build
124 ifndef CC_MAJOR_VERSION
125 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -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 if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
163         else rm -f "$$@.d.tmp" ; exit 1; \
164         fi
165 endef
166
167 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
168 define CMETRIC_o_h_template
169 $(2): $(1)
170         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
171         $(Q)if [ -n `dirname $$@` ] ; then \
172               if [ ! -e `dirname $$@` ] ; then \
173                 mkdir -p `dirname $$@` ; fi ; fi
174         $(Q)echo >$$@ '/* Automatically generated from $$< */'
175         $(Q)echo >>$$@ '/* Conditionals to control compilation */'
176         $(Q)set -o pipefail ; $(NM) $$< \
177                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
178                 | sort >>$$@
179         $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
180         $(Q)set -o pipefail ; $(NM) $$< \
181                 | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
182                 | sort >>$$@
183 endef
184
185 # Syntax: $(call PROGRAM_template,<dir>,<executable-name>,<link-variant>)
186 define PROGRAM_template
187 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
188 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
189 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
190 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
191 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
192 $(1)_OBJS := $$(sort $$($(1)_OBJS))
193
194 USER_OBJS  += $$($(1)_OBJS)
195 USER_SOURCES += $$($(1)_SOURCES)
196 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
197
198 $(2)/$(1): $(USER_LIB_DIR)/timestamp
199
200 $(2)/$(1): $$($(1)_OBJS)
201         @$(QUIET_CMD_ECHO) "  LINK    $$@"
202         $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
203           then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \
204           else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
205           $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
206           -o $(2)/$(1)
207 #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d
208 #@sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(USER_OBJS_DIR)/$(1).exe.map  >>$(USER_OBJS_DIR)/$(1).exe.d
209 #@echo >>$(USER_OBJS_DIR)/$(1).exe.d
210 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map
211 # FIXME: Why the map file was commented out?
212 endef
213
214
215
216 # Syntax: $(call LIBRARY_template,<library-name>)
217 define LIBRARY_template
218 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
219 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
220 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
221 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
222 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
223 $(1)_OBJS := $$(sort $$($(1)_OBJS))
224
225 USER_OBJS  += $$($(1)_OBJS)
226 USER_SOURCES += $$($(1)_SOURCES)
227 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
228
229 $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
230         @$(QUIET_CMD_ECHO) "  AR      $$@"
231         $(Q) $(AR) rcs $$@ $$^
232         @touch $(USER_LIB_DIR)/timestamp
233 endef
234
235
236
237 # Syntax: $(call SOLIB_template,<library-name>)
238 define SOLIB_template
239 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
240 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
241 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
242 $(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
243 $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o)
244 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
245
246 SOLIB_OBJS  += $$($(1)_OBJSLO)
247 SOLIB_SOURCES += $$($(1)_SOURCES)
248 USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES)
249
250 $(USER_LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
251         @$(QUIET_CMD_ECHO) "  LINK    $$@"
252         $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
253 endef
254
255
256
257 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
258                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
259
260 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/% $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%)
261
262 # Special rules for CMETRIC generated headers
263
264 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
265                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
266                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
267 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
268                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
269                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
270
271 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
272
273 # Generate rules for compilation of programs and libraries
274
275 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
276
277 $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
278
279 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
280
281 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
282
283 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
284
285 -include $(USER_OBJS_DIR)/*.d
286
287 endif
288
289 #=====================================================================
290
291
292 $(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
293 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
294 $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
295
296 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
297
298 check-dir:
299         @$(call mkdir_def,$(USER_INCLUDE_DIR))
300         @$(call mkdir_def,$(USER_LIB_DIR))
301         @$(call mkdir_def,$(USER_BIN_DIR))
302         @$(call mkdir_def,$(USER_UTILS_DIR))
303         @$(call mkdir_def,$(USER_TESTS_DIR))
304
305 include-pass-local:
306         $(call include-pass-template,$(USER_INCLUDE_DIR),include)
307
308 ifdef USER_RULE_TEMPLATES
309
310 # User-space static libraries and applications object files
311
312 USER_SOURCES := $(sort $(USER_SOURCES))
313
314 #$(warning USER_SOURCES = $(USER_SOURCES))
315
316 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
317
318 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
319
320 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
321
322 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
323
324 # User-space shared libraries object files
325
326 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
327
328 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
329
330 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
331
332 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
333
334 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
335
336 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
337
338 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
339
340 endif
341
342
343 clean-local:
344         @echo Cleaning in $(USER_OBJS_DIR)
345         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
346                $(USER_OBJS_DIR)/*.d \
347                $(USER_OBJS_DIR)/*.map \
348                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
349                $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile)
350
351
352 default: include-pass library-pass binary-pass
353
354 # Local Variables:
355 # mode:makefile
356 # End: