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