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