don't define the touchfileflag in the wrong location
[AROS.git] / config / make.tmpl
blob410e5377c71bd7006210bd6b56259818765406d4
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16     %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
17 else
18     %(var) := %(string)
19 endif
20 %end
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" opt="$(strip $(CFLAGS) $(CPPFLAGS))" from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         $(Q)$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         $(Q)$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -D__SRCFILENAME__="\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))"\" -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                         $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -D__SRCFILENAME__=\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))\" -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                         tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31                 else \
32                         $(NOP) ; \
33                 fi ; \
34         else \
35                 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -D__SRCFILENAME__=\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))\" -c %(from) -o %(to)" 1>&2 ; \
36                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37                 exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd="$(strip $(CC) $(TARGET_SYSROOT))" opt="$(strip $(AFLAGS) $(CPPFLAGS))" from=$< to=$@
46         $(Q)$(ECHO) "Assembling $(notdir %(from))..."
47         $(Q)$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                         $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                         $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51                 else \
52                         $(NOP) ; \
53                 fi ; \
54         else \
55                 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57                 exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP) objdir=$(GENDIR)/$(CURDIR) coverageinstr=
66         $(Q)$(eval LINKTARGET=%(to))
67         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$(LINKTARGET))..."
68         $(Q)$(eval LINKTMPFILE=%(objdir)/$(notdir $(LINKTARGET)))
69         $(Q)$(IF) %(cmd) %(from) -o $(LINKTMPFILE) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
70                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
71                                 $(ECHO) "$(LINKTARGET): %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" >> $(GENDIR)/errors ; \
72                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
73                 else \
74                         $(NOP) ; \
75                 fi ; \
76                 $(CP) $(LINKTMPFILE) $(LINKTARGET) ; \
77         else \
78                 $(ECHO) "Link failed: %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" 1>&2 ; \
79                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
80                 exit 1 ; \
81         fi
82         $(Q)$(IF) [ "$(DEBUG)" = "yes" ]; then \
83                 %(strip) $(LINKTARGET) --only-keep-debug -o $(LINKTARGET).dbg ; \
84         fi
85         $(Q)%(strip) $(LINKTARGET)
86         $(Q)$(IF) [ "$(DEBUG)" = "yes" ]; then \
87                 $(IF) $(TEST) -s $(LINKTARGET).dbg ; then \
88                         $(OBJCOPY) --add-gnu-debuglink=$(LINKTARGET).dbg $(LINKTARGET) ; \
89                 fi ; \
90         fi
91         $(Q)$(IF) [ "%(coverageinstr)" = "yes" ]; then \
92                 LINKBASEFILES="$(strip $(notdir $(basename %(from))))" ; \
93                 $(FOR) covext in $(TARGET_COVERAGEINSTR_EXTS) ; do \
94                         $(FOR) file in $$LINKBASEFILES ; do \
95                                 COVERAGEFILE=`echo $$file$$covext` ; \
96                                 $(IF) $(TEST) -s %(objdir)/$$COVERAGEFILE ; then \
97                                         $(CP) %(objdir)/$$COVERAGEFILE $(dir $(LINKTARGET))$$COVERAGEFILE ; \
98                                 fi ; \
99                         done ; \
100                 done ; \
101         fi
102 %end
103 #------------------------------------------------------------------------------
106 #-------------------------------------------------------------------------
107 # Link a module based upon a number of arguments and the standard $(LIBS)
108 # and $(DEPLIBS) make variables.
110 %define link_module_q cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
111         $(Q)$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
112         $(Q)$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
113                 $(GENMAP) %(objdir)/%(module).map \
114                 %(objs) %(libs) %(ldflags) %(endtag) \
115                 -o $@ 2>&1 > %(objdir)/%(err); \
116         then \
117                 cat %(objdir)/%(err); \
118         else \
119                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
120                 cat %(objdir)/%(err); \
121                 exit 1; \
122         fi
123         $(Q)$(IF) $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
124         $(Q)$(IF) [ "$(DEBUG)" = "yes" ]; then \
125                 $(STRIP) $@ --only-keep-debug -o $@.dbg; \
126         fi
127         $(Q)$(STRIP) $@
128         $(Q)$(IF) [ "$(DEBUG)" = "yes" ]; then \
129                 $(IF) $(TEST) -s $@.dbg ; then \
130                         $(OBJCOPY) --add-gnu-debuglink=$@.dbg $@; \
131                 fi ; \
132         fi
133 %end
134 #------------------------------------------------------------------------------
137 #------------------------------------------------------------------------------
138 # Create the library
139 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
140         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
141         $(Q)%(ar) %(to) %(from)
142         $(Q)%(ranlib) %(to)
143 %end
144 #------------------------------------------------------------------------------
147 #------------------------------------------------------------------------------
148 # Create the dependency file %(to) for %(from)
149 %define mkdepend_q flags="$(strip $(CFLAGS) $(CPPFLAGS))" from=$< to=$@ cc="$(strip $(AROS_CC) $(TARGET_SYSROOT))"
150         %mkdir_q dir="$(dir %(to))"
151         $(Q)$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
152         $(Q)AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Create one directory without any output
159 %define mkdir_q dir=.
160         $(Q)$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
161 %end
162 #------------------------------------------------------------------------------
165 #------------------------------------------------------------------------------
166 # Create several directories without any output
167 %define mkdirs_q dirs=/M
168         $(Q)$(FOR) dir in %(dirs) ; do \
169                 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
170         done
171 %end
172 #------------------------------------------------------------------------------
175 #############################################################################
176 #############################################################################
177 ##                                                                         ##
178 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
179 ## mmakefile. They consist of one or more full makefile rules.             ##
180 ## In general the files generated in these macros are also defined as      ##
181 ## make targets so that they can be used as a dependency in other rules    ##
182 ##                                                                         ##
183 #############################################################################
184 #############################################################################
186 #------------------------------------------------------------------------------
187 # Generate a unique id for each of the %build... rules
188 %define buildid targets=/A
189 BDID := $(BDID)_
190 ifneq ($(filter $(TARGET),%(targets)),)
191     BDTARGETID := $(BDID)
192 endif
193 %end
194 #------------------------------------------------------------------------------
197 #------------------------------------------------------------------------------
198 # Copy file %(from) to %(to) in a makefile rule
199 %define rule_copy from=/A to=/A
200 %(to) : %(from)
201         $(Q)$(CP) $< $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Copy the files %(files) to %(targetdir). For each file in %(files),
208 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
209 # appropriate subdirs are not generated by this rule so they have to be
210 # present.
211 %define rule_copy_multi files=/A targetdir=/A srcdir=.
213 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
214         $(Q)$(CP) $< $@
215 %end
216 #------------------------------------------------------------------------------
219 #------------------------------------------------------------------------------
220 # Copy the files %(files) to %(targetdir). For each file in %(files),
221 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
222 # %(stampfile) is used to keep track of when the last time the comparison has
223 # been done. The targetdir and the appropriate subdirs are not generated by 
224 # this rule so they have to be present.
225 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
226     stampfile=$(TMP_SRCDIR)/.copy_stamp
228 TMP_SRCDIR := %(srcdir)
230 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
232 %(stampfile) : COPYSRCDIR := %(srcdir)
233 %(stampfile) : TGTDIR := %(targetdir)
234 %(stampfile) : FILES := %(files)
235 %(stampfile) : $(addprefix %(srcdir)/,%(files))
236         $(Q)for f in $(FILES); do \
237                 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
238                         $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
239                 fi ; \
240         done
241         $(Q)$(TOUCH) $@
242 %end
243 #------------------------------------------------------------------------------
246 #------------------------------------------------------------------------------
247 # Will join all the files in %(from) to %(to). When text is specified it will
248 # be displayed.
249 # Restriction: at the moment when using a non-empty target dir %(from) may
250 # not have 
251 %define rule_join to=/A from=/A text=
253 %(to) : %(from)
254 ifneq (%(text),)
255         $(Q)$(ECHO) %(text)
256 endif
257         $(Q)$(CAT) $^ >$@
258 %end
259 #------------------------------------------------------------------------------
262 #------------------------------------------------------------------------------
263 # Include the dependency files and add some internal rules
264 # When depstargets is provided the depencies will only be included when one of
265 # these targets is the $(TARGET). Otherwise the dependencies will only be
266 # included when the $(TARGET) is not for setup or clean 
267 %define include_deps deps=$(DEPS)/M  depstargets=
268 ifneq (%(deps),)
269   ifneq (%(depstargets),)
270     ifneq ($(findstring $(TARGET),%(depstargets)),)
271       -include %(deps)
272     endif
273   else
274     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
275       -include %(deps)
276     endif
277   endif
278 endif
279 %end
280 #------------------------------------------------------------------------------
283 #------------------------------------------------------------------------------
284 # Create the directories %(dirs). The creation will be done by adding rules to
285 # the %(setuptarget) make target with setup as the default. 
286 %define rule_makedirs dirs=/A setuptarget=setup
288 %(setuptarget) :: %(dirs)
290 GLOB_MKDIRS += %(dirs)
292 %end
293 #------------------------------------------------------------------------------
296 #------------------------------------------------------------------------------
297 # Generate a rule to compile a C source file to an object file and generate
298 # the dependency file. Basename may contain a directory part, then the source
299 # file has to be in that directory. The generated file will be put in the
300 # object directory without the directory.
301 # options
302 # - basename: the basename of the file to compile. Use % for a wildcard rule
303 # - cflags (default $(CFLAGS)): the C flags to use for compilation
304 # - dflags: the flags used during creation of dependency file. If not specified
305 #   the same value as cflags will be used
306 # - targetdir: the directory to put the .o file and the .d file. By default
307 #   it is put in the same directory as the .c file
308 %define rule_compile mmake=TMP basename=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= targetdir= compiler=target
310 %(mmake)_NIXFLAG ?= -nix
312 ifeq (%(targetdir),)
313   %(mmake)_TARGETBASE := %(basename)
314 else
315   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
316 endif
318 # Adjust compiler flags to suit C
319 %(mmake)_C_CPPFLAGS := %(cppflags)
320 %(mmake)_CFLAGS := %(cflags)
321 %(mmake)_CFLAGS := $(subst -fpermissive,, $(%(mmake)_CFLAGS))
322 ifeq (%(dflags),)
323   %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
324 else
325   %(mmake)_DFLAGS := %(dflags)
326 endif
328 ifeq ($(findstring %(compiler),host kernel target),)
329   $(error unknown compiler %(compiler))
330 endif
331 ifeq (%(compiler),target)
332 %(mmake)_LINK ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
333 %(mmake)_STRIP ?= $(TARGET_STRIP)
334 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
335 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
336 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(%(mmake)_C_CPPFLAGS)
337 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(%(mmake)_C_CPPFLAGS)
338 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(%(mmake)_CFLAGS) $(SAFETY_CFLAGS))
339 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(%(mmake)_DFLAGS)
340 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
341 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
342 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
343 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
344 endif
345 ifeq (%(compiler),host)
346 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
347 %(mmake)_STRIP ?= $(HOST_STRIP)
348 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CC)
349 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CC)
350 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(strip $(HOST_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS))
351 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(strip $(HOST_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS))
352 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_CFLAGS))
353 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_DFLAGS))
354 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
355 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
356 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
357 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
358 endif
359 ifeq (%(compiler),kernel)
360 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
361 %(mmake)_STRIP ?= $(ECHO) >/dev/null
362 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
363 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
364 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(strip $(KERNEL_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS))
365 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(strip $(KERNEL_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS))
366 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
367 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_DFLAGS))
368 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
369 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
370 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
371 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
372 endif
374 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_C_CPPFLAGS)
375 $(%(mmake)_TARGETBASE).o : CFLAGS := $(%(mmake)_CFLAGS)
376 $(%(mmake)_TARGETBASE).o : %(basename).c
377         %compile_q cmd=$(%(mmake)_CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
379 ifeq (%(nix),yes)
380   $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_DFLAGS))
381 endif
382 $(%(mmake)_TARGETBASE).d : %(basename).c
383         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_DFLAGS) $(%(mmake)_C_CPPFLAGS))"
384 %end
385 #------------------------------------------------------------------------------
388 #------------------------------------------------------------------------------
389 # Generate a rule to compile a C++ source file to an object file and generate
390 # the dependency file. Basename may contain a directory part, then the source
391 # file has to be in that directory. The generated file will be put in the
392 # object directory without the directory.
393 # options
394 # - basename: the basename of the file to compile. Use % for a wildcard rule
395 # - cflags (default $(CFLAGS)): the C flags to use for compilation
396 # - dflags: the flags used during creation of dependency file. If not specified
397 #   the same value as cflags will be used
398 # - targetdir: the directory to put the .o file and the .d file. By default
399 #   it is put in the same directory as the .c file
400 %define rule_compile_cxx mmake=TMP basename=/A cppflags=$(CPPFLAGS) cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
402 ifneq (%(basename),)
403 %(mmake)_NIXFLAG ?= -nix
404 ifeq (%(targetdir),)
405   %(mmake)_TARGETBASE := %(basename)
406 else
407   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
408 endif
410 # Adjust compiler flags to suit C++
411 %(mmake)_CXX_CPPFLAGS := %(cppflags)
412 %(mmake)_CXXFLAGS := %(cxxflags) 
413 ifeq (%(dxxflags),)
414   %(mmake)_DXXFLAGS := %(cxxflags)
415 else
416   %(mmake)_DXXFLAGS := %(dxxflags)
417 endif
419 ifeq ($(findstring %(compiler),host kernel target),)
420   $(error unknown compiler %(compiler))
421 endif
422 ifeq (%(compiler),target)
423 %(mmake)_LINK ?= $(strip $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
424 %(mmake)_STRIP ?= $(TARGET_STRIP)
425 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
426 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
427 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(%(mmake)_CXX_CPPFLAGS)
428 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(%(mmake)_CXX_CPPFLAGS)
429 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(%(mmake)_CXXFLAGS) $(SAFETY_CFLAGS))
430 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(%(mmake)_DXXFLAGS)
431 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
432 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
433 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
434 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
435 endif
436 ifeq (%(compiler),host)
437 %(mmake)_LINK ?= $(strip $(HOST_CXX) $(HOST_LDFLAGS))
438 %(mmake)_STRIP ?= $(HOST_STRIP)
439 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CXX)
440 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CXX)
441 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(strip $(HOST_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS))
442 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(strip $(HOST_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS))
443 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(HOST_CXXFLAGS) $(%(mmake)_CXXFLAGS))
444 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(HOST_CXXFLAGS) $(%(mmake)_DXXFLAGS))
445 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
446 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
447 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
448 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
449 endif
450 ifeq (%(compiler),kernel)
451 KERNEL_CXX ?= $(KERNEL_CC)
452 %(mmake)_LINK ?= $(strip $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
453 %(mmake)_STRIP ?= $(ECHO) >/dev/null
454 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
455 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
456 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(strip $(KERNEL_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS))
457 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(strip $(KERNEL_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS))
458 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(KERNEL_CXXFLAGS) $(%(mmake)_CXXFLAGS))
459 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(KERNEL_CXXFLAGS) $(%(mmake)_DXXFLAGS))
460 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
461 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
462 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
463 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
464 endif
466 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_CXX_CPPFLAGS)
467 $(%(mmake)_TARGETBASE).o : CXXFLAGS := $(%(mmake)_CXXFLAGS)
468 $(%(mmake)_TARGETBASE).o : %(basename).cpp
469         %compile_q cmd=$(%(mmake)_CMD) opt="$(strip $(CXXFLAGS) $(CPPFLAGS))" iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
471 ifeq (%(nix),yes)
472   $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_DXXFLAGS))
473 endif
474 $(%(mmake)_TARGETBASE).d : %(basename).cpp
475         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_DXXFLAGS) $(%(mmake)_CXX_CPPFLAGS))"
477 endif
479 %end
480 #------------------------------------------------------------------------------
483 #------------------------------------------------------------------------------
484 # Generate a rule to compile an ObjC source file to an object file and generate
485 # the dependency file. Basename may contain a directory part, then the source
486 # file has to be in that directory. The generated file will be put in the
487 # object directory without the directory.
488 # options
489 # - basename: the basename of the file to compile. Use % for a wildcard rule
490 # - cflags (default $(CFLAGS)): the C flags to use for compilation
491 # - dflags: the flags used during creation of dependency file. If not specified
492 #   the same value as cflags will be used
493 # - targetdir: the directory to put the .o file and the .d file. By default
494 #   it is put in the same directory as the .m file
495 %define rule_compile_objc mmake=TMP basename=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= targetdir= compiler=target
497 ifneq (%(basename),)
498 %(mmake)_NIXFLAG ?= -nix
499 ifeq (%(targetdir),)
500   %(mmake)_TARGETBASE := %(basename)
501 else
502   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
503 endif
505 # Adjust compiler flags to suit ObjC
506 %(mmake)_OBJC_CPPFLAGS :=  %(cppflags)
507 %(mmake)_OBJCFLAGS := %(cflags)
508 %(mmake)_OBJCFLAGS := $(%(mmake)_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
509 %(mmake)_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(%(mmake)_OBJCFLAGS)))
510 ifeq (%(dflags),)
511   %(mmake)_OBJCDFLAGS := %(cflags)
512 else
513   %(mmake)_OBJCDFLAGS := %(dflags)
514 endif
516 # Define the use of cross compiler
517 ifeq ($(TARGET_OBJC),)
518   %(mmake)_CC := $(TARGET_CC)
519 else
520   %(mmake)_CC := $(TARGET_OBJC)
521 endif
523 ifeq ($(findstring %(compiler),host kernel target),)
524   $(error unknown compiler %(compiler))
525 endif
526 ifeq (%(compiler),target)
527 %(mmake)_LINK ?= $(strip $(%(mmake)_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
528 %(mmake)_STRIP ?= $(TARGET_STRIP)
529 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
530 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
531 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(%(mmake)_OBJC_CPPFLAGS)
532 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(%(mmake)_OBJC_CPPFLAGS)
533 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(%(mmake)_OBJCFLAGS) $(SAFETY_CFLAGS))
534 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(%(mmake)_OBJCDFLAGS)
535 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
536 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
537 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
538 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
539 endif
540 ifeq (%(compiler),host)
541 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
542 %(mmake)_STRIP ?= $(HOST_STRIP)
543 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CC)
544 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CC)
545 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(strip $(HOST_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS))
546 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(strip $(HOST_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS))
547 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCFLAGS))
548 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCDFLAGS))
549 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
550 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
551 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
552 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
553 endif
554 ifeq (%(compiler),kernel)
555 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
556 %(mmake)_STRIP ?= $(ECHO) >/dev/null
557 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
558 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
559 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(strip $(KERNEL_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS))
560 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(strip $(KERNEL_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS))
561 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
562 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCDFLAGS))
563 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
564 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
565 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
566 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
567 endif
569 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_OBJC_CPPFLAGS)
570 $(%(mmake)_TARGETBASE).o : CFLAGS := $(%(mmake)_OBJCFLAGS)
571 $(%(mmake)_TARGETBASE).o : %(basename).m
572         %compile_q cmd=$(%(mmake)_CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
574 ifeq (%(nix),yes)
575   $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_OBJCDFLAGS))
576 endif
577 $(%(mmake)_TARGETBASE).d : %(basename).m
578         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_OBJCDFLAGS) $(%(mmake)_OBJC_CPPFLAGS))"
580 endif
582 %end
583 #------------------------------------------------------------------------------
586 #------------------------------------------------------------------------------
587 # Generate a rule to compile multiple C source files to an object file and
588 # generate the corresponding dependency files. The generated file will be put
589 # in the object directory without the directory part of the source file.
590 # options
591 # - basenames: the basenames of the files to compile. The names may include
592 #   relative or absolute path names. No wildcard is allowed
593 # - cflags (default $(CFLAGS)): the C flags to use for compilation
594 # - dflags: the flags used during creation of dependency file. If not specified
595 #   the same value as cflags will be used
596 # - targetdir: the directory to put the .o file and the .d file. By default
597 #   it is put in the same directory as the .c file. When targetdir is not
598 #   empty, path names will be stripped from the file names so that all files
599 #   are in that dir and not in subdirectories.
600 # - compiler (default target): compiler to use, target, kernel or host
601 %define rule_compile_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= srcdir= targetdir= \
602     compiler=target
604 ifeq (%(srcdir),)
605 %(mmake)_MC_SRCWILDCARD := %
606 else
607 %(mmake)_MC_SRCWILDCARD := %(srcdir)/%
608 endif
610 ifeq (%(targetdir),)
611 %(mmake)_MC_TARGETS := $(addsuffix .o,%(basenames))
612 %(mmake)_MC_DTARGETS := $(addsuffix .d,%(basenames))
613 %(mmake)_MC_TGTWILDCARD := %
614 else
615 %(mmake)_MC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
616 %(mmake)_MC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
617 %(mmake)_MC_TGTWILDCARD := %(targetdir)/%
619 # Be sure that all .c files are generated
620 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : | $(addsuffix .c,%(basenames))
622 # Be sure that all .c files are found
623 %(mmake)_MC_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
624 %(mmake)_MC_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
625 %(mmake)_MC_DIRS := $(foreach dir, $(%(mmake)_MC_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)_MC_SRCDIR)/$(CURDIR)/$(dir)))
626 ifneq ($(%(mmake)_MC_DIRS),)
627     %(mmake)_MC_DIRS := $(shell echo $(%(mmake)_MC_DIRS) | sed 's/\(.\):\//\/\1\//g')
628     vpath %.c $(%(mmake)_MC_DIRS)
629 endif
631 endif
633 %(mmake)_MC_CPPFLAGS := %(cppflags)
634 %(mmake)_CFLAGS := %(cflags)
635 ifeq (%(dflags),)
636   %(mmake)_DFLAGS := %(cflags)
637 else
638   %(mmake)_DFLAGS := %(dflags)
639 endif
641 ifeq ($(findstring %(compiler),host kernel target),)
642   $(error unknown compiler %(compiler))
643 endif
644 ifeq (%(compiler),target)
645 %(mmake)_LINK ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
646 %(mmake)_STRIP ?= $(TARGET_STRIP)
647 %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
648 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
649 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(%(mmake)_MC_CPPFLAGS)
650 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(%(mmake)_CFLAGS) $(SAFETY_CFLAGS))
651 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(%(mmake)_DFLAGS)
652 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
653 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
654 endif
655 ifeq (%(compiler),host)
656 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
657 %(mmake)_STRIP ?= $(HOST_STRIP)
658 %(mmake)_ASSEMBLER ?= $(strip $HOST_CC) $(HOST_SYSROOT))
659 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(HOST_CC)
660 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(strip $(HOST_MC_CPPFLAGS) $(%(mmake)_MC_CPPFLAGS))
661 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_CFLAGS))
662 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_DFLAGS))
663 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
664 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
665 endif
666 ifeq (%(compiler),kernel)
667 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
668 %(mmake)_STRIP ?= $(ECHO) >/dev/null
669 %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
670 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
671 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(strip $(KERNEL_MC_CPPFLAGS) $(%(mmake)_MC_CPPFLAGS))
672 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
673 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_DFLAGS))
674 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
675 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
676 endif
678 $(%(mmake)_MC_TARGETS) : CPPFLAGS := $(%(mmake)_MC_CPPFLAGS)
679 $(%(mmake)_MC_TARGETS) : CFLAGS := $(%(mmake)_CFLAGS)
680 $(%(mmake)_MC_TARGETS) : $(%(mmake)_MC_TGTWILDCARD).o : $(%(mmake)_MC_SRCWILDCARD).c
681         %compile_q cmd=$(CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
683 $(%(mmake)_MC_DTARGETS) : $(%(mmake)_MC_TGTWILDCARD).d : $(%(mmake)_MC_SRCWILDCARD).c
684         %mkdepend_q cc=$(CMD) flags="$(strip $(%(mmake)_DFLAGS) $(%(mmake)_MC_CPPFLAGS))"
685 %end
686 #------------------------------------------------------------------------------
689 #------------------------------------------------------------------------------
690 # Generate a rule to compile multiple C++ source files to an object file and
691 # generate the corresponding dependency files. The generated file will be put
692 # in the object directory without the directory part of the source file.
693 # options
694 # - basenames: the basenames of the files to compile. The names may include
695 #   relative or absolute path names. No wildcard is allowed. basenames will be 
696 #   matched to supported AROS_CXXEXTS.
697 # - cflags (default $(CFLAGS)): the C flags to use for compilation
698 # - dflags: the flags used during creation of dependency file. If not specified
699 #   the same value as cflags will be used
700 # - targetdir: the directory to put the .o file and the .d file. By default
701 #   it is put in the same directory as the .c file. When targetdir is not
702 #   empty, path names will be stripped from the file names so that all files
703 #   are in that dir and not in subdirectories.
704 # - compiler (default target): compiler to use, target, kernel or host
705 %define rule_compile_cxx_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cxxflags=$(CXXFLAGS) dxxflags= \
706     targetdir= compiler=target
708 %(mmake)_CXXABSBASENAMES := $(foreach %(mmake)_CXXBASE,%(basenames),$(if $(filter /%,$(%(mmake)_CXXBASE)),$(%(mmake)_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(%(mmake)_CXXBASE))))
710 ifneq ($(%(mmake)_CXXABSBASENAMES),)
712 %(mmake)_CXXBASENAMES := $(basename $(%(mmake)_CXXABSBASENAMES))
714 # Identify the "real" c++ files from the passed in basenames
715 %(mmake)_MCXX_FILES  := $(strip $(foreach %(mmake)_CXXBASE,$(%(mmake)_CXXABSBASENAMES), $(firstword $(wildcard $(foreach %(mmake)_EXT, $(AROS_CXXEXTS),$(addsuffix .$(%(mmake)_EXT),$(%(mmake)_CXXBASE)))))))
717 ifeq (%(targetdir),)
718   %(mmake)_CXXTARGETS := $(notdir $(%(mmake)_CXXBASENAMES:=.o))
719   %(mmake)_CXXDTARGETS := $(notdir $(%(mmake)_CXXBASENAMES:=.d))
720   %(mmake)_MCXX_WILDCARD := %
721 else
722   %(mmake)_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(%(mmake)_CXXBASENAMES:=.o)))
723   %(mmake)_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(%(mmake)_CXXBASENAMES:=.d)))
724   %(mmake)_MCXX_WILDCARD := %(targetdir)/%
726   # Be sure that all source files are generated
727   $(%(mmake)_CXXTARGETS) $(%(mmake)_CXXDTARGETS) : | $(%(mmake)_MCXX_FILES)
728 endif
730 # Adjust compiler flags to suit C++
731 %(mmake)_MCXX_CPPFLAGS := %(cppflags)
732 %(mmake)_CXXFLAGS := %(cxxflags)
733 ifeq (%(dxxflags),)
734   %(mmake)_DXXFLAGS := %(cxxflags)
735 else
736   %(mmake)_DXXFLAGS := %(dxxflags)
737 endif
739 ifeq ($(findstring %(compiler),host kernel target),)
740   $(error unknown compiler %(compiler))
741 endif
742 ifeq (%(compiler),host)
743   %(mmake)_LINK ?= $(strip $(HOST_CXX) $(HOST_LDFLAGS))
744   %(mmake)_STRIP ?= $(HOST_STRIP)
745   %(mmake)_ASSEMBLER ?= $(strip $(HOST_CC) $(HOST_SYSROOT))
746   %(mmake)_CXXCMD:=$(HOST_CXX)
747   %(mmake)_MCXX_CPPFLAGS := $(strip $(HOST_MCXX_CPPFLAGS) $(%(mmake)_MCXX_CPPFLAGS))
748   %(mmake)_CXXFLAGS := $(strip $(HOST_CXXFLAGS) $(%(mmake)_CXXFLAGS))
749   %(mmake)_DXXFLAGS := $(strip $(HOST_CXXFLAGS) $(%(mmake)_DXXFLAGS))
750   %(mmake)_CXXIQUOTE:=$(HOST_IQUOTE)
751   %(mmake)_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
752 endif
753 ifeq (%(compiler),target)
754   %(mmake)_LINK ?= $(strip $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
755   %(mmake)_STRIP ?= $(TARGET_STRIP)
756   %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
757   %(mmake)_CXXCMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
758   %(mmake)_MCXX_CPPFLAGS := $(%(mmake)_MCXX_CPPFLAGS)
759   %(mmake)_CXXFLAGS := $(strip $(%(mmake)_CXXFLAGS) $(SAFETY_CFLAGS))
760   %(mmake)_DXXFLAGS := $(%(mmake)_DXXFLAGS)
761   %(mmake)_CXXIQUOTE:=$(CFLAGS_IQUOTE)
762   %(mmake)_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
763 endif
764 ifeq (%(compiler),kernel)
765   KERNEL_CXX ?= $(KERNEL_CC)
766   %(mmake)_LINK ?= $(strip $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
767   %(mmake)_STRIP ?= $(ECHO) >/dev/null
768   %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
769   %(mmake)_CXXCMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
770   %(mmake)_CXXFLAGS := $(strip $(KERNEL_MCXX_CPPFLAGS) $(%(mmake)_MCXX_CPPFLAGS))
771   %(mmake)_CXXFLAGS := $(strip $(KERNEL_CXXFLAGS) $(%(mmake)_CXXFLAGS))
772   %(mmake)_DXXFLAGS := $(strip $(KERNEL_CXXFLAGS) $(%(mmake)_DXXFLAGS))
773   %(mmake)_CXXIQUOTE:=$(KERNEL_IQUOTE)
774   %(mmake)_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
775 endif
777 define cxx_multi_recipe_template
778  $(1).o : $(2)
779         %compile_q cmd=$(%(mmake)_CXXCMD) opt="$(strip $(%(mmake)_CXXFLAGS) $(%(mmake)_MCXX_CPPFLAGS))" iquote=$(%(mmake)_CXXIQUOTE) iquote_end=$(%(mmake)_CXXIQUOTE_END) from=$(2) to=$(1).o
781  $(1).d : $(2)
782         %mkdepend_q cc=$(%(mmake)_CXXCMD) flags="$(strip $(%(mmake)_DXXFLAGS) $(%(mmake)_MCXX_CPPFLAGS))" from=$(2) to=$(1).d
783 endef
784 ifeq (%(targetdir),)
785   $(foreach %(mmake)_CXXFILE,$(%(mmake)_MCXX_FILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(%(mmake)_CXXFILE))),$(%(mmake)_CXXFILE))))
786 else
787   $(foreach %(mmake)_CXXFILE,$(%(mmake)_MCXX_FILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(%(mmake)_CXXFILE)))),$(%(mmake)_CXXFILE))))
788 endif
790 endif
792 %end
793 #------------------------------------------------------------------------------
796 #------------------------------------------------------------------------------
797 # Generate a rule to compile multiple ObjC source files to an object file and
798 # generate the corresponding dependency files. The generated file will be put
799 # in the object directory without the directory part of the source file.
800 # options
801 # - basenames: the basenames of the files to compile. The names may include
802 #   relative or absolute path names. No wildcard is allowed
803 # - cflags (default $(CFLAGS)): the C flags to use for compilation
804 # - dflags: the flags used during creation of dependency file. If not specified
805 #   the same value as cflags will be used
806 # - targetdir: the directory to put the .o file and the .d file. By default
807 #   it is put in the same directory as the .m file. When targetdir is not
808 #   empty, path names will be stripped from the file names so that all files
809 #   are in that dir and not in subdirectories.
810 # - compiler (default target): compiler to use, target, kernel or host
811 %define rule_compile_objc_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= \
812     targetdir= compiler=target
814 ifneq (%(basenames),)
816 ifeq (%(targetdir),)
817   %(mmake)_MOBJC_TARGETS := $(addsuffix .o,%(basenames))
818   %(mmake)_MOBJC_DTARGETS := $(addsuffix .d,%(basenames))
819   %(mmake)_MOBJC_WILDCARD := %
820 else
821   %(mmake)_MOBJC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
822   %(mmake)_MOBJC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
823   %(mmake)_MOBJC_WILDCARD := %(targetdir)/%
825   # Be sure that all .m files are generated
826   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : | $(addsuffix .m,%(basenames))
828   # Be sure that all .m files are found
829   %(mmake)_MOBJC_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
830   %(mmake)_MOBJC_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
831   %(mmake)_MOBJC_DIRS := $(foreach dir, $(%(mmake)_MOBJC_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)_MOBJC_SRCDIR)/$(CURDIR)/$(dir)))
832   ifneq ($(%(mmake)_MOBJC_DIRS),)
833     %(mmake)_MOBJC_DIRS := $(shell echo $(%(mmake)_MOBJC_DIRS) | sed 's/\(.\):\//\/\1\//g')
834     vpath %.m $(%(mmake)_MOBJC_DIRS)
835   endif
836 endif
838 # Define the use of cross compiler
839 ifeq ($(TARGET_OBJC),)
840   %(mmake)_CC := $(TARGET_CC)
841 else
842   %(mmake)_CC := $(TARGET_OBJC)
843 endif
845 # Adjust compiler flags to suit ObjC
846 %(mmake)_MOBJC_CPPFLAGS := %(cppflags)
847 %(mmake)_OBJCFLAGS := %(cflags)
848 %(mmake)_OBJCFLAGS := $(%(mmake)_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
849 %(mmake)_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(%(mmake)_OBJCFLAGS)))
850 ifeq (%(dflags),)
851   %(mmake)_OBJCDFLAGS := %(cflags)
852 else
853   %(mmake)_OBJCDFLAGS := %(dflags)
854 endif
856 ifeq ($(findstring %(compiler),host kernel target),)
857   $(error unknown compiler %(compiler))
858 endif
859 ifeq (%(compiler),target)
860   %(mmake)_LINK ?= $(strip $(%(mmake)_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
861   %(mmake)_STRIP ?= $(TARGET_STRIP)
862   %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
863   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
864   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(%(mmake)_MOBJC_CPPFLAGS)
865   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(%(mmake)_OBJCFLAGS) $(SAFETY_CFLAGS))
866   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(%(mmake)_OBJCDFLAGS)
867   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
868   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
869 endif
870 ifeq (%(compiler),host)
871   %(mmake)_LINK ?= $(strip $(HOST_OBJC) $(HOST_LDFLAGS))
872   %(mmake)_STRIP ?= $(HOST_STRIP)
873   %(mmake)_ASSEMBLER ?= $(strip $(HOST_CC) $(HOST_SYSROOT))
874   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(HOST_OBJC)
875   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(strip $(HOST_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_CPPFLAGS))
876   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCFLAGS))
877   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCDFLAGS))
878   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
879   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
880 endif
881 ifeq (%(compiler),kernel)
882   KERNEL_OBJC ?= $(KERNEL_CC)
883   %(mmake)_LINK ?= $(strip $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
884   %(mmake)_STRIP ?= $(ECHO) >/dev/null
885   %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
886   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(strip $(KERNEL_OBJC) $(KERNEL_SYSROOT))
887   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(strip $(KERNEL_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_CPPFLAGS))
888   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
889   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCDFLAGS))
890   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
891   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
892 endif
894 $(%(mmake)_MOBJC_TARGETS) : CPPFLAGS := $(%(mmake)_MOBJC_CPPFLAGS)
895 $(%(mmake)_MOBJC_TARGETS) : CFLAGS := $(%(mmake)_OBJCFLAGS)
896 $(%(mmake)_MOBJC_TARGETS) : $(%(mmake)_MOBJC_WILDCARD).o : %.m
897         %compile_q cmd=$(CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
899 $(%(mmake)_MOBJC_DTARGETS) : $(%(mmake)_MOBJC_WILDCARD).d : %.m
900         %mkdepend_q cc=$(CMD) flags="$(strip $(%(mmake)_OBJCDFLAGS) $(%(mmake)_MOBJC_CPPFLAGS))"
902 endif
904 %end
905 #------------------------------------------------------------------------------
908 #------------------------------------------------------------------------------
909 # Make an alias from one arch specific build to another arch.
910 # arguments:
911 # - mainmmake: the mmake of the module in the main tree
912 # - arch: the current arch
913 # - alias: the alias to which this should point
914 %define rule_archalias mainmmake=\A arch=\A alias=\A
916 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
917 %end
918 #------------------------------------------------------------------------------
921 #------------------------------------------------------------------------------
922 # Generate a rule to assemble a source file to an object file. Basename may
923 # contain a directory part, then the source file has to be in that directory.
924 # The generated file will be put in the object directory without the directory.
925 # options
926 # - basename: the basename of the file to compile. Use % for a wildcard rule
927 # - flags (default $(AFLAGS)): the asm flags to use for assembling
928 # - targetdir: the directory to put the .o file in. By default it is put in the
929 #   same directory as the .s file
930 %define rule_assemble basename=/A cppflags=$(CPPFLAGS) aflags=$(AFLAGS) targetdir=
932 ifeq (%(targetdir),)
933 %(basename).o : CPPFLAGS := %(cppflags)
934 %(basename).o : AFLAGS := %(aflags)
935 %(basename).o : %(basename).s
936         %assemble_q
937 %(basename).o : %(basename).S
938         %assemble_q
940 else
941 %(targetdir)/$(notdir %(basename)).o : CPPFLAGS := %(cppflags)
942 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
943 %(targetdir)/$(notdir %(basename)).o : %(basename).s
944         %assemble_q
945 %(targetdir)/$(notdir %(basename)).o : %(basename).S
946         %assemble_q
948 endif
949 %end
950 #------------------------------------------------------------------------------
953 #------------------------------------------------------------------------------
954 # Generate a rule to assemble multiple source files to an object file. The
955 # generated file will be put in the object directory with the directory part
956 # of the source file stripped off.
957 # options
958 # - basenames: the basenames of the files to compile. The names may include
959 #   relative or absolute path names. No wildcard is allowed
960 # - aflags (default $(AFLAGS)): the flags to use for assembly
961 # - targetdir: the directory to put the .o file and the .d file. By default
962 #   it is put in the same directory as the .c file. When targetdir is not
963 #   empty, path names will be stripped from the file names so that all files
964 #   are in that dir and not in subdirectories.
965 %define rule_assemble_multi mmake=TMP cmd="$(strip $(CC) $(TARGET_SYSROOT))"  basenames=/A cppflags=$(CPPFLAGS) aflags=$(AFLAGS) targetdir= suffix=.s
967 ifeq (%(targetdir),)
968 %(mmake)-MA_TARGETS := $(addsuffix .o,%(basenames))
969 %(mmake)-MA_WILDCARD := %
970 else
971 %(mmake)-MA_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
972 %(mmake)-MA_WILDCARD := %(targetdir)/%
974 # Be sure that all .s files are generated
975 $(%(mmake)-MA_TARGETS) : | $(addsuffix %(suffix),%(basenames))
977 # Be sure that all .c files are found
978 %(mmake)-MA_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
979 %(mmake)-MA_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
980 %(mmake)-MA_DIRS := $(foreach dir, $(%(mmake)-MA_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)-MA_SRCDIR)/$(CURDIR)/$(dir)))
981 ifneq ($(%(mmake)-MA_DIRS),)
982     %(mmake)-MA_DIRS := $(shell echo $(%(mmake)-MA_DIRS) | sed 's/\(.\):\//\/\1\//g')
983     vpath %%(suffix) $(%(mmake)-MA_DIRS)
984 endif
986 endif
988 %(mmake)-MA_ASSEMBLER ?= %(cmd)
990 $(%(mmake)-MA_TARGETS) : %(mmake)-MA_CMD:= $(%(mmake)-MA_ASSEMBLER)
992 $(%(mmake)-MA_TARGETS) : CPPFLAGS := %(cppflags)
993 $(%(mmake)-MA_TARGETS) : AFLAGS := %(aflags)
994 $(%(mmake)-MA_TARGETS) : $(%(mmake)-MA_WILDCARD).o : %%(suffix)
995         %assemble_q cmd=$(%(mmake)-MA_CMD)
996 %end
997 #------------------------------------------------------------------------------
1000 #------------------------------------------------------------------------------
1001 # Link %(objs) to %(prog) using the libraries in %(uselibs)
1002 %define rule_link_prog mmake=TMP prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
1003     usehostlibs= usestartup=yes detach=no nix=no cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR) coverageinstr=$(TARGET_COVERAGEINSTR)
1005 %(mmake)-link_EXTRA_LDFLAGS := 
1006 %(mmake)-link_EXTRA_LIBS :=
1007 ifeq (%(nix),yes)
1008     %(mmake)-link_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1009 endif
1010 ifeq (%(usestartup),no)
1011     %(mmake)-link_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1012 endif
1013 ifeq (%(detach),yes)
1014     %(mmake)-link_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1015 endif
1017 # Make a list of the lib files this program depends on.
1018 # In LDFLAGS remove white space between -L and directory
1019 %(mmake)-link_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1020 # Filter out only the libdirs and remove -L
1021 %(mmake)-link_DIRS := $(patsubst -L%,%,$(filter -L%,$(%(mmake)-link_DIRS)))
1022 # Add trailing /
1023 %(mmake)-link_DIRS := $(subst //,/,$(addsuffix /,$(%(mmake)-link_DIRS)))
1024 # Add normal linklib path
1025 %(mmake)-link_DIRS += $(AROS_LIB)/
1026 # add lib and .a to static linklib names
1027 %(mmake)-link_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(%(mmake)-link_EXTRA_LIBS)))
1028 ifeq (%(usestartup),yes)
1029     %(mmake)-link_LIBS += startup.o
1030 endif
1031 ifeq (%(detach),yes)
1032     %(mmake)-link_LIBS += detach.o
1033 endif
1034 # search for the linklibs in the given path, ignore ones not found
1035 %(mmake)-link_DEPLIBS := $(foreach lib,$(%(mmake)-link_LIBS), \
1036     $(firstword $(wildcard $(addsuffix $(lib),$(%(mmake)-link_DIRS)))) \
1039 %(prog) : OBJDIR := %(objdir)
1040 %(prog) : OBJS := %(objs)
1041 %(prog) : LDFLAGS := $(strip %(ldflags) $(%(mmake)-link_EXTRA_LDFLAGS))
1042 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(%(mmake)-link_EXTRA_LIBS) %(usehostlibs))
1043 %(prog) : %(objs) $(%(mmake)-link_DEPLIBS)
1044         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR) coverageinstr=%(coverageinstr)
1045 %end
1046 #------------------------------------------------------------------------------
1049 #------------------------------------------------------------------------------
1050 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
1051 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
1052 %define rule_link_progs mmake=TMP progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
1053     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
1054     usestartup=yes detach=no cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" strip=$(TARGET_STRIP) coverageinstr=$(TARGET_COVERAGEINSTR)
1056 %(mmake)-link_EXTRA_LDFLAGS := 
1057 %(mmake)-link_EXTRA_LIBS :=
1058 ifeq (%(nix),yes)
1059     %(mmake)-link_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1060 endif
1061 ifeq (%(usestartup),no)
1062     %(mmake)-link_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1063 endif
1064 ifeq (%(detach),yes)
1065     %(mmake)-link_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1066 endif
1068 # Make a list of the lib files the programs depend on.
1069 # In LDFLAGS remove white space between -L and directory
1070 %(mmake)-link_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1071 # Filter out only the libdirs and remove -L
1072 %(mmake)-link_DIRS := $(patsubst -L%,%,$(filter -L%,$(%(mmake)-link_DIRS)))
1073 # Add trailing /
1074 %(mmake)-link_DIRS := $(subst //,/,$(addsuffix /,$(%(mmake)-link_DIRS)))
1075 # Add normal linklib path
1076 %(mmake)-link_DIRS += $(AROS_LIB)/
1077 # add lib and .a to static linklib names
1078 %(mmake)-link_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(%(mmake)-link_EXTRA_LIBS)))
1079 # search for the linklibs in the given path, ignore ones not found
1080 %(mmake)-link_DEPLIBS := $(foreach lib,$(%(mmake)-link_LIBS), \
1081     $(firstword $(wildcard $(addsuffix $(lib),$(%(mmake)-link_DIRS)))) \
1083 %(mmake)-link_PROGS := $(addprefix %(targetdir)/,%(progs))
1085 $(%(mmake)-link_PROGS) : OBJDIR := %(objdir)
1086 $(%(mmake)-link_PROGS) : LDFLAGS := $(strip %(ldflags) $(%(mmake)-link_EXTRA_LDFLAGS))
1087 $(%(mmake)-link_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(%(mmake)-link_EXTRA_LIBS) %(usehostlibs))
1088 $(%(mmake)-link_PROGS) : %(targetdir)/% : %(objdir)/%.o $(%(mmake)-link_DEPLIBS)
1089         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR) coverageinstr=%(coverageinstr)
1090 %end
1091 #------------------------------------------------------------------------------
1094 #------------------------------------------------------------------------------
1095 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1096 %define rule_link_linklib mmake=TMP libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1098 ifeq (%(linker),target)
1099 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(AR)
1100 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(RANLIB)
1101 endif
1102 ifeq (%(linker),host)
1103 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(HOST_AR)
1104 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(HOST_RANLIB)
1105 endif
1106 ifeq (%(linker),kernel)
1107 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(KERNEL_AR)
1108 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(KERNEL_RANLIB)
1109 endif
1111 %(libdir)/lib%(libname).a : %(objs)
1112         %mklib_q from=$^ ar=$(%(mmake)_AR) ranlib=$(%(mmake)_RANLIB)
1113 %end
1114 #------------------------------------------------------------------------------
1116 #------------------------------------------------------------------------------
1117 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1118 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1119 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1120     cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1122 TMP_LDFLAGS  := %(ldflags)
1123 # Make a list of the lib files the programs depend on.
1124 # In LDFLAGS remove white space between -L and directory
1125 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1126 # Filter out only the libdirs and remove -L
1127 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1128 # Add trailing /
1129 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1130 # Add normal linklib path
1131 TMP_DIRS += $(AROS_LIB)/
1132 # add lib and .a to static linklib names
1133 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1134 # search for the linklibs in the given path, ignore ones not found
1135 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1136     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1139 %(module) : LIB_NAMES := %(uselibs)
1140 %(module) : OBJS := %(objs)
1141 %(module) : ENDTAG := %(endobj)
1142 %(module) : ERR := %(err)
1143 %(module) : OBJDIR := %(objdir)
1144 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1145 ifeq (%(usehostlibs),)
1146 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1147 else
1148 # Warning: the -L/usr/lib here can result in modules
1149 # linking against host libs instead of AROS libs (e.g stdc++) !!
1150 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1151                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1152 endif 
1153 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1154         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1156 %end
1157 #------------------------------------------------------------------------------
1160 #------------------------------------------------------------------------------
1161 # Generate the libdefs.h include file for a module.
1162 %define rule_genmodule_genlibdefs modname=/A version= flavour= modtype=/A modsuffix= conffile= targetdir=
1164 TMP_OPTS := 
1165 ifneq (%(flavour),)
1166     TMP_OPTS += -f %(flavour)
1167     TMP_MODNAME := %(modname)_%(flavour)
1168 else
1169     TMP_MODNAME := %(modname)
1170 endif
1171 TMP_TARGET := $(TMP_MODNAME)_libdefs.h
1172 TMP_DEPS := $(GENMODULE)
1173 ifneq (%(conffile),)
1174     ifeq ($(dir %(conffile)),./)
1175         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1176         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1177     else
1178         TMP_OPTS += -c %(conffile)
1179         TMP_DEPS += %(conffile)
1180     endif 
1181 else
1182     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1183     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1184 endif
1185 ifneq (%(modsuffix),)
1186     TMP_OPTS += -s %(modsuffix)
1187 endif
1188 ifneq (%(targetdir),)
1189     TMP_OPTS += -d %(targetdir)
1190     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1191 endif
1192 ifneq (%(version),)
1193     TMP_OPTS += -v %(version)
1194 endif
1196 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1197 $(TMP_TARGET) : MODNAME := %(modname)
1198 $(TMP_TARGET) : MODTYPE := %(modtype)
1199 $(TMP_TARGET) : $(TMP_DEPS)
1200         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1201         $(Q)$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1202 %end
1203 #------------------------------------------------------------------------------
1205 #------------------------------------------------------------------------------
1206 # Generate the _lib.fd file for a module.
1207 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1209 TMP_TARGET := %(modname)_lib.fd
1210 TMP_DEPS := $(GENMODULE)
1211 TMP_OPTS := 
1212 ifneq (%(conffile),)
1213     ifeq ($(dir %(conffile)),./)
1214         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1215         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1216     else
1217         TMP_OPTS += -c %(conffile)
1218         TMP_DEPS += %(conffile)
1219     endif 
1220 else
1221     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1222     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1223 endif
1224 ifneq (%(modsuffix),)
1225     TMP_OPTS += -s %(modsuffix)
1226 endif
1227 ifneq (%(targetdir),)
1228     TMP_OPTS += -d %(targetdir)
1229     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1230 endif
1232 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1233 $(TMP_TARGET) : MODNAME := %(modname)
1234 $(TMP_TARGET) : MODTYPE := %(modtype)
1235 $(TMP_TARGET) : $(TMP_DEPS)
1236         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1237         $(Q)$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1238 %end
1239 #------------------------------------------------------------------------------
1241 #------------------------------------------------------------------------------
1242 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1243 # generated file in this Makefile
1244 %define rule_genmodule_makefile modname=/A flavour= modtype=/A modsuffix= conffile= \
1245     targetdir=
1247 TMP_OPTS := 
1248 ifneq (%(flavour),)
1249     TMP_OPTS += -f %(flavour)
1250     TMP_MODNAME := %(modname)_%(flavour)
1251 else
1252     TMP_MODNAME := %(modname)
1253 endif
1254 TMP_TARGET := Makefile.$(TMP_MODNAME)%(modtype)
1255 TMP_DEPS := $(GENMODULE)
1256 ifneq (%(conffile),)
1257     ifeq ($(dir %(conffile)),./)
1258         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1259         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1260     else
1261         TMP_OPTS += -c %(conffile)
1262         TMP_DEPS += %(conffile)
1263     endif 
1264 else
1265     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1266     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1267 endif
1268 ifneq (%(modsuffix),)
1269     TMP_OPTS += -s %(modsuffix)
1270 endif
1271 ifneq (%(targetdir),)
1272     TMP_OPTS += -d %(targetdir)
1273     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1274 endif
1276 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1277 $(TMP_TARGET) : MODNAME := %(modname)
1278 $(TMP_TARGET) : MODTYPE := %(modtype)
1279 $(TMP_TARGET) : $(TMP_DEPS)
1280         $(Q)$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1281 %end
1282 #------------------------------------------------------------------------------
1285 #------------------------------------------------------------------------------
1286 # Generate the support files for compiling a module. This includes include
1287 # files and source files. This rule has to be preceeded by
1288 # %rule_genmodule_makefile
1289 %define rule_genmodule_files modname=/A flavour= modtype=/A modsuffix= targetdir= stubdir= \
1290     conffile=
1292 TMP_OPTS :=
1293 ifneq (%(flavour),)
1294     TMP_OPTS += -f %(flavour)
1295     TMP_MODNAME := %(modname)_%(flavour)
1296 else
1297     TMP_MODNAME := %(modname)
1298 endif
1299 TMP_GENTARGETS := $($(TMP_MODNAME)_STARTFILES) $($(TMP_MODNAME)_ENDFILES)
1300 TMP_STUBTARGETS := $($(TMP_MODNAME)_LINKLIBFILES) $($(TMP_MODNAME)_RELLINKLIBFILES)
1301 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1302 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1303                $(addsuffix .S, $($(TMP_MODNAME)_LINKLIBAFILES) $($(TMP_MODNAME)_RELLINKLIBAFILES))
1305 TMP_DEPS := $(GENMODULE)
1306 ifneq (%(conffile),)
1307     ifeq ($(dir %(conffile)),./)
1308         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1309         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1310     else
1311         TMP_OPTS += -c %(conffile)
1312         TMP_DEPS += %(conffile)
1313     endif 
1314 else
1315     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1316     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1317 endif
1318 ifneq (%(modsuffix),)
1319     TMP_OPTS += -s %(modsuffix)
1320 endif
1321 ifneq (%(targetdir),)
1322     TMP_OPTS += -d %(targetdir)
1323     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1324     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1325     TMP_GENFILEFLAG=$(TMP_TARGETDIR)/.%(modname).%(modtype)-genfiles
1326 else
1327     TMP_GENFILEFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-genfiles
1328 endif
1329 ifneq (%(stubdir),)
1330     TMP_OPTS += -l %(stubdir)
1331     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1332     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1333     TMP_TARGETDIRS += %(stubdir)
1334 else
1335 ifneq (%(targetdir),)
1336     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1337 endif
1338 endif
1340 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1341 ifneq ($(TMP_TARGETDIRS),)
1342 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1343 endif
1345 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENFILEFLAG)
1347 $(TMP_GENFILEFLAG) : OPTS := $(TMP_OPTS)
1348 $(TMP_GENFILEFLAG) : MODNAME := %(modname)
1349 $(TMP_GENFILEFLAG) : MODTYPE := %(modtype)
1350 $(TMP_GENFILEFLAG) : $(TMP_DEPS)
1351         $(Q)$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1352 ifneq (%(conffile),lib.conf)
1353         $(Q)$(IF) $(TEST) -f lib.conf; then \
1354           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1355         fi
1356 endif
1357         $(Q)$(IF) $(TEST) -f libdefs.h; then \
1358           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1359         fi
1360         $(Q)$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1361         $(Q)$(TOUCH) $@
1362 %end
1363 #------------------------------------------------------------------------------
1366 #------------------------------------------------------------------------------
1367 # Generate the support files for compiling a module. This includes include
1368 # files and source files.
1369 %define rule_genmodule_includes modname=/A flavour= modtype=/A modsuffix= \
1370     targetdir= conffile=
1372 ifneq (%(flavour),)
1373     TMP_MODNAME := %(modname)_%(flavour)
1374 else
1375     TMP_MODNAME := %(modname)
1376 endif
1378 ifneq ($($(TMP_MODNAME)_INCLUDES),)
1380 TMP_TARGETS := $($(TMP_MODNAME)_INCLUDES)
1382 TMP_DEPS := $(GENMODULE)
1383 TMP_OPTS :=
1385 ifneq (%(conffile),)
1386     ifeq ($(dir %(conffile)),./)
1387         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1388         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1389     else
1390         TMP_OPTS += -c %(conffile)
1391         TMP_DEPS += %(conffile)
1392     endif 
1393 else
1394     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1395     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1396 endif
1397 ifneq (%(modsuffix),)
1398     TMP_OPTS += -s %(modsuffix)
1399 endif
1400 ifneq (%(targetdir),)
1401     TMP_OPTS += -d %(targetdir)
1402     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1403     TMP_GENINCFLAG=%(targetdir)/.%(modname).%(modtype)-includes
1404 else
1405     TMP_GENINCFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-includes
1406 endif
1408 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENINCFLAG)
1410 $(TMP_GENINCFLAG) : OPTS := $(TMP_OPTS)
1411 $(TMP_GENINCFLAG) : MODNAME := %(modname)
1412 $(TMP_GENINCFLAG) : MODTYPE := %(modtype)
1413 $(TMP_GENINCFLAG) : $(TMP_DEPS)
1414         $(Q)$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1415         $(Q)$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1416         $(Q)$(TOUCH) $@
1417 endif
1418 %end
1419 #------------------------------------------------------------------------------
1421 #------------------------------------------------------------------------------
1422 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1423 # 'start' is an optional starting address
1424 # 'ldflags' is optional additional flags for the linker
1425 %define rule_link_binary mmake=BD file=/A name=/A objs= files= start=0 ldflags=
1427 %(mmake)_OUTDIR := $(dir %(file))
1428 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1429 %(mmake)_OUTDIR := $(subst /*,,$(addsuffix *,$(%(mmake)_OUTDIR)))
1430 %(mmake)_TMPDIR := $(GENDIR)/$(CURDIR)
1431 %(mmake)_OBJS := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir %(files))))
1432 %(mmake)_DEPS := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir %(files))))
1433 %(mmake)_OBJS += %(objs)
1435 %rule_compile_multi basenames="%(files)" targetdir=$(%(mmake)_OBJDIR)
1437 %(file) : $(%(mmake)_OBJS) $(%(mmake)_DEPS)
1438         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1439         $(Q)$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(%(mmake)_TMPDIR)/%(name) $(%(mmake)_OBJS)
1440         $(Q)cd $(%(mmake)_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1442 ifeq ($(findstring $(%(mmake)_OUTDIR),$(GLOB_MKDIRS)),)
1443     %rule_makedirs dirs="$(%(mmake)_OUTDIR)" setuptarget=%(file)
1444 endif
1446 %end
1448 #------------------------------------------------------------------------------
1449 # Common rules for all makefiles
1450 %define common
1451 # Delete generated makefiles
1453 clean ::
1454         $(Q)$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1456 include $(SRCDIR)/config/make.tail
1458 BDID := $(BDTARGETID)
1459 %end
1460 #------------------------------------------------------------------------------
1461       
1463 #############################################################################
1464 #############################################################################
1465 ##                                                                         ##
1466 ## Here are the mmakefile build macros. These are macros that takes care   ##
1467 ## of everything to go from the sources to the generated target. Also all  ##
1468 ## intermediate files and directories that are needed are created by these ##
1469 ## rules.                                                                  ##
1470 ##                                                                         ##
1471 #############################################################################
1472 #############################################################################
1474 #------------------------------------------------------------------------------
1475 # Build a program
1476 %define build_prog mmake=/A progname=/A files= cxxfiles= \
1477     objcfiles= \
1478     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1479     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= ldflags=$(LDFLAGS) \
1480     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1481     includedir= libdir= \
1482     compiler=target linker= \
1483     coverageinstr=$(TARGET_COVERAGEINSTR) funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1485 .PHONY : %(mmake)
1487 %(mmake)_PROGNAME  := %(progname)
1488 %(mmake)_OBJDIR    := %(objdir)
1489 %(mmake)_TARGETDIR := %(targetdir)
1490 %(mmake)_LINKER    := %(linker)
1491 %(mmake)_LIBS := %(uselibs)
1492 # If not supplied, linker is equal to compiler
1493 ifeq ($(%(mmake)_LINKER),)
1494     %(mmake)_LINKER := %(compiler)
1495 endif
1497 ifneq ("$(strip %(files) %(cxxfiles) %(objcfiles) %(asmfiles))","")
1498     %(mmake)_FILES     := %(files)
1499     %(mmake)_OBJCFILES := %(objcfiles)
1500     %(mmake)_ASMFILES  := %(asmfiles)
1501     %(mmake)_CXXFILES := %(cxxfiles)
1502 else
1503     %(mmake)_FILES     := $(%(mmake)_PROGNAME)
1504     %(mmake)_OBJCFILES :=
1505     %(mmake)_ASMFILES  :=
1506     %(mmake)_CXXFILES :=
1507 endif
1509 %(mmake)_ARCHOBJS   := $(wildcard $(%(mmake)_OBJDIR)/arch/*.o)
1510 %(mmake)_ARCHFILES  := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
1511 %(mmake)_C_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_FILES))
1512 %(mmake)_CXX_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_CXXFILES))
1513 %(mmake)_OBJC_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_OBJCFILES))
1515 TMP_FILES := $(%(mmake)_C_NARCHFILES) $(%(mmake)_CXX_NARCHFILES) $(%(mmake)_ASMFILES) $(%(mmake)_OBJC_NARCHFILES)
1516 %(mmake)_OBJS := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(TMP_FILES))))
1517 %(mmake)_DEPS := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(TMP_FILES))))
1519 %(mmake)_CPPFLAGS :=  %(cppflags)
1520 ifneq (%(includedir),)
1521 %(mmake)_CPPFLAGS    += -I%(includedir)
1522 endif
1523 %(mmake)_CFLAGS    := %(cflags)
1524 %(mmake)_CXXFLAGS := %(cxxflags)
1525 %(mmake)_COVERAGE := no
1526 ifeq (%(compiler),target)
1527 ifeq (%(usestartup),yes)
1528 ifeq (%(coverageinstr),yes)
1529 %(mmake)_COVERAGE := yes
1530 %(mmake)_COVERAGEFLAGS   ?= $(COVERAGEINSTR_FLAGS)
1531 %(mmake)_COVERAGELIBS    ?= $(COVERAGEINSTR_LIBS)
1532 %(mmake)_CFLAGS    := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CFLAGS))
1533 %(mmake)_CXXFLAGS := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CXXFLAGS))
1534 %(mmake)_LIBS += $(%(mmake)_COVERAGELIBS)
1535 endif
1536 ifeq (%(funcinstr),yes)
1537 %(mmake)_FUNCINSTR := yes
1538 %(mmake)_INSTRFUNCFLAGS   ?= $(FUNCINSTR_FLAGS)
1539 %(mmake)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
1540 %(mmake)_CFLAGS    := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CFLAGS))
1541 %(mmake)_CXXFLAGS := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CXXFLAGS))
1542 %(mmake)_LIBS += $(%(mmake)_INSTRFUNCLIBS)
1543 endif
1544 endif
1545 ifeq (%(lto),yes)
1546 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CFLAGS))
1547 %(mmake)_CXXFLAGS := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CXXFLAGS))
1548 endif
1549 endif
1550 %(mmake)_AFLAGS    := %(aflags)
1551 ifneq (%(dflags),)
1552     %(mmake)_DFLAGS     := %(dflags)
1553 else
1554     %(mmake)_DFLAGS     := $(%(mmake)_CFLAGS)
1555 endif
1556 ifneq (%(dxxflags),)
1557     %(mmake)_DXXFLAGS     := %(dxxflags)
1558 else
1559     %(mmake)_DXXFLAGS     := $(%(mmake)_CXXFLAGS)
1560 endif
1561 %(mmake)_LDFLAGS   := %(ldflags)
1562 ifneq (%(libdir),)
1563 %(mmake)_LDFLAGS   += -L%(libdir)
1564 endif
1567 %(mmake)-quick : %(mmake)
1569 #MM %(mmake) : includes-generate-deps core-linklibs
1570 %(mmake) : $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME)
1572 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1573 %rule_compile_cxx_multi mmake=%(mmake) \
1574     basenames=$(%(mmake)_CXX_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1575     cppflags=$(%(mmake)_CPPFLAGS) cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
1576     compiler="%(compiler)"
1577 %rule_compile_objc_multi mmake=%(mmake) \
1578     basenames=$(%(mmake)_OBJC_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1579     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1580     compiler="%(compiler)"
1581 %rule_compile_multi mmake=%(mmake) \
1582     basenames=$(%(mmake)_C_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1583     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1584     compiler="%(compiler)"
1585 %rule_assemble_multi mmake=%(mmake) \
1586     cmd=$(%(mmake)_ASSEMBLER) basenames=$(%(mmake)_ASMFILES) targetdir=$(%(mmake)_OBJDIR) \
1587     cppflags=$(%(mmake)_CPPFLAGS) aflags=$(%(mmake)_AFLAGS)
1589 %rule_link_prog mmake=%(mmake) prog=$(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME) \
1590     objs="$(%(mmake)_OBJS) $(%(mmake)_ARCHOBJS) $(USER_OBJS)" ldflags=$(%(mmake)_LDFLAGS) \
1591     uselibs="$(%(mmake)_LIBS)" usehostlibs="%(usehostlibs)" \
1592     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1593     cmd=$(%(mmake)_LINK) strip=$(%(mmake)_STRIP) objdir=$(%(mmake)_OBJDIR) coverageinstr=$(%(mmake)_COVERAGE) 
1595 endif
1597 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
1599 $(%(mmake)_OBJS) $(%(mmake)_DEPS) : | $(%(mmake)_OBJDIR)
1600 $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME) : | $(%(mmake)_TARGETDIR)
1601 %rule_makedirs dirs="$(%(mmake)_OBJDIR) $(%(mmake)_TARGETDIR)"
1603 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME) $(%(mmake)_DEPS)
1605 %(mmake)-clean ::
1606         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
1607         $(Q)$(RM) $(FILES)
1609 %end
1610 #------------------------------------------------------------------------------
1613 #------------------------------------------------------------------------------
1614 # Build programs, for every C file an executable will be built with the same
1615 # name as the C file
1616 %define build_progs mmake=/A files=/A nix=no \
1617     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1618     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= ldflags=$(LDFLAGS) \
1619     includedir= libdir= \
1620     compiler=target \
1621     uselibs= usehostlibs= usestartup=yes detach=no \
1622     coverageinstr=$(TARGET_COVERAGEINSTR) funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1624 .PHONY : %(mmake)
1626 %(mmake)_OBJDIR    := %(objdir)
1627 %(mmake)_TARGETDIR := %(targetdir)
1628 %(mmake)_LIBS := %(uselibs)
1630 %(mmake)_FILES     := %(files)
1631 %(mmake)_OBJS      := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_FILES)))
1632 %(mmake)_DEPS      := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_FILES)))
1633 %(mmake)_EXES      := $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_FILES))
1635 %(mmake)_CPPFLAGS := %(cppflags)
1636 ifneq (%(includedir),)
1637     %(mmake)_CPPFLAGS += -I%(includedir)
1638 endif
1639 %(mmake)_CFLAGS    := %(cflags)
1640 %(mmake)_COVERAGE := no
1641 ifeq (%(compiler),target)
1642 ifeq (%(usestartup),yes)
1643 ifeq (%(coverageinstr),yes)
1644 %(mmake)_COVERAGE := yes
1645 %(mmake)_COVERAGEFLAGS   ?= $(COVERAGEINSTR_FLAGS)
1646 %(mmake)_COVERAGELIBS    ?= $(COVERAGEINSTR_LIBS)
1647 %(mmake)_CFLAGS    := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CFLAGS))
1648 %(mmake)_LIBS += $(%(mmake)_COVERAGELIBS)
1649 endif
1650 ifeq (%(funcinstr),yes)
1651 %(mmake)_FUNCINSTR := yes
1652 %(mmake)_INSTRFUNCFLAGS   ?= $(FUNCINSTR_FLAGS)
1653 %(mmake)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
1654 %(mmake)_CFLAGS    := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CFLAGS))
1655 %(mmake)_LIBS += $(%(mmake)_INSTRFUNCLIBS)
1656 endif
1657 endif
1658 ifeq (%(lto),yes)
1659 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CFLAGS))
1660 endif
1661 endif
1662 ifneq (%(dflags),)
1663     %(mmake)_DFLAGS := %(dflags)
1664 else
1665     %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
1666 endif
1667 %(mmake)_LDFLAGS   := %(ldflags)
1668 ifneq (%(libdir),)
1669     %(mmake)_LDFLAGS += -L%(libdir)
1670 endif
1673 %(mmake)-quick : %(mmake)
1675 #MM %(mmake) : includes-generate-deps core-linklibs
1676 %(mmake) : $(%(mmake)_EXES)
1678 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1679 %rule_compile_multi mmake=%(mmake) basenames=$(%(mmake)_FILES) targetdir=$(%(mmake)_OBJDIR) \
1680     cflags=$(%(mmake)_CFLAGS) cppflags=$(%(mmake)_CPPFLAGS) dflags=$(%(mmake)_DFLAGS) compiler="%(compiler)"
1682 %rule_link_progs mmake=%(mmake) progs=$(%(mmake)_FILES) nix="%(nix)" \
1683     targetdir=$(%(mmake)_TARGETDIR) objdir=$(%(mmake)_OBJDIR) \
1684     ldflags=$(%(mmake)_LDFLAGS) \
1685     uselibs="$(%(mmake)_LIBS)" usehostlibs="%(usehostlibs)" \
1686     usestartup="%(usestartup)" detach="%(detach)" \
1687     cmd=$(%(mmake)_LINK) strip=$(%(mmake)_STRIP) objdir=$(%(mmake)_OBJDIR) coverageinstr=$(%(mmake)_COVERAGE)
1689 endif
1691 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
1693 $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_FILES)) : | $(%(mmake)_TARGETDIR)
1694 $(%(mmake)_DEPS) $(%(mmake)_OBJS) : | $(%(mmake)_OBJDIR)
1695 %rule_makedirs dirs="$(%(mmake)_TARGETDIR) $(%(mmake)_OBJDIR)"
1697 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_EXES) $(%(mmake)_DEPS)
1699 %(mmake)-clean ::
1700         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
1701         $(Q)$(RM) $(FILES)
1703 %end
1704 #------------------------------------------------------------------------------
1707 #------------------------------------------------------------------------------
1708 # Build a module.
1709 # This is a bare version: It just compiles and links the given files. It is
1710 # assumed that all needed boiler plate code is in the files. This should only
1711 # be used for compiling external code. For AROS code use %build_module
1712 %define build_module_simple mmake=/A modname=/A modtype=/A \
1713     files="$(basename $(call WILDCARD, *.c))" \
1714     objcfiles= \
1715     cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1716     cppflags=$(CPPFLAGS) \
1717     cflags=$(CFLAGS) dflags= \
1718     cxxflags=$(CXXFLAGS) dxxflags= \
1719     objdir=$(OBJDIR) moduledir= \
1720     uselibs= usehostlibs= compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1722 # Define metamake targets and their dependencies
1723 #MM %(mmake) : core-linklibs includes-generate-deps
1724 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1725 #MM %(mmake)-kobj-quick
1726 #MM %(mmake)-quick
1727 #MM %(mmake)-clean
1729 %(mmake)_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1731 .PHONY : $(%(mmake)_ALLTARGETS)
1733 ifeq (%(modname),)
1734 $(error using %build_module_simple: modname may not be empty)
1735 endif
1736 ifeq (%(modtype),)
1737 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1738 endif
1740 # Default values for variables and arguments
1741 %(mmake)_DEFLINKLIBNAME := %(modname)
1742 %(mmake)_CFLAGS := %(cflags)
1743 %(mmake)_CXXFLAGS := %(cxxflags)
1744 ifeq (%(compiler),target)
1745 ifeq (%(lto),yes)
1746 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(%(mmake)_CFLAGS))
1747 endif
1748 ifeq (%(funcinstr),yes)
1749 %(mmake)_FUNCINSTR := yes
1750 %(mmake)_CFLAGS    := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)_CFLAGS))
1751 endif
1752 endif
1753 ifneq (%(dflags),)
1754     %(mmake)_DFLAGS := %(dflags)
1755 else
1756     %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
1757 endif
1758 %(mmake)_DEFDXXFLAGS := %(dxxflags)
1759 OBJDIR ?= $(GENDIR)/$(CURDIR)
1760 %(mmake)_MODDIR := %(moduledir)
1761 ifeq ($(%(mmake)_MODDIR),)
1762   ifeq (%(modtype),library)
1763     %(mmake)_MODDIR  := $(AROS_LIBRARIES)
1764   endif
1765   ifeq (%(modtype),gadget)
1766     %(mmake)_MODDIR  := $(AROS_GADGETS)
1767   endif
1768   ifeq (%(modtype),datatype)
1769     %(mmake)_MODDIR  := $(AROS_DATATYPES)
1770   endif
1771   ifeq (%(modtype),handler)
1772     %(mmake)_MODDIR  := $(AROS_FS)
1773   endif
1774   ifeq (%(modtype),device)
1775     %(mmake)_MODDIR  := $(AROS_DEVS)
1776   endif
1777   ifeq (%(modtype),resource)
1778     %(mmake)_MODDIR  := $(AROS_RESOURCES)
1779   endif
1780   ifeq (%(modtype),hook)
1781     %(mmake)_MODDIR  := $(AROS_RESOURCES)
1782   endif
1783   ifeq (%(modtype),mui)
1784     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1785   endif
1786   ifeq (%(modtype),mcc)
1787     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1788   endif
1789   ifeq (%(modtype),mcp)
1790     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1791   endif
1792   ifeq (%(modtype),usbclass)
1793     %(mmake)_MODDIR  := $(AROS_CLASSES)/USB
1794   endif
1795   ifeq (%(modtype),hidd)
1796     %(mmake)_MODDIR  := $(AROS_DRIVERS)
1797   endif
1798   ifeq (%(modtype),printer)
1799     %(mmake)_MODDIR  := $(AROS_PRINTERS)
1800   endif
1801 endif
1802 ifeq ($(%(mmake)_MODDIR),)
1803   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1804 endif
1806 %(mmake)_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1807 %(mmake)_ARCHFILES  := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
1808 %(mmake)_C_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(files))
1809 %(mmake)_CXX_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(cxxfiles))
1810 %(mmake)_OBJC_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(objcfiles))
1812 %rule_compile_cxx_multi mmake=%(mmake) \
1813     basenames=$(%(mmake)_CXX_NARCHFILES) targetdir="%(objdir)" \
1814     cppflags="%(cppflags)" cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
1815     compiler="%(compiler)"
1816 %rule_compile_objc_multi mmake=%(mmake) \
1817     basenames=$(%(mmake)_OBJC_NARCHFILES) targetdir="%(objdir)" \
1818     cppflags="%(cppflags)" cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1819     compiler="%(compiler)"
1820 %rule_compile_multi mmake=%(mmake) \
1821     basenames=$(%(mmake)_C_NARCHFILES) targetdir="%(objdir)" \
1822     cppflags="%(cppflags)" cflags="$(%(mmake)_CFLAGS)" dflags="$(%(mmake)_DFLAGS)" \
1823     compiler="%(compiler)"
1825 # Handlers use dash instead of dot in their names
1826 ifeq (%(modtype),handler)
1827 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname)-%(modtype)
1828 else
1829 ifeq (%(modtype),printer)
1830 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname)
1831 else
1832 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname).%(modtype)
1833 endif
1834 endif
1835 %(mmake)_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1837 %(mmake)-quick : %(mmake)
1838 %(mmake)-kobj-quick : $(%(mmake)_KOBJ)
1839 %(mmake)       : $(%(mmake)_MODULE)
1840 %(mmake)-kobj  : $(%(mmake)_KOBJ)
1842 # The module is linked from all the compiled .o files
1843 %(mmake)_OBJS       := $(%(mmake)_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(%(mmake)_C_NARCHFILES))))
1845 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1846 # This breaks con-handler build. Here we work around this
1847 ifeq (%(modname),con)
1848     %(mmake)_ERR := $(notdir $(%(mmake)_MODULE)).err
1849 else
1850     %(mmake)_ERR := %(modname).err
1851 endif
1853 %rule_linkmodule module=$(%(mmake)_MODULE) objs=$(%(mmake)_OBJS) \
1854     endobj= err=$(%(mmake)_ERR) objdir="%(objdir)" \
1855     ldflags="$(strip $(LDFLAGS) $(%(modname)_LDFLAGS))" \
1856     uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1858 # Link kernel object file
1859 %(mmake)_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1861 # Make these symbols local
1862 %(mmake)_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1863     UtilityBase ExpansionBase KeymapBase KernelBase
1865 %(mmake)_SYMBOLS := $(%(mmake)_KBASE)
1867 %(mmake)_KLIB := hiddstubs amiga arossupport autoinit libinit
1868 %(mmake)_KOBJ_LIBS := $(filter-out $(%(mmake)_KLIB),%(uselibs)) $(%(mmake)_KAUTOLIB)
1869 $(%(mmake)_KOBJ) : LINKLIBS:=$(%(mmake)_KOBJ_LIBS)
1870 $(%(mmake)_KOBJ) : FILTBASES:=$(addprefix -L ,$(%(mmake)_SYMBOLS))
1871 $(%(mmake)_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1872 $(%(mmake)_KOBJ) : $(%(mmake)_OBJS) $(%(mmake)_ENDOBJS)
1873         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1874         $(Q)$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1875         $(Q)$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1878 ## Dependency fine-tuning
1880 %(mmake)_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1881 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(%(mmake)_DEPS)
1883 $(%(mmake)_OBJS) $(%(mmake)_DEPS) : | %(objdir)
1884 $(%(mmake)_MODULE) : | $(%(mmake)_MODDIR)
1885 $(%(mmake)_KOBJ) : | $(KOBJSDIR)
1886 %rule_makedirs dirs="%(objdir) $(%(mmake)_MODDIR) $(KOBJSDIR)"
1888 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_MODULE) $(%(mmake)_KOBJ) $(%(mmake)_DEPS)
1889 %(mmake)-clean ::
1890         $(Q)$(ECHO) "Cleaning up for module %(modname)"
1891         $(Q)$(RM) $(FILES)
1892 %end
1893 #------------------------------------------------------------------------------
1896 #------------------------------------------------------------------------------
1897 # Build a module - core routine
1898 # Explanation of this macro is done in the developer's manual
1899 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
1900     files="$(basename $(call WILDCARD, *.c))" \
1901     objcfiles= \
1902     cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1903     linklibfiles= linklibobjs= \
1904     cppflags=$(CPPFLAGS) \
1905     cflags=$(CFLAGS) dflags= \
1906     cxxflags=$(CXXFLAGS) dxxflags= \
1907     objdir= moduledir= prefix=$(AROSDIR) \
1908     linklibname= uselibs= usehostlibs= \
1909     compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1910     include_set=includes-all includedir= libdir= \
1911     build_abi= build_library=
1913 # We will employ a terrifying, but unavoidable, hack here.
1914 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1915 # ignores GNU Make ifeq() statements, but will process any #MM
1916 # headed lines in the file.
1918 # So, to make the following #MM lines conditional on whether we want
1919 # to build the ABI, Library, or both, we define build_abi= and 
1920 # build_library as 'M' to enable, or '' to disable, which allows genmf
1921 # to do the following conversions:
1923 #  #%(build_abi)M includes-foo: foo-include
1924 #    becomes, when build_abi=M
1925 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1926 #    but, when build_abi= ...
1927 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1929 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1931 # Define metamake targets and their dependencies
1932 #MM %(mmake)
1933 #MM %(mmake)-quick
1934 #MM %(mmake)-makefile
1935 #MM %(mmake)-clean
1937 # ABI targets:
1938 #M%(build_abi)- %(include_set) : %(mmake)-includes
1939 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1940 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1941 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1942 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1943 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1944 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1945 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1946 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1947 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1948 #M%(build_abi) %(mmake)-includes-quick
1949 #M%(build_abi) %(mmake)-includes-dirs
1950 #M%(build_abi) %(mmake)-fd
1952 # Library targets
1953 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1954 #%(build_library)M %(mmake)-kobj-quick : 
1956 # Library with ABI targets:
1957 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1958 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1960 # All MetaMake targets defined by this macro
1961 %(mmake)%(flavour)_ALLTARGETS       := %(mmake) %(mmake)-quick %(mmake)-clean
1963 ifeq (%(build_library),M)
1964 %(mmake)%(flavour)_ALLTARGETS       += %(mmake)-kobj %(mmake)-kobj-quick
1965 endif
1967 ifeq (%(build_abi),M)
1968 %(mmake)%(flavour)_ALLTARGETS += %(mmake)-includes \
1969                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1970                  %(mmake)-linklib %(mmake)-fd
1971 endif
1973 .PHONY : $(%(mmake)%(flavour)_ALLTARGETS) %(mmake)-makefile
1975 ifeq (%(modname),)
1976 $(error using %build_module: modname may not be empty)
1977 endif
1978 ifeq (%(modtype),)
1979 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1980 endif
1982 # Default values for variables and arguments
1983 ifneq (%(flavour),)
1984     %(mmake)%(flavour)_DEFNAME      := %(modname)_%(flavour)
1985 else
1986     %(mmake)%(flavour)_DEFNAME      := %(modname)
1987 endif
1988 %(mmake)%(flavour)_DEFLINKLIBNAME   := $(%(mmake)%(flavour)_DEFNAME)
1989 ifneq (%(linklibname),)
1990     %(mmake)%(flavour)_LINKLIBNAME  := %(linklibname)
1991 else
1992     %(mmake)%(flavour)_LINKLIBNAME  = $(%(mmake)%(flavour)_DEFLINKLIBNAME)
1993 endif
1994 %(mmake)%(flavour)_DEFCPPFLAGS      := %(cppflags)
1995 ifneq (%(includedir),)
1996     %(mmake)%(flavour)_DEFCPPFLAGS  += -I%(includedir)
1997 endif
1998 %(mmake)%(flavour)_DEFDFLAGS        := %(cflags)
1999 ifneq (%(dflags),)
2000     %(mmake)%(flavour)_DFLAGS       := %(dflags)
2001 else
2002     %(mmake)%(flavour)_DFLAGS       = $(%(mmake)%(flavour)_DEFDFLAGS)
2003 endif
2004 %(mmake)%(flavour)_DEFDXXFLAGS      := %(cxxflags)
2005 ifneq (%(dxxflags),)
2006     %(mmake)%(flavour)_DXXFLAGS     := %(dxxflags)
2007 else
2008     %(mmake)%(flavour)_DXXFLAGS     = $(%(mmake)%(flavour)_DEFDXXFLAGS)
2009 endif
2010 ifeq (%(compiler),target)
2011 ifeq (%(lto),yes)
2012 %(mmake)%(flavour)_DEFDFLAGS        := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(%(mmake)%(flavour)_DEFDFLAGS))
2013 %(mmake)%(flavour)_DEFDXXFLAGS      := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(%(mmake)%(flavour)_DEFDXXFLAGS))
2014 endif
2015 ifeq (%(funcinstr),yes)
2016 %(mmake)_FUNCINSTR := yes
2017 %(mmake)%(flavour)_DEFDFLAGS        := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)%(flavour)_DEFDFLAGS))
2018 %(mmake)%(flavour)_DEFDXXFLAGS      := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)%(flavour)_DEFDXXFLAGS))
2019 endif
2020 endif
2021 OBJDIR                              ?= $(GENDIR)/$(CURDIR)
2022 ifneq (%(objdir),)
2023 %(mmake)_OBJDIR                     := %(objdir)
2024 ifneq (%(flavour),)
2025 %(mmake)%(flavour)_OBJDIR           := %(objdir)
2026 endif
2027 else
2028 %(mmake)_OBJDIR := $(OBJDIR)/%(modname)
2029 ifneq (%(flavour),)
2030 %(mmake)%(flavour)_OBJDIR           := $(OBJDIR)/$(%(mmake)%(flavour)_DEFNAME)
2031 endif
2032 endif
2034 ## Create genmodule include Makefile for the module
2036 %(mmake)-makefile : $(%(mmake)%(flavour)_OBJDIR)/Makefile.$(%(mmake)%(flavour)_DEFNAME)%(modtype)
2038 %rule_genmodule_makefile \
2039     modname="%(modname)" flavour="%(flavour)" modtype="%(modtype)" \
2040     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2041     conffile="%(conffile)"
2043 $(%(mmake)%(flavour)_OBJDIR)/Makefile.$(%(mmake)%(flavour)_DEFNAME)%(modtype) : | $(%(mmake)%(flavour)_OBJDIR)
2045 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)"
2046 ifneq (%(flavour),)
2047 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)"
2048 endif
2050 # Do not parse these statements if metatarget is not appropriate
2051 ifneq ($(filter $(TARGET),$(%(mmake)%(flavour)_ALLTARGETS)),)
2053 # suppress makes warning that the Makefile doesnt yet exist
2054 # on early passes (it will generate the file as needed though)
2055 # when we include it.
2056 -include $(%(mmake)%(flavour)_OBJDIR)/Makefile.$(%(mmake)%(flavour)_DEFNAME)%(modtype)
2058 %(mmake)%(flavour)_DEFMODDIR        := $($(%(mmake)%(flavour)_DEFNAME)_MODDIR)
2059 ifeq (%(archspecific),yes)
2060 %(mmake)%(flavour)_DEFMODDIR        := $(AROS_DIR_ARCH)/$(%(mmake)%(flavour)_DEFMODDIR)
2061 endif
2062 ifneq (%(moduledir),)
2063     %(mmake)%(flavour)_MODDIR       := %(moduledir)
2064 else
2065     %(mmake)%(flavour)_MODDIR       := $(%(mmake)%(flavour)_DEFMODDIR)
2066 endif
2068 ## include files generation
2070 ifneq (%(includedir),)
2071 %(mmake)%(flavour)_INCDIR           := %(includedir)
2072 else
2073 %(mmake)%(flavour)_INCDIR           := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
2074 endif
2075 %(mmake)%(flavour)_LIBDEFSINC       := $(%(mmake)%(flavour)_OBJDIR)/include/$(%(mmake)%(flavour)_DEFNAME)_libdefs.h
2076 %(mmake)%(flavour)_DEFLIBDEFSINC    := $(%(mmake)%(flavour)_OBJDIR)/include/$(%(mmake)%(flavour)_DEFNAME)_deflibdefs.h
2078 ifeq (%(build_abi),M)
2079 %(mmake)-includes-quick : %(mmake)-includes
2080 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2081     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2082     $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC)
2084 ifneq ($($(%(mmake)%(flavour)_DEFNAME)_INCLUDES),)
2085 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
2086     modsuffix="%(modsuffix)" targetdir="$(%(mmake)_OBJDIR)/include" \
2087     conffile="%(conffile)" flavour="%(flavour)"
2089 %rule_copy_diff_multi \
2090     files=$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES) srcdir="$(%(mmake)_OBJDIR)/include" targetdir=$(GENINCDIR) \
2091     stampfile="$(%(mmake)_OBJDIR)/%(modname)_geninc"
2093 %rule_copy_diff_multi \
2094     files=$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES) srcdir="$(%(mmake)_OBJDIR)/include" targetdir=$(%(mmake)%(flavour)_INCDIR) \
2095     stampfile="$(%(mmake)_OBJDIR)/%(modname)_incs"
2097 %(mmake)%(flavour)_INCDIRS := $(filter-out ./,$(sort $(dir $($(%(mmake)%(flavour)_DEFNAME)_INCLUDES))))
2099 TMP%(modname)_INCDIRS := \
2100     $(%(mmake)_OBJDIR)/include $(addprefix $(%(mmake)_OBJDIR)/include/,$(%(mmake)%(flavour)_INCDIRS)) \
2101     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(%(mmake)%(flavour)_INCDIRS)) \
2102     $(%(mmake)%(flavour)_INCDIR) $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$(%(mmake)%(flavour)_INCDIRS))
2103 %rule_makedirs dirs="$(TMP%(modname)_INCDIRS)" setuptarget="%(mmake)-includes-dirs"
2105 endif
2107 endif
2109 %rule_genmodule_genlibdefs modname="%(modname)" flavour="%(flavour)" modtype="%(modtype)" \
2110     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)/include" \
2111     conffile="%(conffile)" version="%(version)"
2113 $(%(mmake)%(flavour)_DEFLIBDEFSINC) : FILENAME := $(%(mmake)%(flavour)_LIBDEFSINC)
2114 $(%(mmake)%(flavour)_DEFLIBDEFSINC) :
2115         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
2116         $(Q)$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2118 $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC) : | $(%(mmake)%(flavour)_OBJDIR)/include
2119 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)/include"
2121 ## Extra genmodule src files generation
2122 ## 
2123 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
2124     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)" stubdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2125     conffile="%(conffile)" flavour="%(flavour)"
2127 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)/linklib"
2129 ifeq (%(build_abi),M)
2130 ## Create FD file
2131 ifeq (%(includedir),)
2132 %(mmake)%(flavour)_FDDIR            := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_SDK)/$(AROS_DIR_FD)
2133 else
2134 %(mmake)%(flavour)_FDDIR            := %(includedir)/../$(AROS_DIR_FD)
2135 endif
2136 %(mmake)-fd : $(%(mmake)%(flavour)_FDDIR)/%(modname)_lib.fd
2138 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
2139     modsuffix="%(modsuffix)" targetdir=$(%(mmake)%(flavour)_FDDIR) conffile="%(conffile)"
2141 $(%(mmake)%(flavour)_FDDIR)/%(modname)_lib.fd : | $(%(mmake)%(flavour)_FDDIR)
2143 %rule_makedirs dirs="$(%(mmake)%(flavour)_FDDIR)"
2144 endif
2146 ## Compilation
2148 %(mmake)%(flavour)_FILES            := %(files)
2149 %(mmake)%(flavour)_OBJCFILES        := %(objcfiles)
2150 %(mmake)%(flavour)_CXXFILES         := %(cxxfiles)
2152 %(mmake)%(flavour)_LIBFILES         := %(linklibfiles)
2153 %(mmake)%(flavour)_LIBS             := %(uselibs)
2155 %(mmake)%(flavour)_FDIRS            := $(sort $(dir $(%(mmake)%(flavour)_FILES)))
2157 %(mmake)%(flavour)_FILEMATCH        = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
2158 %(mmake)%(flavour)_MATCHARCH        = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call %(mmake)%(flavour)_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
2159 %(mmake)%(flavour)_FILTERARCH       = $(filter-out $(call %(mmake)%(flavour)_MATCHARCH,$(1),$(2)),$(2))
2160 %(mmake)%(flavour)_STARTFILES       := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_STARTFILES))
2161 %(mmake)%(flavour)_ENDFILES         := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_ENDFILES))
2163 %(mmake)%(flavour)_ARCHOBJS         := $(wildcard $(%(mmake)%(flavour)_OBJDIR)/arch/*.o)
2164 %(mmake)%(flavour)_LIBARCHOBJS      := $(wildcard $(%(mmake)%(flavour)_OBJDIR)/linklib/arch/*.o)
2165 %(mmake)%(flavour)_ARCHFILES        := $(basename $(notdir $(%(mmake)%(flavour)_ARCHOBJS)))
2166 %(mmake)%(flavour)_LIBARCHFILES     := $(basename $(notdir $(%(mmake)%(flavour)_LIBARCHOBJS)))
2167 %(mmake)%(flavour)_C_NARCHFILES     := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_FILES))
2168 %(mmake)%(flavour)_CXX_NARCHFILES   := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_CXXFILES))
2169 %(mmake)%(flavour)_OBJC_NARCHFILES  := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_OBJCFILES))
2170 %(mmake)%(flavour)_NLIBARCHFILES    := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_LIBARCHFILES),$(%(mmake)%(flavour)_LIBFILES))
2171 %(mmake)%(flavour)_ARCHNLIBFILES    := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_LIBFILES),$(%(mmake)%(flavour)_LIBARCHFILES))
2173 %(mmake)%(flavour)_CPPFLAGS         := $(strip %(cppflags) -I$(%(mmake)%(flavour)_OBJDIR)/include -include $(%(mmake)%(flavour)_DEFLIBDEFSINC))
2174 ifneq (%(includedir),)
2175 %(mmake)%(flavour)_CPPFLAGS         += -I%(includedir)
2176 endif
2177 %(mmake)%(flavour)_LINKLIBCPPFLAGS  := $(%(mmake)%(flavour)_CPPFLAGS)
2178 %(mmake)%(flavour)_CPPFLAGS         += $(strip $($(%(mmake)%(flavour)_DEFNAME)_CPPFLAGS))
2179 %(mmake)%(flavour)_LINKLIBCPPFLAGS  += $(strip $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBCPPFLAGS))
2180 %(mmake)%(flavour)_CFLAGS           := $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_CFLAGS))
2181 %(mmake)%(flavour)_LINKLIBCFLAGS    := $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBCFLAGS))
2182 %(mmake)%(flavour)_CXXFLAGS         := $(strip %(cxxflags) $($(%(mmake)%(flavour)_DEFNAME)_CXXFLAGS))
2183 ifeq (%(compiler),target)
2184 ifeq (%(lto),yes)
2185 %(mmake)%(flavour)_LTOFLAGS         ?= $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH))
2186 %(mmake)%(flavour)_CFLAGS           := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CFLAGS))
2187 %(mmake)%(flavour)_LINKLIBCFLAGS    := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_LINKLIBCFLAGS))
2188 %(mmake)%(flavour)_CXXFLAGS         := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CXXFLAGS))
2189 endif
2190 ifeq (%(funcinstr),yes)
2191 %(mmake)%(flavour)_SUBSTNULL  :=
2192 %(mmake)%(flavour)_SUBSTSPACE := $(%(mmake)%(flavour)_SUBSTNULL) #
2193 %(mmake)%(flavour)_SUBSTCOMMA := ,
2194 %(mmake)%(flavour)_INSTRFUNCFLAGS   ?= $(strip $(FUNCINSTR_FLAGS) -finstrument-functions-exclude-file-list=$(subst $(%(mmake)%(flavour)_SUBSTSPACE),$(%(mmake)%(flavour)_SUBSTCOMMA),$(strip $($(%(mmake)%(flavour)_DEFNAME)_STARTFILES))))
2195 %(mmake)%(flavour)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
2196 %(mmake)%(flavour)_CFLAGS           := $(strip $(%(mmake)%(flavour)_INSTRFUNCFLAGS) $(%(mmake)%(flavour)_CFLAGS))
2197 %(mmake)%(flavour)_CXXFLAGS         := $(strip $(%(mmake)%(flavour)_INSTRFUNCFLAGS) $(%(mmake)%(flavour)_CXXFLAGS))
2198 %(mmake)%(flavour)_LIBS             += $(%(mmake)%(flavour)_INSTRFUNCLIBS)
2199 endif
2200 endif
2201 %(mmake)%(flavour)_DFLAGS           := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DFLAGS))
2202 %(mmake)%(flavour)_LINKLIBDFLAGS    := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBDFLAGS))
2203 %(mmake)%(flavour)_DXXFLAGS         := $(strip $(%(mmake)%(flavour)_DXXFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DXXFLAGS))
2205 ifeq (%(modtype),library)
2206     %(mmake)%(flavour)_LIBSUFFIX    := 
2207 else
2208     %(mmake)%(flavour)_LIBSUFFIX    := .%(modtype)
2209 endif
2211 ifeq (%(libdir),)
2212 %(mmake)%(flavour)_LIBDIR           := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
2213 else
2214 %(mmake)%(flavour)_LIBDIR           := %(libdir)
2215 endif
2217 ifeq (%(build_abi),M)
2218 %(mmake)%(flavour)_LINKLIBCFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES))
2219 %(mmake)%(flavour)_LINKLIBAFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES))
2220 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2221     %(mmake)%(flavour)_LINKLIB      :=
2222 else
2223     %(mmake)%(flavour)_LINKLIB      := $(%(mmake)%(flavour)_LIBDIR)/lib%(modname)$(%(mmake)%(flavour)_LIBSUFFIX).a
2224     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2225         %(mmake)%(flavour)_LINKLIB  += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX).a
2226     endif
2227 endif
2228 %(mmake)%(flavour)_LINKLIBFILES     := $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_LINKLIBAFILES)
2230 %(mmake)%(flavour)_RELLINKLIBCFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES))
2231 %(mmake)%(flavour)_RELLINKLIBAFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES))
2232 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2233     %(mmake)%(flavour)_RELLINKLIB   :=
2234 else
2235     %(mmake)%(flavour)_RELLINKLIB   := $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2236     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2237         %(mmake)%(flavour)_RELLINKLIB += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2238     endif
2239 endif
2240 %(mmake)%(flavour)_RELLINKLIBFILES  := $(%(mmake)%(flavour)_RELLINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)
2241 endif
2243 %(mmake)%(flavour)_ENDOBJS          := $(addsuffix .o,$(%(mmake)%(flavour)_ENDFILES))
2244 %(mmake)%(flavour)_LINKLIBOBJS      := $(addsuffix .o,$(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$(notdir $(%(mmake)%(flavour)_NLIBARCHFILES))) $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/arch/,$(notdir $(%(mmake)%(flavour)_ARCHNLIBFILES))) $(%(mmake)%(flavour)_LINKLIBFILES)) \
2245                  %(linklibobjs)
2246 %(mmake)%(flavour)_RELLINKLIBOBJS   := $(addsuffix .o,$(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$(notdir $(%(mmake)%(flavour)_NLIBARCHFILES))) $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/arch/,$(notdir $(%(mmake)%(flavour)_ARCHNLIBFILES))) $(%(mmake)%(flavour)_RELLINKLIBFILES)) \
2247                  %(linklibobjs)
2248 $(%(mmake)%(flavour)_LINKLIBFILES) $(%(mmake)%(flavour)_RELLINKLIBFILES) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2249 $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_RELLINKLIBOBJS) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2251 %(mmake)%(flavour)_CCFILES := $(%(mmake)%(flavour)_C_NARCHFILES)
2252 %(mmake)%(flavour)_TARGETCCFILES    := $(strip $(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES))
2253 %(mmake)%(flavour)_LINKLIBCCFILES   := $(strip $(%(mmake)%(flavour)_NLIBARCHFILES) $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2254 %(mmake)%(flavour)_LINKLIBCCGENFILES := $(strip $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2256 %rule_compile_cxx_multi mmake=%(mmake)%(flavour) \
2257     basenames=$(%(mmake)%(flavour)_CXX_NARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2258     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cxxflags=$(%(mmake)%(flavour)_CXXFLAGS) dxxflags=$(%(mmake)%(flavour)_DXXFLAGS) \
2259     compiler="%(compiler)"
2260 %rule_compile_objc_multi mmake=%(mmake)%(flavour) \
2261     basenames=$(%(mmake)%(flavour)_OBJC_NARCHFILES) targetdir=$(%(mmake)%(flavour)_OBJDIR) \
2262     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2263     compiler="%(compiler)"
2264 %rule_compile_multi mmake=%(mmake)%(flavour) \
2265     basenames=$(%(mmake)%(flavour)_CCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2266     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2267     compiler="%(compiler)"
2268 %rule_compile_multi mmake=%(mmake)%(flavour) \
2269     basenames=$(%(mmake)%(flavour)_TARGETCCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2270     cppflags="$(%(mmake)%(flavour)_CPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2271     compiler="%(compiler)"
2272 %rule_compile_multi mmake=%(mmake)%(flavour) \
2273     basenames=$(%(mmake)%(flavour)_NLIBARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2274     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_LINKLIBCFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2275     compiler="%(compiler)"
2276 %rule_compile_multi mmake=%(mmake)%(flavour) \
2277     basenames=$(%(mmake)%(flavour)_LINKLIBCCGENFILES) srcdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2278     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_LINKLIBCFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2279     compiler="%(compiler)"
2281 ifneq ($(%(mmake)%(flavour)_LINKLIBAFILES),)
2282 %rule_assemble_multi  mmake=%(mmake)%(flavour) \
2283     cmd=$(%(mmake)%(flavour)_ASSEMBLER) basenames="$(%(mmake)%(flavour)_LINKLIBAFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" suffix=.S
2284 endif
2286 ## Linking
2288 ifeq (%(modsuffix),)
2289 %(mmake)%(flavour)_SUFFIX           := %(modtype)
2290 else
2291 %(mmake)%(flavour)_SUFFIX           := %(modsuffix)
2292 endif
2294 ifeq (%(build_library),M)
2295 # Handlers use dash instead of dot in their names
2296 ifeq ($(%(mmake)%(flavour)_SUFFIX),handler)
2297 %(mmake)%(flavour)_MODULE           := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME)-$(%(mmake)%(flavour)_SUFFIX)
2298 else
2299 %(mmake)%(flavour)_MODULE           := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME).$(%(mmake)%(flavour)_SUFFIX)
2300 endif
2301 %(mmake)%(flavour)_KOBJ             := $(KOBJSDIR)/$(%(mmake)%(flavour)_DEFNAME)_$(%(mmake)%(flavour)_SUFFIX).o
2302 else
2303 %(mmake)%(flavour)_MODULE           :=
2304 %(mmake)%(flavour)_KOBJ             :=
2305 endif
2307 %(mmake)-quick      : %(mmake)
2308 %(mmake)            : $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2309 ifeq (%(build_library),M)
2310 %(mmake)-kobj       : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2311 %(mmake)-kobj-quick : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2312 endif
2313 ifeq (%(build_abi),M)
2314 %(mmake)-linklib    : $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2315 endif
2317 %(mmake)%(flavour)_OBJS := $(addsuffix .o,$(%(mmake)%(flavour)_STARTFILES)) $(%(mmake)%(flavour)_ARCHOBJS) \
2318            $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$(notdir $(%(mmake)%(flavour)_C_NARCHFILES:=.o) $(%(mmake)%(flavour)_CXXFILES:=.o)))
2320 ifeq (%(nostartup),yes)
2321 # Handlers always have entry point
2322 ifneq (%(modtype),handler)
2323 %(mmake)%(flavour)_STARTOBJS        := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2324 endif
2325 endif
2327 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2328 # This breaks con-handler build. Here we work around this
2329 ifeq (%(modname),con)
2330     %(mmake)%(flavour)_ERR          := $(notdir $(%(mmake)%(flavour)_MODULE)).err
2331 else
2332     %(mmake)%(flavour)_ERR          := %(modname).err
2333 endif
2335 ifeq (%(build_library),M)
2336 # The module is linked from all the compiled .o files
2337 %rule_linkmodule module=$(%(mmake)%(flavour)_MODULE) objs="$(%(mmake)%(flavour)_STARTOBJS) $(%(mmake)%(flavour)_OBJS) $(USER_OBJS)" \
2338                  endobj=$(%(mmake)%(flavour)_ENDOBJS) err=$(%(mmake)%(flavour)_ERR) objdir="$(%(mmake)%(flavour)_OBJDIR)" \
2339                  cmd=$(%(mmake)%(flavour)_LINK) ldflags="$(LDFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LDFLAGS)" \
2340                  uselibs="$(%(mmake)%(flavour)_LIBS) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)" usehostlibs="%(usehostlibs)"
2341 endif
2343 ifeq (%(build_abi),M)
2344 # Link static lib
2345 %(mmake)%(flavour)_LC_LINKLIBNAME   := $(shell echo $(%(mmake)%(flavour)_LINKLIBNAME) | tr A-Z a-z)
2346 %(mmake)%(flavour)_LC_MODNAME       := $(shell echo %(modname) | tr A-Z a-z)
2347 ifneq ($(%(mmake)%(flavour)_LINKLIB),)
2348 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2349 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2350 %rule_link_linklib mmake=%(mmake) libname="%(modname)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2351 endif
2353 $(%(mmake)%(flavour)_LINKLIB) : | $(%(mmake)%(flavour)_LIBDIR)
2354 %rule_makedirs dirs="$(%(mmake)%(flavour)_LIBDIR)"
2355 endif
2357 ifneq ($(%(mmake)%(flavour)_RELLINKLIB),)
2358 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2359 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2360 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2361 endif
2363 $(%(mmake)%(flavour)_RELLINKLIB) : | $(%(mmake)%(flavour)_LIBDIR)
2364 %rule_makedirs dirs="$(%(mmake)%(flavour)_LIBDIR)"
2365 endif
2366 endif
2368 ifeq (%(build_library),M)
2369 # Link kernel object file
2370 %(mmake)%(flavour)_KAUTOLIB         := dos intuition layers graphics oop utility expansion keymap
2372 # Make these symbols local
2373 %(mmake)%(flavour)_KBASE            := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2374             UtilityBase ExpansionBase KeymapBase KernelBase
2376 %(mmake)%(flavour)_SYMBOLS := $(%(mmake)%(flavour)_KBASE)
2378 %(mmake)%(flavour)_KLIB             := hiddstubs amiga arossupport autoinit libinit
2379 %(mmake)%(flavour)_KOBJ_LIBS        := $(filter-out $(%(mmake)%(flavour)_KLIB),$(%(mmake)%(flavour)_LIBS)) $(%(mmake)%(flavour)_KAUTOLIB)
2380 $(%(mmake)%(flavour)_KOBJ) : LINKLIBS:=$(%(mmake)%(flavour)_KOBJ_LIBS) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)
2381 $(%(mmake)%(flavour)_KOBJ) : FILTBASES:=$(addprefix -L ,$(%(mmake)%(flavour)_SYMBOLS))
2382 $(%(mmake)%(flavour)_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2383 $(%(mmake)%(flavour)_KOBJ) : $(%(mmake)%(flavour)_OBJS) $(USER_OBJS) $(%(mmake)%(flavour)_ENDOBJS)
2384         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2385         $(Q)$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2386         $(Q)$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2387 endif
2389 ## Dependency fine-tuning
2391 %(mmake)%(flavour)_DEPS             := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$(notdir $(%(mmake)%(flavour)_CCFILES:=.d) $(%(mmake)%(flavour)_TARGETCCFILES:=.d) $(%(mmake)%(flavour)_CXXFILES:=.d))) $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$(notdir $(%(mmake)%(flavour)_LINKLIBCCFILES:=.d)))
2393 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(%(mmake)%(flavour)_DEPS)
2395 $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) : | $(%(mmake)%(flavour)_OBJDIR) $(%(mmake)%(flavour)_OBJDIR)/linklib
2396 $(%(mmake)%(flavour)_MODULE) : | %(prefix)/$(%(mmake)%(flavour)_MODDIR)
2397 $(%(mmake)%(flavour)_KOBJ)   : | $(KOBJSDIR)
2398 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR) %(prefix)/$(%(mmake)%(flavour)_MODDIR) $(KOBJSDIR)"
2400 # Some include files need to be generated before the .c can be parsed.
2401 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2403 %(mmake)%(flavour)_DFILE_DEPS := $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC) \
2404     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES))
2405 $(%(mmake)%(flavour)_DEPS) : $(%(mmake)%(flavour)_DFILE_DEPS)
2406 endif
2408 %(mmake)%(flavour)_TOCLEAN := $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) \
2409     $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_KOBJ) \
2410     $(%(mmake)%(flavour)_OBJDIR)/Makefile.%(modname)%(modtype) \
2411     $(addprefix $(%(mmake)%(flavour)_OBJDIR)/include/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2412     $(addprefix $(GENINCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2413     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2414     $(%(mmake)%(flavour)_OBJDIR)/%(modname)_geninc $(%(mmake)%(flavour)_OBJDIR)/%(modname)_incs \
2415     $(addsuffix .c,$(%(mmake)%(flavour)_LINKLIBFILES)) $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_LIBDEFSINC) \
2416     $(%(mmake)%(flavour)_DEFLIBDEFSINC) $(addsuffix .c,$(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES)) \
2417     $(%(mmake)%(flavour)_ENDOBJS)
2418 %(mmake)-clean : FILES              := $(%(mmake)%(flavour)_TOCLEAN)
2419 %(mmake)-clean ::
2420         $(Q)$(ECHO) "Cleaning up for module %(modname)"
2421         $(Q)$(RM) $(FILES)
2423 endif # $(TARGET) in $(%(mmake)%(flavour)_ALLTARGETS)
2424 %end
2425 #------------------------------------------------------------------------------
2427 #------------------------------------------------------------------------------
2428 # Build a module - ABI and library
2429 # Explanation of this macro is done in the developer's manual
2430 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2431   files="$(basename $(call WILDCARD, *.c))" \
2432   objcfiles= \
2433   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2434   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2435   objdir= moduledir= prefix=$(AROSDIR) \
2436   linklibname= uselibs= usehostlibs= \
2437   compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2438   include_set=includes-all includedir= libdir=
2440 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2441    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2442    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2443    linklibname="%(linklibname)" \
2444    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2445    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2446    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2447    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" funcinstr=%(funcinstr) lto=%(lto) \
2448    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2449    include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2450    build_abi=M build_library=M
2452 %end
2453 #------------------------------------------------------------------------------
2456 #------------------------------------------------------------------------------
2457 # Build a module skeleton ABI
2458 # This is a stripped-down version of build_module, it only creates include
2459 # files and the linklibs.
2460 # This is used when for plugins or classes with the same API, but no actual
2461 # implementation here.
2462 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2463   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2464   objdir= moduledir= prefix=$(AROSDIR) \
2465   linklibname= uselibs= usehostlibs= \
2466   compiler=target nostartup=yes archspecific=no \
2467   include_set=includes-all includedir= libdir=
2469 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2470   modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2471   linklibname="%(linklibname)" \
2472   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2473   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2474   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2475   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2476   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2477   include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2478   build_abi=M build_library=
2480 %end
2481 #------------------------------------------------------------------------------
2483 #------------------------------------------------------------------------------
2484 # Build a module library - no includes nor linklibs
2485 # Explanation of this macro is done in the developer's manual
2486 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2487   files="$(basename $(call WILDCARD, *.c))" \
2488   objcfiles= \
2489   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2490   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags="$(CXXFLAGS)" dxxflags= \
2491   objdir= moduledir= prefix=$(AROSDIR) \
2492   uselibs= usehostlibs= \
2493   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2494   include_set=includes-all includedir= libdir=
2496 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2497    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2498    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2499    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2500    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2501    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2502    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2503    include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2504    build_abi= build_library=M
2506 %end
2507 #------------------------------------------------------------------------------
2511 #------------------------------------------------------------------------------
2512 # Build a linklib.
2513 # - mmake is the mmaketarget
2514 # - libname is the baselibname e.g. lib%(libname).a will be created
2515 # - files are the C source files to include in the lib. The list of files
2516 #   has to be given without the .c suffix
2517 # - cxxfiles are C++ source files without suffix.
2518 #   NB: files will be matched in the order .cpp > .cxx > .cc
2519 # - asmfiles are the asm files to include in the lib. The list of files has to
2520 #   be given without the .s suffix
2521 # - objs additional object to link into the linklib. The objects have to be
2522 #   given with full absolute path and the .o suffix.
2523 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2524 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2525 # - cflags are the flags to compile the source (default $(CFLAGS))
2526 # - dflags are the flags used during makedepend (default equal to cflags)
2527 # - aflags are the flags used during assembling (default $(AFLAGS))
2528 %define build_linklib mmake=/A libname=/A files= objcfiles= cxxfiles= \
2529   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2530   includedir= \
2531   cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2532   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO) usetree=no
2534 # assign and generate the local variables used in this macro
2535 %(mmake)_LIBNAME           := %(libname)
2536 %(mmake)_LINKLIB           := %(libdir)/lib%(libname).a
2538 %(mmake)_FILES             ?= %(files)
2539 %(mmake)_ASMFILES          := %(asmfiles)
2540 %(mmake)_OBJCFILES         := %(objcfiles)
2541 %(mmake)_CXXFILES          := %(cxxfiles)
2543 %(mmake)_OBJDIR            ?= %(objdir)
2544 %(mmake)_ARCHOBJS          := $(wildcard $(%(mmake)_OBJDIR)/arch/*.o)
2545 ifeq (%(usetree),no)
2546     %(mmake)_ARCHFILES     := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
2547 else
2548     %(mmake)_ARCHFILES     := $(basename $(patsubst $(%(mmake)_OBJDIR)/%,%,$(%(mmake)_ARCHOBJS)))
2549 endif
2550 %(mmake)_C_NARCHFILES      := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_FILES))
2551 %(mmake)_C_FILES           ?= $(%(mmake)_C_NARCHFILES)
2552 %(mmake)_CXX_NARCHFILES    := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_CXXFILES))
2553 %(mmake)_CXX_FILES         ?= $(%(mmake)_CXX_NARCHFILES)
2554 %(mmake)_OBJC_NARCHFILES   := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_OBJCFILES))
2555 %(mmake)_OBJC_FILES        ?= $(%(mmake)_OBJC_NARCHFILES)
2557 ifeq (%(usetree),no)
2558     %(mmake)_OBJ_FILES     ?= $(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(%(mmake)_C_NARCHFILES:=.o) $(%(mmake)_CXX_NARCHFILES:=.o) $(%(mmake)_ASMFILES:=.o) $(%(mmake)_OBJC_NARCHFILES:=.o)))
2559 else
2560     %(mmake)_OBJ_FILES     ?= $(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_C_NARCHFILES:=.o) $(%(mmake)_CXX_NARCHFILES:=.o) $(%(mmake)_ASMFILES:=.o) $(%(mmake)_OBJC_NARCHFILES:=.o))
2561 endif
2562 %(mmake)_OBJS              ?= $(%(mmake)_ARCHOBJS) $(%(mmake)_OBJ_FILES) %(objs)
2563 %(mmake)_DEPS              := $(patsubst %.o,%.d,$(%(mmake)_OBJS))
2565 %(mmake)_CPPFLAGS          := %(cppflags)
2566 ifneq (%(includedir),)
2567     %(mmake)_CPPFLAGS      += -I%(includedir)
2568 endif
2569 %(mmake)_CFLAGS            := %(cflags)
2570 %(mmake)_CXXFLAGS          := %(cxxflags)
2571 ifeq (%(lto),yes)
2572 ifeq (%(compiler),target)
2573         %(mmake)_CFLAGS    := $(strip $(LTO_CFLAGS) $(%(mmake)_CFLAGS))
2574         %(mmake)_CXXFLAGS  := $(strip $(LTO_CFLAGS) $(%(mmake)_CXXFLAGS))
2575 endif
2576 endif
2577 %(mmake)_AFLAGS            := %(aflags)
2578 %(mmake)_DFLAGS            := %(dflags)
2579 ifneq (%(dflags),)
2580     %(mmake)_DFLAGS        := %(dflags)
2581 else
2582     %(mmake)_DFLAGS        := $(%(mmake)_CFLAGS)
2583 endif
2584 %(mmake)_DXXFLAGS          := %(dxxflags)
2585 ifneq (%(dxxflags),)
2586     %(mmake)_DXXFLAGS      := %(dxxflags)
2587 else
2588     %(mmake)_DXXFLAGS      := $(%(mmake)_CXXFLAGS)
2589 endif
2591 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2594 %(mmake)-quick : %(mmake)
2596 #MM %(mmake) : includes-generate-deps
2597 %(mmake) : $(%(mmake)_LINKLIB)
2599 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2601 %rule_compile_cxx_multi mmake=%(mmake) \
2602     basenames=$(%(mmake)_CXX_FILES) targetdir="$(%(mmake)_OBJDIR)" \
2603     cppflags=$(%(mmake)_CPPFLAGS) cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
2604     compiler="%(compiler)"
2605 %rule_compile_objc_multi mmake=%(mmake) \
2606     basenames=$(%(mmake)_OBJC_FILES) targetdir=$(%(mmake)_OBJDIR) \
2607     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2608     compiler="%(compiler)"
2609 %rule_compile_multi mmake=%(mmake) \
2610     basenames=$(%(mmake)_C_FILES) targetdir="$(%(mmake)_OBJDIR)" \
2611     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2612     compiler="%(compiler)"
2613 %rule_assemble basename=% targetdir="$(%(mmake)_OBJDIR)" \
2614     aflags=$(%(mmake)_AFLAGS)
2616 %rule_link_linklib mmake=%(mmake) libname="%(libname)" objs=$(%(mmake)_OBJS) libdir="%(libdir)" linker="%(compiler)"
2617 endif
2619 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
2621 $(%(mmake)_OBJS) $(%(mmake)_DEPS) : | $(%(mmake)_OBJDIR)
2622 $(%(mmake)_LINKLIB) : | %(libdir)
2623 %rule_makedirs dirs="$(%(mmake)_OBJDIR) %(libdir)"
2625 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_LINKLIB) $(%(mmake)_DEPS)
2627 %(mmake)-clean ::
2628         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
2629         $(Q)$(RM) $(FILES)
2631 %end
2632 #------------------------------------------------------------------------------
2635 #------------------------------------------------------------------------------
2636 # Build catalogs.
2637 # - mmake is the mmaketarget
2638 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2639 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2640 # - subdir is the destination subdirectory of the catalogs
2641 # - name is the name of the destination catalog, without the .catalog suffix
2642 # - source is the path to the generated source code file
2643 # - dir is the base destination directory (default $(AROS_CATALOGS))
2644 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2645 # - srcdir is the directory in which the *.cd and *.ct files are searched
2647 %define build_catalogs mmake=/A name=/A subdir=/A \
2648  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2649  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2651 ifeq (%(description),)
2652 %(mmake)_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2653 else
2654 %(mmake)_DESC := %(description)
2655 endif
2657 %(mmake)_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2659 ifeq (%(catalogs),)
2660 %(mmake)_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2661 else
2662 %(mmake)_LNGS := %(catalogs)
2663 endif
2665 %(mmake)_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(%(mmake)_LNGS)))
2666 %(mmake)_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(%(mmake)_LNGS))) $(dir %(source))
2669 %(mmake) : $(%(mmake)_OBJS) %(source)
2671 $(%(mmake)_OBJS) : | $(%(mmake)_DIRS)
2672 %rule_makedirs dirs="$(%(mmake)_DIRS)"
2674 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(%(mmake)_DESC).cd
2675         $(Q)$(ECHO) "Creating   %(name) catalog for language $*."
2676         $(Q)$(FLEXCAT) $(%(mmake)_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2678 ifneq (%(source),)
2679 %(source) : %(mmake)_DESC := $(%(mmake)_DESC)
2680 %(source) : %(mmake)_SRC := $(%(mmake)_SRC)
2681 %(source) : $(%(mmake)_DESC).cd $(%(mmake)_SRC).sd | $(dir %(source))
2682         $(Q)$(ECHO) "Creating   %(name) catalog source file $@"
2683         $(Q)$(FLEXCAT) $(%(mmake)_DESC).cd $@=$(%(mmake)_SRC).sd
2684 endif
2686 %(mmake)-clean : FILES := $(%(mmake)_OBJS) %(source)
2688 %(mmake)-clean ::
2689         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
2690         $(Q)$(RM) $(FILES)
2692 .PHONY: %(mmake) %(mmake)-clean
2694 %end
2695 #-----------------------------------------------------------------------------
2698 #-----------------------------------------------------------------------------
2699 # Build icons.
2700 # - mmake is the mmaketarget
2701 # - icons is a list of icon base names (i.e. without the .info suffix)
2702 # - dir is the destination directory
2703 # - srcdir is where *.png and *.info.src are sought
2704 #-----------------------------------------------------------------------------
2706 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2708 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2711 %(mmake) : $(BD_OBJS)
2713 ifeq (%(image),)
2715 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2716         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2717         $(Q)$(ILBMTOICON) $+ $@
2719 else
2721 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2722         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2723         $(Q)$(ILBMTOICON) $+ $@
2725 endif
2727 $(BD_OBJS) : | %(dir)
2728 %rule_makedirs dirs="%(dir)"
2730 %(mmake)-clean : FILES := $(BD_OBJS)
2732 %(mmake)-clean ::
2733         $(Q)$(RM) $(FILES)
2735 .PHONY: %(mmake) %(mmake)-clean
2737 %end
2738 #-----------------------------------------------------------------------------
2741 #------------------------------------------------------------------------------
2742 # Compile files for an arch-specific replacement of code for a module
2743 # - files: the basenames of the C files to compile.
2744 # - asmfiles: the basenames of the asm files to assemble.
2745 # - mainmmake: the mmake of the module in the main directory to compile these
2746 #   arch specific files for.
2747 # - maindir: the object directory for the main module
2748 # - arch: the arch for which to compile these files. It can have the form
2749 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2750 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2751 # - dflags: the flags used during creation of dependency file. If not specified
2752 #   the same value as cflags will be used
2753 # - aflags: the flags used during assembling
2754 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2755 #   the target compiler is used
2756 # - modname: arch_specific builds of modules (built using build_module) MUST
2757 #   specify the name here matching the original module. this insures multiple modules
2758 #   built from the same makefile will not pollute each other.
2759 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2760  cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target objdir= modname=
2762 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2763     $(error no files or asmfiles given)
2764 endif
2766 ifneq (%(cxxfiles),)
2767     $(error cxx support is TODO)
2768 endif
2770 %buildid targets="%(mainmmake)-%(arch)"
2772 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2773 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2774 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2775 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2776 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2777 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2778 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2779 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2780 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2781 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2782 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2783 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2784 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2785 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2786 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2788 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2790 ifneq (%(objdir),)
2791     BD_OBJROOT$(BDID)  := %(objdir)
2792 else
2793 ifneq (%(modname),)
2794     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)/%(modname)
2795 else
2796     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)
2797 endif
2798 endif
2799 BD_OBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/arch
2800 BD_LIBOBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/linklib/arch
2801 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2802 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2803 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2804 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2805 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2806 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2808 ifneq (%(modname),)
2809 BD_DEFLIBDEFSINC$(BDID) := -include $(BD_OBJROOT$(BDID))/include/%(modname)_deflibdefs.h
2810 endif
2812 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2813     BD_TARGET := %(mainmmake)-%(arch)-quick
2814 else
2815     BD_TARGET := %(mainmmake)-%(arch)
2816 endif
2819 ifeq ($(TARGET),$(BD_TARGET))
2820 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2821 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2822 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2823 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2824 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2825 endif
2827 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2828 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))"
2831 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2834 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2836 ifeq ($(findstring %(compiler),host kernel target),)
2837     $(error unknown compiler %(compiler))
2838 endif
2839 ifneq (%(modname),)
2840 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) -I$(BD_OBJROOT$(BDID)) $(BD_DEFLIBDEFSINC$(BDID)))
2841 else
2842 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2843 endif
2844 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2845 ifeq (%(compiler),target)
2846 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
2847 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
2848 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(TMP_CFLAGS) $(SAFETY_CFLAGS))
2849 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2850 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2851 endif
2852 ifeq (%(compiler),host)
2853 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2854 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2855 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2856 endif
2857 ifeq (%(compiler),kernel)
2858 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
2859 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip $(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS))
2860 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(TMP_CFLAGS))
2861 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2862 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2863 endif
2865 ifeq ($(TARGET),$(BD_TARGET))
2866 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2867         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2868 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2869         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2870 endif
2872 ifeq (%(dflags),)
2873 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) $(BD_DEFLIBDEFSINC$(BDID)))
2874 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
2875 else
2876 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2877 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2878 endif
2879 ifeq ($(TARGET),$(BD_TARGET))
2880 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2881         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2883 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2884         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2885 endif
2887 $(BD_ASMOBJS$(BDID)) : CPPFLAGS:=%(cppflags)
2888 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2890 ifeq ($(TARGET),$(BD_TARGET))
2891 $(BD_OBJDIR$(BDID))/%.o : %.s
2892         %assemble_q
2893 $(BD_OBJDIR$(BDID))/%.o : %.S
2894         %assemble_q
2895 endif
2897 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2898 %end
2899 #------------------------------------------------------------------------------
2902 #------------------------------------------------------------------------------
2903 # generate asm files from c files (for debugging purposes)
2904 %define ctoasm_q
2905 %.s : %.c
2906         $(Q)$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2907         $(Q)$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2908 %end
2909 #------------------------------------------------------------------------------
2912 #------------------------------------------------------------------------------
2913 # Copy files from one directory to another.
2915 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2917 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2919 %rule_makedirs dirs="%(dst)"
2921 .PHONY : %(mmake)
2924 %(mmake) : | %(dst) 
2925         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2927 %end
2928 #------------------------------------------------------------------------------
2931 #------------------------------------------------------------------------------
2932 # Copy a directory recursively to another place, preserving the original 
2933 # hierarchical structure
2935 # src: the source directory whose content will be copied.
2936 # dst: the directories where to copy src's content. If not existing, they will be made.
2937 # excludefiles: files which must not be copied. Path must be relative to src.
2939 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2941 .PHONY : %(mmake)
2944 %(mmake) :
2945         $(Q)cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2947 %end
2948 #------------------------------------------------------------------------------
2951 #------------------------------------------------------------------------------
2952 #   Copy include files into the includes directories. There are currently
2953 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2954 #   for building tools that need to run on the host system $(GENINCDIR). The
2955 #   $(GENINCDIR) path must not contain any references to the C runtime
2956 #   library header files.
2958 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2959     dir= compiler=target includedir=$(AROS_INCLUDES)
2961 ifeq ($(findstring %(compiler),host kernel target),)
2962 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2963 endif
2965 ifneq (%(dir),)
2966 TMP_DIR := %(dir)
2967 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2968 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2969 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2970 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2971 ifeq ($(TMP_DIRFIRST),/)
2972 BD_INC_PATH := %(dir)/
2973 else
2974 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2975 endif
2976 else
2977 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2978 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2979 endif
2981 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2982         $(Q)$(CP) $< $@
2984 ifeq (%(compiler),target)
2986 ifneq (%(dir),)
2987 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2988 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2989 else
2990 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2991 endif
2993 BD_INCL_FILES += $(BD_INCL_FILES2)
2995 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2996         $(Q)$(CP) $< $@
2997 endif
3000 %(mmake) : $(BD_INCL_FILES)
3002 .PHONY: %(mmake)
3004 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
3005 %rule_makedirs dirs="$(dir $(BD_INCL_FILES))"
3006 %end
3007 #------------------------------------------------------------------------------
3010 #------------------------------------------------------------------------------
3011 %define make_hidd_stubs hidd=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
3012 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
3013 STUBS_MEM := $(addsuffix .o,$(STUBS))
3014 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
3015 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
3016 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
3018 #MM- linklibs : hidd-%(hidd)-stubs
3019 #MM- %(parenttarget): hidd-%(hidd)-stubs
3020 #MM hidd-%(hidd)-stubs : includes includes-copy
3021 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
3023 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
3024         %mklib_q from=$^
3026 $(STUBS_OBJ) : $(STUBS_SRC) 
3027         %compile_q cmd="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" opt="$(strip %(cflags) %(cppflags))" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
3029 $(STUBS_DEP) : $(STUBS_SRC)
3030         %mkdepend_q flags="$(strip %(dflags) %(cppflags))"
3032 setup ::
3033         %mkdirs_q $(OBJDIR) $(AROS_LIB)
3036 clean ::
3037         -@$(RM) $(HIDD_LIB) $(OBJDIR)
3039 DEPS := $(DEPS) $(STUBS_DEP)
3041 %end
3042 #------------------------------------------------------------------------------
3045 #------------------------------------------------------------------------------
3046 # Build an imported source tree which uses the configure script from the
3047 # autoconf package.  This rule will try to "integrate" the produced files as
3048 # much as possible in the AROS build, for example by putting libraries in the
3049 # standard library directory, includes in the standard include directory, and
3050 # so on. You can however override this behaviour.
3052 # As a special "bonus" for you, the PROGDIR environment variable is defined to
3053 # be %(bindir) (or its deduced value) when running "make install", and
3054 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
3055 # configure script some more parameters whose value depends upon the PROGDIR
3056 # env var, so that the program gets all its stuff installed in the proper place
3057 # when building it, but when running it from inside AROS it can also find that
3058 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
3059 # the configuration parameters set when running ./configure
3061 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
3062 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
3063 # to the name which has to follow it.
3065 # Arguments:
3067 #     - mmake           = the meta make target.
3068 #     - package         = name of the package to be built.
3069 #     - srcdir          = the location of the unpacked source code. Defaults
3070 #                         to $(SRCDIR)/$(CURDIR).
3071 #     - prefix          = the target directory. Must be an absolute path of the
3072 #                         host system. Defaults to $(AROS_CONTRIB).
3073 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3074 #                         Defaults to the value of the prefix option.
3075 #     - extraoptions    = additional options for the configure script.
3076 #     - usecppflags      = enable the use of cpp flags. some external configure
3077 #                         scripts will not set their own cppflags if it is already
3078 #                         set, so this allows them to be disabled (unless you can provide
3079 #                         all the options they would need)
3080 #     - extracppflags      = additional preprocessor flags.
3081 #     - extracflags     = additional flags to use with the C compiler.
3082 #     - extracxxflags   = additional flags to use with the C++ compiler.
3083 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
3084 #                         Defaults to the value of the nix argument.
3085 #     - nix             = enable u*nix path handling, i.e. a path like
3086 #                         /progdir//./file will be translated to
3087 #                         progdir:file during run-time. Defaults to no.
3088 #     - compiler        = target, host or kernel. Defaults to target.
3089 #     - install_target  = the command used for installing. Defaults to install. Leave
3090 #                         it empty if you want to suppress installing.
3091 #     - preconfigure    = a metatarget which is executed before configure is called.
3092 #     - postconfigure   = a metatarget which is executed after configure is called.
3093 #     - postinstall     = a metatarget which is executed after installing.
3094 #     - install_env     = set additional options for installing.
3095 #     - use_build_env   = if yes the configuration environment is used for
3096 #                         installing, too. Defaults to no.
3098 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
3099 # like this:
3101 # if nix_dir_layout
3102 #    --prefix = $(aros_prefix)
3103 #    progdir = $(aros_prefix)/bin
3104 # else
3105 #    if nix
3106 #        --prefix = /PROGDIR
3107 #        --bindir = /PROGDIR
3108 #        --sbindir = /PROGDIR
3109 #        --libdir = /LIB
3110 #        --includedir = /INCLUDE
3111 #        --oldincludedir = /INCLUDE   
3112 #    else
3113 #        --prefix = $(aros_prefix)
3114 #    endif
3116 #    progdir = $(aros_prefix)
3118 #    # Install options
3119 #    bindir = $(prefix)
3120 #    sbindir = $(prefix)
3121 #    libdir = $(AROS_LIB)
3122 #    includedir = $(AROS_INCLUDES)
3123 #    oldincludedir = $(AROS_INCLUDES)
3124 # endif
3127 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
3128     prefix= gendir= basedir=$(CURDIR) extraoptions= \
3129     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3130     hostisaflags="$(TARGET_ISA_CFLAGS)" targetisaflags="$(TARGET_ISA_CFLAGS)" \
3131     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
3132     install_target=install preconfigure= postconfigure= postinstall= \
3133     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes nlsflag=yes xflag=yes
3135 ifneq (%(prefix),)
3136     %(mmake)-prefix := %(prefix)
3137 else
3138     %(mmake)-prefix := $(AROS_CONTRIB)
3139 endif
3141 ifneq (%(aros_prefix),)
3142     %(mmake)-aros_prefix := %(aros_prefix)
3143 else
3144     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3145 endif
3147 BD_NIXFLAG ?= -nix
3149 ifeq (%(nix),yes)
3150     %(mmake)-nix    := $(BD_NIXFLAG)
3151     %(mmake)-volpfx := /
3152     %(mmake)-volsfx := /
3153     
3154     ifeq (%(nix_dir_layout),)
3155         %(mmake)-nix_dir_layout := yes
3156     endif
3157 else
3158     %(mmake)-volsfx := :
3159     
3160     ifeq (%(nix_dir_layout),)
3161         %(mmake)-nix_dir_layout := no
3162     endif
3163 endif
3165 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
3167 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
3168         exec_prefix=$(%(mmake)-prefix) %(install_env)
3170 # Check if chosen compiler is valid
3171 ifeq ($(findstring %(compiler),host target kernel),)
3172   $(error unknown compiler %(compiler))
3173 endif
3175 # Set legacy 'host' variable based on chosen compiler
3176 ifeq (%(compiler),host)
3177     host := yes
3178     ifeq (%(basedir),)
3179         %(mmake)-pkgbasedir := $(HOSTGENDIR)
3180     else
3181         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
3182     endif
3183 else
3184     host := no
3185     ifeq (%(basedir),)
3186         %(mmake)-pkgbasedir := $(GENDIR)
3187     else
3188         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
3189     endif
3190 endif
3191 ifneq (%(gendir),)
3192     ifeq (%(basedir),)
3193         %(mmake)-pkgbasedir := %(gendir)
3194     else
3195         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
3196     endif
3197 endif
3199 ifeq (%(package),)
3200     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
3201 else
3202     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
3203 endif
3205 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
3206 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3208 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
3209     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
3210     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3211 else
3212     ifeq (%(nix),yes)
3213         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
3214         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
3215     else
3216         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3217     endif
3219     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
3220     
3221     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
3222         sbindir=$(%(mmake)-prefix) \
3223         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
3224         oldincludedir=$(AROS_INCLUDES) %(install_env)
3225 endif
3227 ifneq ($(DEBUG),yes)
3228     %(mmake)-s_flag = -s
3229 endif
3231 # Set up build environment, and options for configure script
3232 ifeq (%(compiler),host)
3233     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
3234     # confused configure scripts. We also cannot pass it via _FOR_BUILD
3235     # since that won't get picked up during configure.
3236     # We also cannot pass in the compiler including std flags so we need to use
3237     # the "plain" host compiler.
3238     %(mmake)-cfg-env := %(config_env_extra) \
3239         CPP="$(HOST_CPP)" \
3240         CXXCPP="$(HOST_CPP)" \
3241         CC="$(strip $(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3242         CXX="$(strip $(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3243         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)"
3244 ifeq (%(usecppflags),yes)
3245     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3246 endif
3247     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3248         TARGET_CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3249         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3250         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3251         TARGET_AS="$(TARGET_AS)" \
3252         OBJCOPY="$(OBJCOPY)" \
3253         TARGET_RANLIB="$(RANLIB)" \
3254         TARGET_STRIP="$(STRIP_PLAIN)" \
3255         TARGET_NM="$(NM_PLAIN)" \
3256         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
3257 endif
3258 ifeq (%(compiler),target)
3259     %(mmake)-cfg-env := %(config_env_extra) \
3260         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
3261         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
3262     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3263         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3264         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3265         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3266         LD="$(strip $(TARGET_LD))"
3267 ifeq (%(crossbuild),yes)
3268     %(mmake)-cfg-env += CFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3269         CXXFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3270 ifeq (%(usecppflags),yes)
3271     %(mmake)-cfg-env += CPPFLAGS="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3272 endif
3273 else
3274     %(mmake)-cfg-env += CFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3275         CXXFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3276 ifeq (%(usecppflags),yes)
3277     %(mmake)-cfg-env += CPPFLAGS="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3278 endif
3279 endif
3280     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3281 ifeq (%(usecppflags),yes)
3282     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3283 endif
3284     %(mmake)-cfg-env += CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
3285         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
3286         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
3287         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
3288         LD_FOR_BUILD="$(strip $(HOST_LD))" \
3289         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))"
3290 ifeq (%(usecppflags),yes)
3291     %(mmake)-cfg-env += CPPFLAGS_FOR_HOST="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3292 endif
3293     %(mmake)-cfg-env += CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3294         CFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3295         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3296         CXXFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3297         LD_FOR_HOST="$(strip $(TARGET_LD))" \
3298         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3299 ifeq (%(usecppflags),yes)
3300     %(mmake)-cfg-env += CPPFLAGS_FOR_TARGET="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3301 endif
3302     %(mmake)-cfg-env += CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3303         CFLAGS_FOR_TARGET="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3304         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3305         CXXFLAGS_FOR_TARGET="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3306         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3307         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3308         AR="$(strip $(AR_PLAIN))" \
3309         AS="$(strip $(TARGET_AS))" \
3310         OBJCOPY="$(strip $(OBJCOPY))" \
3311         RANLIB="$(strip $(RANLIB))" \
3312         STRIP="$(strip $(STRIP_PLAIN))"
3313 ifeq (%(usecppflags),yes)
3314     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3315 endif
3316     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3317         TARGET_CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3318         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3319         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3320         TARGET_AS="$(strip $(TARGET_AS))" \
3321         TARGET_RANLIB="$(strip $(RANLIB))" \
3322         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3323         TARGET_NM="$(strip $(NM_PLAIN))"
3324 ifeq (%(buildflags),yes)
3325     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3326     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3327     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3328 endif
3329 ifeq (%(gnuflags),yes)
3330     %(mmake)-config_opts += --without-pic --disable-shared
3331 ifeq (%(nlsflag),yes)
3332 # disable native language support
3333     %(mmake)-config_opts += --disable-nls
3334 endif
3335 ifeq (%(xflag),yes)
3336 # disable X window system
3337     %(mmake)-config_opts += --without-x
3338 endif
3339 endif
3340 endif
3341 ifeq (%(compiler),kernel)
3342     %(mmake)-cfg-env := %(config_env_extra) \
3343         CPP="$(KERNEL_CPP)" \
3344         CXXCPP="$(KERNEL_CPP)"
3345 ifeq (%(usecppflags),yes)
3346     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3347 endif
3348     %(mmake)-cfg-env += CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3349         CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3350         CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3351         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))" \
3352         AS="$(KERNEL_AS)"
3353 ifeq (%(usecppflags),yes)
3354     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3355 endif
3356     %(mmake)-cfg-env += CC_FOR_BUILD="$(HOST_DEF_CC)" \
3357         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3358         CXX_FOR_BUILD="$(HOST_CXX)" \
3359         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3360         RANLIB="$(RANLIB)" \
3361         TARGET_RANLIB="$(RANLIB)" \
3362         TARGET_STRIP="$(STRIP_PLAIN)" \
3363         TARGET_NM="$(NM_PLAIN)"
3364 ifeq (%(buildflags),yes)
3365     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3366     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3367     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3368 endif
3369 ifeq (%(gnuflags),yes)
3370     %(mmake)-config_opts += --without-pic --disable-shared
3371 ifeq (%(nlsflag),yes)
3372 # disable native language support
3373     %(mmake)-config_opts += --disable-nls
3374 endif
3375 ifeq (%(xflag),yes)
3376 # disable X window system
3377     %(mmake)-config_opts += --without-x
3378 endif
3380 endif
3381 endif
3383 ifeq (%(use_build_env),yes)
3384     BUILD_ENV := $(%(mmake)-cfg-env)
3385 endif
3387 %(mmake)-touchfileflag ?= $(%(mmake)-pkgdir)/.files-touched
3389 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3390 # in an ideal world, we would depend on the files in the source directory,
3391 # so we could copy them when they change. unfortunately filenames with
3392 # spaces cause problems with this
3393 $(%(mmake)-pkgdir)/.local-copy:
3394         %mkdirs_q $(%(mmake)-pkgdir)
3395         $(Q)$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3396         $(Q)$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3398 $(%(mmake)-touchfileflag) : $(%(mmake)-pkgdir)/.local-copy
3400     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3401 else
3402     %(mmake)-cfg-srcdir=%(srcdir)
3403 endif
3404 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3406 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3408 # When building for the host, we don't need to build the
3409 # linklibs - this is especially true when building the
3410 # crosstool toolchain on 'foreign' architectures (such as
3411 # building PPC on x86)
3413 #MM- %(mmake)-host : setup includes %(mmake)-quick
3414 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3415 #MM- %(mmake): %(mmake)-%(compiler)
3417 # Using -j1 in install_command may result in a warning but finally
3418 # it does its job. make install for gcc does not work reliably for -jN
3419 # where N > 1.
3420 ifneq (%(install_target),)
3421     %(mmake)-install_command = \
3422         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3423         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3424         $(%(mmake)-make-env) %(install_target) -j1
3426     %(mmake)-uninstall_command = \
3427     $(RM) $(%(mmake)-installflag) && \
3428     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3429     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3430 else
3431     %(mmake)-install_command   := true
3432     %(mmake)-uninstall_command := true
3433 endif
3435 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3438 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3441 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3443 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3444         $(Q)$(IF) ! $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3445             $(RM) $(%(mmake)-installflag) && \
3446             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3447             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3448             $(%(mmake)-install_command) && \
3449             $(TOUCH) $@ -r $^; \
3450         fi
3452 ifneq ($(%(mmake)-touchfileflag),)
3453 $(%(mmake)-touchfileflag):
3454         %mkdirs_q $(%(mmake)-pkgdir)
3455         $(Q)find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3456         $(TOUCH) $@
3457 endif
3460 %(mmake)-uninstall :
3461         $(%(mmake)-uninstall_command)
3464 %(mmake)-configure : $(%(mmake)-configflag)
3466 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3467 $(%(mmake)-configflag) : $(%(mmake)-touchfileflag) $(TOP)/$(CURDIR)/mmakefile
3468         $(Q)$(RM) $@
3469         %mkdirs_q $(%(mmake)-pkgdir)
3470         $(Q)$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3471         $(Q)cd $(%(mmake)-pkgdir) && \
3472         find . -name config.cache -exec $(RM) '{}' \; && \
3473         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3474         $(TOUCH) $@
3477 %(mmake)-clean : %(mmake)-uninstall
3478         $(Q)$(RM) $(%(mmake)-pkgdir)
3479 %end
3480 #------------------------------------------------------------------------------
3483 #------------------------------------------------------------------------------
3484 # Build an imported source tree which uses cmake 
3486 # Arguments:
3488 #     - mmake           = the meta make target.
3489 #     - package         = name of the package to be built.
3490 #     - srcdir          = the location of the unpacked source code. Defaults
3491 #                         to $(SRCDIR)/$(CURDIR).
3492 #     - prefix          = the target directory. Must be an absolute path of the
3493 #                         host system. Defaults to $(AROS_CONTRIB).
3494 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3495 #                         Defaults to the value of the prefix option.
3496 #     - extraoptions    = additional options for the cmake script.
3497 #     - usecppflags     = enable the use of cpp flags. some external cmake
3498 #                         scripts will not set their own cppflags if it is already
3499 #                         set, so this allows them to be disabled (unless you can provide
3500 #                         all the options they would need)
3501 #     - cppflags        = preprocessor flags.
3502 #     - cflags          = flags to use with the C compiler.
3503 #     - cxxflags        = flags to use with the C++ compiler.
3504 #     - installoptions    = additional options for the install step.
3507 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3508     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3509     usecppflags=yes cppflags=$(CPPFLAGS) cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3511 ifneq (%(prefix),)
3512     %(mmake)-prefix := %(prefix)
3513 else
3514     %(mmake)-prefix := $(AROS_CONTRIB)
3515 endif
3517 ifneq (%(aros_prefix),)
3518     %(mmake)-aros_prefix := %(aros_prefix)
3519 else
3520     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3521 endif
3523 ifeq (%(compiler),host)
3524     BD_LDFLAGS   := $(strip -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS))
3525     BD_CFLAGS := $(strip $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include)
3526     BD_CXXFLAGS := $(strip $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include)
3527     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3528     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)"
3529     ifeq (%(usecppflags),yes)
3530         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3531     endif
3532     %(mmake)-cmake_opts += -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3533     ifeq (%(package),)
3534         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3535     else
3536         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3537     endif
3538 else
3539     BD_LDFLAGS   := %(ldflags)
3540     BD_CFLAGS := %(cflags) 
3541     BD_CXXFLAGS := %(cxxflags)
3542     BD_CPPFLAGS := %(cppflags)
3543     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3544     ifeq (%(usecppflags),yes)
3545         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3546     endif
3547     %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))" -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3548     ifeq (%(package),)
3549         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3550     else
3551         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3552     endif
3553 endif
3554 ifneq (%(gendir),)
3555     ifeq (%(package),)
3556         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3557     else
3558         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3559     endif
3560 endif
3562 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3563 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3565 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3567 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3569 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3572 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3574 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3575         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3576             $(RM)  $(%(mmake)-installflag) && \
3577             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3578             cd $(%(mmake)-pkgdir) && \
3579             cmake %(installoptions) -P cmake_install.cmake && \
3580             $(TOUCH) $@ -r $^; \
3581         fi
3583 %(mmake)-touchfileflag ?= $(%(mmake)-pkgdir)/.files-touched
3584 ifneq ($(%(mmake)-touchfileflag),)
3585 $(%(mmake)-touchfileflag):
3586         %mkdirs_q $(%(mmake)-pkgdir)
3587         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3588         $(TOUCH) $@
3589 endif
3592 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3594 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3595 $(%(mmake)-cmakeflag) : $(%(mmake)-touchfileflag) $(TOP)/$(CURDIR)/mmakefile
3596         $(RM) $@
3597         %mkdirs_q $(%(mmake)-pkgdir)
3598         cd $(%(mmake)-pkgdir) && \
3599         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3600         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3601         $(TOUCH) $@
3604 %(mmake)-clean : %(mmake)-uninstall
3605         $(Q)$(RM) $(%(mmake)-pkgdir)
3606 %end
3607 #------------------------------------------------------------------------------
3610 #------------------------------------------------------------------------------
3611 # Given an archive name, patches names and locations where to find them, fetch
3612 # the archive and the patches from any of those locations, unpack the archive
3613 # and then apply the patches.
3615 # Locations currently supported are http and ftp sites, plus local filesystem
3616 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3617 # the fetch.sh script needs to be modified, since this macro relies on that script.
3619 # Arguments:
3621 #     - mmake           = mmaketarget
3622 #     - archive_origins = list of locations where to find the archive. They are tried
3623 #                         in sequence, until the archive is found and fetching it 
3624 #                         succeeded. If not specified, the current directory is assumed.
3625 #     - archive         = the archive name. Mandatory.
3626 #     - suffixes        = a list of suffixes to append to the package name plus the
3627 #                         version. Each one of them is tried until a matching archive is
3628 #                         found. They are appended to patches and these are tried the
3629 #                         same way as packages are.
3630 #     - location        = the local directory where to put the fetched archive and patches.
3631 #                         If not specified, the directory specified by destination is used.
3632 #     - destination     = the directory to unpack the archive to.
3633 #                         If not specified, the current directory is assumed.
3634 #     - patches_origins = list of locations where to find the patches. They are tried
3635 #                         in sequence, until a patch is found and fetching it 
3636 #                         succeeded. If not specified, the current directory is assumed.
3637 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3638 #                         patch_name[:[patch_subdir][:patch_opt]].
3640 #                             - patch_name   = the name of the patch file
3641 #                             - patch_subdir = the directory within \destination\ where to
3642 #                                              apply the patch.
3643 #                             - patch_opt    = any options to pass to the `patch' command
3644 #                                              when applying the patch.
3645 #                         
3646 #                         The patch_subdir and patch_opt fields are optional.
3648 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3649     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3651 .PHONY: %(mmake)
3653 ifneq (%(location),)
3654     %(mmake)-location := %(location)
3655 else
3656     %(mmake)-location := %(destination)
3657 endif
3660 %(mmake) :
3661         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3662         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3663 %end
3664 #------------------------------------------------------------------------------
3667 #------------------------------------------------------------------------------
3668 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3669 # unpatched source tree and runs diff against this and a previously fetched and possibly
3670 # patched tree. Depending on what happens after patching during a normal build it might
3671 # give best results if the new patch is created directly after fetch.
3673 # Arguments:
3675 #     - mmake       = mmaketarget
3676 #     - archive     = archive base name
3677 #     - srcdir      = the top level directory the package is unpacked to, useful if
3678 #                     an archive unpacks to a directory other than its name suggests.
3679 #                     this should not be deeper than a single path element.
3680 #     - suffixes    = a list of suffixes to append to the the package name plus the
3681 #                     version. Each one of them is tried until a matching archive is
3682 #                     found.
3683 #     - destination = the directory to unpack the archive to.
3684 #     - excludes    = diff patterns to exclude files or directories from the patch
3686 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3688 .PHONY: %(mmake)
3690 ifneq (%(excludes),)
3691     %(mmake)-exclude := -X ./exclude.patterns
3692 endif
3694 ifneq (%(srcdir),)
3695     %(mmake)-srcdir := %(srcdir)
3696 else
3697     %(mmake)-srcdir := %(archive)
3698 endif
3700 #MM- %(mmake) : %(mmake)-diff
3701 #MM- %(mmake)-quick : %(mmake)-diff
3704 %(mmake)-diff:
3705         $(Q)$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3706         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3707         cd %(destination)/tmp ; \
3708         $(FOR) f in %(excludes) ; do \
3709             $(ECHO) $$f >> ./exclude.patterns ; \
3710         done ; \
3711     $(ECHO) "Creating   \`%(archive)-aros-new.diff'" ; \
3712         diff -ruN $(%(mmake)-exclude) \
3713             $(%(mmake)-srcdir) \
3714             $(%(mmake)-srcdir).aros \
3715             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3716         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3717         $(RM) %(destination)/tmp
3718 %end
3719 #------------------------------------------------------------------------------
3722 #------------------------------------------------------------------------------
3723 # Joins the features of %fetch and %build_with_configure.
3725 # If a patch is provided, it *must* be named the following way:
3727 #    <package name>-<version number>-aros.diff
3729 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3730 # CD'ing into the archive's extracted directory.
3732 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3733 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3734 # to make that patch fully comprehensive.
3736 # Arguments:
3738 #    - mmake            = the meta make target.
3739 #    - package          = the GNU package name, sans version and archive format suffixes.
3740 #    - subpackage       = ???
3741 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3742 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3743 #    - version          = the package's version number, or otherwise any other version string.
3744 #                         It gets appended to the package name to form the basename of the archive.
3745 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3746 #                         version. Each one of them is tried until a matching archive is found.
3747 #                         Defaults to "tar.bz2 tar.gz".
3748 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3749 #    - builddir         = override the location we expect to run configure/make in.
3750 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3751 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3752 #                         fetched or not. Default to no.
3753 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3754 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3755 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3756 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3757 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3758 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3759 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3760 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3761 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3762 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3763 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3764 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3765 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3766 #    - nix              = same meaning as the one for the %build_with_configure macro.
3767 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3768 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3770 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3771     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3772     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3773     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3774     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no buildflags=yes gnuflags=yes nlsflag=yes xflag=yes hostisaflags="$(TARGET_ISA_CFLAGS)" targetisaflags="$(TARGET_ISA_CFLAGS)"
3776 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3777 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3778 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3779 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3780 #MM- %(mmake)-create-patch-quick : %(mmake)-%(subpackage)-create-patch
3782 %(mmake)-archbase  := %(package)-%(version)
3784 ifeq (%(compiler),host)
3785     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3786 else
3787     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3788 endif
3790 ifeq (%(prefix),)
3791     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3792 else
3793     %(mmake)-prefix := %(prefix)
3794 endif
3796 ifneq (%(subpackage),)
3797     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3798 else
3799     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3800 endif
3802 ifneq (%(srcdir),)
3803     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3804 else
3805     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3806 endif
3808 ifneq (%(builddir),)
3809     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3810 else
3811     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3812 endif
3814 ifeq (%(patch),yes)
3815     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3816 else
3817     %(mmake)-%(subpackage)-patches_specs := ::
3818 endif
3820 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3821     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3822     archive_origins=". %(package_repo)" \
3823     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3825 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3826     archive=$(%(mmake)-%(subpackage)-archbase) \
3827     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3828     suffixes="%(suffixes)" \
3829     destination=$(%(mmake)-portdir)
3831 #MM- %(mmake) : %(mmake)-%(subpackage)
3833 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3835 %(mmake)-%(subpackage)-package-basename := \
3836     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3838 ifneq (%(create_pkg),no)
3839     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3840 endif
3842 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3843      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3844      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3845      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix)  aros_prefix="%(aros_prefix)" \
3846      preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) %(mmake)-%(subpackage)-make-package" \
3847      extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3848      buildflags=%(buildflags) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag) hostisaflags=%(hostisaflags) targetisaflags=%(targetisaflags)
3850 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3851 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3854 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3856 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3857 #that $^ and $@ have exactly the same mtime, and in that case make tries
3858 #to rebuild $@ again, which would fail because the directory where
3859 #the package got installed would not exist anymore. 
3860 #We work this around by using an if statement to manually check the mtimes.
3861 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3862         $(Q)$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -s $@; then \
3863             $(RM) $@ ; \
3864             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3865             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3866             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3867             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3868             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3869             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3870         fi
3871 %end
3872 #------------------------------------------------------------------------------
3875 #------------------------------------------------------------------------------
3876 # Joins the features of %fetch and %build_with_configure, taking advantage of
3877 # the naming scheme of GNU packages. GNU packages names are in the form
3879 #     <package name>-<version number>.<archive format suffix>
3881 # If a patch is provided, it *must* be named the following way:
3883 #    <package name>-<version number>-aros.diff
3885 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3886 # CD'ing into the archive's extracted directory.
3888 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3889 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3890 # to make that patch fully comprehensive.
3892 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3894 # Arguments:
3896 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3898 #    - prefix           = defaults to $(GNUDIR).
3899 #    - aros_prefix      = defaults to /GNU.
3901 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3902     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3903     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall= \
3904     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3905     hostisaflags="$(TARGET_ISA_CFLAGS)" targetisaflags="$(TARGET_ISA_CFLAGS)" \
3906     nix=yes gnuflags=yes nlsflag=yes xflag=yes
3908 GNU_REPOSITORY := gnu://
3910 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3911     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3912     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3913     patch="%(patch)" patch_repo="%(patch_repo)" \
3914     prefix="%(prefix)" aros_prefix="%(aros_prefix)" \
3915     extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3916     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
3917     hostisaflags="%(hostisaflags)" targetisaflags="%(targetisaflags)" \
3918     nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
3920 %end
3921 #------------------------------------------------------------------------------
3924 #------------------------------------------------------------------------------
3925 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3926 # that the package is a "Developer" package, and as such it needs to be placed
3927 # under the $(AROS_DEVELOPER) directory, as a default. 
3929 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3930 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3931 # "mmake" argument, because the metatarget is implicitely defined as
3933 #     #MM- development-%(package)
3935 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3936     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3937     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall= \
3938     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3939     hostisaflags="$(TARGET_ISA_CFLAGS)" targetisaflags="$(TARGET_ISA_CFLAGS)"  \
3940     nix=yes gnuflags=yes nlsflag=yes xflag=yes
3942 #MM- development : development-%(package)
3945 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3946    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3947    package_repo="%(package_repo)" \
3948    patch="%(patch)" patch_repo="%(patch_repo)" \
3949    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" \
3950    extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3951    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3952    hostisaflags="%(hostisaflags)" targetisaflags="%(targetisaflags)" \
3953    nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
3956 postinstall-%(package)-delete-la-files:
3957         $(RM) %(prefix)/lib/*.la
3959 %end
3960 #------------------------------------------------------------------------------
3962 # Builds a kickstart package in PKG format
3964 # Arguments:
3966 #    - mmake   = target name
3967 #    - file    = destination file name with path
3969 # Other arguments are self-explanatory
3971 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3972     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3974 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3975 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3976 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3977 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3978 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3979 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3981 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3982 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3983 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3984 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3985 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3986 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3988 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3989     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3990 PKG_DIR   := $(dir %(file))
3993 %(mmake) : %(file)
3996 %(mmake)-quick : %(file)
3998 %(file): $(PKG_FILES) | $(PKG_DIR)
3999         $(Q)$(ECHO) Packaging $@...
4000         $(Q)$(SRCDIR)/tools/package/pkg c $@ $^
4002 %compress_file mmake="%(mmake)" file="%(file)"
4004 %rule_makedirs dirs="$(PKG_DIR)"
4006 %end
4008 #------------------------------------------------------------------------------
4009 # Compresses %(file) with a gzip.
4010 # Good in conjunction with for example %build_prog
4012 %define compress_file mmake=/A file=/A
4014 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
4017 %(mmake)-gz-quick : %(file).gz
4019 %(file).gz: %(file)
4020         $(Q)$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
4021         $(Q)gzip -9 -f $^
4023 %end
4025 #------------------------------------------------------------------------------
4026 # Links a kickstart module in ELF format
4027 # Arguments are similar to make_package
4029 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
4030     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
4032 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
4033 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
4034 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
4035 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
4036 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
4037 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
4039 ifeq (%(startup),)
4040     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
4041 else
4042     KOBJ_STARTUP := %(startup)
4043 endif
4045 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
4047 TMP_LDFLAGS := %(ldflags)
4049 # Make a list of the lib files this program depends on.
4050 # In LDFLAGS remove white space between -L and directory
4051 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
4052 # Filter out only the libdirs and remove -L
4053 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
4054 # Add trailing /
4055 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
4056 # Add normal linklib path
4057 TMP_DIRS += $(AROS_LIB)/
4058 # add lib and .a to static linklib names
4059 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
4060 # search for the linklibs in the given path, ignore ones not found
4061 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
4062     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
4065 TMP_DIRS += $(dir %(file))
4066 ifneq (%(map),)
4067     TMP_LDFLAGS += $(GENMAP) %(map)
4068     TMP_DIRS    += $(dir %(map))
4069 endif
4071 #MM %(mmake) : %(deps)
4074 %(mmake) : %(file)
4077 %(mmake)-quick : %(file)
4079 %(file): KOBJS := $(KOBJS)
4080 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
4081                     -static -nosysbase -Wl,-Ur
4082 %(file): LDLIBS := $(addprefix -l, %(uselibs))
4083 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
4084         $(Q)$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
4085         $(Q)$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
4086 ifeq ($(DEBUG),yes)
4087         $(Q)$(STRIP) $@ --only-keep-debug -o $@.dbg
4088 endif
4089         $(Q)$(STRIP) $@
4090 ifeq ($(DEBUG),yes)
4091         $(Q)$(OBJCOPY) --add-gnu-debuglink=$@.dbg $@
4092 endif
4094 %compress_file mmake="%(mmake)" file="%(file)"
4096 %rule_makedirs dirs="$(TMP_DIRS)"
4098 %end
4100 #------------------------------------------------------------------------------
4101 # Generate generic rules for a subtarget
4103 %define subtarget parentmmake= mmake=/A mmbase=MM-
4104 #%(mmbase) %(parentmmake) : %(mmake)
4105 #%(mmbase) %(parentmmake)-includes : %(mmake)-includes
4106 #%(mmbase) %(parentmmake)-quick : %(mmake)-quick
4107 %end
4109 #------------------------------------------------------------------------------
4110 # Create a target directory
4112 %define directorytarget mmake=/A directory=  icontarget= mmbase=MM-
4114 %(mmake)-makedir ::
4115     %mkdirs_q %(directory)
4117 #%(mmbase) %(mmake) : %(mmake)-makedir
4118 %end