]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/sysless
a5f56b84d65bc6d4b77a43d91aae1830878aa2e2
[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
37
38 # -------------------------------------
39 # Rules for compilation for target
40 ifdef TARGET_RULE_TEMPLATES
41
42 LDFLAGS += -nostartfiles
43
44  # FIXME: These are not used. What they are good for?
45 LIB_CPPFLAGS += $(CPPFLAGS)
46 LIB_CFLAGS   += $(CFLAGS)
47
48 SOLIB_PICFLAGS += -shared -fpic
49
50 CFLAGS += -DOMK_FOR_TARGET
51
52 INCLUDE_DIR := $(USER_INCLUDE_DIR)
53 LIB_DIR     := $(USER_LIB_DIR)
54 OBJS_DIR    := $(USER_OBJS_DIR)
55
56 $(eval $(COMPILER_DEFS_template))
57
58 # Special rules for CMETRIC generated headers
59
60 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
61                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
62                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
63 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
64                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
65                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
66
67 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
68
69 # Generate rules for compilation of programs and libraries
70 $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
71 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
72 #$(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix .o,$(basename $(src)))))) # FIXME: This can't work LIBOBJ_template is not defined
73 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
74
75 # User-space static libraries and applications object files
76 SOURCES := $(sort $(SOURCES))
77 #$(warning SOURCES = $(SOURCES))
78
79 # User-space shared libraries object files
80 SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
81 #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
82
83
84 # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
85 # variables. Now generate rules for compilation of theese sources
86 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
87 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
88 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
89 $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
90
91 $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
92 $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
93 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
94 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
95
96 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
97                     $(lib_LIBRARIES:%=$(LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(LIB_DIR)/lib%.so) \
98                     $(addprefix $(LIB_DIR)/,$(lib_OBJS))
99
100 binary-pass-local:  $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) \
101                     $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of))))
102
103
104 endif # TARGET_RULE_TEMPLATES
105
106
107 # -------------------------------------
108 # Rules for compilation utilities for host (user space)
109 ifdef HOST_RULE_TEMPLATES
110
111 CROSS_COMPILE =
112 TARGET_ARCH =
113
114 SOLIB_PICFLAGS += -shared -fpic
115
116 # For host compilation, we don't use a specfic ld script
117 LD_SCRIPT =
118
119 # TODO: It is probably better to use different directories for host
120 # includes, libraries and objects
121 INCLUDE_DIR := $(USER_INCLUDE_DIR)
122 LIB_DIR     := $(USER_LIB_DIR)
123 OBJS_DIR    := $(USER_OBJS_DIR)
124
125 $(eval $(COMPILER_DEFS_template))
126
127  #User-space static libraries and applications object files
128 #SOURCES := $(sort $(SOURCES))
129 #$(warning SOURCES = $(SOURCES))
130
131 # Generate rules for compilation of utility programs
132 $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
133
134 # The above generated rule produced $(SOURCES) variable. Now generate
135 # rules for compilation of theese sources
136 $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),)))
137 $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),)))
138 $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
139 $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
140
141 utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
142
143 endif # HOST_RULE_TEMPLATES
144
145
146 #=====================================================================
147 # Automatic loading of compiled program by issuing "make load"
148
149 ifneq ($(OUTPUT_FORMATS),)
150 # Select a file extension (e.g. .bin) for "make load" command to load.
151 LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
152 endif
153
154 # Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
155 # Used to load program to the target hardware
156 define LOAD_PROGRAM_template
157 .PHONY: load-$(1)$(3:%=-%)
158 load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
159         @$(QUIET_CMD_ECHO) "  LOAD    $$<"
160         @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
161         $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
162 endef
163
164 # Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
165 # Used to load and/or run non-default variant of the default program
166 define LOAD_RUN_VARIANT_template
167 .PHONY: load-$(1) run-$(1)
168
169 load-$(1): load-$(firstword $(bin_PROGRAMS))-$(1)
170
171 run-$(1):
172         @$(QUIET_CMD_ECHO) "  RUN     $(1)"
173         @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
174         $(Q) $(RUN_CMD-$(1))
175
176 endef
177
178 $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
179 $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
180
181 .PHONY: load run
182 load: $(addprefix load-,$(firstword $(bin_PROGRAMS))-$(firstword $(link_VARIANTS)))
183
184 run: run-$(firstword $(link_VARIANTS))
185
186
187
188 #=====================================================================
189 # Generate pass rules from generic templates
190 OTHER_PASSES = dep clean install
191
192 $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,-n "$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)"))
193 $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_OBJS)"))
194 $(eval $(call omk_pass_template, binary-pass,  $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(bin_PROGRAMS)"))
195 $(eval $(call omk_pass_template, utils-pass,   $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,-n "$(utils_PROGRAMS)"))
196
197
198 $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR)))
199
200
201 dep-local:
202
203 install-local:
204
205 include-pass-local:
206         $(call include-pass-template,$(USER_INCLUDE_DIR),include)
207         @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
208            || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
209
210
211 .PHONY: clean-custom
212 clean-local: clean-custom
213         @echo Cleaning in $(USER_OBJS_DIR)
214         @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
215                $(USER_OBJS_DIR)/*.d \
216                $(USER_OBJS_DIR)/*.map \
217                $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
218
219 check-dir:
220         @$(call mkdir_def,$(USER_INCLUDE_DIR))
221         @$(call mkdir_def,$(USER_LIB_DIR))
222         @$(call mkdir_def,$(USER_BIN_DIR))
223         @$(call mkdir_def,$(USER_UTILS_DIR))
224
225 # Create directories only for the first time
226 ifndef CHECK_DIR_DONE
227 check-dir = check-dir
228 CHECK_DIR_DONE = y
229 endif
230 export CHECK_DIR_DONE
231
232 # Which passes to pass
233 default: $(check-dir) include-pass library-pass binary-pass utils-pass
234
235 # Local Variables:
236 # mode:makefile
237 # End: