]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - omk-devel/rtems/Makefile.rules
3436e8db842926307993fe0f3a5bf51e84e270c6
[omk/sssa.git] / omk-devel / rtems / Makefile.rules
1 #  Makefile.rules - OCERA make framework common project rules
2 #                   This version is adapted for RTEMS build
3 #
4 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
5 #
6 #  The uLan driver is distributed under the Gnu General Public License.
7 #  See file COPYING for details.
8 #
9 #
10 # input variables
11 # V                .. if set to 1, full command text is shown else short form is used
12 # SUBDIRS          .. list of subdirectories intended for make from actual directory
13 # lib_LIBRARIES    .. list of the user-space libraries
14 # shared_LIBRARIES .. list of the user-space shared libraries
15 # include_HEADERS  .. list of the user-space public header files
16 # nobase_include_HEADERS .. public headers copied even with directory part
17 # renamed_include_HEADERS .. public headers copied to the different target name
18 # bin_PROGRAMS     .. list of the require binary programs
19 # utils_PROGRAMS   .. list of the development utility programs
20 # xxx_SOURCES      .. list of specific target sources
21 # INCLUDES         .. additional include directories and defines for user-space
22 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
23 # tar_EMBEDFILES   .. list of tars with embedded files
24 #
25
26 # Include RTEMS target configuration defining RTEMS_MAKEFILE_PATH
27 include $(MAKERULES_DIR)/config.target
28
29 include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
30 include $(RTEMS_CUSTOM)
31 include $(CONFIG.CC)
32
33 BUILD_DIR_NAME = _build/$(RTEMS_BSP)
34 COMPILED_DIR_NAME = _compiled/$(RTEMS_BSP)
35 GROUP_DIR_NAME =
36
37
38 # We need to ensure definition of sources directory first
39 ifndef SOURCES_DIR
40 SOURCES_DIR := $(shell ( pwd -L ) )
41 endif
42
43 all: default
44
45 USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
46 USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
47 USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
48 USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
49 USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
50 ifndef CONFIG_FILE
51 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
52 endif
53 ifneq ($(wildcard $(CONFIG_FILE)-default),)
54 -include $(CONFIG_FILE)-default
55 else
56 $(warning Please, run "make default-config" first)
57 endif
58 ifneq ($(wildcard $(CONFIG_FILE)),)
59 include $(CONFIG_FILE)
60 CONFIG_FILE_OK = y
61 endif
62
63 # Check and include real OCERA style Makefile.omk now
64 ifndef OMK_INCLUDED
65 include $(SOURCES_DIR)/Makefile.omk
66 OMK_INCLUDED := 1
67 endif
68
69 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
70 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
71
72 #CFLAGS += -ggdb
73 #CFLAGS += -O2
74 #CFLAGS += -Wall
75 #CXXFLAGS += -ggdb
76 #CXXFLAGS += -O2
77 #CXXFLAGS += -Wall
78
79 DEFAULT_INCLUDES = -I $(PROJECT_INCLUDE)
80
81 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
82
83 CPPFLAGS  += $(CONFIG_OMK_DEFINES)
84
85 #CPPFLAGS  += $(AM_CPPFLAGS)
86 #CFLAGS    += $(AM_CFLAGS)
87 #CXXFLAGS  += $(AM_CXXFLAGS)
88 #LDFLAGS   += $(CFLAGS) $(AM_CFLAGS) $(LD_PATHS:%=-L%)
89
90 LOADLIBES += -L$(USER_LIB_DIR)
91
92 LOADLIBES += $(lib_LOADLIBES:%=-l%)
93
94 SOLIB_PICFLAGS += -shared -fpic
95
96 ifndef RELATIVE_DIR
97 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
98 endif
99 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
100 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
101 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
102
103 #$(warning SOURCES_DIR = $(SOURCES_DIR))
104 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
105 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
106
107 #vpath %.c $(SOURCES_DIR)
108 #vpath %.cc $(SOURCES_DIR)
109 #vpath %.cxx $(SOURCES_DIR)
110
111 VPATH = $(SOURCES_DIR)
112 srcdir = $(SOURCES_DIR)
113
114 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
115
116 .PHONY: default dep subdirs clean cleandepend default-config
117 .PHONY: check-make-ver check-dir include-pass library-pass binary-pass utils-pass
118 .PHONY: default-config-pass
119 .PHONY: check-dir-local include-pass-local library-pass-local binary-pass-local
120 .PHONY: utils-pass-local default-config-pass-local
121
122 # Some support to serialize some targets for parallel make
123 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
124 include-pass: check-dir
125 library-pass: include-pass
126 binary-pass utils-pass: library-pass
127
128 OMK_SERIALIZE_INCLUDED = y
129 endif
130
131 # Defines for quiet compilation
132 ifdef V
133   ifeq ("$(origin V)", "command line")
134     OMK_VERBOSE = $(V)
135   endif
136 endif
137 ifndef OMK_VERBOSE
138   OMK_VERBOSE = 0
139 endif
140 ifeq ($(OMK_VERBOSE),1)
141   Q =
142 else
143   Q = @
144 endif
145 ifneq ($(findstring s,$(MAKEFLAGS)),)
146   QUIET_CMD_ECHO = true
147   OMK_SILENT = 1
148 else
149   QUIET_CMD_ECHO = echo
150   CPHEADER_FLAGS += -v
151 endif
152
153 default: check-make-ver check-dir include-pass library-pass binary-pass utils-pass
154
155 #=====================================================================
156 # Common utility rules
157
158 define mkdir_def
159         [ -d $(1) ] || mkdir -p $(1) || exit 1
160 endef
161
162 ifdef LOCAL_CONFIG_H
163
164 $(LOCAL_CONFIG_H) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default)
165         @echo LOCAL_CONFIG_H=`pwd`/$(LOCAL_CONFIG_H)
166         @echo "/* Automatically generated from */" > "$(LOCAL_CONFIG_H).tmp"
167         @echo "/* config file : $< */" >> "$(LOCAL_CONFIG_H).tmp"
168         @echo "#ifndef _LOCAL_CONFIG_H" >> "$(LOCAL_CONFIG_H).tmp"
169         @echo "#define _LOCAL_CONFIG_H" >> "$(LOCAL_CONFIG_H).tmp"
170         @( $(foreach x, $(shell echo $(default_CONFIG) | sed -e 's/\<\([^ ]*\)=[^ ]\>/\1/g' ), \
171                 echo $(x).$($(x)) ; ) echo ; ) | \
172                 sed -n -e 's/^\(.*\)\.[ym]$$/#define \1 1/p' \
173                   >> "$(LOCAL_CONFIG_H).tmp"
174         @echo "#endif /*_LOCAL_CONFIG_H*/" >> "$(LOCAL_CONFIG_H).tmp"
175         @if cmp --quiet "$(LOCAL_CONFIG_H).tmp" "$(LOCAL_CONFIG_H)" ; then \
176         echo rm "$(LOCAL_CONFIG_H).tmp" ; \
177         else mv "$(LOCAL_CONFIG_H).tmp" "$(LOCAL_CONFIG_H)" ; \
178         echo Updated configuration "$(LOCAL_CONFIG_H)" ; fi
179
180 endif
181
182 check-make-ver:
183         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
184         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
185                 echo "Your make program version is too old and does not support OMK system." ; \
186                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
187         fi
188
189 #=====================================================================
190 # Special rules for target filesystem and data preparation
191
192
193 define TARFILE_template
194
195 .PHONY: $(2)
196
197 $(2):
198         $(Q) ABSOLUTETARFILE=`cd $$(dir $$@) ; pwd`/$$@ ; \
199              ( test -e $$$$ABSOLUTETARFILE && ( cd  $(3) && tar -df $$$$ABSOLUTETARFILE ) ) || \
200              ( cd  $(3) && tar -cf $$$$ABSOLUTETARFILE . )
201
202 $(2).o: $(2)
203         @$(QUIET_CMD_ECHO) "  TARFILE $$@"
204         $(Q) $(OBJCOPY) -I binary -O elf32-littlearm  $$^ $$@
205
206 endef
207
208 #=====================================================================
209 # User-space rules and templates to compile programs, libraries etc.
210
211 ifdef USER_RULE_TEMPLATES
212
213 include $(MAKERULES_DIR)/Makefile.rules.gcc
214
215 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
216                     $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so)
217
218 binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%)
219
220 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
221
222 # Special rules for CMETRIC generated headers
223
224 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
225                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
226                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
227 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
228                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
229                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
230
231 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
232
233 # Generate rules for compilation of programs and libraries
234
235 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR))))
236
237 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
238
239 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
240
241 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
242
243 -include $(USER_OBJS_DIR)/*.d
244
245 endif
246
247 #=====================================================================
248
249
250 library-pass binary-pass utils-pass:
251         +@$(foreach dir, $(SUBDIRS), $(call mkdir_def,$(USER_OBJS_DIR)/$(dir)) ; \
252                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
253                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(USER_OBJS_DIR)/$(dir) \
254                 -f $(SOURCES_DIR)/$(dir)/Makefile $@ || exit 1 ;)
255         +@$(call mkdir_def,$(USER_OBJS_DIR))
256         @$(MAKE) --no-print-directory -C $(USER_OBJS_DIR) \
257                 -f $(SOURCES_DIR)/Makefile USER_RULE_TEMPLATES=y $(@:%=%-local)
258
259
260 dep clean install check-dir include-pass default-config-pass:
261         +@$(foreach dir, $(SUBDIRS), $(call mkdir_def,$(USER_OBJS_DIR)/$(dir)) ; \
262                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
263                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(USER_OBJS_DIR)/$(dir) \
264                 -f $(SOURCES_DIR)/$(dir)/Makefile $@ || exit 1 ;)
265         +@$(call mkdir_def,$(USER_OBJS_DIR))
266         @$(MAKE) --no-print-directory -C $(USER_OBJS_DIR) \
267                 -f $(SOURCES_DIR)/Makefile $(@:%=%-local)
268
269
270 dep-local:
271
272 check-dir-local:
273         @$(call mkdir_def,$(USER_OBJS_DIR))
274         @$(call mkdir_def,$(USER_INCLUDE_DIR))
275         @$(call mkdir_def,$(USER_LIB_DIR))
276         @$(call mkdir_def,$(USER_BIN_DIR))
277         @$(call mkdir_def,$(USER_UTILS_DIR))
278
279 install-local:
280
281 default-config:
282         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
283         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
284         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
285         @echo >> "$(CONFIG_FILE)-default"
286         @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
287                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
288                 -f $(MAKERULES_DIR)/Makefile default-config-pass
289
290 default-config-pass-local:
291         @echo Default config for $(RELATIVE_DIR)
292         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
293         @$(foreach x, $(default_CONFIG), echo $(x) | \
294                 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
295
296 include-pass-local:
297         @$(call mkdir_def,$(USER_INCLUDE_DIR))
298         @$(foreach f, $(include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) \
299            || cp $(CPHEADER_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) || exit 1 ; )
300         @$(foreach f, $(nobase_include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) \
301            || ( mkdir -p $(USER_INCLUDE_DIR)/$(dir $(f)) && cp $(CPHEADER_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) ) || exit 1 ; )
302         @$(foreach f, $(renamed_include_HEADERS), \
303            srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \
304            cmp --quiet $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} \
305            || ( mkdir -p `dirname $(USER_INCLUDE_DIR)/$${destfname}` && cp $(CPHEADER_FLAGS) $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} ) || exit 1 ; )
306
307 ifdef USER_RULE_TEMPLATES
308
309 # User-space static libraries and applications object files
310
311 USER_SOURCES := $(sort $(USER_SOURCES))
312
313 #$(warning USER_SOURCES = $(USER_SOURCES))
314
315 $(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
316
317 $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
318
319 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
320
321 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
322
323 # User-space shared libraries object files
324
325 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
326
327 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
328
329 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
330
331 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
332
333 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
334
335 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
336
337 $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile),$(tarfile)_tarfile,$(SOURCES_DIR)/$(tarfile))))
338
339 endif
340
341
342 clean-local:
343         @echo Cleaning in $(USER_OBJS_DIR)
344         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
345                $(USER_OBJS_DIR)/*.d \
346                $(USER_OBJS_DIR)/*.map \
347                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \
348                $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile)
349
350