define a new template to handle stripping of files (strip_q), and use it instead...
[AROS.git] / config / make.tmpl
blobce815488b233829ec0b2f3f1bce483bf9a6cbd7b
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 %define strip_q strip=$(STRIP) file=
64         $(Q)$(IF) $(TEST) "%(strip)" != ""; then \
65                 $(IF) $(TEST) "$(DEBUG)" = "yes"; then \
66                         %(strip) %(file) --only-keep-debug -o %(file).dbg ; \
67                 fi ; \
68                 %(strip) %(file) ; \
69                 $(IF) $(TEST) "$(DEBUG)" = "yes"; then \
70                         $(IF) $(TEST) -s %(file).dbg ; then \
71                                 $(OBJCOPY) --add-gnu-debuglink=%(file).dbg %(file) ; \
72                         fi ; \
73                 fi ; \
74         fi
76 #------------------------------------------------------------------------------
77 # Link a specified number of objects to an executable
78 %define link_q cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP) objdir=$(GENDIR)/$(CURDIR) coverageinstr=
79         $(Q)$(eval LINKTARGET=%(to))
80         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$(LINKTARGET))..."
81         $(Q)$(eval LINKTMPFILE=%(objdir)/$(notdir $(LINKTARGET)))
82         $(Q)$(IF) %(cmd) %(from) -o $(LINKTMPFILE) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
83                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
84                                 $(ECHO) "$(LINKTARGET): %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" >> $(GENDIR)/errors ; \
85                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
86                 else \
87                         $(NOP) ; \
88                 fi ; \
89                 $(CP) $(LINKTMPFILE) $(LINKTARGET) ; \
90         else \
91                 $(ECHO) "Link failed: %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" 1>&2 ; \
92                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
93                 exit 1 ; \
94         fi
95         %strip_q strip=%(strip) file=$(LINKTARGET)
96         $(Q)$(IF) $(TEST) "%(coverageinstr)" = "yes"; then \
97                 LINKBASEFILES="$(strip $(notdir $(basename %(from))))" ; \
98                 $(FOR) covext in $(TARGET_COVERAGEINSTR_EXTS) ; do \
99                         $(FOR) file in $$LINKBASEFILES ; do \
100                                 COVERAGEFILE=`echo $$file$$covext` ; \
101                                 $(IF) $(TEST) -s %(objdir)/$$COVERAGEFILE ; then \
102                                         $(CP) %(objdir)/$$COVERAGEFILE $(dir $(LINKTARGET))$$COVERAGEFILE ; \
103                                 fi ; \
104                         done ; \
105                 done ; \
106         fi
107 %end
108 #------------------------------------------------------------------------------
111 #-------------------------------------------------------------------------
112 # Link a module based upon a number of arguments and the standard $(LIBS)
113 # and $(DEPLIBS) make variables.
115 %define link_module_q cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" err="$(notdir $@).err" strip=$(STRIP) objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
116         $(Q)$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
117         $(Q)$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
118                 $(GENMAP) %(objdir)/%(module).map \
119                 %(objs) %(libs) %(ldflags) %(endtag) \
120                 -o $@ 2>&1 > %(objdir)/%(err); \
121         then \
122                 cat %(objdir)/%(err); \
123         else \
124                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
125                 cat %(objdir)/%(err); \
126                 exit 1; \
127         fi
128         $(Q)$(IF) $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
129         %strip_q strip=%(strip) file=$@
130 %end
131 #------------------------------------------------------------------------------
134 #------------------------------------------------------------------------------
135 # Create the library
136 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
137         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
138         $(Q)%(ar) %(to) %(from)
139         $(Q)%(ranlib) %(to)
140 %end
141 #------------------------------------------------------------------------------
144 #------------------------------------------------------------------------------
145 # Create the dependency file %(to) for %(from)
146 %define mkdepend_q flags="$(strip $(CFLAGS) $(CPPFLAGS))" from=$< to=$@ cc="$(strip $(AROS_CC) $(TARGET_SYSROOT))"
147         %mkdir_q dir="$(dir %(to))"
148         $(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))))..."
149         $(Q)AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
150 %end
151 #------------------------------------------------------------------------------
154 #------------------------------------------------------------------------------
155 # Create one directory without any output
156 %define mkdir_q dir=.
157         $(Q)$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
158 %end
159 #------------------------------------------------------------------------------
162 #------------------------------------------------------------------------------
163 # Create several directories without any output
164 %define mkdirs_q dirs=/M
165         $(Q)$(FOR) dir in %(dirs) ; do \
166                 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
167         done
168 %end
169 #------------------------------------------------------------------------------
172 #############################################################################
173 #############################################################################
174 ##                                                                         ##
175 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
176 ## mmakefile. They consist of one or more full makefile rules.             ##
177 ## In general the files generated in these macros are also defined as      ##
178 ## make targets so that they can be used as a dependency in other rules    ##
179 ##                                                                         ##
180 #############################################################################
181 #############################################################################
183 #------------------------------------------------------------------------------
184 # Generate a unique id for each of the %build... rules
185 %define buildid targets=/A
186 BDID := $(BDID)_
187 ifneq ($(filter $(TARGET),%(targets)),)
188     BDTARGETID := $(BDID)
189 endif
190 %end
191 #------------------------------------------------------------------------------
194 #------------------------------------------------------------------------------
195 # Copy file %(from) to %(to) in a makefile rule
196 %define rule_copy from=/A to=/A
197 %(to) : %(from)
198         $(Q)$(CP) $< $@
199 %end
200 #------------------------------------------------------------------------------
203 #------------------------------------------------------------------------------
204 # Copy the files %(files) to %(targetdir). For each file in %(files),
205 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
206 # appropriate subdirs are not generated by this rule so they have to be
207 # present.
208 %define rule_copy_multi files=/A targetdir=/A srcdir=.
210 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
211         $(Q)$(CP) $< $@
212 %end
213 #------------------------------------------------------------------------------
216 #------------------------------------------------------------------------------
217 # Copy the files %(files) to %(targetdir). For each file in %(files),
218 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
219 # %(stampfile) is used to keep track of when the last time the comparison has
220 # been done. The targetdir and the appropriate subdirs are not generated by 
221 # this rule so they have to be present.
222 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
223     stampfile=$(TMP_SRCDIR)/.copy_stamp
225 TMP_SRCDIR := %(srcdir)
227 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
229 %(stampfile) : COPYSRCDIR := %(srcdir)
230 %(stampfile) : TGTDIR := %(targetdir)
231 %(stampfile) : FILES := %(files)
232 %(stampfile) : $(addprefix %(srcdir)/,%(files))
233         $(Q)for f in $(FILES); do \
234                 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
235                         $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
236                 fi ; \
237         done
238         $(Q)$(TOUCH) $@
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Will join all the files in %(from) to %(to). When text is specified it will
245 # be displayed.
246 # Restriction: at the moment when using a non-empty target dir %(from) may
247 # not have 
248 %define rule_join to=/A from=/A text=
250 %(to) : %(from)
251         $(Q)$(IF) $(TEST) "%(text)" != "" ; then \
252                 $(Q)$(ECHO) %(text) ; \
253         fi
254         $(Q)$(CAT) $^ >$@
255 %end
256 #------------------------------------------------------------------------------
259 #------------------------------------------------------------------------------
260 # Include the dependency files and add some internal rules
261 # When depstargets is provided the depencies will only be included when one of
262 # these targets is the $(TARGET). Otherwise the dependencies will only be
263 # included when the $(TARGET) is not for setup or clean 
264 %define include_deps deps=$(DEPS)/M  depstargets=
265 ifneq (%(deps),)
266   ifneq (%(depstargets),)
267     ifneq ($(findstring $(TARGET),%(depstargets)),)
268       -include %(deps)
269     endif
270   else
271     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
272       -include %(deps)
273     endif
274   endif
275 endif
276 %end
277 #------------------------------------------------------------------------------
280 #------------------------------------------------------------------------------
281 # Create the directories %(dirs). The creation will be done by adding rules to
282 # the %(setuptarget) make target with setup as the default. 
283 %define rule_makedirs dirs=/A setuptarget=setup
285 ifneq (%(setuptarget),)
286 %(setuptarget) : | %(dirs)
287 else
288 %(setuptarget) :: %(dirs)
289 endif
291 GLOB_MKDIRS += %(dirs)
293 %end
294 #------------------------------------------------------------------------------
297 #------------------------------------------------------------------------------
298 # Generate a rule to compile a C source file to an object file and generate
299 # the dependency file. Basename may contain a directory part, then the source
300 # file has to be in that directory. The generated file will be put in the
301 # object directory without the directory.
302 # options
303 # - basename: the basename of the file to compile. Use % for a wildcard rule
304 # - cflags (default $(CFLAGS)): the C flags to use for compilation
305 # - dflags: the flags used during creation of dependency file. If not specified
306 #   the same value as cflags will be used
307 # - targetdir: the directory to put the .o file and the .d file. By default
308 #   it is put in the same directory as the .c file
309 %define rule_compile mmake=TMP basename=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= targetdir= compiler=target
311 %(mmake)_NIXFLAG ?= -nix
313 ifeq (%(targetdir),)
314   %(mmake)_TARGETBASE := %(basename)
315 else
316   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
317 endif
319 # Adjust compiler flags to suit C
320 %(mmake)_C_CPPFLAGS := %(cppflags)
321 %(mmake)_CFLAGS := %(cflags)
322 %(mmake)_CFLAGS := $(subst -fpermissive,, $(%(mmake)_CFLAGS))
323 ifeq (%(dflags),)
324   %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
325 else
326   %(mmake)_DFLAGS := %(dflags)
327 endif
329 ifeq ($(findstring %(compiler),host kernel target),)
330   $(error unknown compiler %(compiler))
331 endif
332 ifeq (%(compiler),target)
333 %(mmake)_LINK ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
334 %(mmake)_STRIP ?= $(TARGET_STRIP)
335 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
336 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
337 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(strip $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
338 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(strip $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
339 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(%(mmake)_CFLAGS) $(SAFETY_CFLAGS))
340 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(%(mmake)_DFLAGS)
341 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
342 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
343 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
344 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
345 endif
346 ifeq (%(compiler),host)
347 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
348 %(mmake)_STRIP ?= $(HOST_STRIP)
349 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CC)
350 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CC)
351 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(strip $(HOST_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
352 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(strip $(HOST_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
353 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_CFLAGS))
354 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_DFLAGS))
355 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
356 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
357 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
358 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
359 endif
360 ifeq (%(compiler),kernel)
361 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
362 %(mmake)_STRIP ?= $(ECHO) >/dev/null
363 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
364 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
365 $(%(mmake)_TARGETBASE).o : %(mmake)_C_CPPFLAGS:=$(strip $(KERNEL_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
366 $(%(mmake)_TARGETBASE).d : %(mmake)_C_CPPFLAGS:=$(strip $(KERNEL_C_CPPFLAGS) $(%(mmake)_C_CPPFLAGS) $(%(mmake)_C_EXTRA_CPPFLAGS))
367 $(%(mmake)_TARGETBASE).o : %(mmake)_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
368 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_DFLAGS))
369 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
370 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
371 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
372 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
373 endif
375 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_C_CPPFLAGS)
376 $(%(mmake)_TARGETBASE).o : CFLAGS := $(%(mmake)_CFLAGS)
377 $(%(mmake)_TARGETBASE).o : %(basename).c
378         %compile_q cmd=$(%(mmake)_CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
380 ifeq (%(nix),yes)
381   $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_DFLAGS))
382 endif
383 $(%(mmake)_TARGETBASE).d : %(basename).c
384         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_DFLAGS) $(%(mmake)_C_CPPFLAGS))"
385 %end
386 #------------------------------------------------------------------------------
389 #------------------------------------------------------------------------------
390 # Generate a rule to compile a C++ source file to an object file and generate
391 # the dependency file. Basename may contain a directory part, then the source
392 # file has to be in that directory. The generated file will be put in the
393 # object directory without the directory.
394 # options
395 # - basename: the basename of the file to compile. Use % for a wildcard rule
396 # - cflags (default $(CFLAGS)): the C flags to use for compilation
397 # - dflags: the flags used during creation of dependency file. If not specified
398 #   the same value as cflags will be used
399 # - targetdir: the directory to put the .o file and the .d file. By default
400 #   it is put in the same directory as the .c file
401 %define rule_compile_cxx mmake=TMP basename=/A cppflags=$(CPPFLAGS) cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
403 ifneq (%(basename),)
404 %(mmake)_NIXFLAG ?= -nix
405 ifeq (%(targetdir),)
406   %(mmake)_TARGETBASE := %(basename)
407 else
408   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
409 endif
411 # Adjust compiler flags to suit C++
412 %(mmake)_CXX_CPPFLAGS := %(cppflags)
413 %(mmake)_CXXFLAGS := %(cxxflags) 
414 ifeq (%(dxxflags),)
415   %(mmake)_DXXFLAGS := %(cxxflags)
416 else
417   %(mmake)_DXXFLAGS := %(dxxflags)
418 endif
420 ifeq ($(findstring %(compiler),host kernel target),)
421   $(error unknown compiler %(compiler))
422 endif
423 ifeq (%(compiler),target)
424 %(mmake)_LINK ?= $(strip $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
425 %(mmake)_STRIP ?= $(TARGET_STRIP)
426 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
427 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
428 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(strip $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
429 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(strip $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
430 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(%(mmake)_CXXFLAGS) $(SAFETY_CFLAGS))
431 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(%(mmake)_DXXFLAGS)
432 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
433 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
434 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
435 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
436 endif
437 ifeq (%(compiler),host)
438 %(mmake)_LINK ?= $(strip $(HOST_CXX) $(HOST_LDFLAGS))
439 %(mmake)_STRIP ?= $(HOST_STRIP)
440 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CXX)
441 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CXX)
442 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(strip $(HOST_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
443 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(strip $(HOST_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
444 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(HOST_CXXFLAGS) $(%(mmake)_CXXFLAGS))
445 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(HOST_CXXFLAGS) $(%(mmake)_DXXFLAGS))
446 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
447 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
448 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
449 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
450 endif
451 ifeq (%(compiler),kernel)
452 KERNEL_CXX ?= $(KERNEL_CC)
453 %(mmake)_LINK ?= $(strip $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
454 %(mmake)_STRIP ?= $(ECHO) >/dev/null
455 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
456 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
457 $(%(mmake)_TARGETBASE).o : %(mmake)_CXX_CPPFLAGS:=$(strip $(KERNEL_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
458 $(%(mmake)_TARGETBASE).d : %(mmake)_CXX_CPPFLAGS:=$(strip $(KERNEL_CXX_CPPFLAGS) $(%(mmake)_CXX_CPPFLAGS) $(%(mmake)_CXX_EXTRA_CPPFLAGS))
459 $(%(mmake)_TARGETBASE).o : %(mmake)_CXXFLAGS:=$(strip $(KERNEL_CXXFLAGS) $(%(mmake)_CXXFLAGS))
460 $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(KERNEL_CXXFLAGS) $(%(mmake)_DXXFLAGS))
461 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
462 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
463 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
464 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
465 endif
467 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_CXX_CPPFLAGS)
468 $(%(mmake)_TARGETBASE).o : CXXFLAGS := $(%(mmake)_CXXFLAGS)
469 $(%(mmake)_TARGETBASE).o : %(basename).cpp
470         %compile_q cmd=$(%(mmake)_CMD) opt="$(strip $(CXXFLAGS) $(CPPFLAGS))" iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
472 ifeq (%(nix),yes)
473   $(%(mmake)_TARGETBASE).d : %(mmake)_DXXFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_DXXFLAGS))
474 endif
475 $(%(mmake)_TARGETBASE).d : %(basename).cpp
476         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_DXXFLAGS) $(%(mmake)_CXX_CPPFLAGS))"
478 endif
480 %end
481 #------------------------------------------------------------------------------
484 #------------------------------------------------------------------------------
485 # Generate a rule to compile an ObjC source file to an object file and generate
486 # the dependency file. Basename may contain a directory part, then the source
487 # file has to be in that directory. The generated file will be put in the
488 # object directory without the directory.
489 # options
490 # - basename: the basename of the file to compile. Use % for a wildcard rule
491 # - cflags (default $(CFLAGS)): the C flags to use for compilation
492 # - dflags: the flags used during creation of dependency file. If not specified
493 #   the same value as cflags will be used
494 # - targetdir: the directory to put the .o file and the .d file. By default
495 #   it is put in the same directory as the .m file
496 %define rule_compile_objc mmake=TMP basename=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= targetdir= compiler=target
498 ifneq (%(basename),)
499 %(mmake)_NIXFLAG ?= -nix
500 ifeq (%(targetdir),)
501   %(mmake)_TARGETBASE := %(basename)
502 else
503   %(mmake)_TARGETBASE := %(targetdir)/$(notdir %(basename))
504 endif
506 # Adjust compiler flags to suit ObjC
507 %(mmake)_OBJC_CPPFLAGS :=  %(cppflags)
508 %(mmake)_OBJCFLAGS := %(cflags)
509 %(mmake)_OBJCFLAGS := $(%(mmake)_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
510 %(mmake)_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(%(mmake)_OBJCFLAGS)))
511 ifeq (%(dflags),)
512   %(mmake)_OBJCDFLAGS := %(cflags)
513 else
514   %(mmake)_OBJCDFLAGS := %(dflags)
515 endif
517 # Define the use of cross compiler
518 ifeq ($(TARGET_OBJC),)
519   %(mmake)_CC := $(TARGET_CC)
520 else
521   %(mmake)_CC := $(TARGET_OBJC)
522 endif
524 ifeq ($(findstring %(compiler),host kernel target),)
525   $(error unknown compiler %(compiler))
526 endif
527 ifeq (%(compiler),target)
528 %(mmake)_LINK ?= $(strip $(%(mmake)_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
529 %(mmake)_STRIP ?= $(TARGET_STRIP)
530 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
531 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
532 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(strip $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
533 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(strip $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
534 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(%(mmake)_OBJCFLAGS) $(SAFETY_CFLAGS))
535 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(%(mmake)_OBJCDFLAGS)
536 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
537 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
538 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
539 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
540 endif
541 ifeq (%(compiler),host)
542 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
543 %(mmake)_STRIP ?= $(HOST_STRIP)
544 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(HOST_CC)
545 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(HOST_CC)
546 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(strip $(HOST_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
547 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(strip $(HOST_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
548 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCFLAGS))
549 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCDFLAGS))
550 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
551 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
552 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
553 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
554 endif
555 ifeq (%(compiler),kernel)
556 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
557 %(mmake)_STRIP ?= $(ECHO) >/dev/null
558 $(%(mmake)_TARGETBASE).o : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
559 $(%(mmake)_TARGETBASE).d : %(mmake)_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
560 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJC_CPPFLAGS:=$(strip $(KERNEL_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
561 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJC_CPPFLAGS:=$(strip $(KERNEL_OBJC_CPPFLAGS) $(%(mmake)_OBJC_CPPFLAGS) $(%(mmake)_OBJC_EXTRA_CPPFLAGS))
562 $(%(mmake)_TARGETBASE).o : %(mmake)_OBJCFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
563 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCDFLAGS))
564 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
565 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
566 $(%(mmake)_TARGETBASE).o : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
567 $(%(mmake)_TARGETBASE).d : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
568 endif
570 $(%(mmake)_TARGETBASE).o : CPPFLAGS := $(%(mmake)_OBJC_CPPFLAGS)
571 $(%(mmake)_TARGETBASE).o : CFLAGS := $(%(mmake)_OBJCFLAGS)
572 $(%(mmake)_TARGETBASE).o : %(basename).m
573         %compile_q cmd=$(%(mmake)_CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
575 ifeq (%(nix),yes)
576   $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(%(mmake)_NIXFLAG) $(%(mmake)_OBJCDFLAGS))
577 endif
578 $(%(mmake)_TARGETBASE).d : %(basename).m
579         %mkdepend_q cc=$(%(mmake)_CMD) flags="$(strip $(%(mmake)_OBJCDFLAGS) $(%(mmake)_OBJC_CPPFLAGS))"
581 endif
583 %end
584 #------------------------------------------------------------------------------
587 #------------------------------------------------------------------------------
588 # Generate a rule to compile multiple C source files to an object file and
589 # generate the corresponding dependency files. The generated file will be put
590 # in the object directory without the directory part of the source file.
591 # options
592 # - basenames: the basenames of the files to compile. The names may include
593 #   relative or absolute path names. No wildcard is allowed
594 # - cflags (default $(CFLAGS)): the C flags to use for compilation
595 # - dflags: the flags used during creation of dependency file. If not specified
596 #   the same value as cflags will be used
597 # - targetdir: the directory to put the .o file and the .d file. By default
598 #   it is put in the same directory as the .c file. When targetdir is not
599 #   empty, path names will be stripped from the file names so that all files
600 #   are in that dir and not in subdirectories.
601 # - compiler (default target): compiler to use, target, kernel or host
602 %define rule_compile_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= srcdir= targetdir= \
603     compiler=target usetree=no
605 ifeq (%(srcdir),)
606 %(mmake)_MC_SRCWILDCARD := %
607 else
608 %(mmake)_MC_SRCWILDCARD := %(srcdir)/%
609 endif
611 ifeq (%(targetdir),)
612 %(mmake)_MC_TARGETS := $(addsuffix .o,%(basenames))
613 %(mmake)_MC_DTARGETS := $(addsuffix .d,%(basenames))
614 %(mmake)_MC_TGTWILDCARD := %
615 else
616 ifeq (%(usetree),no)
617     %(mmake)_MC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
618     %(mmake)_MC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
619 else
620 ifeq (%(srcdir),)
621     %(mmake)_MC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
622     %(mmake)_MC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
623 else
624     %(mmake)_MC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(patsubst %(srcdir)/%,%,%(basenames))))
625     %(mmake)_MC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(patsubst %(srcdir)/%,%,%(basenames))))
626 endif
627 endif
628 %(mmake)_MC_TGTWILDCARD := %(targetdir)/%
630 # Be sure that all .c files are generated
631 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : | $(addsuffix .c,%(basenames))
633 # Be sure that all .c files are found
634 %(mmake)_MC_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
635 %(mmake)_MC_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
636 %(mmake)_MC_DIRS := $(foreach dir, $(%(mmake)_MC_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)_MC_SRCDIR)/$(CURDIR)/$(dir)))
637 ifneq ($(%(mmake)_MC_DIRS),)
638     %(mmake)_MC_DIRS := $(shell echo $(%(mmake)_MC_DIRS) | sed 's/\(.\):\//\/\1\//g')
639     vpath %.c $(%(mmake)_MC_DIRS)
640 endif
642 endif
644 %(mmake)_MC_CPPFLAGS := %(cppflags)
645 %(mmake)_CFLAGS := %(cflags)
646 ifeq (%(dflags),)
647   %(mmake)_DFLAGS := %(cflags)
648 else
649   %(mmake)_DFLAGS := %(dflags)
650 endif
652 ifeq ($(findstring %(compiler),host kernel target),)
653   $(error unknown compiler %(compiler))
654 endif
655 ifeq (%(compiler),target)
656 %(mmake)_LINK ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
657 %(mmake)_STRIP ?= $(TARGET_STRIP)
658 %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
659 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
660 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(strip $(%(mmake)_MC_CPPFLAGS) $(%(mmake)_MC_EXTRA_CPPFLAGS))
661 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(%(mmake)_CFLAGS) $(SAFETY_CFLAGS))
662 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(%(mmake)_DFLAGS)
663 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
664 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
665 endif
666 ifeq (%(compiler),host)
667 %(mmake)_LINK ?= $(strip $(HOST_CC) $(HOST_LDFLAGS))
668 %(mmake)_STRIP ?= $(HOST_STRIP)
669 %(mmake)_ASSEMBLER ?= $(strip $HOST_CC) $(HOST_SYSROOT))
670 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(HOST_CC)
671 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(strip $(HOST_MC_CPPFLAGS) $(%(mmake)_MC_CPPFLAGS) $(%(mmake)_MC_EXTRA_CPPFLAGS))
672 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_CFLAGS))
673 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_DFLAGS))
674 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
675 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
676 endif
677 ifeq (%(compiler),kernel)
678 %(mmake)_LINK ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
679 %(mmake)_STRIP ?= $(ECHO) >/dev/null
680 %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
681 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
682 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_MC_CPPFLAGS:=$(strip $(KERNEL_MC_CPPFLAGS) $(%(mmake)_MC_CPPFLAGS) $(%(mmake)_MC_EXTRA_CPPFLAGS))
683 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
684 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_DFLAGS))
685 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
686 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
687 endif
689 $(%(mmake)_MC_TARGETS) : CPPFLAGS := $(%(mmake)_MC_CPPFLAGS)
690 $(%(mmake)_MC_TARGETS) : CFLAGS := $(%(mmake)_CFLAGS)
691 $(%(mmake)_MC_TARGETS) : $(%(mmake)_MC_TGTWILDCARD).o : $(%(mmake)_MC_SRCWILDCARD).c
692         %compile_q cmd=$(CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
694 $(%(mmake)_MC_DTARGETS) : $(%(mmake)_MC_TGTWILDCARD).d : $(%(mmake)_MC_SRCWILDCARD).c
695         %mkdepend_q cc=$(CMD) flags="$(strip $(%(mmake)_DFLAGS) $(%(mmake)_MC_CPPFLAGS))"
696 %end
697 #------------------------------------------------------------------------------
700 #------------------------------------------------------------------------------
701 # Generate a rule to compile multiple C++ source files to an object file and
702 # generate the corresponding dependency files. The generated file will be put
703 # in the object directory without the directory part of the source file.
704 # options
705 # - basenames: the basenames of the files to compile. The names may include
706 #   relative or absolute path names. No wildcard is allowed. basenames will be 
707 #   matched to supported AROS_CXXEXTS.
708 # - cflags (default $(CFLAGS)): the C flags to use for compilation
709 # - dflags: the flags used during creation of dependency file. If not specified
710 #   the same value as cflags will be used
711 # - targetdir: the directory to put the .o file and the .d file. By default
712 #   it is put in the same directory as the .c file. When targetdir is not
713 #   empty, path names will be stripped from the file names so that all files
714 #   are in that dir and not in subdirectories.
715 # - compiler (default target): compiler to use, target, kernel or host
716 %define rule_compile_cxx_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cxxflags=$(CXXFLAGS) dxxflags= \
717     targetdir= compiler=target srcdir=
719 %(mmake)_CXXABSBASENAMES := $(foreach %(mmake)_CXXBASE,%(basenames),$(if $(filter /%,$(%(mmake)_CXXBASE)),$(%(mmake)_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(%(mmake)_CXXBASE))))
721 ifneq ($(%(mmake)_CXXABSBASENAMES),)
723 %(mmake)_CXXBASENAMES := $(basename $(%(mmake)_CXXABSBASENAMES))
725 # Identify the "real" c++ files from the passed in basenames
726 %(mmake)_MCXX_FILES  := $(strip $(foreach %(mmake)_CXXBASE,$(%(mmake)_CXXABSBASENAMES), $(firstword $(wildcard $(foreach %(mmake)_EXT, $(AROS_CXXEXTS),$(addsuffix .$(%(mmake)_EXT),$(%(mmake)_CXXBASE)))))))
728 ifeq (%(srcdir),)
729 %(mmake)_MCXX_SRCWILDCARD := %
730 else
731 %(mmake)_MCXX_SRCWILDCARD := %(srcdir)/%
732 endif
734 ifeq (%(targetdir),)
735   %(mmake)_CXXTARGETS := $(notdir $(%(mmake)_CXXBASENAMES:=.o))
736   %(mmake)_CXXDTARGETS := $(notdir $(%(mmake)_CXXBASENAMES:=.d))
737   %(mmake)_MCXX_WILDCARD := %
738 else
739   %(mmake)_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(%(mmake)_CXXBASENAMES:=.o)))
740   %(mmake)_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(%(mmake)_CXXBASENAMES:=.d)))
741   %(mmake)_MCXX_WILDCARD := %(targetdir)/%
743   # Be sure that all source files are generated
744   $(%(mmake)_CXXTARGETS) $(%(mmake)_CXXDTARGETS) : | $(%(mmake)_MCXX_FILES)
745 endif
747 # Adjust compiler flags to suit C++
748 %(mmake)_MCXX_CPPFLAGS := %(cppflags)
749 %(mmake)_CXXFLAGS := %(cxxflags)
750 ifeq (%(dxxflags),)
751   %(mmake)_DXXFLAGS := %(cxxflags)
752 else
753   %(mmake)_DXXFLAGS := %(dxxflags)
754 endif
756 ifeq ($(findstring %(compiler),host kernel target),)
757   $(error unknown compiler %(compiler))
758 endif
759 ifeq (%(compiler),host)
760   %(mmake)_LINK ?= $(strip $(HOST_CXX) $(HOST_LDFLAGS))
761   %(mmake)_STRIP ?= $(HOST_STRIP)
762   %(mmake)_ASSEMBLER ?= $(strip $(HOST_CC) $(HOST_SYSROOT))
763   %(mmake)_CXXCMD:=$(HOST_CXX)
764   %(mmake)_MCXX_CPPFLAGS := $(strip $(HOST_MCXX_CPPFLAGS) $(%(mmake)_MCXX_CPPFLAGS) $(%(mmake)_MCXX_EXTRA_CPPFLAGS))
765   %(mmake)_CXXFLAGS := $(strip $(HOST_CXXFLAGS) $(%(mmake)_CXXFLAGS))
766   %(mmake)_DXXFLAGS := $(strip $(HOST_CXXFLAGS) $(%(mmake)_DXXFLAGS))
767   %(mmake)_CXXIQUOTE:=$(HOST_IQUOTE)
768   %(mmake)_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
769 endif
770 ifeq (%(compiler),target)
771   %(mmake)_LINK ?= $(strip $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
772   %(mmake)_STRIP ?= $(TARGET_STRIP)
773   %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
774   %(mmake)_CXXCMD:=$(strip $(AROS_CXX) $(TARGET_SYSROOT))
775   %(mmake)_MCXX_CPPFLAGS := $(strip $(%(mmake)_MCXX_CPPFLAGS) $(%(mmake)_MCXX_EXTRA_CPPFLAGS))
776   %(mmake)_CXXFLAGS := $(strip $(%(mmake)_CXXFLAGS) $(SAFETY_CFLAGS))
777   %(mmake)_DXXFLAGS := $(%(mmake)_DXXFLAGS)
778   %(mmake)_CXXIQUOTE:=$(CFLAGS_IQUOTE)
779   %(mmake)_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
780 endif
781 ifeq (%(compiler),kernel)
782   KERNEL_CXX ?= $(KERNEL_CC)
783   %(mmake)_LINK ?= $(strip $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
784   %(mmake)_STRIP ?= $(ECHO) >/dev/null
785   %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
786   %(mmake)_CXXCMD:=$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))
787   %(mmake)_CXXFLAGS := $(strip $(KERNEL_MCXX_CPPFLAGS) $(%(mmake)_MCXX_CPPFLAGS) $(%(mmake)_MCXX_EXTRA_CPPFLAGS))
788   %(mmake)_CXXFLAGS := $(strip $(KERNEL_CXXFLAGS) $(%(mmake)_CXXFLAGS))
789   %(mmake)_DXXFLAGS := $(strip $(KERNEL_CXXFLAGS) $(%(mmake)_DXXFLAGS))
790   %(mmake)_CXXIQUOTE:=$(KERNEL_IQUOTE)
791   %(mmake)_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
792 endif
794 define cxx_multi_recipe_template
795  $(1).o : $(2)
796         %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
798  $(1).d : $(2)
799         %mkdepend_q cc=$(%(mmake)_CXXCMD) flags="$(strip $(%(mmake)_DXXFLAGS) $(%(mmake)_MCXX_CPPFLAGS))" from=$(2) to=$(1).d
800 endef
801 ifeq (%(targetdir),)
802   $(foreach %(mmake)_CXXFILE,$(%(mmake)_MCXX_FILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(%(mmake)_CXXFILE))),$(%(mmake)_CXXFILE))))
803 else
804   $(foreach %(mmake)_CXXFILE,$(%(mmake)_MCXX_FILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(%(mmake)_CXXFILE)))),$(%(mmake)_CXXFILE))))
805 endif
807 endif
809 %end
810 #------------------------------------------------------------------------------
813 #------------------------------------------------------------------------------
814 # Generate a rule to compile multiple ObjC source files to an object file and
815 # generate the corresponding dependency files. The generated file will be put
816 # in the object directory without the directory part of the source file.
817 # options
818 # - basenames: the basenames of the files to compile. The names may include
819 #   relative or absolute path names. No wildcard is allowed
820 # - cflags (default $(CFLAGS)): the C flags to use for compilation
821 # - dflags: the flags used during creation of dependency file. If not specified
822 #   the same value as cflags will be used
823 # - targetdir: the directory to put the .o file and the .d file. By default
824 #   it is put in the same directory as the .m file. When targetdir is not
825 #   empty, path names will be stripped from the file names so that all files
826 #   are in that dir and not in subdirectories.
827 # - compiler (default target): compiler to use, target, kernel or host
828 %define rule_compile_objc_multi mmake=TMP basenames=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= \
829     targetdir= compiler=target srcdir=
831 ifneq (%(basenames),)
833 ifeq (%(srcdir),)
834 %(mmake)_MOBJC_SRCWILDCARD := %
835 else
836 %(mmake)_MOBJC_SRCWILDCARD := %(srcdir)/%
837 endif
839 ifeq (%(targetdir),)
840   %(mmake)_MOBJC_TARGETS := $(addsuffix .o,%(basenames))
841   %(mmake)_MOBJC_DTARGETS := $(addsuffix .d,%(basenames))
842   %(mmake)_MOBJC_WILDCARD := %
843 else
844   %(mmake)_MOBJC_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
845   %(mmake)_MOBJC_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
846   %(mmake)_MOBJC_WILDCARD := %(targetdir)/%
848   # Be sure that all .m files are generated
849   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : | $(addsuffix .m,%(basenames))
851   # Be sure that all .m files are found
852   %(mmake)_MOBJC_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
853   %(mmake)_MOBJC_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
854   %(mmake)_MOBJC_DIRS := $(foreach dir, $(%(mmake)_MOBJC_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)_MOBJC_SRCDIR)/$(CURDIR)/$(dir)))
855   ifneq ($(%(mmake)_MOBJC_DIRS),)
856     %(mmake)_MOBJC_DIRS := $(shell echo $(%(mmake)_MOBJC_DIRS) | sed 's/\(.\):\//\/\1\//g')
857     vpath %.m $(%(mmake)_MOBJC_DIRS)
858   endif
859 endif
861 # Define the use of cross compiler
862 ifeq ($(TARGET_OBJC),)
863   %(mmake)_CC := $(TARGET_CC)
864 else
865   %(mmake)_CC := $(TARGET_OBJC)
866 endif
868 # Adjust compiler flags to suit ObjC
869 %(mmake)_MOBJC_CPPFLAGS := %(cppflags)
870 %(mmake)_OBJCFLAGS := %(cflags)
871 %(mmake)_OBJCFLAGS := $(%(mmake)_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
872 %(mmake)_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(%(mmake)_OBJCFLAGS)))
873 ifeq (%(dflags),)
874   %(mmake)_OBJCDFLAGS := %(cflags)
875 else
876   %(mmake)_OBJCDFLAGS := %(dflags)
877 endif
879 ifeq ($(findstring %(compiler),host kernel target),)
880   $(error unknown compiler %(compiler))
881 endif
882 ifeq (%(compiler),target)
883   %(mmake)_LINK ?= $(strip $(%(mmake)_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS))
884   %(mmake)_STRIP ?= $(TARGET_STRIP)
885   %(mmake)_ASSEMBLER ?= $(strip $(TARGET_CC) $(TARGET_SYSROOT))
886   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(strip $(%(mmake)_CC) $(TARGET_SYSROOT))
887   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(strip $(%(mmake)_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_EXTRA_CPPFLAGS))
888   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(%(mmake)_OBJCFLAGS) $(SAFETY_CFLAGS))
889   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(%(mmake)_OBJCDFLAGS)
890   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(CFLAGS_IQUOTE)
891   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
892 endif
893 ifeq (%(compiler),host)
894   %(mmake)_LINK ?= $(strip $(HOST_OBJC) $(HOST_LDFLAGS))
895   %(mmake)_STRIP ?= $(HOST_STRIP)
896   %(mmake)_ASSEMBLER ?= $(strip $(HOST_CC) $(HOST_SYSROOT))
897   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(HOST_OBJC)
898   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(strip $(HOST_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_EXTRA_CPPFLAGS))
899   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCFLAGS))
900   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(strip $(HOST_CFLAGS) $(%(mmake)_OBJCDFLAGS))
901   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(HOST_IQUOTE)
902   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(HOST_IQUOTE_END)
903 endif
904 ifeq (%(compiler),kernel)
905   KERNEL_OBJC ?= $(KERNEL_CC)
906   %(mmake)_LINK ?= $(strip $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS))
907   %(mmake)_STRIP ?= $(ECHO) >/dev/null
908   %(mmake)_ASSEMBLER ?= $(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
909   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : CMD:=$(strip $(KERNEL_OBJC) $(KERNEL_SYSROOT))
910   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_MOBJC_CPPFLAGS:=$(strip $(KERNEL_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_CPPFLAGS) $(%(mmake)_MOBJC_EXTRA_CPPFLAGS))
911   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
912   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCDFLAGS))
913   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE:=$(KERNEL_IQUOTE)
914   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_IQUOTE_END:=$(KERNEL_IQUOTE_END)
915 endif
917 $(%(mmake)_MOBJC_TARGETS) : CPPFLAGS := $(%(mmake)_MOBJC_CPPFLAGS)
918 $(%(mmake)_MOBJC_TARGETS) : CFLAGS := $(%(mmake)_OBJCFLAGS)
919 $(%(mmake)_MOBJC_TARGETS) : $(%(mmake)_MOBJC_WILDCARD).o : $(%(mmake)_MOBJC_SRCWILDCARD).m
920         %compile_q cmd=$(CMD) iquote=$(%(mmake)_IQUOTE) iquote_end=$(%(mmake)_IQUOTE_END)
922 $(%(mmake)_MOBJC_DTARGETS) : $(%(mmake)_MOBJC_WILDCARD).d : $(%(mmake)_MOBJC_SRCWILDCARD).m
923         %mkdepend_q cc=$(CMD) flags="$(strip $(%(mmake)_OBJCDFLAGS) $(%(mmake)_MOBJC_CPPFLAGS))"
925 endif
927 %end
928 #------------------------------------------------------------------------------
931 #------------------------------------------------------------------------------
932 # Make an alias from one arch specific build to another arch.
933 # arguments:
934 # - mainmmake: the mmake of the module in the main tree
935 # - arch: the current arch
936 # - alias: the alias to which this should point
937 %define rule_archalias mainmmake=\A arch=\A alias=\A
939 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
940 %end
941 #------------------------------------------------------------------------------
944 #------------------------------------------------------------------------------
945 # Generate a rule to assemble a source file to an object file. Basename may
946 # contain a directory part, then the source file has to be in that directory.
947 # The generated file will be put in the object directory without the directory.
948 # options
949 # - basename: the basename of the file to compile. Use % for a wildcard rule
950 # - flags (default $(AFLAGS)): the asm flags to use for assembling
951 # - targetdir: the directory to put the .o file in. By default it is put in the
952 #   same directory as the .s file
953 %define rule_assemble basename=/A cppflags=$(CPPFLAGS) aflags=$(AFLAGS) targetdir=
955 ifeq (%(targetdir),)
956 %(basename).o : CPPFLAGS := %(cppflags)
957 %(basename).o : AFLAGS := %(aflags)
958 %(basename).o : %(basename).s
959         %assemble_q
960 %(basename).o : %(basename).S
961         %assemble_q
963 else
964 %(targetdir)/$(notdir %(basename)).o : CPPFLAGS := %(cppflags)
965 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
966 %(targetdir)/$(notdir %(basename)).o : %(basename).s
967         %assemble_q
968 %(targetdir)/$(notdir %(basename)).o : %(basename).S
969         %assemble_q
971 endif
972 %end
973 #------------------------------------------------------------------------------
976 #------------------------------------------------------------------------------
977 # Generate a rule to assemble multiple source files to an object file. The
978 # generated file will be put in the object directory with the directory part
979 # of the source file stripped off.
980 # options
981 # - basenames: the basenames of the files to compile. The names may include
982 #   relative or absolute path names. No wildcard is allowed
983 # - aflags (default $(AFLAGS)): the flags to use for assembly
984 # - targetdir: the directory to put the .o file and the .d file. By default
985 #   it is put in the same directory as the .c file. When targetdir is not
986 #   empty, path names will be stripped from the file names so that all files
987 #   are in that dir and not in subdirectories.
988 %define rule_assemble_multi mmake=TMP cmd="$(strip $(CC) $(TARGET_SYSROOT))"  basenames=/A cppflags=$(CPPFLAGS) aflags=$(AFLAGS) targetdir= suffix=.s
990 ifeq (%(targetdir),)
991 %(mmake)-MA_TARGETS := $(addsuffix .o,%(basenames))
992 %(mmake)-MA_WILDCARD := %
993 else
994 %(mmake)-MA_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
995 %(mmake)-MA_WILDCARD := %(targetdir)/%
997 # Be sure that all .s files are generated
998 $(%(mmake)-MA_TARGETS) : | $(addsuffix %(suffix),%(basenames))
1000 # Be sure that all .c files are found
1001 %(mmake)-MA_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1002 %(mmake)-MA_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
1003 %(mmake)-MA_DIRS := $(foreach dir, $(%(mmake)-MA_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(%(mmake)-MA_SRCDIR)/$(CURDIR)/$(dir)))
1004 ifneq ($(%(mmake)-MA_DIRS),)
1005     %(mmake)-MA_DIRS := $(shell echo $(%(mmake)-MA_DIRS) | sed 's/\(.\):\//\/\1\//g')
1006     vpath %%(suffix) $(%(mmake)-MA_DIRS)
1007 endif
1009 endif
1011 %(mmake)-MA_ASSEMBLER ?= %(cmd)
1013 $(%(mmake)-MA_TARGETS) : %(mmake)-MA_CMD:= $(%(mmake)-MA_ASSEMBLER)
1015 $(%(mmake)-MA_TARGETS) : CPPFLAGS := %(cppflags)
1016 $(%(mmake)-MA_TARGETS) : AFLAGS := %(aflags)
1017 $(%(mmake)-MA_TARGETS) : $(%(mmake)-MA_WILDCARD).o : %%(suffix)
1018         %assemble_q cmd=$(%(mmake)-MA_CMD)
1019 %end
1020 #------------------------------------------------------------------------------
1023 #------------------------------------------------------------------------------
1024 # Link %(objs) to %(prog) using the libraries in %(uselibs)
1025 %define rule_link_prog mmake=TMP prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
1026     usehostlibs= usestartup=yes detach=no nix=no cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR) coverageinstr=$(TARGET_COVERAGEINSTR)
1028 %(mmake)-link_EXTRA_LDFLAGS := 
1029 %(mmake)-link_EXTRA_LIBS :=
1030 ifeq (%(nix),yes)
1031     %(mmake)-link_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1032 endif
1033 ifeq (%(usestartup),no)
1034     %(mmake)-link_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1035 endif
1036 ifeq (%(detach),yes)
1037     %(mmake)-link_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1038 endif
1040 # Make a list of the lib files this program depends on.
1041 # In LDFLAGS remove white space between -L and directory
1042 %(mmake)-link_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1043 # Filter out only the libdirs and remove -L
1044 %(mmake)-link_DIRS := $(patsubst -L%,%,$(filter -L%,$(%(mmake)-link_DIRS)))
1045 # Add trailing /
1046 %(mmake)-link_DIRS := $(subst //,/,$(addsuffix /,$(%(mmake)-link_DIRS)))
1047 # Add normal linklib path
1048 %(mmake)-link_DIRS += $(AROS_LIB)/
1049 # add lib and .a to static linklib names
1050 %(mmake)-link_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(%(mmake)-link_EXTRA_LIBS)))
1051 ifeq (%(usestartup),yes)
1052     %(mmake)-link_LIBS += startup.o
1053 endif
1054 ifeq (%(detach),yes)
1055     %(mmake)-link_LIBS += detach.o
1056 endif
1057 # search for the linklibs in the given path, ignore ones not found
1058 %(mmake)-link_DEPLIBS := $(foreach lib,$(%(mmake)-link_LIBS), \
1059     $(firstword $(wildcard $(addsuffix $(lib),$(%(mmake)-link_DIRS)))) \
1062 %(prog) : OBJDIR := %(objdir)
1063 %(prog) : OBJS := %(objs)
1064 %(prog) : LDFLAGS := $(strip %(ldflags) $(%(mmake)-link_EXTRA_LDFLAGS))
1065 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(%(mmake)-link_EXTRA_LIBS) %(usehostlibs))
1066 %(prog) : %(objs) $(%(mmake)-link_DEPLIBS)
1067         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR) coverageinstr=%(coverageinstr)
1068 %end
1069 #------------------------------------------------------------------------------
1072 #------------------------------------------------------------------------------
1073 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
1074 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
1075 %define rule_link_progs mmake=TMP progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
1076     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
1077     usestartup=yes detach=no cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" strip=$(TARGET_STRIP) coverageinstr=$(TARGET_COVERAGEINSTR)
1079 %(mmake)-link_EXTRA_LDFLAGS := 
1080 %(mmake)-link_EXTRA_LIBS :=
1081 ifeq (%(nix),yes)
1082     %(mmake)-link_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1083 endif
1084 ifeq (%(usestartup),no)
1085     %(mmake)-link_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1086 endif
1087 ifeq (%(detach),yes)
1088     %(mmake)-link_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1089 endif
1091 # Make a list of the lib files the programs depend on.
1092 # In LDFLAGS remove white space between -L and directory
1093 %(mmake)-link_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1094 # Filter out only the libdirs and remove -L
1095 %(mmake)-link_DIRS := $(patsubst -L%,%,$(filter -L%,$(%(mmake)-link_DIRS)))
1096 # Add trailing /
1097 %(mmake)-link_DIRS := $(subst //,/,$(addsuffix /,$(%(mmake)-link_DIRS)))
1098 # Add normal linklib path
1099 %(mmake)-link_DIRS += $(AROS_LIB)/
1100 # add lib and .a to static linklib names
1101 %(mmake)-link_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(%(mmake)-link_EXTRA_LIBS)))
1102 # search for the linklibs in the given path, ignore ones not found
1103 %(mmake)-link_DEPLIBS := $(foreach lib,$(%(mmake)-link_LIBS), \
1104     $(firstword $(wildcard $(addsuffix $(lib),$(%(mmake)-link_DIRS)))) \
1106 %(mmake)-link_PROGS := $(addprefix %(targetdir)/,%(progs))
1108 $(%(mmake)-link_PROGS) : OBJDIR := %(objdir)
1109 $(%(mmake)-link_PROGS) : LDFLAGS := $(strip %(ldflags) $(%(mmake)-link_EXTRA_LDFLAGS))
1110 $(%(mmake)-link_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(%(mmake)-link_EXTRA_LIBS) %(usehostlibs))
1111 $(%(mmake)-link_PROGS) : %(targetdir)/% : %(objdir)/%.o $(%(mmake)-link_DEPLIBS)
1112         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR) coverageinstr=%(coverageinstr)
1113 %end
1114 #------------------------------------------------------------------------------
1117 #------------------------------------------------------------------------------
1118 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1119 %define rule_link_linklib mmake=TMP libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1121 ifeq (%(linker),target)
1122 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(AR)
1123 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(RANLIB)
1124 endif
1125 ifeq (%(linker),host)
1126 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(HOST_AR)
1127 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(HOST_RANLIB)
1128 endif
1129 ifeq (%(linker),kernel)
1130 %(libdir)/lib%(libname).a : %(mmake)_AR:=$(KERNEL_AR)
1131 %(libdir)/lib%(libname).a : %(mmake)_RANLIB:=$(KERNEL_RANLIB)
1132 endif
1134 %(libdir)/lib%(libname).a : %(objs)
1135         %mklib_q from=$^ ar=$(%(mmake)_AR) ranlib=$(%(mmake)_RANLIB)
1136 %end
1137 #------------------------------------------------------------------------------
1139 #------------------------------------------------------------------------------
1140 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1141 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1142 %define rule_linkmodule mmake=TMP module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1143     cmd="$(strip $(AROS_CC) $(TARGET_SYSROOT))" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1145 %(mmake)_LDFLAGS  := %(ldflags)
1146 # Make a list of the lib files the programs depend on.
1147 # In LDFLAGS remove white space between -L and directory
1148 %(mmake)_DIRS := $(subst -L ,-L,$(strip $(%(mmake)_LDFLAGS)))
1149 # Filter out only the libdirs and remove -L
1150 %(mmake)_DIRS := $(patsubst -L%,%,$(filter -L%,$(%(mmake)_DIRS)))
1151 # Add trailing /
1152 %(mmake)_DIRS := $(subst //,/,$(addsuffix /,$(%(mmake)_DIRS)))
1153 # Add normal linklib path
1154 %(mmake)_DIRS += $(AROS_LIB)/
1155 # add lib and .a to static linklib names
1156 %(mmake)_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1157 # search for the linklibs in the given path, ignore ones not found
1158 %(mmake)_DEPLIBS := $(foreach lib,$(%(mmake)_LIBS), \
1159     $(firstword $(wildcard $(addsuffix $(lib),$(%(mmake)_DIRS)))) \
1162 %(module) : LIB_NAMES := %(uselibs)
1163 %(module) : OBJS := %(objs)
1164 %(module) : ENDTAG := %(endobj)
1165 %(module) : ERR := %(err)
1166 %(module) : OBJDIR := %(objdir)
1167 %(module) : LDFLAGS := $(%(mmake)_LDFLAGS)
1168 ifeq (%(usehostlibs),)
1169 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1170 else
1171 # Warning: the -L/usr/lib here can result in modules
1172 # linking against host libs instead of AROS libs (e.g stdc++) !!
1173 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1174                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1175 endif 
1176 %(module) : %(objs) %(endobj) $(%(mmake)_DEPLIBS) $(USER_DEPLIBS)
1177         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1179 %end
1180 #------------------------------------------------------------------------------
1183 #------------------------------------------------------------------------------
1184 # Generate the libdefs.h include file for a module.
1185 %define rule_genmodule_genlibdefs mmake=TMP modname=/A version= flavour= modtype=/A modsuffix= conffile= targetdir=
1187 %(mmake)_OPTS := 
1188 ifneq (%(flavour),)
1189     %(mmake)_OPTS += -f %(flavour)
1190     %(mmake)_MODNAME := %(modname)_%(flavour)
1191 else
1192     %(mmake)_MODNAME := %(modname)
1193 endif
1194 %(mmake)_TARGET := $(%(mmake)_MODNAME)_libdefs.h
1195 %(mmake)_DEPS := $(GENMODULE)
1196 ifneq (%(conffile),)
1197     ifeq ($(dir %(conffile)),./)
1198         %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1199         %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1200     else
1201         %(mmake)_OPTS += -c %(conffile)
1202         %(mmake)_DEPS += %(conffile)
1203     endif 
1204 else
1205     %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1206     %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1207 endif
1208 ifneq (%(modsuffix),)
1209     %(mmake)_OPTS += -s %(modsuffix)
1210 endif
1211 ifneq (%(targetdir),)
1212     %(mmake)_OPTS += -d %(targetdir)
1213     %(mmake)_TARGET := %(targetdir)/$(%(mmake)_TARGET)
1214 endif
1215 ifneq (%(version),)
1216     %(mmake)_OPTS += -v %(version)
1217 endif
1219 $(%(mmake)_TARGET) : OPTS := $(%(mmake)_OPTS)
1220 $(%(mmake)_TARGET) : MODNAME := %(modname)
1221 $(%(mmake)_TARGET) : MODTYPE := %(modtype)
1222 $(%(mmake)_TARGET) : $(%(mmake)_DEPS)
1223         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1224         $(Q)$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1225 %end
1226 #------------------------------------------------------------------------------
1228 #------------------------------------------------------------------------------
1229 # Generate the _lib.fd file for a module.
1230 %define rule_genmodule_fd mmake=TMP modname=/A modtype=/A modsuffix= conffile= targetdir=
1232 %(mmake)_TARGET := %(modname)_lib.fd
1233 %(mmake)_DEPS := $(GENMODULE)
1234 %(mmake)_OPTS := 
1235 ifneq (%(conffile),)
1236     ifeq ($(dir %(conffile)),./)
1237         %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1238         %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1239     else
1240         %(mmake)_OPTS += -c %(conffile)
1241         %(mmake)_DEPS += %(conffile)
1242     endif 
1243 else
1244     %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1245     %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1246 endif
1247 ifneq (%(modsuffix),)
1248     %(mmake)_OPTS += -s %(modsuffix)
1249 endif
1250 ifneq (%(targetdir),)
1251     %(mmake)_OPTS += -d %(targetdir)
1252     %(mmake)_TARGET := %(targetdir)/$(%(mmake)_TARGET)
1253 endif
1255 $(%(mmake)_TARGET) : OPTS := $(%(mmake)_OPTS)
1256 $(%(mmake)_TARGET) : MODNAME := %(modname)
1257 $(%(mmake)_TARGET) : MODTYPE := %(modtype)
1258 $(%(mmake)_TARGET) : $(%(mmake)_DEPS)
1259         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1260         $(Q)$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1261 %end
1262 #------------------------------------------------------------------------------
1264 #------------------------------------------------------------------------------
1265 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1266 # generated file in this Makefile
1267 %define rule_genmodule_makefile mmake=TMP modname=/A flavour= modtype=/A modsuffix= conffile= \
1268     targetdir=
1270 %(mmake)_OPTS := 
1271 ifneq (%(flavour),)
1272     %(mmake)_OPTS += -f %(flavour)
1273     %(mmake)_MODNAME := %(modname)_%(flavour)
1274 else
1275     %(mmake)_MODNAME := %(modname)
1276 endif
1277 %(mmake)_TARGET := Makefile.$(%(mmake)_MODNAME)%(modtype)
1278 %(mmake)_DEPS := $(GENMODULE)
1279 ifneq (%(conffile),)
1280     ifeq ($(dir %(conffile)),./)
1281         %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1282         %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1283     else
1284         %(mmake)_OPTS += -c %(conffile)
1285         %(mmake)_DEPS += %(conffile)
1286     endif 
1287 else
1288     %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1289     %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1290 endif
1291 ifneq (%(modsuffix),)
1292     %(mmake)_OPTS += -s %(modsuffix)
1293 endif
1294 ifneq (%(targetdir),)
1295     %(mmake)_OPTS += -d %(targetdir)
1296     %(mmake)_TARGET := %(targetdir)/$(%(mmake)_TARGET)
1297 endif
1299 $(%(mmake)_TARGET) : OPTS := $(%(mmake)_OPTS)
1300 $(%(mmake)_TARGET) : MODNAME := %(modname)
1301 $(%(mmake)_TARGET) : MODTYPE := %(modtype)
1302 $(%(mmake)_TARGET) : $(%(mmake)_DEPS)
1303         $(Q)$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1304 %end
1305 #------------------------------------------------------------------------------
1308 #------------------------------------------------------------------------------
1309 # Generate the support files for compiling a module. This includes include
1310 # files and source files. This rule has to be preceeded by
1311 # %rule_genmodule_makefile
1312 %define rule_genmodule_files mmake=TMP modname=/A flavour= modtype=/A modsuffix= targetdir= stubdir= \
1313     conffile=
1315 %(mmake)_OPTS :=
1316 ifneq (%(flavour),)
1317     %(mmake)_OPTS += -f %(flavour)
1318     %(mmake)_MODNAME := %(modname)_%(flavour)
1319 else
1320     %(mmake)_MODNAME := %(modname)
1321 endif
1322 %(mmake)_GENTARGETS := $($(%(mmake)_MODNAME)_STARTFILES) $($(%(mmake)_MODNAME)_ENDFILES)
1323 %(mmake)_STUBTARGETS := $($(%(mmake)_MODNAME)_LINKLIBFILES) $($(%(mmake)_MODNAME)_RELLINKLIBFILES)
1324 %(mmake)_GENTARGETS := $(addsuffix .c,$(%(mmake)_GENTARGETS))
1325 %(mmake)_STUBTARGETS := $(addsuffix .c,$(%(mmake)_STUBTARGETS)) \
1326                $(addsuffix .S, $($(%(mmake)_MODNAME)_LINKLIBAFILES) $($(%(mmake)_MODNAME)_RELLINKLIBAFILES))
1328 %(mmake)_DEPS := $(GENMODULE)
1329 ifneq (%(conffile),)
1330     ifeq ($(dir %(conffile)),./)
1331         %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1332         %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1333     else
1334         %(mmake)_OPTS += -c %(conffile)
1335         %(mmake)_DEPS += %(conffile)
1336     endif 
1337 else
1338     %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1339     %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1340 endif
1341 ifneq (%(modsuffix),)
1342     %(mmake)_OPTS += -s %(modsuffix)
1343 endif
1344 ifneq (%(targetdir),)
1345     %(mmake)_OPTS += -d %(targetdir)
1346     %(mmake)_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1347     %(mmake)_GENTARGETS := $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_GENTARGETS))
1348     %(mmake)_GENFILEFLAG=$(%(mmake)_TARGETDIR)/.%(modname).%(modtype)-genfiles
1349 else
1350     %(mmake)_GENFILEFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-genfiles
1351 endif
1352 ifneq (%(stubdir),)
1353     %(mmake)_OPTS += -l %(stubdir)
1354     %(mmake)_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1355     %(mmake)_STUBTARGETS := $(addprefix $(%(mmake)_STUBTARGETDIR)/,$(%(mmake)_STUBTARGETS))
1356     %(mmake)_TARGETDIRS += %(stubdir)
1357 else
1358 ifneq (%(targetdir),)
1359     %(mmake)_STUBTARGETS := $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_STUBTARGETS))
1360 endif
1361 endif
1363 %(mmake)_TARGETS := $(%(mmake)_GENTARGETS) $(%(mmake)_STUBTARGETS)
1364 ifneq ($(%(mmake)_TARGETDIRS),)
1365 $(%(mmake)_TARGETS) : | $(%(mmake)_TARGETDIRS)
1366 endif
1368 $(%(mmake)_TARGETS) : $(%(mmake)_DEPS) $(%(mmake)_GENFILEFLAG)
1370 $(%(mmake)_GENFILEFLAG) : OPTS := $(%(mmake)_OPTS)
1371 $(%(mmake)_GENFILEFLAG) : MODNAME := %(modname)
1372 $(%(mmake)_GENFILEFLAG) : MODTYPE := %(modtype)
1373 $(%(mmake)_GENFILEFLAG) : $(%(mmake)_DEPS)
1374         $(Q)$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1375         $(Q)$(IF) $(TEST) "%(conffile)" = "lib.conf" && $(TEST) -f lib.conf; then \
1376                 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1377         fi
1378         $(Q)$(IF) $(TEST) -f libdefs.h; then \
1379                 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1380         fi
1381         $(Q)$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1382         $(Q)$(TOUCH) $@
1383 %end
1384 #------------------------------------------------------------------------------
1387 #------------------------------------------------------------------------------
1388 # Generate the support files for compiling a module. This includes include
1389 # files and source files.
1390 %define rule_genmodule_includes mmake=TMP modname=/A flavour= modtype=/A modsuffix= \
1391     targetdir= conffile=
1393 ifneq (%(flavour),)
1394     %(mmake)_MODNAME := %(modname)_%(flavour)
1395 else
1396     %(mmake)_MODNAME := %(modname)
1397 endif
1399 ifneq ($($(%(mmake)_MODNAME)_INCLUDES),)
1401 %(mmake)_TARGETS := $($(%(mmake)_MODNAME)_INCLUDES)
1403 %(mmake)_DEPS := $(GENMODULE)
1404 %(mmake)_OPTS :=
1406 ifneq (%(conffile),)
1407     ifeq ($(dir %(conffile)),./)
1408         %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1409         %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1410     else
1411         %(mmake)_OPTS += -c %(conffile)
1412         %(mmake)_DEPS += %(conffile)
1413     endif 
1414 else
1415     %(mmake)_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1416     %(mmake)_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1417 endif
1418 ifneq (%(modsuffix),)
1419     %(mmake)_OPTS += -s %(modsuffix)
1420 endif
1421 ifneq (%(targetdir),)
1422     %(mmake)_OPTS += -d %(targetdir)
1423     %(mmake)_TARGETS := $(addprefix %(targetdir)/,$(%(mmake)_TARGETS))
1424     %(mmake)_GENINCFLAG=%(targetdir)/.%(modname).%(modtype)-includes
1425 else
1426     %(mmake)_GENINCFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-includes
1427 endif
1429 $(%(mmake)_TARGETS) : $(%(mmake)_DEPS) $(%(mmake)_GENINCFLAG)
1431 $(%(mmake)_GENINCFLAG) : OPTS := $(%(mmake)_OPTS)
1432 $(%(mmake)_GENINCFLAG) : MODNAME := %(modname)
1433 $(%(mmake)_GENINCFLAG) : MODTYPE := %(modtype)
1434 $(%(mmake)_GENINCFLAG) : $(%(mmake)_DEPS)
1435         $(Q)$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1436         $(Q)$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1437         $(Q)$(TOUCH) $@
1438 endif
1439 %end
1440 #------------------------------------------------------------------------------
1442 #------------------------------------------------------------------------------
1443 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1444 # 'start' is an optional starting address
1445 # 'ldflags' is optional additional flags for the linker
1446 %define rule_link_binary mmake=BD file=/A name=/A objs= files= start=0 ldflags=
1448 %(mmake)_OUTDIR := $(dir %(file))
1449 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1450 %(mmake)_OUTDIR := $(subst /*,,$(addsuffix *,$(%(mmake)_OUTDIR)))
1451 %(mmake)_TMPDIR := $(GENDIR)/$(CURDIR)
1452 %(mmake)_OBJS := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir %(files))))
1453 %(mmake)_DEPS := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir %(files))))
1454 %(mmake)_OBJS += %(objs)
1456 %rule_compile_multi basenames="%(files)" targetdir=$(%(mmake)_OBJDIR)
1458 %(file) : $(%(mmake)_OBJS) $(%(mmake)_DEPS)
1459         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1460         $(Q)$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(%(mmake)_TMPDIR)/%(name) $(%(mmake)_OBJS)
1461         $(Q)cd $(%(mmake)_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1463 ifeq ($(findstring $(%(mmake)_OUTDIR),$(GLOB_MKDIRS)),)
1464     %rule_makedirs dirs="$(%(mmake)_OUTDIR)" setuptarget=%(file)
1465 endif
1467 %end
1469 #------------------------------------------------------------------------------
1470 # Common rules for all makefiles
1471 %define common
1472 # Delete generated makefiles
1474 clean ::
1475         $(Q)$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1477 include $(SRCDIR)/config/make.tail
1479 BDID := $(BDTARGETID)
1480 %end
1481 #------------------------------------------------------------------------------
1482       
1484 #############################################################################
1485 #############################################################################
1486 ##                                                                         ##
1487 ## Here are the mmakefile build macros. These are macros that takes care   ##
1488 ## of everything to go from the sources to the generated target. Also all  ##
1489 ## intermediate files and directories that are needed are created by these ##
1490 ## rules.                                                                  ##
1491 ##                                                                         ##
1492 #############################################################################
1493 #############################################################################
1495 #------------------------------------------------------------------------------
1496 # Build a program
1497 %define build_prog mmake=/A progname=/A files= cxxfiles= \
1498     objcfiles= \
1499     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1500     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= ldflags=$(LDFLAGS) \
1501     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1502     includedir= libdir= \
1503     compiler=target linker= \
1504     coverageinstr=$(TARGET_COVERAGEINSTR) funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1506 .PHONY : %(mmake)
1508 %(mmake)_PROGNAME  := %(progname)
1509 %(mmake)_OBJDIR    := %(objdir)
1510 %(mmake)_TARGETDIR := %(targetdir)
1511 %(mmake)_LINKER    := %(linker)
1512 %(mmake)_LIBS := %(uselibs)
1513 # If not supplied, linker is equal to compiler
1514 ifeq ($(%(mmake)_LINKER),)
1515     %(mmake)_LINKER := %(compiler)
1516 endif
1518 ifneq ("$(strip %(files) %(cxxfiles) %(objcfiles) %(asmfiles))","")
1519     %(mmake)_FILES     := %(files)
1520     %(mmake)_OBJCFILES := %(objcfiles)
1521     %(mmake)_ASMFILES  := %(asmfiles)
1522     %(mmake)_CXXFILES := %(cxxfiles)
1523 else
1524     %(mmake)_FILES     := $(%(mmake)_PROGNAME)
1525     %(mmake)_OBJCFILES :=
1526     %(mmake)_ASMFILES  :=
1527     %(mmake)_CXXFILES :=
1528 endif
1530 %(mmake)_ARCHOBJS   := $(wildcard $(%(mmake)_OBJDIR)/arch/*.o)
1531 %(mmake)_ARCHFILES  := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
1532 %(mmake)_C_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_FILES))
1533 %(mmake)_CXX_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_CXXFILES))
1534 %(mmake)_OBJC_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_OBJCFILES))
1536 TMP_FILES := $(%(mmake)_C_NARCHFILES) $(%(mmake)_CXX_NARCHFILES) $(%(mmake)_ASMFILES) $(%(mmake)_OBJC_NARCHFILES)
1537 %(mmake)_OBJS := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(TMP_FILES))))
1538 %(mmake)_DEPS := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(TMP_FILES))))
1540 %(mmake)_CPPFLAGS :=  %(cppflags)
1541 ifneq (%(includedir),)
1542 %(mmake)_CPPFLAGS    += -I%(includedir)
1543 endif
1544 %(mmake)_CFLAGS    := %(cflags)
1545 %(mmake)_CXXFLAGS := %(cxxflags)
1546 %(mmake)_COVERAGE := no
1547 ifeq (%(compiler),target)
1548 ifeq (%(usestartup),yes)
1549 ifeq (%(coverageinstr),yes)
1550 %(mmake)_COVERAGE := yes
1551 %(mmake)_COVERAGEFLAGS   ?= $(COVERAGEINSTR_FLAGS)
1552 %(mmake)_COVERAGELIBS    ?= $(COVERAGEINSTR_LIBS)
1553 %(mmake)_CFLAGS    := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CFLAGS))
1554 %(mmake)_CXXFLAGS := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CXXFLAGS))
1555 %(mmake)_LIBS += $(%(mmake)_COVERAGELIBS)
1556 endif
1557 ifeq (%(funcinstr),yes)
1558 %(mmake)_FUNCINSTR := yes
1559 %(mmake)_INSTRFUNCFLAGS   ?= $(FUNCINSTR_FLAGS)
1560 %(mmake)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
1561 %(mmake)_CFLAGS    := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CFLAGS))
1562 %(mmake)_CXXFLAGS := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CXXFLAGS))
1563 %(mmake)_LIBS += $(%(mmake)_INSTRFUNCLIBS)
1564 endif
1565 endif
1566 ifeq (%(lto),yes)
1567 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CFLAGS))
1568 %(mmake)_CXXFLAGS := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CXXFLAGS))
1569 endif
1570 endif
1571 %(mmake)_AFLAGS    := %(aflags)
1572 ifneq (%(dflags),)
1573     %(mmake)_DFLAGS     := %(dflags)
1574 else
1575     %(mmake)_DFLAGS     := $(%(mmake)_CFLAGS)
1576 endif
1577 ifneq (%(dxxflags),)
1578     %(mmake)_DXXFLAGS     := %(dxxflags)
1579 else
1580     %(mmake)_DXXFLAGS     := $(%(mmake)_CXXFLAGS)
1581 endif
1582 %(mmake)_LDFLAGS   := %(ldflags)
1583 ifneq (%(libdir),)
1584 %(mmake)_LDFLAGS   += -L%(libdir)
1585 endif
1588 %(mmake)-quick : %(mmake)
1590 #MM %(mmake) : includes-generate-deps core-linklibs
1591 %(mmake) : $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME)
1593 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1594 %rule_compile_cxx_multi mmake=%(mmake) \
1595     basenames=$(%(mmake)_CXX_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1596     cppflags=$(%(mmake)_CPPFLAGS) cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
1597     compiler="%(compiler)"
1598 %rule_compile_objc_multi mmake=%(mmake) \
1599     basenames=$(%(mmake)_OBJC_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1600     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1601     compiler="%(compiler)"
1602 %rule_compile_multi mmake=%(mmake) \
1603     basenames=$(%(mmake)_C_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
1604     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1605     compiler="%(compiler)"
1606 %rule_assemble_multi mmake=%(mmake) \
1607     cmd=$(%(mmake)_ASSEMBLER) basenames=$(%(mmake)_ASMFILES) targetdir=$(%(mmake)_OBJDIR) \
1608     cppflags=$(%(mmake)_CPPFLAGS) aflags=$(%(mmake)_AFLAGS)
1610 %rule_link_prog mmake=%(mmake) prog=$(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME) \
1611     objs="$(%(mmake)_OBJS) $(%(mmake)_ARCHOBJS) $(USER_OBJS)" ldflags=$(%(mmake)_LDFLAGS) \
1612     uselibs="$(%(mmake)_LIBS)" usehostlibs="%(usehostlibs)" \
1613     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1614     cmd=$(%(mmake)_LINK) strip=$(%(mmake)_STRIP) objdir=$(%(mmake)_OBJDIR) coverageinstr=$(%(mmake)_COVERAGE) 
1616 endif
1618 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
1620 %rule_makedirs dirs="$(%(mmake)_OBJDIR) $(%(mmake)_TARGETDIR)" setuptarget="$(%(mmake)_OBJS) $(%(mmake)_DEPS) $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME)"
1622 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_TARGETDIR)/$(%(mmake)_PROGNAME) $(%(mmake)_DEPS)
1624 %(mmake)-clean ::
1625         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
1626         $(Q)$(RM) $(FILES)
1628 %end
1629 #------------------------------------------------------------------------------
1632 #------------------------------------------------------------------------------
1633 # Build programs, for every C file an executable will be built with the same
1634 # name as the C file
1635 %define build_progs mmake=/A files=/A nix=no \
1636     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1637     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= ldflags=$(LDFLAGS) \
1638     includedir= libdir= \
1639     compiler=target \
1640     uselibs= usehostlibs= usestartup=yes detach=no \
1641     coverageinstr=$(TARGET_COVERAGEINSTR) funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1643 .PHONY : %(mmake)
1645 %(mmake)_OBJDIR    := %(objdir)
1646 %(mmake)_TARGETDIR := %(targetdir)
1647 %(mmake)_LIBS := %(uselibs)
1649 %(mmake)_FILES     := %(files)
1650 %(mmake)_OBJS      := $(addsuffix .o,$(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_FILES)))
1651 %(mmake)_DEPS      := $(addsuffix .d,$(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_FILES)))
1652 %(mmake)_EXES      := $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_FILES))
1654 %(mmake)_CPPFLAGS := %(cppflags)
1655 ifneq (%(includedir),)
1656     %(mmake)_CPPFLAGS += -I%(includedir)
1657 endif
1658 %(mmake)_CFLAGS    := %(cflags)
1659 %(mmake)_COVERAGE := no
1660 ifeq (%(compiler),target)
1661 ifeq (%(usestartup),yes)
1662 ifeq (%(coverageinstr),yes)
1663 %(mmake)_COVERAGE := yes
1664 %(mmake)_COVERAGEFLAGS   ?= $(COVERAGEINSTR_FLAGS)
1665 %(mmake)_COVERAGELIBS    ?= $(COVERAGEINSTR_LIBS)
1666 %(mmake)_CFLAGS    := $(strip $(%(mmake)_COVERAGEFLAGS) $(%(mmake)_CFLAGS))
1667 %(mmake)_LIBS += $(%(mmake)_COVERAGELIBS)
1668 endif
1669 ifeq (%(funcinstr),yes)
1670 %(mmake)_FUNCINSTR := yes
1671 %(mmake)_INSTRFUNCFLAGS   ?= $(FUNCINSTR_FLAGS)
1672 %(mmake)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
1673 %(mmake)_CFLAGS    := $(strip $(%(mmake)_INSTRFUNCFLAGS) $(%(mmake)_CFLAGS))
1674 %(mmake)_LIBS += $(%(mmake)_INSTRFUNCLIBS)
1675 endif
1676 endif
1677 ifeq (%(lto),yes)
1678 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(%(mmake)_CFLAGS))
1679 endif
1680 endif
1681 ifneq (%(dflags),)
1682     %(mmake)_DFLAGS := %(dflags)
1683 else
1684     %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
1685 endif
1686 %(mmake)_LDFLAGS   := %(ldflags)
1687 ifneq (%(libdir),)
1688     %(mmake)_LDFLAGS += -L%(libdir)
1689 endif
1692 %(mmake)-quick : %(mmake)
1694 #MM %(mmake) : includes-generate-deps core-linklibs
1695 %(mmake) : $(%(mmake)_EXES)
1697 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1698 %rule_compile_multi mmake=%(mmake) basenames=$(%(mmake)_FILES) targetdir=$(%(mmake)_OBJDIR) \
1699     cflags=$(%(mmake)_CFLAGS) cppflags=$(%(mmake)_CPPFLAGS) dflags=$(%(mmake)_DFLAGS) compiler="%(compiler)"
1701 %rule_link_progs mmake=%(mmake) progs=$(%(mmake)_FILES) nix="%(nix)" \
1702     targetdir=$(%(mmake)_TARGETDIR) objdir=$(%(mmake)_OBJDIR) \
1703     ldflags=$(%(mmake)_LDFLAGS) \
1704     uselibs="$(%(mmake)_LIBS)" usehostlibs="%(usehostlibs)" \
1705     usestartup="%(usestartup)" detach="%(detach)" \
1706     cmd=$(%(mmake)_LINK) strip=$(%(mmake)_STRIP) objdir=$(%(mmake)_OBJDIR) coverageinstr=$(%(mmake)_COVERAGE)
1708 endif
1710 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
1712 %rule_makedirs dirs="$(%(mmake)_TARGETDIR) $(%(mmake)_OBJDIR)" setuptarget="$(%(mmake)_DEPS) $(%(mmake)_OBJS) $(addprefix $(%(mmake)_TARGETDIR)/,$(%(mmake)_FILES))"
1714 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_EXES) $(%(mmake)_DEPS)
1716 %(mmake)-clean ::
1717         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
1718         $(Q)$(RM) $(FILES)
1720 %end
1721 #------------------------------------------------------------------------------
1724 #------------------------------------------------------------------------------
1725 # Build a module.
1726 # This is a bare version: It just compiles and links the given files. It is
1727 # assumed that all needed boiler plate code is in the files. This should only
1728 # be used for compiling external code. For AROS code use %build_module
1729 %define build_module_simple mmake=/A modname=/A modtype=/A \
1730     files="$(basename $(call WILDCARD, *.c))" \
1731     objcfiles= \
1732     cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1733     cppflags=$(CPPFLAGS) \
1734     cflags=$(CFLAGS) dflags= \
1735     cxxflags=$(CXXFLAGS) dxxflags= \
1736     objdir=$(OBJDIR) moduledir= \
1737     uselibs= usehostlibs= compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO)
1739 # Define metamake targets and their dependencies
1740 #MM %(mmake) : core-linklibs includes-generate-deps
1741 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1742 #MM %(mmake)-kobj-quick
1743 #MM %(mmake)-quick
1744 #MM %(mmake)-clean
1746 %(mmake)_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1748 .PHONY : $(%(mmake)_ALLTARGETS)
1750 ifeq (%(modname),)
1751 $(error using %build_module_simple: modname may not be empty)
1752 endif
1753 ifeq (%(modtype),)
1754 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1755 endif
1757 # Default values for variables and arguments
1758 %(mmake)_DEFLINKLIBNAME := %(modname)
1759 %(mmake)_CFLAGS := %(cflags)
1760 %(mmake)_CXXFLAGS := %(cxxflags)
1761 ifeq (%(compiler),target)
1762 ifeq (%(lto),yes)
1763 %(mmake)_CFLAGS    := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(%(mmake)_CFLAGS))
1764 endif
1765 ifeq (%(funcinstr),yes)
1766 %(mmake)_FUNCINSTR := yes
1767 %(mmake)_CFLAGS    := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)_CFLAGS))
1768 endif
1769 endif
1770 ifneq (%(dflags),)
1771     %(mmake)_DFLAGS := %(dflags)
1772 else
1773     %(mmake)_DFLAGS := $(%(mmake)_CFLAGS)
1774 endif
1775 %(mmake)_DEFDXXFLAGS := %(dxxflags)
1776 OBJDIR ?= $(GENDIR)/$(CURDIR)
1777 %(mmake)_MODDIR := %(moduledir)
1778 ifeq ($(%(mmake)_MODDIR),)
1779   ifeq (%(modtype),library)
1780     %(mmake)_MODDIR  := $(AROS_LIBRARIES)
1781   endif
1782   ifeq (%(modtype),gadget)
1783     %(mmake)_MODDIR  := $(AROS_GADGETS)
1784   endif
1785   ifeq (%(modtype),datatype)
1786     %(mmake)_MODDIR  := $(AROS_DATATYPES)
1787   endif
1788   ifeq (%(modtype),handler)
1789     %(mmake)_MODDIR  := $(AROS_FS)
1790   endif
1791   ifeq (%(modtype),device)
1792     %(mmake)_MODDIR  := $(AROS_DEVS)
1793   endif
1794   ifeq (%(modtype),resource)
1795     %(mmake)_MODDIR  := $(AROS_RESOURCES)
1796   endif
1797   ifeq (%(modtype),hook)
1798     %(mmake)_MODDIR  := $(AROS_RESOURCES)
1799   endif
1800   ifeq (%(modtype),mui)
1801     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1802   endif
1803   ifeq (%(modtype),mcc)
1804     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1805   endif
1806   ifeq (%(modtype),mcp)
1807     %(mmake)_MODDIR  := $(AROS_CLASSES)/Zune
1808   endif
1809   ifeq (%(modtype),usbclass)
1810     %(mmake)_MODDIR  := $(AROS_CLASSES)/USB
1811   endif
1812   ifeq (%(modtype),hidd)
1813     %(mmake)_MODDIR  := $(AROS_DRIVERS)
1814   endif
1815   ifeq (%(modtype),printer)
1816     %(mmake)_MODDIR  := $(AROS_PRINTERS)
1817   endif
1818 endif
1819 ifeq ($(%(mmake)_MODDIR),)
1820   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1821 endif
1823 %(mmake)_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1824 %(mmake)_ARCHFILES  := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
1825 %(mmake)_C_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(files))
1826 %(mmake)_CXX_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(cxxfiles))
1827 %(mmake)_OBJC_NARCHFILES := $(filter-out $(%(mmake)_ARCHFILES),%(objcfiles))
1829 %rule_compile_cxx_multi mmake=%(mmake) \
1830     basenames=$(%(mmake)_CXX_NARCHFILES) targetdir="%(objdir)" \
1831     cppflags="%(cppflags)" cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
1832     compiler="%(compiler)"
1833 %rule_compile_objc_multi mmake=%(mmake) \
1834     basenames=$(%(mmake)_OBJC_NARCHFILES) targetdir="%(objdir)" \
1835     cppflags="%(cppflags)" cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
1836     compiler="%(compiler)"
1837 %rule_compile_multi mmake=%(mmake) \
1838     basenames=$(%(mmake)_C_NARCHFILES) targetdir="%(objdir)" \
1839     cppflags="%(cppflags)" cflags="$(%(mmake)_CFLAGS)" dflags="$(%(mmake)_DFLAGS)" \
1840     compiler="%(compiler)"
1842 # Handlers use dash instead of dot in their names
1843 ifeq (%(modtype),handler)
1844 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname)-%(modtype)
1845 else
1846 ifeq (%(modtype),printer)
1847 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname)
1848 else
1849 %(mmake)_MODULE := $(%(mmake)_MODDIR)/%(modname).%(modtype)
1850 endif
1851 endif
1852 %(mmake)_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1854 %(mmake)-quick : %(mmake)
1855 %(mmake)-kobj-quick : $(%(mmake)_KOBJ)
1856 %(mmake)       : $(%(mmake)_MODULE)
1857 %(mmake)-kobj  : $(%(mmake)_KOBJ)
1859 # The module is linked from all the compiled .o files
1860 %(mmake)_OBJS       := $(%(mmake)_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(%(mmake)_C_NARCHFILES))))
1862 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1863 # This breaks con-handler build. Here we work around this
1864 ifeq (%(modname),con)
1865     %(mmake)_ERR := $(notdir $(%(mmake)_MODULE)).err
1866 else
1867     %(mmake)_ERR := %(modname).err
1868 endif
1870 %rule_linkmodule module=$(%(mmake)_MODULE) objs=$(%(mmake)_OBJS) \
1871     endobj= err=$(%(mmake)_ERR) objdir="%(objdir)" \
1872     ldflags="$(strip $(LDFLAGS) $(%(modname)_LDFLAGS))" \
1873     uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1875 # Link kernel object file
1876 %(mmake)_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1878 # Make these symbols local
1879 %(mmake)_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1880     UtilityBase ExpansionBase KeymapBase KernelBase
1882 %(mmake)_SYMBOLS := $(%(mmake)_KBASE)
1884 %(mmake)_KLIB := hiddstubs amiga arossupport autoinit libinit
1885 %(mmake)_KOBJ_LIBS := $(filter-out $(%(mmake)_KLIB),%(uselibs)) $(%(mmake)_KAUTOLIB)
1886 $(%(mmake)_KOBJ) : LINKLIBS:=$(%(mmake)_KOBJ_LIBS)
1887 $(%(mmake)_KOBJ) : FILTBASES:=$(addprefix -L ,$(%(mmake)_SYMBOLS))
1888 $(%(mmake)_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1889 $(%(mmake)_KOBJ) : $(%(mmake)_OBJS) $(%(mmake)_ENDOBJS)
1890         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1891         $(Q)$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1892         $(Q)$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1895 ## Dependency fine-tuning
1897 %(mmake)_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1898 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(%(mmake)_DEPS)
1900 %rule_makedirs dirs="%(objdir) $(%(mmake)_MODDIR) $(KOBJSDIR)" setuptarget="$(%(mmake)_OBJS) $(%(mmake)_DEPS) $(%(mmake)_MODULE) $(%(mmake)_KOBJ) "
1902 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_MODULE) $(%(mmake)_KOBJ) $(%(mmake)_DEPS)
1903 %(mmake)-clean ::
1904         $(Q)$(ECHO) "Cleaning up for module %(modname)"
1905         $(Q)$(RM) $(FILES)
1906 %end
1907 #------------------------------------------------------------------------------
1910 #------------------------------------------------------------------------------
1911 # Build a module - core routine
1912 # Explanation of this macro is done in the developer's manual
1913 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
1914     files="$(basename $(call WILDCARD, *.c))" \
1915     objcfiles= \
1916     cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1917     linklibfiles= linklibobjs= \
1918     cppflags=$(CPPFLAGS) \
1919     cflags=$(CFLAGS) dflags= \
1920     cxxflags=$(CXXFLAGS) dxxflags= \
1921     objdir= moduledir= prefix=$(AROSDIR) \
1922     linklibname= uselibs= usehostlibs= \
1923     compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1924     include_set=includes-all includedir= libdir= \
1925     build_abi= build_library=
1927 # We will employ a terrifying, but unavoidable, hack here.
1928 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1929 # ignores GNU Make ifeq() statements, but will process any #MM
1930 # headed lines in the file.
1932 # So, to make the following #MM lines conditional on whether we want
1933 # to build the ABI, Library, or both, we define build_abi= and 
1934 # build_library as 'M' to enable, or '' to disable, which allows genmf
1935 # to do the following conversions:
1937 #  #%(build_abi)M includes-foo: foo-include
1938 #    becomes, when build_abi=M
1939 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1940 #    but, when build_abi= ...
1941 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1943 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1945 # Define metamake targets and their dependencies
1946 #MM %(mmake)
1947 #MM %(mmake)-quick
1948 #MM %(mmake)-makefile
1949 #MM %(mmake)-clean
1951 # ABI targets:
1952 #M%(build_abi)- %(include_set) : %(mmake)-includes
1953 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1954 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1955 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1956 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1957 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1958 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1959 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1960 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1961 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1962 #M%(build_abi) %(mmake)-includes-quick
1963 #M%(build_abi) %(mmake)-includes-dirs
1964 #M%(build_abi) %(mmake)-fd
1966 # Library targets
1967 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1968 #%(build_library)M %(mmake)-kobj-quick : 
1970 # Library with ABI targets:
1971 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1972 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1974 # All MetaMake targets defined by this macro
1975 %(mmake)%(flavour)_ALLTARGETS       := %(mmake) %(mmake)-quick %(mmake)-clean
1977 ifeq (%(build_library),M)
1978 %(mmake)%(flavour)_ALLTARGETS       += %(mmake)-kobj %(mmake)-kobj-quick
1979 endif
1981 ifeq (%(build_abi),M)
1982 %(mmake)%(flavour)_ALLTARGETS += %(mmake)-includes \
1983                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1984                  %(mmake)-linklib %(mmake)-fd
1985 endif
1987 .PHONY : $(%(mmake)%(flavour)_ALLTARGETS) %(mmake)-makefile
1989 ifeq (%(modname),)
1990 $(error using %build_module: modname may not be empty)
1991 endif
1992 ifeq (%(modtype),)
1993 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1994 endif
1996 # Default values for variables and arguments
1997 ifneq (%(flavour),)
1998     %(mmake)%(flavour)_DEFNAME      := %(modname)_%(flavour)
1999 else
2000     %(mmake)%(flavour)_DEFNAME      := %(modname)
2001 endif
2002 %(mmake)%(flavour)_DEFLINKLIBNAME   := $(%(mmake)%(flavour)_DEFNAME)
2003 ifneq (%(linklibname),)
2004     %(mmake)%(flavour)_LINKLIBNAME  := %(linklibname)
2005 else
2006     %(mmake)%(flavour)_LINKLIBNAME  = $(%(mmake)%(flavour)_DEFLINKLIBNAME)
2007 endif
2008 %(mmake)%(flavour)_DEFCPPFLAGS      := %(cppflags)
2009 ifneq (%(includedir),)
2010     %(mmake)%(flavour)_DEFCPPFLAGS  += -I%(includedir)
2011 endif
2012 %(mmake)%(flavour)_DEFDFLAGS        := %(cflags)
2013 ifneq (%(dflags),)
2014     %(mmake)%(flavour)_DFLAGS       := %(dflags)
2015 else
2016     %(mmake)%(flavour)_DFLAGS       = $(%(mmake)%(flavour)_DEFDFLAGS)
2017 endif
2018 %(mmake)%(flavour)_DEFDXXFLAGS      := %(cxxflags)
2019 ifneq (%(dxxflags),)
2020     %(mmake)%(flavour)_DXXFLAGS     := %(dxxflags)
2021 else
2022     %(mmake)%(flavour)_DXXFLAGS     = $(%(mmake)%(flavour)_DEFDXXFLAGS)
2023 endif
2025 ifeq (%(compiler),target)
2026 ifeq (%(lto),yes)
2027 %(mmake)%(flavour)_DEFDFLAGS        := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(%(mmake)%(flavour)_DEFDFLAGS))
2028 %(mmake)%(flavour)_DEFDXXFLAGS      := $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(%(mmake)%(flavour)_DEFDXXFLAGS))
2029 endif
2030 ifeq (%(funcinstr),yes)
2031 %(mmake)_FUNCINSTR := yes
2032 %(mmake)%(flavour)_DEFDFLAGS        := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)%(flavour)_DEFDFLAGS))
2033 %(mmake)%(flavour)_DEFDXXFLAGS      := $(strip $(FUNCINSTR_FLAGS) $(%(mmake)%(flavour)_DEFDXXFLAGS))
2034 endif
2035 endif
2037 OBJDIR                              ?= $(GENDIR)/$(CURDIR)
2038 ifneq (%(objdir),)
2039 %(mmake)_OBJDIR                     := %(objdir)
2040 else
2041 %(mmake)_OBJDIR                     := $(OBJDIR)/$(%(mmake)%(flavour)_DEFNAME)
2042 endif
2043 ifneq (%(flavour),)
2044 %(mmake)%(flavour)_OBJDIR           := $(%(mmake)_OBJDIR)
2045 endif
2047 ## Create genmodule include Makefile for the module
2049 %(mmake)%(flavour)-makefile         := $(%(mmake)%(flavour)_OBJDIR)/Makefile.$(%(mmake)%(flavour)_DEFNAME)%(modtype)
2050 %(mmake)%(flavour)-genmakefile : $(%(mmake)%(flavour)-makefile)
2052 %rule_genmodule_makefile \
2053     mmake=%(mmake)-genmakefile modname="%(modname)" flavour="%(flavour)" modtype="%(modtype)" \
2054     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2055     conffile="%(conffile)"
2057 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)" setuptarget=$(%(mmake)%(flavour)-makefile)
2059 # Do not parse these statements if metatarget is not appropriate
2060 ifneq ($(filter $(TARGET),$(%(mmake)%(flavour)_ALLTARGETS)),)
2062 # suppress makes warning that the Makefile doesnt yet exist
2063 # on early passes (it will generate the file as needed though)
2064 # when we include it.
2065 -include $(%(mmake)%(flavour)-makefile)
2067 %(mmake)%(flavour)_DEFMODDIR        := $($(%(mmake)%(flavour)_DEFNAME)_MODDIR)
2068 ifeq (%(archspecific),yes)
2069 %(mmake)%(flavour)_DEFMODDIR        := $(AROS_DIR_ARCH)/$(%(mmake)%(flavour)_DEFMODDIR)
2070 endif
2071 ifneq (%(moduledir),)
2072     %(mmake)%(flavour)_MODDIR       := %(moduledir)
2073 else
2074     %(mmake)%(flavour)_MODDIR       := $(%(mmake)%(flavour)_DEFMODDIR)
2075 endif
2077 ## include files generation
2079 ifneq (%(includedir),)
2080 %(mmake)%(flavour)_INCDIR           := %(includedir)
2081 else
2082 %(mmake)%(flavour)_INCDIR           := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
2083 endif
2084 %(mmake)%(flavour)_LIBDEFSINC       := $(%(mmake)%(flavour)_OBJDIR)/include/$(%(mmake)%(flavour)_DEFNAME)_libdefs.h
2085 %(mmake)%(flavour)_DEFLIBDEFSINC    := $(%(mmake)%(flavour)_OBJDIR)/include/$(%(mmake)%(flavour)_DEFNAME)_deflibdefs.h
2087 ifeq (%(build_abi),M)
2088 %(mmake)-includes-quick : %(mmake)-includes
2089 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2090     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2091     $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC)
2093 ifneq ($($(%(mmake)%(flavour)_DEFNAME)_INCLUDES),)
2094 %rule_genmodule_includes mmake=%(mmake)-includes modname="%(modname)" modtype="%(modtype)" \
2095     modsuffix="%(modsuffix)" targetdir="$(%(mmake)_OBJDIR)/include" \
2096     conffile="%(conffile)" flavour="%(flavour)"
2098 %rule_copy_diff_multi \
2099     files=$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES) srcdir="$(%(mmake)_OBJDIR)/include" targetdir=$(GENINCDIR) \
2100     stampfile="$(%(mmake)_OBJDIR)/%(modname)_geninc"
2102 %rule_copy_diff_multi \
2103     files=$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES) srcdir="$(%(mmake)_OBJDIR)/include" targetdir=$(%(mmake)%(flavour)_INCDIR) \
2104     stampfile="$(%(mmake)_OBJDIR)/%(modname)_incs"
2106 %(mmake)%(flavour)_INCDIRS := $(filter-out ./,$(sort $(dir $($(%(mmake)%(flavour)_DEFNAME)_INCLUDES))))
2108 TMP%(modname)_INCDIRS := \
2109     $(%(mmake)_OBJDIR)/include $(addprefix $(%(mmake)_OBJDIR)/include/,$(%(mmake)%(flavour)_INCDIRS)) \
2110     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(%(mmake)%(flavour)_INCDIRS)) \
2111     $(%(mmake)%(flavour)_INCDIR) $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$(%(mmake)%(flavour)_INCDIRS))
2112 %rule_makedirs dirs="$(TMP%(modname)_INCDIRS)" setuptarget="%(mmake)-includes-dirs"
2114 endif
2116 endif
2118 %rule_genmodule_genlibdefs mmake=%(mmake)-genlibdefs modname="%(modname)" flavour="%(flavour)" modtype="%(modtype)" \
2119     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)/include" \
2120     conffile="%(conffile)" version="%(version)"
2122 $(%(mmake)%(flavour)_DEFLIBDEFSINC) : FILENAME := $(%(mmake)%(flavour)_LIBDEFSINC)
2123 $(%(mmake)%(flavour)_DEFLIBDEFSINC) : $(%(mmake)%(flavour)_LIBDEFSINC)
2124         $(Q)$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
2125         $(Q)$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2127 $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC) : | $(%(mmake)%(flavour)_OBJDIR)/include
2128 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)/include" setuptarget=%(mmake)%(flavour)-includes-dirs
2130 ## Extra genmodule src files generation
2131 ## 
2132 %rule_genmodule_files mmake=%(mmake)-genmodfiles modname="%(modname)" modtype="%(modtype)" \
2133     modsuffix="%(modsuffix)" targetdir="$(%(mmake)%(flavour)_OBJDIR)" stubdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2134     conffile="%(conffile)" flavour="%(flavour)"
2136 $(%(mmake)-genmodfiles_GENFILEFLAG) : $(%(mmake)%(flavour)_DEFLIBDEFSINC) $(%(mmake)%(flavour)-makefile)
2138 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR)/linklib" setuptarget=%(mmake)%(flavour)-linklib-setup
2140 ifeq (%(build_abi),M)
2141 ## Create FD file
2142 ifeq (%(includedir),)
2143 %(mmake)%(flavour)_FDDIR            := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_SDK)/$(AROS_DIR_FD)
2144 else
2145 %(mmake)%(flavour)_FDDIR            := %(includedir)/../$(AROS_DIR_FD)
2146 endif
2147 %(mmake)-fd : $(%(mmake)%(flavour)_FDDIR)/%(modname)_lib.fd
2149 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
2150     modsuffix="%(modsuffix)" targetdir=$(%(mmake)%(flavour)_FDDIR) conffile="%(conffile)"
2152 $(%(mmake)%(flavour)_FDDIR)/%(modname)_lib.fd : | $(%(mmake)%(flavour)_FDDIR)
2154 %rule_makedirs dirs="$(%(mmake)%(flavour)_FDDIR)" setuptarget=%(mmake)%(flavour)-fd-setup
2155 endif
2157 ## Compilation
2159 %(mmake)%(flavour)_FILES            := %(files)
2160 %(mmake)%(flavour)_OBJCFILES        := %(objcfiles)
2161 %(mmake)%(flavour)_CXXFILES         := %(cxxfiles)
2163 %(mmake)%(flavour)_LIBFILES         := %(linklibfiles)
2164 %(mmake)%(flavour)_LIBS             := %(uselibs)
2166 %(mmake)%(flavour)_FDIRS            := $(sort $(dir $(%(mmake)%(flavour)_FILES)))
2168 %(mmake)%(flavour)_FILEMATCH        = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
2169 %(mmake)%(flavour)_MATCHARCH        = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call %(mmake)%(flavour)_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
2170 %(mmake)%(flavour)_FILTERARCH       = $(filter-out $(call %(mmake)%(flavour)_MATCHARCH,$(1),$(2)),$(2))
2171 %(mmake)%(flavour)_STARTFILES       := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_STARTFILES))
2172 %(mmake)%(flavour)_ENDFILES         := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_ENDFILES))
2174 %(mmake)%(flavour)_ARCHOBJS         := $(wildcard $(%(mmake)%(flavour)_OBJDIR)/arch/*.o)
2175 %(mmake)%(flavour)_LIBARCHOBJS      := $(wildcard $(%(mmake)%(flavour)_OBJDIR)/linklib/arch/*.o)
2176 %(mmake)%(flavour)_ARCHFILES        := $(basename $(notdir $(%(mmake)%(flavour)_ARCHOBJS)))
2177 %(mmake)%(flavour)_LIBARCHFILES     := $(basename $(notdir $(%(mmake)%(flavour)_LIBARCHOBJS)))
2178 %(mmake)%(flavour)_C_NARCHFILES     := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_FILES))
2179 %(mmake)%(flavour)_CXX_NARCHFILES   := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_CXXFILES))
2180 %(mmake)%(flavour)_OBJC_NARCHFILES  := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_ARCHFILES),$(%(mmake)%(flavour)_OBJCFILES))
2181 %(mmake)%(flavour)_NLIBARCHFILES    := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_LIBARCHFILES),$(%(mmake)%(flavour)_LIBFILES))
2182 %(mmake)%(flavour)_ARCHNLIBFILES    := $(call %(mmake)%(flavour)_FILTERARCH,$(%(mmake)%(flavour)_LIBFILES),$(%(mmake)%(flavour)_LIBARCHFILES))
2184 %(mmake)%(flavour)_CPPFLAGS         := $(strip %(cppflags) -I$(%(mmake)%(flavour)_OBJDIR)/include -include $(%(mmake)%(flavour)_DEFLIBDEFSINC))
2185 ifneq (%(includedir),)
2186 %(mmake)%(flavour)_CPPFLAGS         += -I%(includedir)
2187 endif
2188 %(mmake)%(flavour)_LINKLIBCPPFLAGS  := $(%(mmake)%(flavour)_CPPFLAGS)
2189 %(mmake)%(flavour)_CPPFLAGS         += $(strip $($(%(mmake)%(flavour)_DEFNAME)_CPPFLAGS))
2190 %(mmake)%(flavour)_LINKLIBCPPFLAGS  += $(strip $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBCPPFLAGS))
2191 %(mmake)%(flavour)_CFLAGS           := $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_CFLAGS))
2192 %(mmake)%(flavour)_LINKLIBCFLAGS    := $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBCFLAGS))
2193 %(mmake)%(flavour)_CXXFLAGS         := $(strip %(cxxflags) $($(%(mmake)%(flavour)_DEFNAME)_CXXFLAGS))
2194 ifeq (%(compiler),target)
2195 ifeq (%(lto),yes)
2196 %(mmake)%(flavour)_LTOFLAGS         ?= $(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH))
2197 %(mmake)%(flavour)_CFLAGS           := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CFLAGS))
2198 %(mmake)%(flavour)_LINKLIBCFLAGS    := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_LINKLIBCFLAGS))
2199 %(mmake)%(flavour)_CXXFLAGS         := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CXXFLAGS))
2200 endif
2201 ifeq (%(funcinstr),yes)
2202 %(mmake)%(flavour)_SUBSTNULL        :=
2203 %(mmake)%(flavour)_SUBSTSPACE       := $(%(mmake)%(flavour)_SUBSTNULL) #
2204 %(mmake)%(flavour)_SUBSTCOMMA       := ,
2205 %(mmake)%(flavour)_INSTRFUNCFLAGS   ?= $(strip $(FUNCINSTR_FLAGS) -finstrument-functions-exclude-file-list=$(subst $(%(mmake)%(flavour)_SUBSTSPACE),$(%(mmake)%(flavour)_SUBSTCOMMA),$(strip $($(%(mmake)%(flavour)_DEFNAME)_STARTFILES))))
2206 %(mmake)%(flavour)_INSTRFUNCLIBS    ?= $(FUNCINSTR_LIBS)
2207 %(mmake)%(flavour)_CFLAGS           := $(strip $(%(mmake)%(flavour)_INSTRFUNCFLAGS) $(%(mmake)%(flavour)_CFLAGS))
2208 %(mmake)%(flavour)_CXXFLAGS         := $(strip $(%(mmake)%(flavour)_INSTRFUNCFLAGS) $(%(mmake)%(flavour)_CXXFLAGS))
2209 %(mmake)%(flavour)_LIBS             += $(%(mmake)%(flavour)_INSTRFUNCLIBS)
2210 endif
2211 endif
2212 %(mmake)%(flavour)_DFLAGS           := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DFLAGS))
2213 %(mmake)%(flavour)_LINKLIBDFLAGS    := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBDFLAGS))
2214 %(mmake)%(flavour)_DXXFLAGS         := $(strip $(%(mmake)%(flavour)_DXXFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DXXFLAGS))
2216 ifeq (%(modtype),library)
2217     %(mmake)%(flavour)_LIBSUFFIX    := 
2218 else
2219     %(mmake)%(flavour)_LIBSUFFIX    := .%(modtype)
2220 endif
2222 ifeq (%(libdir),)
2223 %(mmake)%(flavour)_LIBDIR           := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
2224 else
2225 %(mmake)%(flavour)_LIBDIR           := %(libdir)
2226 endif
2228 ifeq (%(build_abi),M)
2229 %(mmake)%(flavour)_LINKLIBCFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES))
2230 %(mmake)%(flavour)_LINKLIBAFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES))
2231 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2232     %(mmake)%(flavour)_LINKLIB      :=
2233 else
2234     %(mmake)%(flavour)_LINKLIB      := $(%(mmake)%(flavour)_LIBDIR)/lib%(modname)$(%(mmake)%(flavour)_LIBSUFFIX).a
2235     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2236         %(mmake)%(flavour)_LINKLIB  += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX).a
2237     endif
2238 endif
2239 %(mmake)%(flavour)_LINKLIBFILES     := $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_LINKLIBAFILES)
2241 %(mmake)%(flavour)_RELLINKLIBCFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES))
2242 %(mmake)%(flavour)_RELLINKLIBAFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES))
2243 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2244     %(mmake)%(flavour)_RELLINKLIB   :=
2245 else
2246     %(mmake)%(flavour)_RELLINKLIB   := $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2247     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2248         %(mmake)%(flavour)_RELLINKLIB += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2249     endif
2250 endif
2251 %(mmake)%(flavour)_RELLINKLIBFILES  := $(%(mmake)%(flavour)_RELLINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)
2252 endif
2254 %(mmake)%(flavour)_ENDOBJS          := $(addsuffix .o,$(%(mmake)%(flavour)_ENDFILES))
2255 %(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)) \
2256                  %(linklibobjs)
2257 %(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)) \
2258                  %(linklibobjs)
2259 $(%(mmake)%(flavour)_LINKLIBFILES) $(%(mmake)%(flavour)_RELLINKLIBFILES) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2260 $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_RELLINKLIBOBJS) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2262 %(mmake)%(flavour)_CCFILES := $(%(mmake)%(flavour)_C_NARCHFILES)
2263 %(mmake)%(flavour)_TARGETCCFILES    := $(strip $(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES))
2264 %(mmake)%(flavour)_LINKLIBCCFILES   := $(strip $(%(mmake)%(flavour)_NLIBARCHFILES) $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2265 %(mmake)%(flavour)_LINKLIBCCGENFILES := $(strip $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2267 %rule_compile_cxx_multi mmake=%(mmake)%(flavour) \
2268     basenames=$(%(mmake)%(flavour)_CXX_NARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2269     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cxxflags=$(%(mmake)%(flavour)_CXXFLAGS) dxxflags=$(%(mmake)%(flavour)_DXXFLAGS) \
2270     compiler="%(compiler)"
2271 %rule_compile_objc_multi mmake=%(mmake)%(flavour) \
2272     basenames=$(%(mmake)%(flavour)_OBJC_NARCHFILES) targetdir=$(%(mmake)%(flavour)_OBJDIR) \
2273     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2274     compiler="%(compiler)"
2275 %rule_compile_multi mmake=%(mmake)%(flavour) \
2276     basenames=$(%(mmake)%(flavour)_CCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2277     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2278     compiler="%(compiler)"
2279 %rule_compile_multi mmake=%(mmake)%(flavour) \
2280     basenames=$(%(mmake)%(flavour)_TARGETCCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2281     cppflags="$(%(mmake)%(flavour)_CPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2282     compiler="%(compiler)"
2283 %rule_compile_multi mmake=%(mmake)%(flavour) \
2284     basenames=$(%(mmake)%(flavour)_NLIBARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2285     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_LINKLIBCFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2286     compiler="%(compiler)"
2287 %rule_compile_multi mmake=%(mmake)%(flavour) \
2288     basenames=$(%(mmake)%(flavour)_LINKLIBCCGENFILES) srcdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2289     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_LINKLIBCFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2290     compiler="%(compiler)"
2292 ifneq ($(%(mmake)%(flavour)_LINKLIBAFILES),)
2293 %rule_assemble_multi  mmake=%(mmake)%(flavour) \
2294     cmd=$(%(mmake)%(flavour)_ASSEMBLER) basenames="$(%(mmake)%(flavour)_LINKLIBAFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" suffix=.S
2295 endif
2297 ## Linking
2299 ifeq (%(modsuffix),)
2300 %(mmake)%(flavour)_SUFFIX           := %(modtype)
2301 else
2302 %(mmake)%(flavour)_SUFFIX           := %(modsuffix)
2303 endif
2305 ifeq (%(build_library),M)
2306 # Handlers use dash instead of dot in their names
2307 ifeq ($(%(mmake)%(flavour)_SUFFIX),handler)
2308 %(mmake)%(flavour)_MODULE           := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME)-$(%(mmake)%(flavour)_SUFFIX)
2309 else
2310 %(mmake)%(flavour)_MODULE           := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME).$(%(mmake)%(flavour)_SUFFIX)
2311 endif
2312 %(mmake)%(flavour)_KOBJ             := $(KOBJSDIR)/$(%(mmake)%(flavour)_DEFNAME)_$(%(mmake)%(flavour)_SUFFIX).o
2313 else
2314 %(mmake)%(flavour)_MODULE           :=
2315 %(mmake)%(flavour)_KOBJ             :=
2316 endif
2318 %(mmake)-quick      : %(mmake)
2319 %(mmake)            : $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2320 ifeq (%(build_library),M)
2321 %(mmake)-kobj       : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2322 %(mmake)-kobj-quick : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2323 endif
2324 ifeq (%(build_abi),M)
2325 %(mmake)-linklib    : $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2326 endif
2328 %(mmake)%(flavour)_OBJS := $(addsuffix .o,$(%(mmake)%(flavour)_STARTFILES)) $(%(mmake)%(flavour)_ARCHOBJS) \
2329            $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$(notdir $(%(mmake)%(flavour)_C_NARCHFILES:=.o) $(%(mmake)%(flavour)_CXXFILES:=.o)))
2331 ifeq (%(nostartup),yes)
2332 # Handlers always have entry point
2333 ifneq (%(modtype),handler)
2334 %(mmake)%(flavour)_STARTOBJS        := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2335 endif
2336 endif
2338 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2339 # This breaks con-handler build. Here we work around this
2340 ifeq (%(modname),con)
2341     %(mmake)%(flavour)_ERR          := $(notdir $(%(mmake)%(flavour)_MODULE)).err
2342 else
2343     %(mmake)%(flavour)_ERR          := %(modname).err
2344 endif
2346 ifeq (%(build_library),M)
2347 # The module is linked from all the compiled .o files
2348 %rule_linkmodule module=$(%(mmake)%(flavour)_MODULE) objs="$(%(mmake)%(flavour)_STARTOBJS) $(%(mmake)%(flavour)_OBJS) $(USER_OBJS)" \
2349                  endobj=$(%(mmake)%(flavour)_ENDOBJS) err=$(%(mmake)%(flavour)_ERR) objdir="$(%(mmake)%(flavour)_OBJDIR)" \
2350                  cmd=$(%(mmake)%(flavour)_LINK) ldflags="$(LDFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LDFLAGS)" \
2351                  uselibs="$(%(mmake)%(flavour)_LIBS) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)" usehostlibs="%(usehostlibs)"
2352 endif
2354 ifeq (%(build_abi),M)
2355 # Link static lib
2356 %(mmake)%(flavour)_LC_LINKLIBNAME   := $(shell echo $(%(mmake)%(flavour)_LINKLIBNAME) | tr A-Z a-z)
2357 %(mmake)%(flavour)_LC_MODNAME       := $(shell echo %(modname) | tr A-Z a-z)
2358 ifneq ($(%(mmake)%(flavour)_LINKLIB),)
2359 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2360 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2361 %rule_link_linklib mmake=%(mmake) libname="%(modname)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2362 endif
2364 %rule_makedirs dirs="$(%(mmake)%(flavour)_LIBDIR)" setuptarget=$(%(mmake)%(flavour)_LINKLIB)
2365 endif
2367 ifneq ($(%(mmake)%(flavour)_RELLINKLIB),)
2368 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2369 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2370 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2371 endif
2373 %rule_makedirs dirs="$(%(mmake)%(flavour)_LIBDIR)" setuptarget=$(%(mmake)%(flavour)_RELLINKLIB)
2374 endif
2375 endif
2377 ifeq (%(build_library),M)
2378 # Link kernel object file
2379 %(mmake)%(flavour)_KAUTOLIB         := dos intuition layers graphics oop utility expansion keymap
2381 # Make these symbols local
2382 %(mmake)%(flavour)_KBASE            := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2383             UtilityBase ExpansionBase KeymapBase KernelBase
2385 %(mmake)%(flavour)_SYMBOLS := $(%(mmake)%(flavour)_KBASE)
2387 %(mmake)%(flavour)_KLIB             := hiddstubs amiga arossupport autoinit libinit
2388 %(mmake)%(flavour)_KOBJ_LIBS        := $(filter-out $(%(mmake)%(flavour)_KLIB),$(%(mmake)%(flavour)_LIBS)) $(%(mmake)%(flavour)_KAUTOLIB)
2389 $(%(mmake)%(flavour)_KOBJ) : LINKLIBS:=$(%(mmake)%(flavour)_KOBJ_LIBS) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)
2390 $(%(mmake)%(flavour)_KOBJ) : FILTBASES:=$(addprefix -L ,$(%(mmake)%(flavour)_SYMBOLS))
2391 $(%(mmake)%(flavour)_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2392 $(%(mmake)%(flavour)_KOBJ) : $(%(mmake)%(flavour)_OBJS) $(USER_OBJS) $(%(mmake)%(flavour)_ENDOBJS)
2393         $(Q)$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2394         $(Q)$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2395         $(Q)$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2396 endif
2398 ## Dependency fine-tuning
2400 %(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)))
2402 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(%(mmake)%(flavour)_DEPS)
2404 $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2405 %rule_makedirs dirs="$(%(mmake)%(flavour)_OBJDIR) %(prefix)/$(%(mmake)%(flavour)_MODDIR) $(KOBJSDIR)" setuptarget="$(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_KOBJ)"
2407 # Some include files need to be generated before the .c can be parsed.
2408 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2410 %(mmake)%(flavour)_DFILE_DEPS := $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC) \
2411     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES))
2412 $(%(mmake)%(flavour)_DEPS) : $(%(mmake)%(flavour)_DFILE_DEPS)
2413 endif
2415 %(mmake)%(flavour)_TOCLEAN := $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) \
2416     $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_KOBJ) \
2417     $(%(mmake)%(flavour)_OBJDIR)/Makefile.%(modname)%(modtype) \
2418     $(addprefix $(%(mmake)%(flavour)_OBJDIR)/include/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2419     $(addprefix $(GENINCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2420     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2421     $(%(mmake)_OBJDIR)/%(modname)_geninc $(%(mmake)_OBJDIR)/%(modname)_incs \
2422     $(addsuffix .c,$(%(mmake)%(flavour)_LINKLIBFILES)) $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_LIBDEFSINC) \
2423     $(%(mmake)%(flavour)_DEFLIBDEFSINC) $(addsuffix .c,$(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES)) \
2424     $(%(mmake)%(flavour)_ENDOBJS)
2425 %(mmake)-clean : FILES              := $(%(mmake)%(flavour)_TOCLEAN)
2426 %(mmake)-clean ::
2427         $(Q)$(ECHO) "Cleaning up for module %(modname)"
2428         $(Q)$(RM) $(FILES)
2430 endif # $(TARGET) in $(%(mmake)%(flavour)_ALLTARGETS)
2431 %end
2432 #------------------------------------------------------------------------------
2434 #------------------------------------------------------------------------------
2435 # Build a module - ABI and library
2436 # Explanation of this macro is done in the developer's manual
2437 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2438   files="$(basename $(call WILDCARD, *.c))" \
2439   objcfiles= \
2440   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2441   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2442   objdir= moduledir= prefix=$(AROSDIR) \
2443   linklibname= uselibs= usehostlibs= \
2444   compiler=target funcinstr=$(TARGET_FUNCINSTR) lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2445   include_set=includes-all includedir= libdir=
2447 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2448    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2449    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2450    linklibname="%(linklibname)" \
2451    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2452    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2453    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2454    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" funcinstr=%(funcinstr) lto=%(lto) \
2455    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2456    include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2457    build_abi=M build_library=M
2459 %end
2460 #------------------------------------------------------------------------------
2463 #------------------------------------------------------------------------------
2464 # Build a module skeleton ABI
2465 # This is a stripped-down version of build_module, it only creates include
2466 # files and the linklibs.
2467 # This is used when for plugins or classes with the same API, but no actual
2468 # implementation here.
2469 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2470   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2471   objdir= moduledir= prefix=$(AROSDIR) \
2472   linklibname= uselibs= usehostlibs= \
2473   compiler=target nostartup=yes archspecific=no \
2474   include_set=includes-all includedir= libdir=
2476 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2477   modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2478   linklibname="%(linklibname)" \
2479   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2480   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2481   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2482   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2483   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2484   include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2485   build_abi=M build_library=
2487 %end
2488 #------------------------------------------------------------------------------
2490 #------------------------------------------------------------------------------
2491 # Build a module library - no includes nor linklibs
2492 # Explanation of this macro is done in the developer's manual
2493 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2494   files="$(basename $(call WILDCARD, *.c))" \
2495   objcfiles= \
2496   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2497   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags="$(CXXFLAGS)" dxxflags= \
2498   objdir= moduledir= prefix=$(AROSDIR) \
2499   uselibs= usehostlibs= \
2500   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2501   include_set=includes-all includedir= libdir=
2503 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2504    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2505    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2506    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2507    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2508    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2509    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2510    include_set=%(include_set) includedir="%(includedir)" libdir="%(libdir)" \
2511    build_abi= build_library=M
2513 %end
2514 #------------------------------------------------------------------------------
2518 #------------------------------------------------------------------------------
2519 # Build a linklib.
2520 # - mmake is the mmaketarget
2521 # - libname is the baselibname e.g. lib%(libname).a will be created
2522 # - files are the C source files to include in the lib. The list of files
2523 #   has to be given without the .c suffix
2524 # - cxxfiles are C++ source files without suffix.
2525 #   NB: files will be matched in the order .cpp > .cxx > .cc
2526 # - asmfiles are the asm files to include in the lib. The list of files has to
2527 #   be given without the .s suffix
2528 # - objs additional object to link into the linklib. The objects have to be
2529 #   given with full absolute path and the .o suffix.
2530 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2531 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2532 # - cflags are the flags to compile the source (default $(CFLAGS))
2533 # - dflags are the flags used during makedepend (default equal to cflags)
2534 # - aflags are the flags used during assembling (default $(AFLAGS))
2535 %define build_linklib mmake=/A libname=/A files= objcfiles= cxxfiles= \
2536   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2537   includedir= srcdir= \
2538   cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2539   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO) usetree=no
2541 # assign and generate the local variables used in this macro
2542 %(mmake)_LIBNAME           := %(libname)
2543 %(mmake)_LINKLIB           := %(libdir)/lib%(libname).a
2545 %(mmake)_FILES             ?= %(files)
2546 %(mmake)_ASMFILES          := %(asmfiles)
2547 %(mmake)_OBJCFILES         := %(objcfiles)
2548 %(mmake)_CXXFILES          := %(cxxfiles)
2550 %(mmake)_OBJDIR            ?= %(objdir)
2551 %(mmake)_ARCHOBJS          := $(wildcard $(%(mmake)_OBJDIR)/arch/*.o)
2552 ifeq (%(usetree),no)
2553     %(mmake)_ARCHFILES     := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
2554 else
2555     %(mmake)_ARCHFILES     := $(basename $(patsubst $(%(mmake)_OBJDIR)/%,%,$(%(mmake)_ARCHOBJS)))
2556 endif
2557 %(mmake)_C_NARCHFILES      := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_FILES))
2558 %(mmake)_C_FILES           ?= $(%(mmake)_C_NARCHFILES)
2559 %(mmake)_CXX_NARCHFILES    := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_CXXFILES))
2560 %(mmake)_CXX_FILES         ?= $(%(mmake)_CXX_NARCHFILES)
2561 %(mmake)_OBJC_NARCHFILES   := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_OBJCFILES))
2562 %(mmake)_OBJC_FILES        ?= $(%(mmake)_OBJC_NARCHFILES)
2564 ifeq (%(usetree),no)
2565     %(mmake)_OBJ_FILES     ?= $(addprefix $(%(mmake)_OBJDIR)/,$(notdir $(%(mmake)_C_NARCHFILES:=.o) $(%(mmake)_CXX_NARCHFILES:=.o) $(%(mmake)_ASMFILES:=.o) $(%(mmake)_OBJC_NARCHFILES:=.o)))
2566 else
2567     %(mmake)_OBJ_FILES     ?= $(addprefix $(%(mmake)_OBJDIR)/,$(%(mmake)_C_NARCHFILES:=.o) $(%(mmake)_CXX_NARCHFILES:=.o) $(%(mmake)_ASMFILES:=.o) $(%(mmake)_OBJC_NARCHFILES:=.o))
2568 endif
2569 %(mmake)_OBJS              ?= $(%(mmake)_ARCHOBJS) $(%(mmake)_OBJ_FILES) %(objs)
2570 %(mmake)_DEPS              := $(patsubst %.o,%.d,$(%(mmake)_OBJS))
2572 %(mmake)_CPPFLAGS          := %(cppflags)
2573 ifneq (%(includedir),)
2574     %(mmake)_CPPFLAGS      += -I%(includedir)
2575 endif
2576 %(mmake)_CFLAGS            := %(cflags)
2577 %(mmake)_CXXFLAGS          := %(cxxflags)
2578 ifeq (%(lto),yes)
2579 ifeq (%(compiler),target)
2580         %(mmake)_CFLAGS    := $(strip $(LTO_CFLAGS) $(%(mmake)_CFLAGS))
2581         %(mmake)_CXXFLAGS  := $(strip $(LTO_CFLAGS) $(%(mmake)_CXXFLAGS))
2582 endif
2583 endif
2584 %(mmake)_AFLAGS            := %(aflags)
2585 %(mmake)_DFLAGS            := %(dflags)
2586 ifneq (%(dflags),)
2587     %(mmake)_DFLAGS        := %(dflags)
2588 else
2589     %(mmake)_DFLAGS        := $(%(mmake)_CFLAGS)
2590 endif
2591 %(mmake)_DXXFLAGS          := %(dxxflags)
2592 ifneq (%(dxxflags),)
2593     %(mmake)_DXXFLAGS      := %(dxxflags)
2594 else
2595     %(mmake)_DXXFLAGS      := $(%(mmake)_CXXFLAGS)
2596 endif
2598 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2601 %(mmake)-quick : %(mmake)
2603 #MM %(mmake) : includes-generate-deps
2604 %(mmake) : $(%(mmake)_LINKLIB)
2606 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2608 %rule_compile_cxx_multi mmake=%(mmake) \
2609     basenames=$(%(mmake)_CXX_FILES) targetdir="$(%(mmake)_OBJDIR)" \
2610     cppflags=$(%(mmake)_CPPFLAGS) cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
2611     compiler="%(compiler)" srcdir=%(srcdir)
2612 %rule_compile_objc_multi mmake=%(mmake) \
2613     basenames=$(%(mmake)_OBJC_FILES) targetdir=$(%(mmake)_OBJDIR) \
2614     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2615     compiler="%(compiler)" srcdir=%(srcdir)
2616 %rule_compile_multi mmake=%(mmake) \
2617     basenames=$(%(mmake)_C_FILES) targetdir="$(%(mmake)_OBJDIR)" \
2618     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2619     compiler="%(compiler)" srcdir=%(srcdir) usetree=%(usetree)
2620 %rule_assemble basename=% targetdir="$(%(mmake)_OBJDIR)" \
2621     aflags=$(%(mmake)_AFLAGS)
2623 %rule_link_linklib mmake=%(mmake) libname="%(libname)" objs=$(%(mmake)_OBJS) libdir="%(libdir)" linker="%(compiler)"
2624 endif
2626 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
2629 %rule_makedirs dirs="$(%(mmake)_OBJDIR) %(libdir)" setuptarget="$(%(mmake)_OBJS) $(%(mmake)_DEPS) $(%(mmake)_LINKLIB)"
2631 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_LINKLIB) $(%(mmake)_DEPS)
2633 %(mmake)-clean ::
2634         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
2635         $(Q)$(RM) $(FILES)
2637 %end
2638 #------------------------------------------------------------------------------
2641 #------------------------------------------------------------------------------
2642 # Build catalogs.
2643 # - mmake is the mmaketarget
2644 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2645 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2646 # - subdir is the destination subdirectory of the catalogs
2647 # - name is the name of the destination catalog, without the .catalog suffix
2648 # - source is the path to the generated source code file
2649 # - dir is the base destination directory (default $(AROS_CATALOGS))
2650 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2651 # - srcdir is the directory in which the *.cd and *.ct files are searched
2653 %define build_catalogs mmake=/A name=/A subdir=/A \
2654  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2655  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2657 ifeq (%(description),)
2658 %(mmake)_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2659 else
2660 %(mmake)_DESC := %(description)
2661 endif
2663 %(mmake)_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2665 ifeq (%(catalogs),)
2666 %(mmake)_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2667 else
2668 %(mmake)_LNGS := %(catalogs)
2669 endif
2671 %(mmake)_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(%(mmake)_LNGS)))
2672 %(mmake)_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(%(mmake)_LNGS))) $(dir %(source))
2675 %(mmake) : $(%(mmake)_OBJS) %(source)
2677 %rule_makedirs dirs="$(%(mmake)_DIRS)" setuptarget=$(%(mmake)_OBJS)
2679 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(%(mmake)_DESC).cd
2680         $(Q)$(ECHO) "Creating   %(name) catalog for language $*."
2681         $(Q)$(FLEXCAT) $(%(mmake)_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2683 ifneq (%(source),)
2684 %(source) : %(mmake)_DESC := $(%(mmake)_DESC)
2685 %(source) : %(mmake)_SRC := $(%(mmake)_SRC)
2686 %(source) : $(%(mmake)_DESC).cd $(%(mmake)_SRC).sd | $(dir %(source))
2687         $(Q)$(ECHO) "Creating   %(name) catalog source file $@"
2688         $(Q)$(FLEXCAT) $(%(mmake)_DESC).cd $@=$(%(mmake)_SRC).sd
2689 endif
2691 %(mmake)-clean : FILES := $(%(mmake)_OBJS) %(source)
2693 %(mmake)-clean ::
2694         $(Q)$(ECHO) "Cleaning up for metatarget %(mmake)"
2695         $(Q)$(RM) $(FILES)
2697 .PHONY: %(mmake) %(mmake)-clean
2699 %end
2700 #-----------------------------------------------------------------------------
2703 #-----------------------------------------------------------------------------
2704 # Build icons.
2705 # - mmake is the mmaketarget
2706 # - icons is a list of icon base names (i.e. without the .info suffix)
2707 # - dir is the destination directory
2708 # - srcdir is where *.png and *.info.src are sought
2709 #-----------------------------------------------------------------------------
2711 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2713 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2716 %(mmake) : $(BD_OBJS)
2718 ifeq (%(image),)
2720 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2721         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2722         $(Q)$(ILBMTOICON) $+ $@
2724 else
2726 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2727         $(Q)$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2728         $(Q)$(ILBMTOICON) $+ $@
2730 endif
2732 %rule_makedirs dirs="%(dir)" setuptarget=$(BD_OBJS)
2734 %(mmake)-clean : FILES := $(BD_OBJS)
2736 %(mmake)-clean ::
2737         $(Q)$(RM) $(FILES)
2739 .PHONY: %(mmake) %(mmake)-clean
2741 %end
2742 #-----------------------------------------------------------------------------
2745 #------------------------------------------------------------------------------
2746 # Compile files for an arch-specific replacement of code for a module
2747 # - files: the basenames of the C files to compile.
2748 # - asmfiles: the basenames of the asm files to assemble.
2749 # - mainmmake: the mmake of the module in the main directory to compile these
2750 #   arch specific files for.
2751 # - maindir: the object directory for the main module
2752 # - arch: the arch for which to compile these files. It can have the form
2753 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2754 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2755 # - dflags: the flags used during creation of dependency file. If not specified
2756 #   the same value as cflags will be used
2757 # - aflags: the flags used during assembling
2758 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2759 #   the target compiler is used
2760 # - modname: arch_specific builds of modules (built using build_module) MUST
2761 #   specify the name here matching the original module. this insures multiple modules
2762 #   built from the same makefile will not pollute each other.
2763 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2764  cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target objdir= modname=
2766 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2767     $(error no files or asmfiles given)
2768 endif
2770 ifneq (%(cxxfiles),)
2771     $(error cxx support is TODO)
2772 endif
2774 %buildid targets="%(mainmmake)-%(arch)"
2776 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2777 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2778 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2779 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2780 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2781 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2782 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2783 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2784 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2785 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2786 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2787 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2788 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2789 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2790 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2792 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2794 ifneq (%(objdir),)
2795     BD_OBJROOT$(BDID)  := %(objdir)
2796 else
2797 ifneq (%(modname),)
2798     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)/%(modname)
2799 else
2800     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)
2801 endif
2802 endif
2803 BD_OBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/arch
2804 BD_LIBOBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/linklib/arch
2805 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2806 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2807 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2808 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2809 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2810 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2812 ifneq (%(modname),)
2813 BD_DEFLIBDEFSINC$(BDID) := -include $(BD_OBJROOT$(BDID))/include/%(modname)_deflibdefs.h
2814 endif
2816 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2817     BD_TARGET := %(mainmmake)-%(arch)-quick
2818 else
2819     BD_TARGET := %(mainmmake)-%(arch)
2820 endif
2823 ifeq ($(TARGET),$(BD_TARGET))
2824 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2825 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2826 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2827 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2828 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2829 endif
2831 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))" setuptarget="$(BD_OBJS$(BDID))"
2834 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2837 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2839 ifeq ($(findstring %(compiler),host kernel target),)
2840     $(error unknown compiler %(compiler))
2841 endif
2842 ifneq (%(modname),)
2843 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) -I$(BD_OBJROOT$(BDID)) $(BD_DEFLIBDEFSINC$(BDID)))
2844 else
2845 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2846 endif
2847 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2848 ifeq (%(compiler),target)
2849 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
2850 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
2851 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(TMP_CFLAGS) $(SAFETY_CFLAGS))
2852 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2853 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2854 endif
2855 ifeq (%(compiler),host)
2856 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2857 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2858 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2859 endif
2860 ifeq (%(compiler),kernel)
2861 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
2862 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip $(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS))
2863 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(TARGET_ISA_CFLAGS) $(KERNEL_CFLAGS) $(TMP_CFLAGS))
2864 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2865 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2866 endif
2868 ifeq ($(TARGET),$(BD_TARGET))
2869 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2870         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2871 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2872         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2873 endif
2875 ifeq (%(dflags),)
2876 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) $(BD_DEFLIBDEFSINC$(BDID)))
2877 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
2878 else
2879 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2880 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2881 endif
2882 ifeq ($(TARGET),$(BD_TARGET))
2883 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2884         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2886 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2887         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2888 endif
2890 $(BD_ASMOBJS$(BDID)) : CPPFLAGS:=%(cppflags)
2891 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2893 ifeq ($(TARGET),$(BD_TARGET))
2894 $(BD_OBJDIR$(BDID))/%.o : %.s
2895         %assemble_q
2896 $(BD_OBJDIR$(BDID))/%.o : %.S
2897         %assemble_q
2898 endif
2900 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2901 %end
2902 #------------------------------------------------------------------------------
2905 #------------------------------------------------------------------------------
2906 # generate asm files from c files (for debugging purposes)
2907 %define ctoasm_q
2908 %.s : %.c
2909         $(Q)$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2910         $(Q)$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2911 %end
2912 #------------------------------------------------------------------------------
2915 #------------------------------------------------------------------------------
2916 # Copy files from one directory to another.
2918 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2920 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2922 %rule_makedirs dirs="%(dst)"
2924 .PHONY : %(mmake)
2927 %(mmake) : | %(dst) 
2928         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2930 %end
2931 #------------------------------------------------------------------------------
2934 #------------------------------------------------------------------------------
2935 # Copy a directory recursively to another place, preserving the original 
2936 # hierarchical structure
2938 # src: the source directory whose content will be copied.
2939 # dst: the directories where to copy src's content. If not existing, they will be made.
2940 # excludefiles: files which must not be copied. Path must be relative to src.
2942 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2944 .PHONY : %(mmake)
2947 %(mmake) :
2948         $(Q)cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2950 %end
2951 #------------------------------------------------------------------------------
2954 #------------------------------------------------------------------------------
2955 #   Copy include files into the includes directories. There are currently
2956 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2957 #   for building tools that need to run on the host system $(GENINCDIR). The
2958 #   $(GENINCDIR) path must not contain any references to the C runtime
2959 #   library header files.
2961 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2962     dir= compiler=target includedir=$(AROS_INCLUDES)
2964 ifeq ($(findstring %(compiler),host kernel target),)
2965 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2966 endif
2968 ifneq (%(dir),)
2969 TMP_DIR                := %(dir)
2970 $(eval TMP_DIRREMAIN   := $$$(TMP_DIR))
2971 TMP_DIRFIRST           := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2972 BD_INCL_FILES          := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2973 BD_INCL_FILES          := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2974 ifeq ($(TMP_DIRFIRST),/)
2975 BD_INC_PATH            := %(dir)/
2976 else
2977 BD_INC_PATH            := $(SRCDIR)/$(CURDIR)/%(dir)/
2978 endif
2979 else
2980 BD_INCL_FILES          := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2981 BD_INC_PATH            := $(SRCDIR)/$(CURDIR)/
2982 endif
2984 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2985         $(Q)$(CP) $< $@
2987 ifeq (%(compiler),target)
2989 ifneq (%(dir),)
2990 BD_INCL_FILES2         := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2991 BD_INCL_FILES2         := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2992 else
2993 BD_INCL_FILES2         := $(addprefix %(includedir)/%(path)/,%(includes))
2994 endif
2996 BD_INCL_FILES          += $(BD_INCL_FILES2)
2998 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2999         $(Q)$(CP) $< $@
3000 endif
3003 %(mmake) : $(BD_INCL_FILES)
3005 .PHONY: %(mmake)
3007 %rule_makedirs dirs="$(dir $(BD_INCL_FILES))" setuptarget=$(BD_INCL_FILES)
3008 %end
3009 #------------------------------------------------------------------------------
3012 #------------------------------------------------------------------------------
3013 %define make_hidd_stubs hidd=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
3014 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
3015 STUBS_MEM := $(addsuffix .o,$(STUBS))
3016 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
3017 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
3018 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
3020 #MM- linklibs : hidd-%(hidd)-stubs
3021 #MM- %(parenttarget): hidd-%(hidd)-stubs
3022 #MM hidd-%(hidd)-stubs : includes includes-copy
3023 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
3025 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
3026         %mklib_q from=$^
3028 $(STUBS_OBJ) : $(STUBS_SRC) 
3029         %compile_q cmd="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" opt="$(strip %(cflags) %(cppflags))" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
3031 $(STUBS_DEP) : $(STUBS_SRC)
3032         %mkdepend_q flags="$(strip %(dflags) %(cppflags))"
3034 setup ::
3035         %mkdirs_q $(OBJDIR) $(AROS_LIB)
3038 clean ::
3039         -@$(RM) $(HIDD_LIB) $(OBJDIR)
3041 DEPS := $(DEPS) $(STUBS_DEP)
3043 %end
3044 #------------------------------------------------------------------------------
3047 #------------------------------------------------------------------------------
3048 # Build an imported source tree which uses the configure script from the
3049 # autoconf package.  This rule will try to "integrate" the produced files as
3050 # much as possible in the AROS build, for example by putting libraries in the
3051 # standard library directory, includes in the standard include directory, and
3052 # so on. You can however override this behaviour.
3054 # As a special "bonus" for you, the PROGDIR environment variable is defined to
3055 # be %(bindir) (or its deduced value) when running "make install", and
3056 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
3057 # configure script some more parameters whose value depends upon the PROGDIR
3058 # env var, so that the program gets all its stuff installed in the proper place
3059 # when building it, but when running it from inside AROS it can also find that
3060 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
3061 # the configuration parameters set when running ./configure
3063 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
3064 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
3065 # to the name which has to follow it.
3067 # Arguments:
3069 #     - mmake           = the meta make target.
3070 #     - package         = name of the package to be built.
3071 #     - srcdir          = the location of the unpacked source code. Defaults
3072 #                         to $(SRCDIR)/$(CURDIR).
3073 #     - prefix          = the target directory. Must be an absolute path of the
3074 #                         host system. Defaults to $(AROS_CONTRIB).
3075 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3076 #                         Defaults to the value of the prefix option.
3077 #     - extraoptions    = additional options for the configure script.
3078 #     - usecppflags      = enable the use of cpp flags. some external configure
3079 #                         scripts will not set their own cppflags if it is already
3080 #                         set, so this allows them to be disabled (unless you can provide
3081 #                         all the options they would need)
3082 #     - extracppflags      = additional preprocessor flags.
3083 #     - usecflags      = same meaning as the one for the %build_with_configure macro.
3084 #     - extracflags     = additional flags to use with the C compiler.
3085 #     - usecxxflags      = same meaning as the one for the %build_with_configure macro.
3086 #     - extracxxflags   = additional flags to use with the C++ compiler.
3087 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
3088 #                         Defaults to the value of the nix argument.
3089 #     - nix             = enable u*nix path handling, i.e. a path like
3090 #                         /progdir//./file will be translated to
3091 #                         progdir:file during run-time. Defaults to no.
3092 #     - compiler        = target, host or kernel. Defaults to target.
3093 #     - install_target  = the command used for installing. Defaults to install. Leave
3094 #                         it empty if you want to suppress installing.
3095 #     - preconfigure    = a metatarget which is executed before configure is called.
3096 #     - postconfigure   = a metatarget which is executed after configure is called.
3097 #     - postinstall     = a metatarget which is executed after installing.
3098 #     - install_env     = set additional options for installing.
3099 #     - use_build_env   = if yes the configuration environment is used for
3100 #                         installing, too. Defaults to no.
3102 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
3103 # like this:
3105 # if nix_dir_layout
3106 #    --prefix = $(aros_prefix)
3107 #    progdir = $(aros_prefix)/bin
3108 # else
3109 #    if nix
3110 #        --prefix = /PROGDIR
3111 #        --bindir = /PROGDIR
3112 #        --sbindir = /PROGDIR
3113 #        --libdir = /LIB
3114 #        --includedir = /INCLUDE
3115 #        --oldincludedir = /INCLUDE   
3116 #    else
3117 #        --prefix = $(aros_prefix)
3118 #    endif
3120 #    progdir = $(aros_prefix)
3122 #    # Install options
3123 #    bindir = $(prefix)
3124 #    sbindir = $(prefix)
3125 #    libdir = $(AROS_LIB)
3126 #    includedir = $(AROS_INCLUDES)
3127 #    oldincludedir = $(AROS_INCLUDES)
3128 # endif
3131 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
3132     prefix= gendir= basedir=$(CURDIR) extraoptions= \
3133     usecppflags=yes extracppflags= \
3134     usecflags=yes extracflags="$(OPTIMIZATION_CFLAGS)" \
3135     usecxxflags=yes extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3136     hostisaflags="$(HOST_ISA_CFLAGS)" \
3137     kernelisaflags="$(TARGET_ISA_CFLAGS)" \
3138     targetisaflags="$(TARGET_ISA_CFLAGS)" \
3139     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
3140     install_target=install preconfigure= postconfigure= postinstall= \
3141     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes nlsflag=yes xflag=yes
3143 ifneq (%(prefix),)
3144     %(mmake)-prefix := %(prefix)
3145 else
3146     %(mmake)-prefix := $(AROS_CONTRIB)
3147 endif
3149 ifneq (%(aros_prefix),)
3150     %(mmake)-aros_prefix := %(aros_prefix)
3151 else
3152     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3153 endif
3155 BD_NIXFLAG ?= -nix
3157 ifeq (%(nix),yes)
3158     %(mmake)-nix    := $(BD_NIXFLAG)
3159     %(mmake)-volpfx := /
3160     %(mmake)-volsfx := /
3161     
3162     ifeq (%(nix_dir_layout),)
3163         %(mmake)-nix_dir_layout := yes
3164     endif
3165 else
3166     %(mmake)-volsfx := :
3167     
3168     ifeq (%(nix_dir_layout),)
3169         %(mmake)-nix_dir_layout := no
3170     endif
3171 endif
3173 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
3175 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
3176         exec_prefix=$(%(mmake)-prefix) %(install_env)
3178 # Check if chosen compiler is valid
3179 ifeq ($(findstring %(compiler),host target kernel),)
3180   $(error unknown compiler %(compiler))
3181 endif
3183 # Set legacy 'host' variable based on chosen compiler
3184 ifeq (%(compiler),host)
3185     host := yes
3186     ifeq (%(basedir),)
3187         %(mmake)-pkgbasedir := $(HOSTGENDIR)
3188     else
3189         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
3190     endif
3191 else
3192     host := no
3193     ifeq (%(basedir),)
3194         %(mmake)-pkgbasedir := $(GENDIR)
3195     else
3196         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
3197     endif
3198 endif
3199 ifneq (%(gendir),)
3200     ifeq (%(basedir),)
3201         %(mmake)-pkgbasedir := %(gendir)
3202     else
3203         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
3204     endif
3205 endif
3207 ifeq (%(package),)
3208     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
3209 else
3210     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
3211 endif
3213 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
3214 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3216 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
3217     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
3218     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3219 else
3220     ifeq (%(nix),yes)
3221         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
3222         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
3223     else
3224         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3225     endif
3227     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
3228     
3229     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
3230         sbindir=$(%(mmake)-prefix) \
3231         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
3232         oldincludedir=$(AROS_INCLUDES) %(install_env)
3233 endif
3235 ifneq ($(DEBUG),yes)
3236     %(mmake)-s_flag = -s
3237 endif
3239 ifeq (%(usecflags),yes)
3240     %(mmake)-HOST_CFLAGS=%(hostisaflags) $(HOST_CFLAGS)
3241     %(mmake)-KERNEL_CFLAGS=%(kernelisaflags) $(KERNEL_CFLAGS) $$(%(mmake)-s_flag)
3242 ifeq (%(crossbuild),yes)
3243     %(mmake)-TARGET_CFLAGS=%(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) $(%(mmake)-s_flag)
3244 else
3245     %(mmake)-TARGET_CFLAGS=%(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)
3246 endif
3247 endif
3248 ifeq (%(usecxxflags),yes)
3249     %(mmake)-HOST_CXXFLAGS=%(hostisaflags) $(HOST_CXXFLAGS)
3250     %(mmake)-KERNEL_CXXFLAGS=%(kernelisaflags) $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)
3251 ifeq (%(crossbuild),yes)
3252     %(mmake)-TARGET_CXXFLAGS=%(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) $(%(mmake)-s_flag)
3253 else
3254     %(mmake)-TARGET_CXXFLAGS=%(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)
3255 endif
3256 endif
3258 # Set up build environment, and options for configure script
3259 ifeq (%(compiler),host)
3260     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
3261     # confused configure scripts. We also cannot pass it via _FOR_BUILD
3262     # since that won't get picked up during configure.
3263     # We also cannot pass in the compiler including std flags so we need to use
3264     # the "plain" host compiler.
3265     %(mmake)-cfg-env := %(config_env_extra) \
3266         CPP="$(HOST_CPP)" \
3267         CXXCPP="$(HOST_CPP)" \
3268         CC="$(strip $(HOST_DEF_CC) $(%(mmake)-HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3269         CXX="$(strip $(HOST_CXX) $(%(mmake)-HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3270         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)"
3271 ifeq (%(usecppflags),yes)
3272     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3273 endif
3274     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3275         TARGET_CFLAGS="$(strip $(%(mmake)-KERNEL_CFLAGS))" \
3276         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3277         TARGET_CXXFLAGS="$(strip $(%(mmake)-KERNEL_CXXFLAGS))" \
3278         TARGET_AS="$(TARGET_AS)" \
3279         OBJCOPY="$(OBJCOPY)" \
3280         TARGET_RANLIB="$(RANLIB)" \
3281         TARGET_STRIP="$(STRIP_PLAIN)" \
3282         TARGET_NM="$(NM_PLAIN)" \
3283         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
3284 endif
3285 ifeq (%(compiler),target)
3286     %(mmake)-cfg-env := %(config_env_extra) \
3287         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
3288         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
3289     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3290         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3291         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3292         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3293         LD="$(strip $(TARGET_LD))"
3294     %(mmake)-cfg-env += CFLAGS="$(%(mmake)-TARGET_CFLAGS) %(extracflags)" \
3295         CXXFLAGS="$(%(mmake)-TARGET_CXXFLAGS) %(extracxxflags)"
3296 ifeq (%(usecppflags),yes)
3297     %(mmake)-cfg-env += CPPFLAGS="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3298 endif
3299     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3300 ifeq (%(usecppflags),yes)
3301     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3302 endif
3303     %(mmake)-cfg-env += CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
3304         CFLAGS_FOR_BUILD="$(strip $(%(mmake)-HOST_CFLAGS))" \
3305         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
3306         CXXFLAGS_FOR_BUILD="$(strip $(%(mmake)-HOST_CXXFLAGS))" \
3307         LD_FOR_BUILD="$(strip $(HOST_LD))" \
3308         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))"
3309 ifeq (%(usecppflags),yes)
3310     %(mmake)-cfg-env += CPPFLAGS_FOR_HOST="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3311 endif
3312     %(mmake)-cfg-env += CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3313         CFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3314         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3315         CXXFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3316         LD_FOR_HOST="$(strip $(TARGET_LD))" \
3317         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3318 ifeq (%(usecppflags),yes)
3319     %(mmake)-cfg-env += CPPFLAGS_FOR_TARGET="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3320 endif
3321     %(mmake)-cfg-env += CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3322         CFLAGS_FOR_TARGET="$(strip $(%(mmake)-TARGET_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags))" \
3323         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3324         CXXFLAGS_FOR_TARGET="$(strip $(%(mmake)-TARGET_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags))" \
3325         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3326         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3327         AR="$(strip $(AR_PLAIN))" \
3328         AS="$(strip $(TARGET_AS))" \
3329         OBJCOPY="$(strip $(OBJCOPY))" \
3330         RANLIB="$(strip $(RANLIB))" \
3331         STRIP="$(strip $(STRIP_PLAIN))"
3332 ifeq (%(usecppflags),yes)
3333     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3334 endif
3335     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3336         TARGET_CFLAGS="$(strip $(%(mmake)-KERNEL_CFLAGS))" \
3337         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3338         TARGET_CXXFLAGS="$(strip $(%(mmake)-KERNEL_CXXFLAGS))" \
3339         TARGET_AS="$(strip $(TARGET_AS))" \
3340         TARGET_RANLIB="$(strip $(RANLIB))" \
3341         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3342         TARGET_NM="$(strip $(NM_PLAIN))"
3343 ifeq (%(buildflags),yes)
3344     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3345     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3346     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3347 endif
3348 ifeq (%(gnuflags),yes)
3349     %(mmake)-config_opts += --without-pic --disable-shared
3350 ifeq (%(nlsflag),yes)
3351 # disable native language support
3352     %(mmake)-config_opts += --disable-nls
3353 endif
3354 ifeq (%(xflag),yes)
3355 # disable X window system
3356     %(mmake)-config_opts += --without-x
3357 endif
3358 endif
3359 endif
3360 ifeq (%(compiler),kernel)
3361     %(mmake)-cfg-env := %(config_env_extra) \
3362         CPP="$(KERNEL_CPP)" \
3363         CXXCPP="$(KERNEL_CPP)"
3364 ifeq (%(usecppflags),yes)
3365     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3366 endif
3367     %(mmake)-cfg-env += CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3368         CFLAGS="$(strip $(%(mmake)-KERNEL_CFLAGS) %(extracflags))" \
3369         CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3370         CXXFLAGS="$(strip $(%(mmake)-KERNEL_CXXFLAGS) %(extracxxflags))" \
3371         AS="$(KERNEL_AS)"
3372 ifeq (%(usecppflags),yes)
3373     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3374 endif
3375     %(mmake)-cfg-env += CC_FOR_BUILD="$(HOST_DEF_CC)" \
3376         CFLAGS_FOR_BUILD="$(%(mmake)-HOST_CFLAGS)" \
3377         CXX_FOR_BUILD="$(HOST_CXX)" \
3378         CXXFLAGS_FOR_BUILD="$(%(mmake)-HOST_CXXFLAGS)" \
3379         RANLIB="$(RANLIB)" \
3380         TARGET_RANLIB="$(RANLIB)" \
3381         TARGET_STRIP="$(STRIP_PLAIN)" \
3382         TARGET_NM="$(NM_PLAIN)"
3383 ifeq (%(buildflags),yes)
3384     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3385     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3386     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3387 endif
3388 ifeq (%(gnuflags),yes)
3389     %(mmake)-config_opts += --without-pic --disable-shared
3390 ifeq (%(nlsflag),yes)
3391 # disable native language support
3392     %(mmake)-config_opts += --disable-nls
3393 endif
3394 ifeq (%(xflag),yes)
3395 # disable X window system
3396     %(mmake)-config_opts += --without-x
3397 endif
3399 endif
3400 endif
3402 ifeq (%(use_build_env),yes)
3403     BUILD_ENV := $(%(mmake)-cfg-env)
3404 endif
3406 %(mmake)-touchfileflag ?= $(%(mmake)-pkgdir)/.files-touched
3408 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3409 # in an ideal world, we would depend on the files in the source directory,
3410 # so we could copy them when they change. unfortunately filenames with
3411 # spaces cause problems with this
3412 $(%(mmake)-pkgdir)/.local-copy:
3413         %mkdirs_q $(%(mmake)-pkgdir)
3414         $(Q)$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3415         $(Q)$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3417 $(%(mmake)-touchfileflag) : $(%(mmake)-pkgdir)/.local-copy
3419     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3420 else
3421     %(mmake)-cfg-srcdir=%(srcdir)
3422 endif
3423 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3425 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3427 # When building for the host, we don't need to build the
3428 # linklibs - this is especially true when building the
3429 # crosstool toolchain on 'foreign' architectures (such as
3430 # building PPC on x86)
3432 #MM- %(mmake)-host : setup includes %(mmake)-quick
3433 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3434 #MM- %(mmake): %(mmake)-%(compiler)
3436 # Using -j1 in install_command may result in a warning but finally
3437 # it does its job. make install for gcc does not work reliably for -jN
3438 # where N > 1.
3439 ifneq (%(install_target),)
3440     %(mmake)-install_command = \
3441         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3442         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3443         $(%(mmake)-make-env) %(install_target) -j1
3445     %(mmake)-uninstall_command = \
3446     $(RM) $(%(mmake)-installflag) && \
3447     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3448     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3449 else
3450     %(mmake)-install_command   := true
3451     %(mmake)-uninstall_command := true
3452 endif
3454 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3457 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3460 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3462 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3463         $(Q)$(IF) ! $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3464             $(RM) $(%(mmake)-installflag) && \
3465             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3466             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3467             $(%(mmake)-install_command) && \
3468             $(TOUCH) $@ -r $^; \
3469         fi
3471 ifneq ($(%(mmake)-touchfileflag),)
3472 $(%(mmake)-touchfileflag):
3473         %mkdirs_q $(%(mmake)-pkgdir)
3474         $(Q)find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3475         $(TOUCH) $@
3476 endif
3479 %(mmake)-uninstall :
3480         $(%(mmake)-uninstall_command)
3483 %(mmake)-configure : $(%(mmake)-configflag)
3485 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3486 $(%(mmake)-configflag) : $(%(mmake)-touchfileflag) $(TOP)/$(CURDIR)/mmakefile
3487         $(Q)$(RM) $@
3488         %mkdirs_q $(%(mmake)-pkgdir)
3489         $(Q)$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3490         $(Q)cd $(%(mmake)-pkgdir) && \
3491         find . -name config.cache -exec $(RM) '{}' \; && \
3492         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3493         $(TOUCH) $@
3496 %(mmake)-clean : %(mmake)-uninstall
3497         $(Q)$(RM) $(%(mmake)-pkgdir)
3498 %end
3499 #------------------------------------------------------------------------------
3502 #------------------------------------------------------------------------------
3503 # Build an imported source tree which uses cmake 
3505 # Arguments:
3507 #     - mmake           = the meta make target.
3508 #     - package         = name of the package to be built.
3509 #     - srcdir          = the location of the unpacked source code. Defaults
3510 #                         to $(SRCDIR)/$(CURDIR).
3511 #     - prefix          = the target directory. Must be an absolute path of the
3512 #                         host system. Defaults to $(AROS_CONTRIB).
3513 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3514 #                         Defaults to the value of the prefix option.
3515 #     - extraoptions    = additional options for the cmake script.
3516 #     - usecppflags     = enable the use of cpp flags. some external cmake
3517 #                         scripts will not set their own cppflags if it is already
3518 #                         set, so this allows them to be disabled (unless you can provide
3519 #                         all the options they would need)
3520 #     - cppflags        = preprocessor flags.
3521 #     - extracppflags      = additional preprocessor flags.
3522 #     - usecflags      = enable the use of the build systems C flags
3523 #     - cflags     = additional flags to use with the C compiler.
3524 #     - usecxxflags      = enable the use of the build systems C flags
3525 #     - cxxflags   = additional flags to use with the C++ compiler.
3526 #     - cflags          = flags to use with the C compiler.
3527 #     - cxxflags        = flags to use with the C++ compiler.
3528 #     - installoptions    = additional options for the install step.
3531 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3532     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3533     usecppflags=yes extracppflags=$(CPPFLAGS) \
3534     usecflags=yes extracflags=$(CFLAGS) \
3535     usecxxflags=yes extracxxflags=$(CXXFLAGS) \
3536     extraldflags=
3538 ifneq (%(prefix),)
3539     %(mmake)-prefix          := %(prefix)
3540 else
3541     %(mmake)-prefix          := $(AROS_CONTRIB)
3542 endif
3544 ifneq (%(aros_prefix),)
3545     %(mmake)-aros_prefix     := %(aros_prefix)
3546 else
3547     %(mmake)-aros_prefix     := $(%(mmake)-prefix)
3548 endif
3550 ifeq (%(compiler),host)
3551     BD_LDFLAGS               := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS) %(extraldflags)
3552     BD_CFLAGS                := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include %(extracflags)
3553     BD_CXXFLAGS              := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include %(extracxxflags)
3554     BD_CPPFLAGS              := $(HOST_CPPFLAGS) %(extracppflags)
3555     %(mmake)-cmake_opts      := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(strip $(HOST_DEF_CC))"
3556     ifeq (%(usecflags),yes)
3557         %(mmake)-cmake_opts  += -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3558     endif
3559     ifeq (%(usecppflags),yes)
3560         %(mmake)-cmake_opts  += -DCMAKE_CPP_FLAGS="$(strip $(BD_CPPFLAGS))"
3561     endif
3562     %(mmake)-cmake_opts      += -DCMAKE_CXX_COMPILER="$(strip $(HOST_CXX))"
3563     ifeq (%(usecxxflags),yes)
3564         %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))"
3565     endif
3566     ifeq (%(package),)
3567         %(mmake)-pkgdir      := $(HOSTGENDIR)/$(CURDIR)
3568     else
3569         %(mmake)-pkgdir      := $(HOSTGENDIR)/$(CURDIR)/%(package)
3570     endif
3571 else
3572     BD_LDFLAGS               := $(strip $(LDFLAGS) %(extraldflags))
3573     BD_CFLAGS                := $(strip $(CFLAGS) %(extracflags))
3574     BD_CXXFLAGS              := $(strip $(CXXFLAGS) %(extracxxflags))
3575     BD_CPPFLAGS              := $(strip $(CPPFLAGS) %(extracppflags))
3576     %(mmake)-cmake_opts      := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix)
3577     ifeq (%(usecflags),yes)
3578         %(mmake)-cmake_opts  += -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3579     endif
3580     ifeq (%(usecppflags),yes)
3581         %(mmake)-cmake_opts  += -DCMAKE_CPP_FLAGS="$(strip $(BD_CPPFLAGS))"
3582     endif
3583     ifeq (%(usecxxflags),yes)
3584         %(mmake)-cmake_opts      += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))"
3585     endif
3586     %(mmake)-cmake_opts  += -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3587     ifeq (%(package),)
3588         %(mmake)-pkgdir      := $(GENDIR)/$(CURDIR)
3589     else
3590         %(mmake)-pkgdir      := $(GENDIR)/$(CURDIR)/%(package)
3591     endif
3592 endif
3593 ifneq (%(gendir),)
3594     ifeq (%(package),)
3595         %(mmake)-pkgdir      := %(gendir)/$(CURDIR)
3596     else
3597         %(mmake)-pkgdir      := %(gendir)/$(CURDIR)/%(package)
3598     endif
3599 endif
3601 %(mmake)-cmakeflag           := $(%(mmake)-pkgdir)/.cmake
3602 %(mmake)-installflag         := $(%(mmake)-pkgdir)/.installed
3604 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3606 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3608 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3611 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3613 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3614         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3615             $(RM)  $(%(mmake)-installflag) && \
3616             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3617             cd $(%(mmake)-pkgdir) && \
3618             cmake %(installoptions) -P cmake_install.cmake && \
3619             $(TOUCH) $@ -r $^; \
3620         fi
3622 %(mmake)-touchfileflag ?= $(%(mmake)-pkgdir)/.files-touched
3623 ifneq ($(%(mmake)-touchfileflag),)
3624 $(%(mmake)-touchfileflag):
3625         %mkdirs_q $(%(mmake)-pkgdir)
3626         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3627         $(TOUCH) $@
3628 endif
3631 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3633 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3634 $(%(mmake)-cmakeflag) : $(%(mmake)-touchfileflag) $(TOP)/$(CURDIR)/mmakefile
3635         $(RM) $@
3636         %mkdirs_q $(%(mmake)-pkgdir)
3637         cd $(%(mmake)-pkgdir) && \
3638         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3639         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3640         $(TOUCH) $@
3643 %(mmake)-clean : %(mmake)-uninstall
3644         $(Q)$(RM) $(%(mmake)-pkgdir)
3645 %end
3646 #------------------------------------------------------------------------------
3649 #------------------------------------------------------------------------------
3650 # Given an archive name, patches names and locations where to find them, fetch
3651 # the archive and the patches from any of those locations, unpack the archive
3652 # and then apply the patches.
3654 # Locations currently supported are http and ftp sites, plus local filesystem
3655 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3656 # the fetch.sh script needs to be modified, since this macro relies on that script.
3658 # Arguments:
3660 #     - mmake           = mmaketarget
3661 #     - archive_origins = list of locations where to find the archive. They are tried
3662 #                         in sequence, until the archive is found and fetching it 
3663 #                         succeeded. If not specified, the current directory is assumed.
3664 #     - archive         = the archive name. Mandatory.
3665 #     - suffixes        = a list of suffixes to append to the package name plus the
3666 #                         version. Each one of them is tried until a matching archive is
3667 #                         found. They are appended to patches and these are tried the
3668 #                         same way as packages are.
3669 #     - location        = the local directory where to put the fetched archive and patches.
3670 #                         If not specified, the directory specified by destination is used.
3671 #     - destination     = the directory to unpack the archive to.
3672 #                         If not specified, the current directory is assumed.
3673 #     - patches_origins = list of locations where to find the patches. They are tried
3674 #                         in sequence, until a patch is found and fetching it 
3675 #                         succeeded. If not specified, the current directory is assumed.
3676 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3677 #                         patch_name[:[patch_subdir][:patch_opt]].
3679 #                             - patch_name   = the name of the patch file
3680 #                             - patch_subdir = the directory within \destination\ where to
3681 #                                              apply the patch.
3682 #                             - patch_opt    = any options to pass to the `patch' command
3683 #                                              when applying the patch.
3684 #                         
3685 #                         The patch_subdir and patch_opt fields are optional.
3687 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3688     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3690 .PHONY: %(mmake)
3692 ifneq (%(location),)
3693     %(mmake)-location := %(location)
3694 else
3695     %(mmake)-location := %(destination)
3696 endif
3698 %(mmake)-fetchedflag := $(%(mmake)-location)/.%(archive)-fetched
3701 %(mmake) :
3702         $(Q)$(ECHO) "Fetching   %(archive) ..."
3703         $(Q)$(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3704         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3705         $(Q)$(IF) ! $(TEST) -f $(%(mmake)-fetchedflag) ; then \
3706                  $(TOUCH) $(%(mmake)-fetchedflag) ; \
3707         fi
3709 #       $(Q)$(IF) ! $(TEST) -f $(%(mmake)-fetchedflag) ; then \
3710 #               $(ECHO) "Fetching   %(archive) ..." \
3711 #               && $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3712 #               -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)" \
3713 #               && $(TOUCH) $(%(mmake)-fetchedflag) ; \
3714 #       fi
3715 %end
3716 #------------------------------------------------------------------------------
3719 #------------------------------------------------------------------------------
3720 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3721 # unpatched source tree and runs diff against this and a previously fetched and possibly
3722 # patched tree. Depending on what happens after patching during a normal build it might
3723 # give best results if the new patch is created directly after fetch.
3725 # Arguments:
3727 #     - mmake       = mmaketarget
3728 #     - archive     = archive base name
3729 #     - srcdir      = the top level directory the package is unpacked to, useful if
3730 #                     an archive unpacks to a directory other than its name suggests.
3731 #                     this should not be deeper than a single path element.
3732 #     - suffixes    = a list of suffixes to append to the the package name plus the
3733 #                     version. Each one of them is tried until a matching archive is
3734 #                     found.
3735 #     - destination = the directory to unpack the archive to.
3736 #     - excludes    = diff patterns to exclude files or directories from the patch
3738 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3740 .PHONY: %(mmake)
3742 ifneq (%(excludes),)
3743     %(mmake)-exclude := -X ./exclude.patterns
3744 endif
3746 ifneq (%(srcdir),)
3747     %(mmake)-srcdir   := %(srcdir)
3748 else
3749     %(mmake)-srcdir   := %(archive)
3750 endif
3752 #MM- %(mmake) : %(mmake)-diff
3753 #MM- %(mmake)-quick : %(mmake)-diff
3756 %(mmake)-diff:
3757         $(Q)$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3758         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3759         cd %(destination)/tmp ; \
3760         $(FOR) f in %(excludes) ; do \
3761             $(ECHO) $$f >> ./exclude.patterns ; \
3762         done ; \
3763     $(ECHO) "Creating   \`%(archive)-aros-new.diff'" ; \
3764         diff -ruN $(%(mmake)-exclude) \
3765             $(%(mmake)-srcdir) \
3766             $(%(mmake)-srcdir).aros \
3767             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3768         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3769         $(RM) %(destination)/tmp
3770 %end
3771 #------------------------------------------------------------------------------
3774 #------------------------------------------------------------------------------
3775 # Joins the features of %fetch and %build_with_configure.
3777 # If a patch is provided, it *must* be named the following way:
3779 #    <package name>-<version number>-aros.diff
3781 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3782 # CD'ing into the archive's extracted directory.
3784 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3785 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3786 # to make that patch fully comprehensive.
3788 # Arguments:
3790 #    - mmake            = the meta make target.
3791 #    - package          = the GNU package name, sans version and archive format suffixes.
3792 #    - subpackage       = ???
3793 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3794 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3795 #    - version          = the package's version number, or otherwise any other version string.
3796 #                         It gets appended to the package name to form the basename of the archive.
3797 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3798 #                         version. Each one of them is tried until a matching archive is found.
3799 #                         Defaults to "tar.bz2 tar.gz".
3800 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3801 #    - builddir         = override the location we expect to run configure/make in.
3802 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3803 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3804 #                         fetched or not. Default to no.
3805 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3806 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3807 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3808 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3809 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3810 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3811 #    - usecflags      = same meaning as the one for the %build_with_configure macro.
3812 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3813 #    - usecxxflags      = same meaning as the one for the %build_with_configure macro.
3814 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3815 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3816 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3817 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3818 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3819 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3820 #    - nix              = same meaning as the one for the %build_with_configure macro.
3821 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3822 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3824 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3825     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3826     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3827     extraoptions= \
3828     usecppflags=yes extracppflags= \
3829     usecflags=yes extracflags="$(OPTIMIZATION_CFLAGS)" \
3830     usecxxflags=yes extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3831     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no \
3832     buildflags=yes gnuflags=yes nlsflag=yes xflag=yes \
3833     hostisaflags= kernelisaflags="$(TARGET_ISA_CFLAGS)" targetisaflags="$(TARGET_ISA_CFLAGS)"
3835 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3836 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3837 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3838 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3839 #MM- %(mmake)-create-patch-quick : %(mmake)-%(subpackage)-create-patch
3841 %(mmake)-archbase                        := %(package)-%(version)
3843 ifeq (%(compiler),host)
3844     %(mmake)-portdir                     := $(HOSTDIR)/Ports/host/%(package)
3845 else
3846     %(mmake)-portdir                     := $(PORTSDIR)/%(package)
3847 endif
3849 ifeq (%(prefix),)
3850     %(mmake)-prefix                      := $(CONTRIB_DIR)/%(package)
3851 else
3852     %(mmake)-prefix                      := %(prefix)
3853 endif
3855 ifneq (%(subpackage),)
3856     %(mmake)-%(subpackage)-archbase      := %(package)-%(subpackage)-%(version)
3857 else
3858     %(mmake)-%(subpackage)-archbase      := %(package)-%(version)
3859 endif
3861 ifneq (%(srcdir),)
3862     %(mmake)-%(subpackage)-srcdir        := %(srcdir)
3863 else
3864     %(mmake)-%(subpackage)-srcdir        := $(%(mmake)-archbase)
3865 endif
3867 ifneq (%(builddir),)
3868     %(mmake)-%(subpackage)-builddir      := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3869 else
3870     %(mmake)-%(subpackage)-builddir      := $(%(mmake)-%(subpackage)-srcdir)
3871 endif
3873 ifeq (%(patch),yes)
3874     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3875 else
3876     %(mmake)-%(subpackage)-patches_specs := ::
3877 endif
3879 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3880     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3881     archive_origins=". %(package_repo)" \
3882     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3884 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3885     archive=$(%(mmake)-%(subpackage)-archbase) \
3886     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3887     suffixes="%(suffixes)" \
3888     destination=$(%(mmake)-portdir)
3890 #MM %(mmake) : %(mmake)-%(subpackage)
3892 %(mmake):
3893         $(NOP)
3895 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3897 %(mmake)-%(subpackage)-package-basename := \
3898     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3900 ifneq (%(create_pkg),no)
3901     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3902 endif
3904 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3905      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3906      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3907      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix)  aros_prefix="%(aros_prefix)" \
3908      preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) %(mmake)-%(subpackage)-make-package" \
3909      extraoptions="%(extraoptions)" \
3910      usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" \
3911      usecflags="%(usecflags)" extracflags="%(extracflags)" \
3912      usecxxflags="%(usecxxflags)" extracxxflags="%(extracxxflags)" \
3913      buildflags=%(buildflags) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag) \
3914      hostisaflags=%(hostisaflags) kernelisaflags="%(kernelisaflags)" targetisaflags=%(targetisaflags)
3916 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3917 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3920 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3922 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3923 #that $^ and $@ have exactly the same mtime, and in that case make tries
3924 #to rebuild $@ again, which would fail because the directory where
3925 #the package got installed would not exist anymore. 
3926 #We work this around by using an if statement to manually check the mtimes.
3927 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3928         $(Q)$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -s $@; then \
3929             $(RM) $@ ; \
3930             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3931             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3932             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3933             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3934             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3935             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3936         fi
3937 %end
3938 #------------------------------------------------------------------------------
3941 #------------------------------------------------------------------------------
3942 # Joins the features of %fetch and %build_with_configure, taking advantage of
3943 # the naming scheme of GNU packages. GNU packages names are in the form
3945 #     <package name>-<version number>.<archive format suffix>
3947 # If a patch is provided, it *must* be named the following way:
3949 #    <package name>-<version number>-aros.diff
3951 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3952 # CD'ing into the archive's extracted directory.
3954 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3955 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3956 # to make that patch fully comprehensive.
3958 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3960 # Arguments:
3962 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3964 #    - prefix           = defaults to $(GNUDIR).
3965 #    - aros_prefix      = defaults to /GNU.
3967 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3968     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3969     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall= \
3970     extraoptions= \
3971     usecppflags=yes extracppflags= \
3972     usecflags=yes extracflags="$(OPTIMIZATION_CFLAGS)" \
3973     usecxxflags=yes extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3974     hostisaflags="$(HOST_ISA_CFLAGS)" \
3975     kernelisaflags="$(TARGET_ISA_CFLAGS)" \
3976     targetisaflags="$(TARGET_ISA_CFLAGS)" \
3977     use_build_env=no nix=yes gnuflags=yes nlsflag=yes xflag=yes
3979 GNU_REPOSITORY := gnu://
3981 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3982     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3983     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3984     patch="%(patch)" patch_repo="%(patch_repo)" \
3985     prefix="%(prefix)" aros_prefix="%(aros_prefix)" \
3986     extraoptions="%(extraoptions)" \
3987     usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" \
3988     usecflags="%(usecflags)" extracflags="%(extracflags)" \
3989     usecxxflags="%(usecxxflags)" extracxxflags="%(extracxxflags)" \
3990     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
3991     hostisaflags="%(hostisaflags)" kernelisaflags="%(kernelisaflags)" targetisaflags="%(targetisaflags)" \
3992     use_build_env=%(use_build_env) nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
3994 %end
3995 #------------------------------------------------------------------------------
3998 #------------------------------------------------------------------------------
3999 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
4000 # that the package is a "Developer" package, and as such it needs to be placed
4001 # under the $(AROS_DEVELOPER) directory, as a default. 
4003 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
4004 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
4005 # "mmake" argument, because the metatarget is implicitely defined as
4007 #     #MM- development-%(package)
4009 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
4010     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
4011     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall= \
4012     extraoptions= \
4013     usecppflags=yes extracppflags= \
4014     usecflags=yes extracflags="$(OPTIMIZATION_CFLAGS)" \
4015     usecxxflags=yes extracxxflags="$(OPTIMIZATION_CFLAGS)" \
4016     hostisaflags="$(HOST_ISA_CFLAGS)" \
4017     kernelisaflags="$(TARGET_ISA_CFLAGS)" \
4018     targetisaflags="$(TARGET_ISA_CFLAGS)" \
4019     use_build_env=no nix=yes gnuflags=yes nlsflag=yes xflag=yes
4021 #MM- development : development-%(package)
4024 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
4025    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
4026    package_repo="%(package_repo)" \
4027    patch="%(patch)" patch_repo="%(patch_repo)" \
4028    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" \
4029    extraoptions="%(extraoptions)" \
4030    usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" \
4031    usecflags="%(usecflags)" extracflags="%(extracflags)" \
4032    usecxxflags="%(usecxxflags)" extracxxflags="%(extracxxflags)" \
4033    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
4034    hostisaflags="%(hostisaflags)" kernelisaflags="%(kernelisaflags)" targetisaflags="%(targetisaflags)" \
4035    use_build_env=%(use_build_env) nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
4038 postinstall-%(package)-delete-la-files:
4039         $(RM) %(prefix)/lib/*.la
4041 %end
4042 #------------------------------------------------------------------------------
4044 # Builds a kickstart package in PKG format
4046 # Arguments:
4048 #    - mmake   = target name
4049 #    - file    = destination file name with path
4051 # Other arguments are self-explanatory
4053 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
4054     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
4056 PKG_CLASSES        := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
4057 PKG_DEVICES        := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
4058 PKG_HANDLERS       := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
4059 PKG_HIDD           := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
4060 PKG_LIBS           := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
4061 PKG_RESOURCES      := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
4063 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
4064 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
4065 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
4066 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
4067 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
4068 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
4070 PKG_FILES          := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
4071     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
4072 PKG_DIR            := $(dir %(file))
4075 %(mmake) : %(file)
4078 %(mmake)-quick : %(file)
4080 %(file): $(PKG_FILES) | $(PKG_DIR)
4081         $(Q)$(ECHO) Packaging $@...
4082         $(Q)$(SRCDIR)/tools/package/pkg c $@ $^
4084 %compress_file mmake="%(mmake)" file="%(file)"
4086 %rule_makedirs dirs="$(PKG_DIR)"
4088 %end
4090 #------------------------------------------------------------------------------
4091 # Compresses %(file) with a gzip.
4092 # Good in conjunction with for example %build_prog
4094 %define compress_file mmake=/A file=/A
4096 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
4099 %(mmake)-gz-quick : %(file).gz
4101 %(file).gz: %(file)
4102         $(Q)$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
4103         $(Q)gzip -9 -f $^
4105 %end
4107 #------------------------------------------------------------------------------
4108 # Links a kickstart module in ELF format
4109 # Arguments are similar to make_package
4111 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
4112     startup= uselibs= ldflags=$(LDFLAGS) map= deps= strip=$(STRIP)
4114 KOBJ_CLASSES     := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
4115 KOBJ_DEVICES     := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
4116 KOBJ_HANDLERS    := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
4117 KOBJ_HIDD        := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
4118 KOBJ_LIBS        := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
4119 KOBJ_RES         := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
4121 ifeq (%(startup),)
4122     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
4123 else
4124     KOBJ_STARTUP := %(startup)
4125 endif
4127 KOBJS            := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
4129 TMP_LDFLAGS      := %(ldflags)
4131 # Make a list of the lib files this program depends on.
4132 # In LDFLAGS remove white space between -L and directory
4133 TMP_DIRS         := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
4134 # Filter out only the libdirs and remove -L
4135 TMP_DIRS         := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
4136 # Add trailing /
4137 TMP_DIRS         := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
4138 # Add normal linklib path
4139 TMP_DIRS         += $(AROS_LIB)/
4140 # add lib and .a to static linklib names
4141 TMP_LIBS         := $(addprefix lib,$(addsuffix .a,%(uselibs)))
4142 # search for the linklibs in the given path, ignore ones not found
4143 TMP_DEPLIBS      := $(foreach lib,$(TMP_LIBS),$(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))))
4145 TMP_DIRS += $(dir %(file))
4146 ifneq (%(map),)
4147     TMP_LDFLAGS  += $(GENMAP) %(map)
4148     TMP_DIRS     += $(dir %(map))
4149 endif
4151 #MM %(mmake) : %(deps)
4154 %(mmake) : %(file)
4157 %(mmake)-quick : %(file)
4159 %(file): KOBJS    := $(KOBJS)
4160 %(file): LDFLAGS  := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
4161                     -static -nosysbase -Wl,-Ur
4162 %(file): LDLIBS   := $(addprefix -l, %(uselibs))
4163 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
4164         $(Q)$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
4165         $(Q)$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
4166         %strip_q strip=%(strip) file=$@
4168 %compress_file mmake="%(mmake)" file="%(file)"
4170 %rule_makedirs dirs="$(TMP_DIRS)"
4172 %end
4174 #------------------------------------------------------------------------------
4175 # Generate generic rules for a subtarget
4177 %define subtarget parentmmake= mmake=/A mmbase=MM-
4178 #%(mmbase) %(parentmmake) : %(mmake)
4179 #%(mmbase) %(parentmmake)-includes : %(mmake)-includes
4180 #%(mmbase) %(parentmmake)-quick : %(mmake)-quick
4181 %end
4183 #------------------------------------------------------------------------------
4184 # Create a target directory
4186 %define directorytarget mmake=/A directory=  icontarget= mmbase=MM-
4188 %(mmake)-makedir ::
4189     %mkdirs_q %(directory)
4191 #%(mmbase) %(mmake) : %(mmake)-makedir
4192 %end