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