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