]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - snippets/sysless
Both sysless and linux rules should work now.
[omk/sssa.git] / snippets / sysless
1 # bin_PROGRAMS     .. list of the require binary programs
2 # include_HEADERS  .. list of the user-space public header files
3 # lib_LIBRARIES    .. list of the user-space libraries
4 # lib_LDSCRIPTS    .. list of LD scripts that should be copied to the lib direcotry
5 # lib_obj_SOURCES  .. list of source files which should be compiled and
6 #                     the produced object file placed to the lib directory (e.g. crt0.S)
7 # shared_LIBRARIES .. list of the user-space shared libraries
8 # nobase_include_HEADERS .. public headers copied even with directory part
9 # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
10 # utils_PROGRAMS   .. list of the development utility programs (compiled for host computer, this might change in future)
11 # xxx_SOURCES      .. list of specific target sources
12 # xxx_LIBS         .. list of specific target libraries
13 # INCLUDES         .. additional include directories and defines for user-space
14 # lib_LOADLIBES    .. list of libraries linked to each executable
15 # link_VARIANTS    .. list of ld script suffixes (after hypen `-') that
16 #                     should be used for linking (e.g. ram flash). If this is not
17 #                     specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
18 # PREFIX_DIR       .. Prefix to  directories in _compiled and _build. Used in config.omk.
19
20 # Some support to serialize some targets for parallel make
21 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
22 include-pass: $(check-dir)
23 library-pass: include-pass
24 binary-pass utils-pass: library-pass
25
26 OMK_SERIALIZE_INCLUDED = y
27 endif
28
29 ifeq ($(wildcard $(MAKERULES_DIR)/config.target),$(MAKERULES_DIR)/config.target)
30 $(error Please, rename $(MAKERULES_DIR)/config.target to config.omk!)
31 endif
32
33 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
34 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
35
36 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
37 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
38
39 #=====================================================================
40 # Common utility rules
41
42 link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
43
44
45 #=====================================================================
46 # Include correct rules for just running pass
47
48 USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
49
50 USER_INCLUDE_DIR := $(USER_COMPILED_DIR_NAME)/include
51 USER_LIB_DIR     := $(USER_COMPILED_DIR_NAME)/lib
52 USER_UTILS_DIR   := $(USER_COMPILED_DIR_NAME)/bin-utils
53 USER_BIN_DIR     := $(USER_COMPILED_DIR_NAME)/bin
54 USER_OBJS_DIR    := $(LOCAL_BUILD_DIR)
55
56
57 # -------------------------------------
58 # Rules for compilation for target
59 ifdef TARGET_RULE_TEMPLATES
60
61 LDFLAGS += -nostartfiles
62
63  # FIXME: These are not used. What they are good for?
64 LIB_CPPFLAGS += $(CPPFLAGS)
65 LIB_CFLAGS   += $(CFLAGS)
66
67 SOLIB_PICFLAGS += -shared -fpic
68
69 CFLAGS += -DOMK_FOR_TARGET
70
71 INCLUDE_DIR := $(USER_INCLUDE_DIR)
72 LIB_DIR     := $(USER_LIB_DIR)
73 OBJS_DIR    := $(USER_OBJS_DIR)
74
75 $(eval $(COMPILER_DEFS_template))
76
77 # Special rules for CMETRIC generated headers
78
79 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
80                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
81                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
82 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
83                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
84                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
85
86 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
87
88 # Generate rules for compilation of programs and libraries
89 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
90 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
91 #$(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix .o,$(basename $(src)))))) # FIXME: This can't work LIBOBJ_template is not defined
92 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
93
94 # User-space static libraries and applications object files
95 SOURCES := $(sort $(SOURCES))
96 #$(warning SOURCES = $(SOURCES))
97
98 # User-space shared libraries object files
99 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
100 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
101
102
103 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
104 # variables. Now generate rules for compilation of theese sources
105 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
106 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
107 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
108 $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
109
110 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
111 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
112 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
113 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
114
115 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
116                     $(lib_LIBRARIES:%=$(LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(LIB_DIR)/lib%.so) \
117                     $(addprefix $(LIB_DIR)/,$(lib_OBJS))
118
119 binary-pass-local:  $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) \
120                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of))))
121
122
123 endif # TARGET_RULE_TEMPLATES
124
125
126 # -------------------------------------
127 # Rules for compilation utilities for host (user space)
128 ifdef HOST_RULE_TEMPLATES
129
130 CROSS_COMPILE =
131 TARGET_ARCH =
132
133 SOLIB_PICFLAGS += -shared -fpic
134
135 # For host compilation, we don't use a specfic ld script
136 LD_SCRIPT =
137
138 # TODO: It is probably better to use different directories for host
139 # includes, libraries and objects
140 INCLUDE_DIR := $(USER_INCLUDE_DIR)
141 LIB_DIR     := $(USER_LIB_DIR)
142 OBJS_DIR    := $(USER_OBJS_DIR)
143
144 $(eval $(COMPILER_DEFS_template))
145
146  #User-space static libraries and applications object files
147 #SOURCES := $(sort $(SOURCES))
148 #$(warning SOURCES = $(SOURCES))
149
150 # Generate rules for compilation of utility programs
151 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
152
153 # The above generated rule produced $(SOURCES) variable. Now generate
154 # rules for compilation of theese sources
155 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
156 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
157 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
158 $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
159
160 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
161
162 endif # HOST_RULE_TEMPLATES
163
164
165 #=====================================================================
166 # Automatic loading of compiled program by issuing "make load"
167
168 ifneq ($(OUTPUT_FORMATS),)
169 # Select a file extension (e.g. .bin) for "make load" command to load.
170 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
171 endif
172
173 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
174 # Used to load program to the target hardware
175 define LOAD_PROGRAM_template
176 .PHONY: load-$(1)$(3:%=-%)
177 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
178         @$(QUIET_CMD_ECHO) "  LOAD    $$<"
179         @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
180         $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
181 endef
182
183 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
184 # Used to load and/or run non-default variant of the default program
185 define LOAD_RUN_VARIANT_template
186 .PHONY: load-$(1) run-$(1)
187
188 load-$(1): load-$(firstword $(bin_PROGRAMS))-$(1)
189
190 run-$(1):
191         @$(QUIET_CMD_ECHO) "  RUN     $(1)"
192         @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
193         $(Q) $(RUN_CMD-$(1))
194
195 endef
196
197 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
198 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
199
200 .PHONY: load run
201 load: $(addprefix load-,$(firstword $(bin_PROGRAMS))-$(firstword $(link_VARIANTS)))
202
203 run: run-$(firstword $(link_VARIANTS))
204
205
206
207 #=====================================================================
208 # Generate pass rules from generic templates
209 OTHER_PASSES = dep clean install
210
211 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,-n "$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)"))
212 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_OBJS)"))
213 $(eval $(call omk_pass_template, binary-pass,  $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(bin_PROGRAMS)"))
214 $(eval $(call omk_pass_template, utils-pass,   $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,-n "$(utils_PROGRAMS)"))
215
216
217 $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR)))
218
219
220 dep-local:
221
222 install-local:
223
224 # TODO: Check modification date of changed header files. If it is
225 # newer that in source dir, show a warning.
226 include-pass-local:
227 #       @$(call mkdir_def,$(USER_INCLUDE_DIR))
228         @$(foreach f, $(include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) \
229            || cp $(CP_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) || exit 1 ; )
230         @$(foreach f, $(nobase_include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) \
231            || ( mkdir -p $(USER_INCLUDE_DIR)/$(dir $(f)) && cp $(CP_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) ) || exit 1 ; )
232         @$(foreach f, $(renamed_include_HEADERS), \
233            srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \
234            cmp --quiet $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} \
235            || ( mkdir -p `dirname $(USER_INCLUDE_DIR)/$${destfname}` && cp $(CP_FLAGS) $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} ) || exit 1 ; )
236         @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
237            || cp $(CP_FLAGS) $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) || exit 1 ; )
238
239
240 .PHONY: clean-custom
241 clean-local: clean-custom
242         @echo Cleaning in $(USER_OBJS_DIR)
243         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
244                $(USER_OBJS_DIR)/*.d \
245                $(USER_OBJS_DIR)/*.map \
246                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
247
248 check-dir:
249         @$(call mkdir_def,$(USER_INCLUDE_DIR))
250         @$(call mkdir_def,$(USER_LIB_DIR))
251         @$(call mkdir_def,$(USER_BIN_DIR))
252         @$(call mkdir_def,$(USER_UTILS_DIR))
253
254 # Create directories only for the first time
255 ifndef CHECK_DIR_DONE
256 check-dir = check-dir
257 CHECK_DIR_DONE = y
258 endif
259 export CHECK_DIR_DONE
260
261 # Which passes to pass
262 default: $(check-dir) include-pass library-pass binary-pass utils-pass
263
264 ETAGS = etags -R -f $(MAKERULES_DIR)/TAGS
265 .PHONY: TAGS
266 TAGS:
267         $(ETAGS)    $(MAKERULES_DIR)/app
268         $(ETAGS) -a $(MAKERULES_DIR)/arch/$(ARCH)/generic
269         $(ETAGS) -a $(MAKERULES_DIR)/arch/$(ARCH)/mach-$(MACH)
270         $(ETAGS) -a $(MAKERULES_DIR)/board/$(BOARD)
271         $(ETAGS) -a $(MAKERULES_DIR)/libs4c
272
273 # Local Variables:
274 # mode:makefile
275 # End: