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