]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/nuttx-compile.omk
NuttX: the adapt to new implementation of ROMFS mounting at /etc
[omk.git] / snippets / nuttx-compile.omk
1
2 # Rules for NuttX binaries compilation of C, C++ and assembler
3 # sources using GNU toolchain.
4
5 # Interface to other rules:
6 # kernel_HEADERS   .. list of the kernel-space public header files
7 # kernel_MODULES   .. list of the kernel side modules/applications
8
9 # Input variables:
10 # NUTTX_EXPORT - export directory of NuttX build
11 #                it should contain subdirectories:
12 #                arch  build  include  libs  registry  startup)
13 # LIB_DIR - directory where compiled libraries are stored
14 # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
15 # INCLUDE_DIR - where includes can be found
16 # from config.omk or Makefile.omk
17 # CROSS_COMPILE - target architecture tools prefix
18 # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
19 # from base: SOURCES_DIR
20 # from Makefile.omk: lib_LOADLIBES
21 # xxx_PROGBUILTIN - list of builtin programs linked into final system image
22 #                   when "all" is used then all programs provided by build are linked
23 # xxx_PROGBUILTIN_EXCLUDE - list of builtin user or NuttX provided programs which are excluded
24 # xxx_KMODBUILTIN - list of builtin programs linked into final system image
25
26 # Output variables:
27 # SOURCES - all the source files that needs to be compiled (except for shared library sources)
28 # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
29 # OBJ_EXT - extension of object files
30 # LIB_EXT - extension of library files
31 # LIB_PREF - prefix for library files
32 # ASM_EXT - extension of assembler sources
33
34 # Templates:
35 # COMPILER_DEFS_template - definitions that should be defined before
36 # the following templates can be used. The input variables needs to be
37 # defined before evaluating this template
38
39 # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
40 # templates that create rules for compilation of sources
41
42 # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
43 # create rules for compilation of a program, library and shared
44 # library. The rules can use rules produced by COMPILE_xxx_template.
45
46 EMPTY :=
47 LD_OPTION_SEP = $(EMPTY) $(EMPTY)
48 TARGET_STDSTARTFILES = y
49
50 define COMPILER_DEFS_template
51 OBJ_EXT ?= $$(OBJEXT)
52 ifeq ($$(OBJ_EXT),)
53 OBJ_EXT = .o
54 endif
55 LIB_EXT ?= $$(LIBEXT)
56 ifeq ($$(LIB_EXT),)
57 LIB_EXT = .a
58 endif
59
60 LIB_PREF = lib
61 ASM_EXT = .S
62
63 CROSS_COMPILE ?= $$(CROSSDEV)
64
65 CC ?= $$(CROSS_COMPILE)gcc
66 CXX ?= $$(CROSS_COMPILE)g++
67 LD ?= $$(CROSS_COMPILE)ld
68 ifneq ($$(filter -Wl%, $$(NXFLATLDFLAGS1)$$(NXFLATLDFLAGS2)$$(LDFLAGS)),)
69 CC_LD_OPTION = -Wl,
70 LD_OPTION_SEP := ,
71 LD_BY_CC := 1
72 LD_RAW ?= $$(CROSS_COMPILE)ld
73 endif
74 LD_RAW ?= $$(LD)
75 AR ?= $$(CROSS_COMPILE)ar
76 OBJCOPY ?= $$(CROSS_COMPILE)objcopy
77 NM ?= $$(CROSS_COMPILE)nm
78
79 ifeq ($$(LDSTARTGROUP),)
80 LDSTARTGROUP = $$(CC_LD_OPTION)--start-group
81 LDENDGROUP = $$(CC_LD_OPTION)--end-group
82 endif
83
84 NUTTXLIBES += $$(LDSTARTGROUP) $$(LDLIBS) $$(EXTRA_LIBS) $$(LDENDGROUP)
85 NUTTXREGISTRY += $$(NUTTX_EXPORT)/registry
86
87 TARGET_ARCH += $$(ARCHCFLAGS) $$(ARCHCPUFLAGS)
88
89 OPTIMIZE ?= $$(ARCHOPTIMIZATION)
90
91 CFLAGS += $$(ARCHWARNINGS)
92 CXXFLAGS += $$(ARCHCXXFLAGS)
93 CXXFLAGS += $$(ARCHWARNINGSXX)
94 DEFAULT_INCLUDES = -isystem $$(NUTTX_EXPORT)/include
95 INCLUDES +=
96
97 CFLAGS += $$(TARGET_ARCH) $$(DEBUG) $$(OPTIMIZE)
98 CFLAGS  += -Wall
99 CFLAGS += -I$$(SOURCES_DIR)
100 CFLAGS += -I$$(INCLUDE_DIR)
101
102 LDFLAGS := $$(filter-out -Map=%, $$(LDFLAGS))
103 LDFLAGS  += -L"$(NUTTX_EXPORT)/libs"
104
105 ifeq ($(word 2,$(AR)),)
106 ARFLAGS = rcs
107 else
108 ARFLAGS =
109 endif
110
111 ifeq ($$(LDNAME),)
112 LDNAME := $$(LDSCRIPT)
113 endif
114
115 LD_SCRIPT ?= $$(LDNAME:%=$$(NUTTX_EXPORT)/scripts/%)
116
117 ifneq ($$(filter-out clean distclean, $$(MAKECMDGOALS)),)
118 ifeq ($(LDNAME),)
119 $$(error no LDNAME or LDSCRIPT is defined)
120 endif
121
122 ifeq ($$(wildcard $$(LD_SCRIPT)),)
123 $$(error LD_SCRIPT='$$(LD_SCRIPT)' does not exists, correct config.target)
124 endif
125 endif
126
127 ELF_FILE_LDSCRIPT?=$$(wildcard $$(NUTTX_EXPORT)/scripts/gnu-elf.ld)
128
129 LOADLIBES += -L$$(LIB_DIR)
130 LOADLIBES += $$(lib_LOADLIBES:%=-l%)
131
132 -include $$(OBJS_DIR)/*.d
133
134 SOURCES2OBJS = $$(OBJ_EXT)/.c $$(OBJ_EXT)/.cc $$(OBJ_EXT)/.cxx $$(OBJ_EXT)/.S $$(OBJ_EXT)/.s $$(OBJ_EXT)/$$(OBJ_EXT)
135
136 SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.s .lo/.lo
137
138 #%.lo: %.c
139 #       $(CC) -o $@ $(LCFLAGS) -c $<
140
141 c_o_COMPILE = $$(CC) $$(DEFS) $$(DEFAULT_INCLUDES) $$(INCLUDES) $$(OMK_CPPFLAGS) \
142         $$(CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS)
143
144 cc_o_COMPILE = $$(CXX) $$(DEFS) $$(DEFAULT_INCLUDES) $$(INCLUDES) $$(OMK_CPPFLAGS) \
145         $$(CPPFLAGS) $$(CXXFLAGS) $$(OMK_CFLAGS) $$(CFLAGS)
146
147 S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $$(INCLUDES) \
148         $$(CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS) $$(ASFLAGS)
149
150
151 # Check GCC version for user build
152 ifndef CC_MAJOR_VERSION
153 CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
154 endif
155 # Prepare suitable define for dependency building
156 ifeq ($$(CC_MAJOR_VERSION),2)
157 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
158 else
159 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
160 endif
161
162 endef # COMPILER_DEFS_template
163
164
165 # Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
166 define COMPILE_c_o_template
167 $(2): $(1) $$(GEN_HEADERS)
168         @$(QUIET_CMD_ECHO) "  CC      $$@"
169         $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
170         then mv -f "$$@.d.tmp" "$$@.d" ; \
171         else rm -f "$$@.d.tmp" ; exit 1; \
172         fi
173 endef
174
175
176 # Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
177 define COMPILE_cc_o_template
178 $(2): $(1) $$(GEN_HEADERS)
179         @$(QUIET_CMD_ECHO) "  CXX     $$@"
180         $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
181         then mv -f "$$@.d.tmp" "$$@.d" ; \
182         else rm -f "$$@.d.tmp" ; exit 1; \
183         fi
184 endef
185
186 # Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
187 define COMPILE_S_o_template
188 $(2): $(1) $$(GEN_HEADERS)
189         @$(QUIET_CMD_ECHO) "  AS      $$@"
190         $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
191         then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
192         else rm -f "$$@.d.tmp" ; exit 1; \
193         fi
194 endef
195
196 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
197 define PROGRAM_template
198
199 GEN_SOURCES += $$($(1)_GEN_SOURCES)
200
201 $(foreach x, $(SOURCES2OBJS),
202 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
203                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
204 )
205 $(1)_OBJS += $$($(1)_EMBEDROMFS:%=%_img$$(OBJ_EXT))
206 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
207
208 SOURCES += $$($(1)_SOURCES)
209 EMBEDROMFS += $$($(1)_EMBEDROMFS)
210
211 ifneq ($$($(1)_PROGBUILTIN),)
212 ifneq ($$($(1)_PROGBUILTIN),all)
213 $(1)_PROGBUILTIN_TMP = $$($(1)_PROGBUILTIN)
214 else
215 $(1)_PROGBUILTIN_TMP1 = $$(wildcard $$(USER_REGISTRY_DIR)/*.pbi)
216 $(1)_PROGBUILTIN_TMP = $$($(1)_PROGBUILTIN_TMP1:$$(USER_REGISTRY_DIR)/%.pbi=%)
217 endif
218 $(1)_PROGBUILTIN_LIST = $$(filter-out $$($(1)_PROGBUILTIN_EXCLUDE),$$($(1)_PROGBUILTIN_TMP))
219
220 $(1)_PROGBUILTIN_OTHER=$$(filter-out $(1),$$($(1)_PROGBUILTIN_LIST))
221 $(1)_PROGBUILTIN_PBI=$$($(1)_PROGBUILTIN_OTHER:%=$$(USER_REGISTRY_DIR)/%.pbi)
222 $(1)_PROGBUILTIN_LDAT=$$($(1)_PROGBUILTIN_LIST:%=$$(USER_REGISTRY_DIR)/%.ldat)
223 $(1)_PROGBUILTIN_PDAT=$$($(1)_PROGBUILTIN_LIST:%=$$(USER_REGISTRY_DIR)/%.pdat) \
224         $$(filter-out $$($(1)_PROGBUILTIN_EXCLUDE:%=$(NUTTXREGISTRY)/%.pdat),\
225         $$(wildcard $(NUTTXREGISTRY)/*.pdat))
226 $(1)_PROGBUILTIN_BDAT=$$($(1)_PROGBUILTIN_LIST:%=$$(USER_REGISTRY_DIR)/%.bdat) \
227         $$(filter-out $$($(1)_PROGBUILTIN_EXCLUDE:%=$(NUTTXREGISTRY)/%.bdat),\
228         $$(wildcard $(NUTTXREGISTRY)/*.bdat))
229
230 ifneq ($$($(1)_KMODBUILTIN),all)
231 $(1)_KMODBUILTIN_LIBS = $$($(1)_KMODBUILTIN:%=$$(KERN_MODULES_DIR)/lib%.ka)
232 else
233 $(1)_KMODBUILTIN_LIBS = $$(wildcard $$(KERN_MODULES_DIR)/lib*.ka)
234 endif
235
236
237 ifneq ($$($(1)_PROGBUILTIN_PDAT),)
238 $(1)_BUILTINTABLE = $(OBJS_DIR)/$(1)-builtintab.c
239
240 $$($(1)_BUILTINTABLE): $$($(1)_PROGBUILTIN_PDAT) $$($(1)_PROGBUILTIN_BDAT)
241         $(Q) cat $$($(1)_PROGBUILTIN_PDAT) >$$@
242         $(Q) echo "#include <nuttx/config.h>" >>$$@
243         $(Q) echo "#include <nuttx/lib/builtin.h>" >>$$@
244         $(Q) echo "const struct builtin_s g_builtins[] = {" >>$$@
245         $(Q) cat $$($(1)_PROGBUILTIN_BDAT) >>$$@
246         $(Q) echo "{ NULL, 0, 0, 0 }};" >>$$@
247         $(Q) echo "const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);" >>$$@
248
249 GEN_SOURCES += $$($(1)_BUILTINTABLE)
250
251 $(1)_BUILTINWRAPMAIN = $(OBJS_DIR)/$(1)-builtinwrapmain.c
252
253 $$($(1)_BUILTINWRAPMAIN):
254         $(Q) echo "#include <nuttx/config.h>" >$$@
255         $(Q) echo "#include <nuttx/compiler.h>" >>$$@
256         $(Q) echo "int main(int argc, FAR char *argv[]);" >>$$@
257         $(Q) echo "int weak_function $(1)_main(int argc, FAR char *argv[]) {return main(argc, argv);}" >>$$@
258
259 GEN_SOURCES += $$($(1)_BUILTINWRAPMAIN)
260
261 endif
262 endif
263
264 ifneq ($$(LD_SCRIPT$(3:%=-%)),)
265 $(1)$(3:%=-%)_LD_SCRIPT_FN = $$(LD_SCRIPT$(3:%=-%))
266 else
267 $(1)$(3:%=-%)_LD_SCRIPT_FN = $$(LD_SCRIPT)
268 endif
269
270 ifeq ($$(dir $$($(1)$(3:%=-%)_LD_SCRIPT_FN)),)
271 $(1)$(3:%=-%)_LD_SCRIPT = $$(LIB_DIR)/$$($(1)$(3:%=-%)_LD_SCRIPT_FN)
272 else
273 $(1)$(3:%=-%)_LD_SCRIPT = $$($(1)$(3:%=-%)_LD_SCRIPT_FN)
274 endif
275
276 $(1)$(3:%=-%)_LDFLAGS = $$($(1)$(3:%=-%)_LD_SCRIPT:%=$$(CC_LD_OPTION)-T$$(LD_OPTION_SEP)%)
277
278 $(2)/$(1)$(3:%=-%): $$($(1)_OBJS) $$($(1)_BUILTINTABLE:%.c=%$$(OBJ_EXT)) $$($(1)_BUILTINWRAPMAIN:%.c=%$$(OBJ_EXT)) $$($(1)_PROGBUILTIN_LDAT) $$($(1)$(3:%=-%)_LD_SCRIPT) $$($(1)_KMODBUILTIN_LIBS)
279         @$(QUIET_CMD_ECHO) "  LINK    $$@"
280         $(Q) $$(if $$(LD_BY_CC) , $$(if $$(filter %.cc,$$($(1)_SOURCES)) , \
281             $$(CXX) $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CXXFLAGS) $$(CXXFLAGS) , \
282             $$(CC)  $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CFLAGS)   $$(CFLAGS) ) , \
283             $$(LD) \
284           ) \
285           $$(OMK_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) $$(CC_LD_OPTION)-Map$$(LD_OPTION_SEP)$(1)$(3:%=-%).map \
286           $$(HEAD_OBJ:%=$$(NUTTX_EXPORT)/startup/%) \
287           $$($(1)_OBJS) $$($(1)_MOREOBJS) $$($(1)_BUILTINTABLE:%.c=%$$(OBJ_EXT)) $$($(1)_BUILTINWRAPMAIN:%.c=%$$(OBJ_EXT)) \
288           $$($(1)_PROGBUILTIN_PBI) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) $$($(1)_KMODBUILTIN_LIBS) \
289           $$(shell for i in $$($(1)_PROGBUILTIN_LDAT); do cat $$$$i ; done) $$(NUTTXLIBES) \
290           -o $$@
291         @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
292         @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(OBJS_DIR)/$(1)$(3:%=-%).map|tr '&' '\134' | grep -v '^  linker [^ ]' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
293         @echo >>$(OBJS_DIR)/$(1).exe.d
294 endef
295
296 # Syntax: $(call ELF_template,<executable-name>,<dir>)
297 define ELF_template
298
299 $(2)/$(1).elf: $$($(1)_OBJS)
300         @$(QUIET_CMD_ECHO) "  ELF     $$@"
301         $(Q) $$(LD_RAW) \
302           $$(filter -m%,$$(LDFLAGS:$$(CC_LD_OPTION)%=%)) \
303           -r -e main -T $$(ELF_FILE_LDSCRIPT) \
304           -Map $(1).elf.map \
305           $$($(1)_OBJS) $$($(1)_MOREOBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \
306           -o $$@
307         @echo "$(2)/$(1).elf: \\" >$(OBJS_DIR)/$(1).elf.d
308         @echo "  $(ELF_FILE_LDSCRIPT) \\" >>$(OBJS_DIR)/$(1).elf.d
309         @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(OBJS_DIR)/$(1).elf.map|tr '&' '\134' | grep -v '^  linker [^ ]' >>$(OBJS_DIR)/$(1).elf.d
310         @echo >>$(OBJS_DIR)/$(1).elf.d
311 endef
312
313 # Syntax: $(call PROGBUILTIN_template,<executable-name>,<dir>,<registry-dir>)
314 define PROGBUILTIN_template
315
316 $(1)_PRIORITY ?= SCHED_PRIORITY_DEFAULT
317 $(1)_STACKSIZE ?= 2048
318
319 $(2)/$(1).pbi: $$($(1)_OBJS)
320         @$(QUIET_CMD_ECHO) "  PROGMOD $$@"
321         $(Q) $(LD_RAW) \
322           $$(filter -m%,$$(LDFLAGS:$$(CC_LD_OPTION)%=%)) \
323           -r -x --defsym=$(1)_main=main \
324           -Map $(1).pbi.map \
325           $$($(1)_OBJS) $$($(1)_MOREOBJS) \
326           -o $(OBJS_DIR)/$(1).pbo
327         $(Q) $(OBJCOPY) --keep-global-symbol=$(1)_main $(OBJS_DIR)/$(1).pbo $$@
328         @echo "$(2)/$(1).pbi: \\" >$(OBJS_DIR)/$(1).pbi.d
329         @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(OBJS_DIR)/$(1).pbi.map|tr '&' '\134' | grep -v '^  linker [^ ]' >>$(OBJS_DIR)/$(1).pbi.d
330         @echo >>$(OBJS_DIR)/$(1).pbi.d
331         @echo "{ \"$1\", $$($(1)_PRIORITY), $$($(1)_STACKSIZE), $(1)_main }," >$(3)/$(1).bdat
332         @echo "int $(1)_main(int argc, char *argv[]);" >$(3)/$(1).pdat
333         @echo "$$(LOADLIBES) $$($(1)_LIBS:%=-l%)" >$(3)/$(1).ldat
334 endef
335
336
337 # Rules for other output formats (can be specified by OUTPUT_FORMATS)
338 %.bin: %
339         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
340         $(Q) $(OBJCOPY)  --output-target=binary -S $< $@
341
342 %.hex: %
343         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
344         $(Q) $(OBJCOPY)  --output-target=ihex -S $< $@
345
346 %.srec: %
347         @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
348         $(Q) $(OBJCOPY)  --output-target=srec -S $< $@
349
350 # Syntax: $(call LIBRARY_template,<library-name>)
351 define LIBRARY_template
352
353 GEN_SOURCES += $$($(1)_GEN_SOURCES)
354
355 $(foreach x, $(SOURCES2OBJS),
356 $(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
357                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
358 )
359 $(1)_OBJS += $$($(1)_EMBEDROMFS:%=%_img$$(OBJ_EXT))
360 $(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
361
362 SOURCES += $$($(1)_SOURCES)
363 EMBEDROMFS += $$($(1)_EMBEDROMFS)
364
365 $(LIB_DIR)/lib$(1)$$(LIB_EXT): $$($(1)_OBJS)
366         @$(QUIET_CMD_ECHO) "  AR      $$@"
367         $(Q) $(AR) $(ARFLAGS) $$@ $$^
368 endef
369
370
371 # Syntax: $(call SOLIB_template,<library-name>)
372 define SOLIB_template
373
374 SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
375
376 $(foreach x, $(SOURCES2OBJSLO),
377 $(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
378                 $$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
379 )
380 $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
381
382 SOLIB_OBJS  += $$($(1)_OBJSLO)
383 SOLIB_SOURCES += $$($(1)_SOURCES)
384
385 $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
386         @$(QUIET_CMD_ECHO) "  LINK    $$@"
387         $(Q) $(LD_RAW) \
388           $$(filter -m%,$$(LDFLAGS:$$(CC_LD_OPTION)%=%) \
389           --shared --soname=lib$(1).so -o $$@ $$^
390 endef
391
392 ifneq ($(bin_PROGRAMS),)
393 library-pass_HOOKS += force_builtin_library_hook
394
395 .PHONY: force_builtin_library_hook
396 force_builtin_library_hook:
397
398 endif
399
400 # Syntax: $(call ROMFS_template,<filename>,<filename2>,<directory>) FIXME: Is this correct?
401 define ROMFS_template
402
403 .PHONY: $(2)
404
405 $(2):
406         $(Q) genromfs -f $(2).tmp -V $(1) -d $(3)
407         $(Q) if ( [ ! -e $(2) ] || ! cmp -s $(2).tmp $(2) ) ; then cp $(2).tmp $(2) ; fi
408
409 $(2)$$(OBJ_EXT): $(2)
410         @$(QUIET_CMD_ECHO) "  ROMFS   $$@"
411         $(Q) $(LD_RAW) -r --accept-unknown-input-arch -b binary \
412                 $$(filter -m%,$$(LDFLAGS:$$(CC_LD_OPTION)%=%)) \
413                 --defsym=$(2)=_binary_$(2)_start \
414                 --defsym=$(2)_size=_binary_$(2)_size \
415                 --defsym=$(2)_start=_binary_$(2)_start \
416                 --defsym=$(2)_end=_binary_$(2)_end \
417                 -o $$@.tmp $$^
418         $(Q) $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents \
419                 $$@.tmp $$@
420
421 endef