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