enable the building of different flavours in build_module macros. (NicJA)
[AROS.git] / config / make.tmpl
blob18733177b6ee338d602f091db34d6ad5787ef043
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 $(ISA_FLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
367 $(%(mmake)_TARGETBASE).d : %(mmake)_DFLAGS:=$(strip $(ISA_FLAGS) $(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 $(ISA_FLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
562 $(%(mmake)_TARGETBASE).d : %(mmake)_OBJCDFLAGS:=$(strip $(ISA_FLAGS) $(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 $(ISA_FLAGS) $(KERNEL_CFLAGS) $(%(mmake)_CFLAGS))
673 $(%(mmake)_MC_TARGETS) $(%(mmake)_MC_DTARGETS) : %(mmake)_DFLAGS:=$(strip $(ISA_FLAGS) $(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 $(ISA_FLAGS) $(KERNEL_CFLAGS) $(%(mmake)_OBJCFLAGS))
889   $(%(mmake)_MOBJC_TARGETS) $(%(mmake)_MOBJC_DTARGETS) : %(mmake)_OBJCDFLAGS:=$(strip $(ISA_FLAGS) $(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)_CPPFLAGS           += $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_CPPFLAGS))
2149 %(mmake)%(flavour)_LINKLIBCPPFLAGS    := $(strip %(cflags) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBCPPFLAGS))
2150 %(mmake)%(flavour)_CXXFLAGS         := $(strip %(cxxflags) $($(%(mmake)%(flavour)_DEFNAME)_CXXFLAGS))
2151 ifeq (%(lto),yes)
2152 ifeq (%(compiler),target)
2153 %(mmake)%(flavour)_LTOFLAGS=$(strip $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH))
2154 %(mmake)%(flavour)_CFLAGS           := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CFLAGS))
2155 %(mmake)%(flavour)_LINKLIBCFLAGS    := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_LINKLIBCFLAGS))
2156 %(mmake)%(flavour)_CXXFLAGS         := $(strip $(%(mmake)%(flavour)_LTOFLAGS) $(%(mmake)%(flavour)_CXXFLAGS))
2157 endif
2158 endif
2159 %(mmake)%(flavour)_DFLAGS           := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DFLAGS))
2160 %(mmake)%(flavour)_LINKLIBDFLAGS    := $(strip $(%(mmake)%(flavour)_DFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBDFLAGS))
2161 %(mmake)%(flavour)_DXXFLAGS         := $(strip $(%(mmake)%(flavour)_DXXFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_DXXFLAGS))
2163 ifeq (%(modtype),library)
2164     %(mmake)%(flavour)_LIBSUFFIX := 
2165 else
2166     %(mmake)%(flavour)_LIBSUFFIX := .%(modtype)
2167 endif
2169 ifeq (%(libdir),)
2170 %(mmake)%(flavour)_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
2171 else
2172 %(mmake)%(flavour)_LIBDIR := %(libdir)
2173 endif
2175 ifeq (%(build_abi),M)
2176 %(mmake)%(flavour)_LINKLIBCFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES))
2177 %(mmake)%(flavour)_LINKLIBAFILES    := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES))
2178 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_LINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2179     %(mmake)%(flavour)_LINKLIB      :=
2180 else
2181     %(mmake)%(flavour)_LINKLIB      := $(%(mmake)%(flavour)_LIBDIR)/lib%(modname)$(%(mmake)%(flavour)_LIBSUFFIX).a
2182     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2183         %(mmake)%(flavour)_LINKLIB  += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX).a
2184     endif
2185 endif
2186 %(mmake)%(flavour)_LINKLIBFILES := $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_LINKLIBAFILES)
2188 %(mmake)%(flavour)_RELLINKLIBCFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES))
2189 %(mmake)%(flavour)_RELLINKLIBAFILES := $(addprefix $(%(mmake)%(flavour)_OBJDIR)/linklib/,$($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES))
2190 ifeq ($(strip $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBFILES) $($(%(mmake)%(flavour)_DEFNAME)_RELLINKLIBAFILES) %(linklibfiles) $(%(mmake)%(flavour)_ARCHNLIBFILES)),)
2191     %(mmake)%(flavour)_RELLINKLIB   :=
2192 else
2193     %(mmake)%(flavour)_RELLINKLIB   := $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2194     ifneq (%(modname),$(%(mmake)%(flavour)_LINKLIBNAME))
2195         %(mmake)%(flavour)_RELLINKLIB += $(%(mmake)%(flavour)_LIBDIR)/lib$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX).a
2196     endif
2197 endif
2198 %(mmake)%(flavour)_RELLINKLIBFILES := $(%(mmake)%(flavour)_RELLINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)
2199 endif
2201 %(mmake)%(flavour)_ENDOBJS    := $(addsuffix .o,$(%(mmake)%(flavour)_ENDFILES))
2202 %(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)) \
2203                  %(linklibobjs)
2204 %(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)) \
2205                  %(linklibobjs)
2206 $(%(mmake)%(flavour)_LINKLIBFILES) $(%(mmake)%(flavour)_RELLINKLIBFILES) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2207 $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_RELLINKLIBOBJS) : | $(%(mmake)%(flavour)_OBJDIR)/linklib
2209 %(mmake)%(flavour)_CCFILES := $(%(mmake)%(flavour)_C_NARCHFILES)
2210 %(mmake)%(flavour)_TARGETCCFILES := $(strip $(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES))
2211 %(mmake)%(flavour)_LINKLIBCCFILES := $(strip $(%(mmake)%(flavour)_NLIBARCHFILES) $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2212 %(mmake)%(flavour)_LINKLIBCCGENFILES := $(strip $(%(mmake)%(flavour)_LINKLIBCFILES) $(%(mmake)%(flavour)_RELLINKLIBCFILES))
2214 %rule_compile_cxx_multi mmake=%(mmake)%(flavour) \
2215     basenames=$(%(mmake)%(flavour)_CXX_NARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2216     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cxxflags=$(%(mmake)%(flavour)_CXXFLAGS) dxxflags=$(%(mmake)%(flavour)_DXXFLAGS) \
2217     compiler="%(compiler)"
2218 %rule_compile_objc_multi mmake=%(mmake)%(flavour) \
2219     basenames=$(%(mmake)%(flavour)_OBJC_NARCHFILES) targetdir=$(%(mmake)%(flavour)_OBJDIR) \
2220     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2221     compiler="%(compiler)"
2222 %rule_compile_multi mmake=%(mmake)%(flavour) \
2223     basenames=$(%(mmake)%(flavour)_CCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2224     cppflags=$(%(mmake)%(flavour)_CPPFLAGS) cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2225     compiler="%(compiler)"
2226 %rule_compile_multi mmake=%(mmake)%(flavour) \
2227     basenames=$(%(mmake)%(flavour)_TARGETCCFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)" \
2228     cppflags="$(%(mmake)%(flavour)_CPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_DFLAGS) \
2229     compiler="%(compiler)"
2230 %rule_compile_multi mmake=%(mmake)%(flavour) \
2231     basenames=$(%(mmake)%(flavour)_NLIBARCHFILES) targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2232     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2233     compiler="%(compiler)"
2234 %rule_compile_multi mmake=%(mmake)%(flavour) \
2235     basenames=$(%(mmake)%(flavour)_LINKLIBCCGENFILES) srcdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" \
2236     cppflags="$(%(mmake)%(flavour)_LINKLIBCPPFLAGS) -D__AROS__" cflags=$(%(mmake)%(flavour)_CFLAGS) dflags=$(%(mmake)%(flavour)_LINKLIBDFLAGS) \
2237     compiler="%(compiler)"
2239 ifneq ($(%(mmake)%(flavour)_LINKLIBAFILES),)
2240 %rule_assemble_multi  mmake=%(mmake)%(flavour) \
2241     cmd=$(%(mmake)%(flavour)_ASSEMBLER) basenames="$(%(mmake)%(flavour)_LINKLIBAFILES) $(%(mmake)%(flavour)_RELLINKLIBAFILES)" targetdir="$(%(mmake)%(flavour)_OBJDIR)/linklib" suffix=.S
2242 endif
2244 ## Linking
2246 ifeq (%(modsuffix),)
2247 %(mmake)%(flavour)_SUFFIX := %(modtype)
2248 else
2249 %(mmake)%(flavour)_SUFFIX := %(modsuffix)
2250 endif
2252 ifeq (%(build_library),M)
2253 # Handlers use dash instead of dot in their names
2254 ifeq ($(%(mmake)%(flavour)_SUFFIX),handler)
2255 %(mmake)%(flavour)_MODULE := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME)-$(%(mmake)%(flavour)_SUFFIX)
2256 else
2257 %(mmake)%(flavour)_MODULE := %(prefix)/$(%(mmake)%(flavour)_MODDIR)/$(%(mmake)%(flavour)_DEFNAME).$(%(mmake)%(flavour)_SUFFIX)
2258 endif
2259 %(mmake)%(flavour)_KOBJ   := $(KOBJSDIR)/$(%(mmake)%(flavour)_DEFNAME)_$(%(mmake)%(flavour)_SUFFIX).o
2260 else
2261 %(mmake)%(flavour)_MODULE :=
2262 %(mmake)%(flavour)_KOBJ   :=
2263 endif
2265 %(mmake)-quick      : %(mmake)
2266 %(mmake)            : $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2267 ifeq (%(build_library),M)
2268 %(mmake)-kobj       : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2269 %(mmake)-kobj-quick : $(%(mmake)%(flavour)_KOBJ) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2270 endif
2271 ifeq (%(build_abi),M)
2272 %(mmake)-linklib    : $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_RELLINKLIB)
2273 endif
2275 %(mmake)%(flavour)_OBJS := $(addsuffix .o,$(%(mmake)%(flavour)_STARTFILES)) $(%(mmake)%(flavour)_ARCHOBJS) \
2276            $(addprefix $(%(mmake)%(flavour)_OBJDIR)/,$(notdir $(%(mmake)%(flavour)_C_NARCHFILES:=.o) $(%(mmake)%(flavour)_CXXFILES:=.o)))
2278 ifeq (%(nostartup),yes)
2279 # Handlers always have entry point
2280 ifneq (%(modtype),handler)
2281 %(mmake)%(flavour)_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2282 endif
2283 endif
2285 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2286 # This breaks con-handler build. Here we work around this
2287 ifeq (%(modname),con)
2288     %(mmake)%(flavour)_ERR := $(notdir $(%(mmake)%(flavour)_MODULE)).err
2289 else
2290     %(mmake)%(flavour)_ERR := %(modname).err
2291 endif
2293 ifeq (%(build_library),M)
2294 # The module is linked from all the compiled .o files
2295 %rule_linkmodule module=$(%(mmake)%(flavour)_MODULE) objs="$(%(mmake)%(flavour)_STARTOBJS) $(%(mmake)%(flavour)_OBJS) $(USER_OBJS)" \
2296                  endobj=$(%(mmake)%(flavour)_ENDOBJS) err=$(%(mmake)%(flavour)_ERR) objdir="$(%(mmake)%(flavour)_OBJDIR)" \
2297                  cmd=$(%(mmake)%(flavour)_LINK) ldflags="$(LDFLAGS) $($(%(mmake)%(flavour)_DEFNAME)_LDFLAGS)" \
2298                  uselibs="%(uselibs) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)" usehostlibs="%(usehostlibs)"
2299 endif
2301 ifeq (%(build_abi),M)
2302 # Link static lib
2303 %(mmake)%(flavour)_LC_LINKLIBNAME := $(shell echo $(%(mmake)%(flavour)_LINKLIBNAME) | tr A-Z a-z)
2304 %(mmake)%(flavour)_LC_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2305 ifneq ($(%(mmake)%(flavour)_LINKLIB),)
2306 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2307 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2308 %rule_link_linklib mmake=%(mmake) libname="%(modname)$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_LINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2309 endif
2311 $(%(mmake)%(flavour)_LINKLIB) : | $(%(mmake)%(flavour)_LIBDIR)
2312 GLOB_MKDIRS += $(%(mmake)%(flavour)_LIBDIR)
2313 endif
2315 ifneq ($(%(mmake)%(flavour)_RELLINKLIB),)
2316 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_LINKLIBNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2317 ifneq ($(%(mmake)%(flavour)_LC_MODNAME),$(%(mmake)%(flavour)_LC_LINKLIBNAME))
2318 %rule_link_linklib mmake=%(mmake) libname="$(%(mmake)%(flavour)_DEFNAME)_rel$(%(mmake)%(flavour)_LIBSUFFIX)" objs=$(%(mmake)%(flavour)_RELLINKLIBOBJS) libdir="$(%(mmake)%(flavour)_LIBDIR)"
2319 endif
2321 $(%(mmake)%(flavour)_RELLINKLIB) : | $(%(mmake)%(flavour)_LIBDIR)
2322 GLOB_MKDIRS += $(%(mmake)%(flavour)_LIBDIR)
2323 endif
2324 endif
2326 ifeq (%(build_library),M)
2327 # Link kernel object file
2328 %(mmake)%(flavour)_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2330 # Make these symbols local
2331 %(mmake)%(flavour)_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2332             UtilityBase ExpansionBase KeymapBase KernelBase
2334 %(mmake)%(flavour)_SYMBOLS := $(%(mmake)%(flavour)_KBASE)
2336 %(mmake)%(flavour)_KLIB := hiddstubs amiga arossupport autoinit libinit
2337 %(mmake)%(flavour)_KOBJ_LIBS := $(filter-out $(%(mmake)%(flavour)_KLIB),%(uselibs)) $(%(mmake)%(flavour)_KAUTOLIB)
2338 $(%(mmake)%(flavour)_KOBJ) : LINKLIBS:=$(%(mmake)%(flavour)_KOBJ_LIBS) $($(%(mmake)%(flavour)_DEFNAME)_LIBS)
2339 $(%(mmake)%(flavour)_KOBJ) : FILTBASES:=$(addprefix -L ,$(%(mmake)%(flavour)_SYMBOLS))
2340 $(%(mmake)%(flavour)_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2341 $(%(mmake)%(flavour)_KOBJ) : $(%(mmake)%(flavour)_OBJS) $(USER_OBJS) $(%(mmake)%(flavour)_ENDOBJS)
2342         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2343         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2344         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2345 endif
2347 ## Dependency fine-tuning
2349 %(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)))
2351 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(%(mmake)%(flavour)_DEPS)
2353 $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) : | $(%(mmake)%(flavour)_OBJDIR) $(%(mmake)%(flavour)_OBJDIR)/linklib
2354 $(%(mmake)%(flavour)_MODULE) : | %(prefix)/$(%(mmake)%(flavour)_MODDIR)
2355 $(%(mmake)%(flavour)_KOBJ)   : | $(KOBJSDIR)
2356 GLOB_MKDIRS += $(%(mmake)%(flavour)_OBJDIR) %(prefix)/$(%(mmake)%(flavour)_MODDIR) $(KOBJSDIR)
2358 # Some include files need to be generated before the .c can be parsed.
2359 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2361 %(mmake)%(flavour)_DFILE_DEPS := $(%(mmake)%(flavour)_LIBDEFSINC) $(%(mmake)%(flavour)_DEFLIBDEFSINC) \
2362     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES))
2363 $(%(mmake)%(flavour)_DEPS) : $(%(mmake)%(flavour)_DFILE_DEPS)
2364 endif
2366 %(mmake)%(flavour)_TOCLEAN := $(%(mmake)%(flavour)_OBJS) $(%(mmake)%(flavour)_DEPS) \
2367     $(%(mmake)%(flavour)_MODULE) $(%(mmake)%(flavour)_LINKLIB) $(%(mmake)%(flavour)_KOBJ) \
2368     $(%(mmake)%(flavour)_OBJDIR)/Makefile.%(modname)%(modtype) \
2369     $(addprefix $(%(mmake)%(flavour)_OBJDIR)/include/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2370     $(addprefix $(GENINCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2371     $(addprefix $(%(mmake)%(flavour)_INCDIR)/,$($(%(mmake)%(flavour)_DEFNAME)_INCLUDES)) \
2372     $(%(mmake)%(flavour)_OBJDIR)/%(modname)_geninc $(%(mmake)%(flavour)_OBJDIR)/%(modname)_incs \
2373     $(addsuffix .c,$(%(mmake)%(flavour)_LINKLIBFILES)) $(%(mmake)%(flavour)_LINKLIBOBJS) $(%(mmake)%(flavour)_LIBDEFSINC) \
2374     $(%(mmake)%(flavour)_DEFLIBDEFSINC) $(addsuffix .c,$(%(mmake)%(flavour)_STARTFILES) $(%(mmake)%(flavour)_ENDFILES)) \
2375     $(%(mmake)%(flavour)_ENDOBJS)
2376 %(mmake)-clean : FILES := $(%(mmake)%(flavour)_TOCLEAN)
2377 %(mmake)-clean ::
2378         @$(ECHO) "Cleaning up for module %(modname)"
2379         @$(RM) $(FILES)
2381 endif # $(TARGET) in $(%(mmake)%(flavour)_ALLTARGETS)
2382 %end
2383 #------------------------------------------------------------------------------
2385 #------------------------------------------------------------------------------
2386 # Build a module - ABI and library
2387 # Explanation of this macro is done in the developer's manual
2388 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2389   files="$(basename $(call WILDCARD, *.c))" \
2390   objcfiles= \
2391   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2392   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2393   objdir= moduledir= prefix=$(AROSDIR) \
2394   linklibname= uselibs= usehostlibs= \
2395   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2396   includedir= libdir=
2398 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2399    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2400    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2401    linklibname="%(linklibname)" \
2402    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2403    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2404    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2405    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2406    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2407    includedir="%(includedir)" libdir="%(libdir)" \
2408    build_abi=M build_library=M
2410 %end
2411 #------------------------------------------------------------------------------
2414 #------------------------------------------------------------------------------
2415 # Build a module skeleton ABI
2416 # This is a stripped-down version of build_module, it only creates include
2417 # files and the linklibs.
2418 # This is used when for plugins or classes with the same API, but no actual
2419 # implementation here.
2420 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2421   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2422   objdir= moduledir= prefix=$(AROSDIR) \
2423   linklibname= uselibs= usehostlibs= \
2424   compiler=target nostartup=yes archspecific=no \
2425   includedir= libdir=
2427 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2428   modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2429   linklibname="%(linklibname)" \
2430   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2431   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2432   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2433   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2434   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2435   includedir="%(includedir)" libdir="%(libdir)" \
2436   build_abi=M build_library=
2438 %end
2439 #------------------------------------------------------------------------------
2441 #------------------------------------------------------------------------------
2442 # Build a module library - no includes nor linklibs
2443 # Explanation of this macro is done in the developer's manual
2444 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= flavour= conffile= \
2445   files="$(basename $(call WILDCARD, *.c))" \
2446   objcfiles= \
2447   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2448   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= cxxflags="$(CXXFLAGS)" dxxflags= \
2449   objdir= moduledir= prefix=$(AROSDIR) \
2450   uselibs= usehostlibs= \
2451   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2452   includedir= libdir=
2454 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2455    modsuffix="%(modsuffix)" version="%(version)" flavour="%(flavour)" conffile="%(conffile)" \
2456    files="%(files)" objcfiles="%(objcfiles)" cxxfiles="%(cxxfiles)" \
2457    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2458    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2459    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2460    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2461   includedir="%(includedir)" libdir="%(libdir)" \
2462    build_abi= build_library=M
2464 %end
2465 #------------------------------------------------------------------------------
2469 #------------------------------------------------------------------------------
2470 # Build a linklib.
2471 # - mmake is the mmaketarget
2472 # - libname is the baselibname e.g. lib%(libname).a will be created
2473 # - files are the C source files to include in the lib. The list of files
2474 #   has to be given without the .c suffix
2475 # - cxxfiles are C++ source files without suffix.
2476 #   NB: files will be matched in the order .cpp > .cxx > .cc
2477 # - asmfiles are the asm files to include in the lib. The list of files has to
2478 #   be given without the .s suffix
2479 # - objs additional object to link into the linklib. The objects have to be
2480 #   given with full absolute path and the .o suffix.
2481 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2482 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2483 # - cflags are the flags to compile the source (default $(CFLAGS))
2484 # - dflags are the flags used during makedepend (default equal to cflags)
2485 # - aflags are the flags used during assembling (default $(AFLAGS))
2486 %define build_linklib mmake=/A libname=/A files= objcfiles= cxxfiles= \
2487   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2488   includedir= \
2489   cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= cxxflags=$(CXXFLAGS) dxxflags= \
2490   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2492 # assign and generate the local variables used in this macro
2493 %(mmake)_LIBNAME      := %(libname)
2494 %(mmake)_LINKLIB      := %(libdir)/lib%(libname).a
2496 %(mmake)_FILES        := %(files)
2497 %(mmake)_ASMFILES     := %(asmfiles)
2498 %(mmake)_OBJCFILES    := %(objcfiles)
2499 %(mmake)_CXXFILES     := %(cxxfiles)
2501 %(mmake)_ARCHOBJS     := $(wildcard %(objdir)/arch/*.o)
2502 %(mmake)_ARCHFILES    := $(basename $(notdir $(%(mmake)_ARCHOBJS)))
2503 %(mmake)_C_NARCHFILES   := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_FILES))
2504 %(mmake)_CXX_NARCHFILES   := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_CXXFILES))
2505 %(mmake)_OBJC_NARCHFILES   := $(filter-out $(%(mmake)_ARCHFILES),$(%(mmake)_OBJCFILES))
2507 %(mmake)_OBJS         := $(%(mmake)_ARCHOBJS) \
2508                  $(addprefix %(objdir)/,$(notdir $(%(mmake)_C_NARCHFILES:=.o) $(%(mmake)_CXX_NARCHFILES:=.o) $(%(mmake)_ASMFILES:=.o) $(%(mmake)_OBJC_NARCHFILES:=.o))) \
2509                  %(objs)
2510 %(mmake)_DEPS         := $(patsubst %.o,%.d,$(%(mmake)_OBJS))
2512 %(mmake)_CPPFLAGS     := %(cppflags)
2513 ifneq (%(includedir),)
2514 %(mmake)_CPPFLAGS     += -I%(includedir)
2515 endif
2516 %(mmake)_CFLAGS       := %(cflags)
2517 %(mmake)_CXXFLAGS     := %(cxxflags)
2518 ifeq (%(lto),yes)
2519 ifeq (%(compiler),target)
2520 %(mmake)_CFLAGS       := $(strip $(LTO_CFLAGS) $(%(mmake)_CFLAGS))
2521 %(mmake)_CXXFLAGS     := $(strip $(LTO_CFLAGS) $(%(mmake)_CXXFLAGS))
2522 endif
2523 endif
2524 %(mmake)_AFLAGS       := %(aflags)
2525 %(mmake)_DFLAGS       := %(dflags)
2526 ifneq (%(dflags),)
2527     %(mmake)_DFLAGS   := %(dflags)
2528 else
2529     %(mmake)_DFLAGS   := $(%(mmake)_CFLAGS)
2530 endif
2531 %(mmake)_DXXFLAGS     := %(dxxflags)
2532 ifneq (%(dxxflags),)
2533     %(mmake)_DXXFLAGS := %(dxxflags)
2534 else
2535     %(mmake)_DXXFLAGS := $(%(mmake)_CXXFLAGS)
2536 endif
2538 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2541 %(mmake)-quick : %(mmake)
2543 #MM %(mmake) : includes-generate-deps
2544 %(mmake) : $(%(mmake)_LINKLIB)
2546 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2548 %rule_compile_cxx_multi mmake=%(mmake) \
2549     basenames=$(%(mmake)_CXX_NARCHFILES) targetdir="%(objdir)" \
2550     cppflags=$(%(mmake)_CPPFLAGS) cxxflags=$(%(mmake)_CXXFLAGS) dxxflags=$(%(mmake)_DXXFLAGS) \
2551     compiler="%(compiler)"
2552 %rule_compile_objc_multi mmake=%(mmake) \
2553     basenames=$(%(mmake)_OBJC_NARCHFILES) targetdir=$(%(mmake)_OBJDIR) \
2554     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2555     compiler="%(compiler)"
2556 %rule_compile_multi mmake=%(mmake) \
2557     basenames=$(%(mmake)_C_NARCHFILES) targetdir="%(objdir)" \
2558     cppflags=$(%(mmake)_CPPFLAGS) cflags=$(%(mmake)_CFLAGS) dflags=$(%(mmake)_DFLAGS) \
2559     compiler="%(compiler)"
2560 %rule_assemble basename=% targetdir="%(objdir)" \
2561     aflags=$(%(mmake)_AFLAGS)
2563 %rule_link_linklib mmake=%(mmake) libname="%(libname)" objs=$(%(mmake)_OBJS) libdir="%(libdir)" linker="%(compiler)"
2564 endif
2566 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(%(mmake)_DEPS)
2568 $(%(mmake)_OBJS) $(%(mmake)_DEPS) : | %(objdir)
2569 $(%(mmake)_LINKLIB) : | %(libdir)
2570 GLOB_MKDIRS += %(objdir) %(libdir)
2572 %(mmake)-clean : FILES := $(%(mmake)_OBJS) $(%(mmake)_LINKLIB) $(%(mmake)_DEPS)
2574 %(mmake)-clean ::
2575         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2576         @$(RM) $(FILES)
2578 %end
2579 #------------------------------------------------------------------------------
2582 #------------------------------------------------------------------------------
2583 # Build catalogs.
2584 # - mmake is the mmaketarget
2585 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2586 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2587 # - subdir is the destination subdirectory of the catalogs
2588 # - name is the name of the destination catalog, without the .catalog suffix
2589 # - source is the path to the generated source code file
2590 # - dir is the base destination directory (default $(AROS_CATALOGS))
2591 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2592 # - srcdir is the directory in which the *.cd and *.ct files are searched
2594 %define build_catalogs mmake=/A name=/A subdir=/A \
2595  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2596  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2598 ifeq (%(description),)
2599 %(mmake)_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2600 else
2601 %(mmake)_DESC := %(description)
2602 endif
2604 %(mmake)_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2606 ifeq (%(catalogs),)
2607 %(mmake)_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2608 else
2609 %(mmake)_LNGS := %(catalogs)
2610 endif
2612 %(mmake)_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(%(mmake)_LNGS)))
2613 %(mmake)_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(%(mmake)_LNGS))) $(dir %(source))
2616 %(mmake) : $(%(mmake)_OBJS) %(source)
2618 $(%(mmake)_OBJS) : | $(%(mmake)_DIRS)
2619 GLOB_MKDIRS += $(%(mmake)_DIRS)
2621 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(%(mmake)_DESC).cd
2622         @$(ECHO) "Creating   %(name) catalog for language $*."
2623         @$(FLEXCAT) $(%(mmake)_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2625 ifneq (%(source),)
2626 %(source) : %(mmake)_DESC := $(%(mmake)_DESC)
2627 %(source) : %(mmake)_SRC := $(%(mmake)_SRC)
2628 %(source) : $(%(mmake)_DESC).cd $(%(mmake)_SRC).sd | $(dir %(source))
2629         @$(ECHO) "Creating   %(name) catalog source file $@"
2630         @$(FLEXCAT) $(%(mmake)_DESC).cd $@=$(%(mmake)_SRC).sd
2631 endif
2633 %(mmake)-clean : FILES := $(%(mmake)_OBJS) %(source)
2635 %(mmake)-clean ::
2636         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2637         @$(RM) $(FILES)
2639 .PHONY: %(mmake) %(mmake)-clean
2641 %end
2642 #-----------------------------------------------------------------------------
2645 #-----------------------------------------------------------------------------
2646 # Build icons.
2647 # - mmake is the mmaketarget
2648 # - icons is a list of icon base names (i.e. without the .info suffix)
2649 # - dir is the destination directory
2650 # - srcdir is where *.png and *.info.src are sought
2651 #-----------------------------------------------------------------------------
2653 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2655 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2658 %(mmake) : $(BD_OBJS)
2660 ifeq (%(image),)
2662 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2663         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2664         @$(ILBMTOICON) $+ $@
2666 else
2668 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2669         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2670         @$(ILBMTOICON) $+ $@
2672 endif
2674 $(BD_OBJS) : | %(dir)
2675 GLOB_MKDIRS += %(dir)
2677 %(mmake)-clean : FILES := $(BD_OBJS)
2679 %(mmake)-clean ::
2680         @$(RM) $(FILES)
2682 .PHONY: %(mmake) %(mmake)-clean
2684 %end
2685 #-----------------------------------------------------------------------------
2688 #------------------------------------------------------------------------------
2689 # Compile files for an arch-specific replacement of code for a module
2690 # - files: the basenames of the C files to compile.
2691 # - asmfiles: the basenames of the asm files to assemble.
2692 # - mainmmake: the mmake of the module in the main directory to compile these
2693 #   arch specific files for.
2694 # - maindir: the object directory for the main module
2695 # - arch: the arch for which to compile these files. It can have the form
2696 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2697 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2698 # - dflags: the flags used during creation of dependency file. If not specified
2699 #   the same value as cflags will be used
2700 # - aflags: the flags used during assembling
2701 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2702 #   the target compiler is used
2703 # - modname: arch_specific builds of modules (built using build_module) MUST
2704 #   specify the name here matching the original module. this insures multiple modules
2705 #   built from the same makefile will not pollute each other.
2706 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2707  cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target objdir= modname=
2709 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2710     $(error no files or asmfiles given)
2711 endif
2713 ifneq (%(cxxfiles),)
2714     $(error cxx support is TODO)
2715 endif
2717 %buildid targets="%(mainmmake)-%(arch)"
2719 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2720 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2721 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2722 #MM- %(mainmmake)-linklib : %(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)-kobj :    %(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-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2729 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2730 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2731 #MM- %(mainmmake)-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
2735 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2737 ifneq (%(objdir),)
2738     BD_OBJROOT$(BDID)  := %(objdir)
2739 else
2740 ifneq (%(modname),)
2741     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)/%(modname)
2742 else
2743     BD_OBJROOT$(BDID)  := $(GENDIR)/%(maindir)
2744 endif
2745 endif
2746 BD_OBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/arch
2747 BD_LIBOBJDIR$(BDID)  := $(BD_OBJROOT$(BDID))/linklib/arch
2748 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2749 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2750 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2751 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2752 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2753 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2755 ifneq (%(modname),)
2756 BD_DEFLIBDEFSINC$(BDID) := -include $(BD_OBJROOT$(BDID))/include/%(modname)_deflibdefs.h
2757 endif
2759 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2760     BD_TARGET := %(mainmmake)-%(arch)-quick
2761 else
2762     BD_TARGET := %(mainmmake)-%(arch)
2763 endif
2766 ifeq ($(TARGET),$(BD_TARGET))
2767 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2768 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2769 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2770 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2771 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2772 endif
2774 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2775 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2778 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2781 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2783 ifeq ($(findstring %(compiler),host kernel target),)
2784     $(error unknown compiler %(compiler))
2785 endif
2786 ifneq (%(modname),)
2787 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) -I$(BD_OBJROOT$(BDID)) $(BD_DEFLIBDEFSINC$(BDID)))
2788 else
2789 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2790 endif
2791 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2792 ifeq (%(compiler),target)
2793 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(TARGET_CC) $(TARGET_SYSROOT))
2794 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
2795 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(TMP_CFLAGS) $(SAFETY_CFLAGS))
2796 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2797 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2798 endif
2799 ifeq (%(compiler),host)
2800 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2801 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2802 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2803 endif
2804 ifeq (%(compiler),kernel)
2805 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))
2806 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(strip $(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS))
2807 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(strip $(ISA_FLAGS) $(KERNEL_CFLAGS) $(TMP_CFLAGS))
2808 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2809 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2810 endif
2812 ifeq ($(TARGET),$(BD_TARGET))
2813 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2814         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2815 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2816         %compile_q cmd=$(TMP_CMD) opt="$(strip $(TMP_CFLAGS) $(TMP_CPPFLAGS))" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2817 endif
2819 ifeq (%(dflags),)
2820 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=$(strip %(cppflags) $(BD_DEFLIBDEFSINC$(BDID)))
2821 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
2822 else
2823 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2824 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2825 endif
2826 ifeq ($(TARGET),$(BD_TARGET))
2827 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2828         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2830 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2831         %mkdepend_q cc=$(TMP_CMD) flags="$(strip $(TMP_DFLAGS) $(TMP_CPPFLAGS))"
2832 endif
2834 $(BD_ASMOBJS$(BDID)) : CPPFLAGS:=%(cppflags)
2835 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2837 ifeq ($(TARGET),$(BD_TARGET))
2838 $(BD_OBJDIR$(BDID))/%.o : %.s
2839         %assemble_q
2840 $(BD_OBJDIR$(BDID))/%.o : %.S
2841         %assemble_q
2842 endif
2844 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2845 %end
2846 #------------------------------------------------------------------------------
2849 #------------------------------------------------------------------------------
2850 # generate asm files from c files (for debugging purposes)
2851 %define ctoasm_q
2852 %.s : %.c
2853         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2854         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2855 %end
2856 #------------------------------------------------------------------------------
2859 #------------------------------------------------------------------------------
2860 # Copy files from one directory to another.
2862 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2864 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2866 GLOB_MKDIRS += %(dst)
2868 .PHONY : %(mmake)
2871 %(mmake) : | %(dst) 
2872         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2874 %end
2875 #------------------------------------------------------------------------------
2878 #------------------------------------------------------------------------------
2879 # Copy a directory recursively to another place, preserving the original 
2880 # hierarchical structure
2882 # src: the source directory whose content will be copied.
2883 # dst: the directories where to copy src's content. If not existing, they will be made.
2884 # excludefiles: files which must not be copied. Path must be relative to src.
2886 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2888 .PHONY : %(mmake)
2891 %(mmake) :
2892         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2894 %end
2895 #------------------------------------------------------------------------------
2898 #------------------------------------------------------------------------------
2899 #   Copy include files into the includes directories. There are currently
2900 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2901 #   for building tools that need to run on the host system $(GENINCDIR). The
2902 #   $(GENINCDIR) path must not contain any references to the C runtime
2903 #   library header files.
2905 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2906     dir= compiler=target includedir=$(AROS_INCLUDES)
2908 ifeq ($(findstring %(compiler),host kernel target),)
2909 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2910 endif
2912 ifneq (%(dir),)
2913 TMP_DIR := %(dir)
2914 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2915 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2916 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2917 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2918 ifeq ($(TMP_DIRFIRST),/)
2919 BD_INC_PATH := %(dir)/
2920 else
2921 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2922 endif
2923 else
2924 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2925 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2926 endif
2928 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2929         @$(CP) $< $@
2931 ifeq (%(compiler),target)
2933 ifneq (%(dir),)
2934 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2935 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2936 else
2937 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2938 endif
2940 BD_INCL_FILES += $(BD_INCL_FILES2)
2942 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2943         @$(CP) $< $@
2944 endif
2947 %(mmake) : $(BD_INCL_FILES)
2949 .PHONY: %(mmake)
2951 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2952 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2953 %end
2954 #------------------------------------------------------------------------------
2957 #------------------------------------------------------------------------------
2958 %define make_hidd_stubs hidd=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2959 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2960 STUBS_MEM := $(addsuffix .o,$(STUBS))
2961 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2962 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2963 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2965 #MM- linklibs : hidd-%(hidd)-stubs
2966 #MM- %(parenttarget): hidd-%(hidd)-stubs
2967 #MM hidd-%(hidd)-stubs : includes includes-copy
2968 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2970 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2971         %mklib_q from=$^
2973 $(STUBS_OBJ) : $(STUBS_SRC) 
2974         %compile_q cmd="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" opt="$(strip %(cflags) %(cppflags))" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2976 $(STUBS_DEP) : $(STUBS_SRC)
2977         %mkdepend_q flags="$(strip %(dflags) %(cppflags))"
2979 setup ::
2980         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2983 clean ::
2984         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2986 DEPS := $(DEPS) $(STUBS_DEP)
2988 %end
2989 #------------------------------------------------------------------------------
2992 #------------------------------------------------------------------------------
2993 # Build an imported source tree which uses the configure script from the
2994 # autoconf package.  This rule will try to "integrate" the produced files as
2995 # much as possible in the AROS build, for example by putting libraries in the
2996 # standard library directory, includes in the standard include directory, and
2997 # so on. You can however override this behaviour.
2999 # As a special "bonus" for you, the PROGDIR environment variable is defined to
3000 # be %(bindir) (or its deduced value) when running "make install", and
3001 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
3002 # configure script some more parameters whose value depends upon the PROGDIR
3003 # env var, so that the program gets all its stuff installed in the proper place
3004 # when building it, but when running it from inside AROS it can also find that
3005 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
3006 # the configuration parameters set when running ./configure
3008 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
3009 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
3010 # to the name which has to follow it.
3012 # Arguments:
3014 #     - mmake           = the meta make target.
3015 #     - package         = name of the package to be built.
3016 #     - srcdir          = the location of the unpacked source code. Defaults
3017 #                         to $(SRCDIR)/$(CURDIR).
3018 #     - prefix          = the target directory. Must be an absolute path of the
3019 #                         host system. Defaults to $(AROS_CONTRIB).
3020 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3021 #                         Defaults to the value of the prefix option.
3022 #     - extraoptions    = additional options for the configure script.
3023 #     - usecppflags      = enable the use of cpp flags. some external configure
3024 #                         scripts will not set their own cppflags if it is already
3025 #                         set, so this allows them to be disabled (unless you can provide
3026 #                         all the options they would need)
3027 #     - extracppflags      = additional preprocessor flags.
3028 #     - extracflags     = additional flags to use with the C compiler.
3029 #     - extracxxflags   = additional flags to use with the C++ compiler.
3030 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
3031 #                         Defaults to the value of the nix argument.
3032 #     - nix             = enable u*nix path handling, i.e. a path like
3033 #                         /progdir//./file will be translated to
3034 #                         progdir:file during run-time. Defaults to no.
3035 #     - compiler        = target, host or kernel. Defaults to target.
3036 #     - install_target  = the command used for installing. Defaults to install. Leave
3037 #                         it empty if you want to suppress installing.
3038 #     - preconfigure    = a metatarget which is executed before configure is called.
3039 #     - postconfigure   = a metatarget which is executed after configure is called.
3040 #     - postinstall     = a metatarget which is executed after installing.
3041 #     - install_env     = set additional options for installing.
3042 #     - use_build_env   = if yes the configuration environment is used for
3043 #                         installing, too. Defaults to no.
3045 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
3046 # like this:
3048 # if nix_dir_layout
3049 #    --prefix = $(aros_prefix)
3050 #    progdir = $(aros_prefix)/bin
3051 # else
3052 #    if nix
3053 #        --prefix = /PROGDIR
3054 #        --bindir = /PROGDIR
3055 #        --sbindir = /PROGDIR
3056 #        --libdir = /LIB
3057 #        --includedir = /INCLUDE
3058 #        --oldincludedir = /INCLUDE   
3059 #    else
3060 #        --prefix = $(aros_prefix)
3061 #    endif
3063 #    progdir = $(aros_prefix)
3065 #    # Install options
3066 #    bindir = $(prefix)
3067 #    sbindir = $(prefix)
3068 #    libdir = $(AROS_LIB)
3069 #    includedir = $(AROS_INCLUDES)
3070 #    oldincludedir = $(AROS_INCLUDES)
3071 # endif
3074 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
3075     prefix= gendir= basedir=$(CURDIR) extraoptions= \
3076     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3077     hostisaflags="$(ISA_FLAGS)" targetisaflags="$(ISA_FLAGS)" \
3078     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
3079     install_target=install preconfigure= postconfigure= postinstall= \
3080     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes nlsflag=yes xflag=yes
3082 ifneq (%(prefix),)
3083     %(mmake)-prefix := %(prefix)
3084 else
3085     %(mmake)-prefix := $(AROS_CONTRIB)
3086 endif
3088 ifneq (%(aros_prefix),)
3089     %(mmake)-aros_prefix := %(aros_prefix)
3090 else
3091     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3092 endif
3094 BD_NIXFLAG ?= -nix
3096 ifeq (%(nix),yes)
3097     %(mmake)-nix    := $(BD_NIXFLAG)
3098     %(mmake)-volpfx := /
3099     %(mmake)-volsfx := /
3100     
3101     ifeq (%(nix_dir_layout),)
3102         %(mmake)-nix_dir_layout := yes
3103     endif
3104 else
3105     %(mmake)-volsfx := :
3106     
3107     ifeq (%(nix_dir_layout),)
3108         %(mmake)-nix_dir_layout := no
3109     endif
3110 endif
3112 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
3114 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
3115         exec_prefix=$(%(mmake)-prefix) %(install_env)
3117 # Check if chosen compiler is valid
3118 ifeq ($(findstring %(compiler),host target kernel),)
3119   $(error unknown compiler %(compiler))
3120 endif
3122 # Set legacy 'host' variable based on chosen compiler
3123 ifeq (%(compiler),host)
3124     host := yes
3125     ifeq (%(basedir),)
3126         %(mmake)-pkgbasedir := $(HOSTGENDIR)
3127     else
3128         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
3129     endif
3130 else
3131     host := no
3132     ifeq (%(basedir),)
3133         %(mmake)-pkgbasedir := $(GENDIR)
3134     else
3135         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
3136     endif
3137 endif
3138 ifneq (%(gendir),)
3139     ifeq (%(basedir),)
3140         %(mmake)-pkgbasedir := %(gendir)
3141     else
3142         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
3143     endif
3144 endif
3146 ifeq (%(package),)
3147     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
3148 else
3149     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
3150 endif
3152 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
3153 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3155 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
3156     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
3157     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3158 else
3159     ifeq (%(nix),yes)
3160         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
3161         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
3162     else
3163         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
3164     endif
3166     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
3167     
3168     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
3169         sbindir=$(%(mmake)-prefix) \
3170         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
3171         oldincludedir=$(AROS_INCLUDES) %(install_env)
3172 endif
3174 ifneq ($(DEBUG),yes)
3175     %(mmake)-s_flag = -s
3176 endif
3178 # Set up build environment, and options for configure script
3179 ifeq (%(compiler),host)
3180     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
3181     # confused configure scripts. We also cannot pass it via _FOR_BUILD
3182     # since that won't get picked up during configure.
3183     # We also cannot pass in the compiler including std flags so we need to use
3184     # the "plain" host compiler.
3185     %(mmake)-cfg-env := %(config_env_extra) \
3186         CPP="$(HOST_CPP)" \
3187         CXXCPP="$(HOST_CPP)" \
3188         CC="$(strip $(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3189         CXX="$(strip $(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include)" \
3190         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)"
3191 ifeq (%(usecppflags),yes)
3192     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3193 endif
3194     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3195         TARGET_CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3196         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3197         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3198         TARGET_AS="$(TARGET_AS)" \
3199         OBJCOPY="$(OBJCOPY)" \
3200         TARGET_RANLIB="$(RANLIB)" \
3201         TARGET_STRIP="$(STRIP_PLAIN)" \
3202         TARGET_NM="$(NM_PLAIN)" \
3203         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
3204 endif
3205 ifeq (%(compiler),target)
3206     %(mmake)-cfg-env := %(config_env_extra) \
3207         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
3208         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
3209     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3210         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3211         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3212         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3213         LD="$(strip $(TARGET_LD))"
3214 ifeq (%(crossbuild),yes)
3215     %(mmake)-cfg-env += CFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3216         CXXFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3217 ifeq (%(usecppflags),yes)
3218     %(mmake)-cfg-env += CPPFLAGS="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3219 endif
3220 else
3221     %(mmake)-cfg-env += CFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3222         CXXFLAGS="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3223 ifeq (%(usecppflags),yes)
3224     %(mmake)-cfg-env += CPPFLAGS="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3225 endif
3226 endif
3227     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3228 ifeq (%(usecppflags),yes)
3229     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3230 endif
3231     %(mmake)-cfg-env += CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
3232         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
3233         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
3234         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
3235         LD_FOR_BUILD="$(strip $(HOST_LD))" \
3236         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))"
3237 ifeq (%(usecppflags),yes)
3238     %(mmake)-cfg-env += CPPFLAGS_FOR_HOST="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3239 endif
3240     %(mmake)-cfg-env += CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3241         CFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3242         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3243         CXXFLAGS_FOR_HOST="$(strip %(hostisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3244         LD_FOR_HOST="$(strip $(TARGET_LD))" \
3245         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3246 ifeq (%(usecppflags),yes)
3247     %(mmake)-cfg-env += CPPFLAGS_FOR_TARGET="$(strip $(BASE_CPPFLAGS) $(USER_CPPFLAGS) %(extracppflags))"
3248 endif
3249     %(mmake)-cfg-env += CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3250         CFLAGS_FOR_TARGET="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3251         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3252         CXXFLAGS_FOR_TARGET="$(strip %(targetisaflags) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3253         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3254         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3255         AR="$(strip $(AR_PLAIN))" \
3256         AS="$(strip $(TARGET_AS))" \
3257         OBJCOPY="$(strip $(OBJCOPY))" \
3258         RANLIB="$(strip $(RANLIB))" \
3259         STRIP="$(strip $(STRIP_PLAIN))"
3260 ifeq (%(usecppflags),yes)
3261     %(mmake)-cfg-env += TARGET_CPPFLAGS="$(KERNEL_CPPFLAGS)"
3262 endif
3263     %(mmake)-cfg-env += TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3264         TARGET_CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3265         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3266         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3267         TARGET_AS="$(strip $(TARGET_AS))" \
3268         TARGET_RANLIB="$(strip $(RANLIB))" \
3269         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3270         TARGET_NM="$(strip $(NM_PLAIN))"
3271 ifeq (%(buildflags),yes)
3272     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3273     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3274     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3275 endif
3276 ifeq (%(gnuflags),yes)
3277     %(mmake)-config_opts += --without-pic --disable-shared
3278 ifeq (%(nlsflag),yes)
3279 # disable native language support
3280     %(mmake)-config_opts += --disable-nls
3281 endif
3282 ifeq (%(xflag),yes)
3283 # disable X window system
3284     %(mmake)-config_opts += --without-x
3285 endif
3286 endif
3287 endif
3288 ifeq (%(compiler),kernel)
3289     %(mmake)-cfg-env := %(config_env_extra) \
3290         CPP="$(KERNEL_CPP)" \
3291         CXXCPP="$(KERNEL_CPP)"
3292 ifeq (%(usecppflags),yes)
3293     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3294 endif
3295     %(mmake)-cfg-env += CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3296         CFLAGS="$(strip %(targetisaflags) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3297         CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3298         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))" \
3299         AS="$(KERNEL_AS)"
3300 ifeq (%(usecppflags),yes)
3301     %(mmake)-cfg-env += CPPFLAGS_FOR_BUILD="$(HOST_CPPFLAGS)"
3302 endif
3303     %(mmake)-cfg-env += CC_FOR_BUILD="$(HOST_DEF_CC)" \
3304         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3305         CXX_FOR_BUILD="$(HOST_CXX)" \
3306         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3307         RANLIB="$(RANLIB)" \
3308         TARGET_RANLIB="$(RANLIB)" \
3309         TARGET_STRIP="$(STRIP_PLAIN)" \
3310         TARGET_NM="$(NM_PLAIN)"
3311 ifeq (%(buildflags),yes)
3312     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3313     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3314     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3315 endif
3316 ifeq (%(gnuflags),yes)
3317     %(mmake)-config_opts += --without-pic --disable-shared
3318 ifeq (%(nlsflag),yes)
3319 # disable native language support
3320     %(mmake)-config_opts += --disable-nls
3321 endif
3322 ifeq (%(xflag),yes)
3323 # disable X window system
3324     %(mmake)-config_opts += --without-x
3325 endif
3327 endif
3328 endif
3330 ifeq (%(use_build_env),yes)
3331     BUILD_ENV := $(%(mmake)-cfg-env)
3332 endif
3334 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3335 # in an ideal world, we would depend on the files in the source directory,
3336 # so we could copy them when they change. unfortunately filenames with
3337 # spaces causes problems with this
3338 $(%(mmake)-pkgdir)/.local-copy:
3339         %mkdirs_q $(%(mmake)-pkgdir)
3340         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3341         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3343 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3345     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3346 else
3347     %(mmake)-cfg-srcdir=%(srcdir)
3348 endif
3349 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3351 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3353 # When building for the host, we don't need to build the
3354 # linklibs - this is especially true when building the
3355 # crosstool toolchain on 'foreign' architectures (such as
3356 # building PPC on x86)
3358 #MM- %(mmake)-host : setup includes %(mmake)-quick
3359 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3360 #MM- %(mmake): %(mmake)-%(compiler)
3362 # Using -j1 in install_command may result in a warning but finally
3363 # it does its job. make install for gcc does not work reliably for -jN
3364 # where N > 1.
3365 ifneq (%(install_target),)
3366     %(mmake)-install_command = \
3367         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3368         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3369         $(%(mmake)-make-env) %(install_target) -j1
3371     %(mmake)-uninstall_command = \
3372     $(RM) $(%(mmake)-installflag) && \
3373     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3374     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3375 else
3376     %(mmake)-install_command   := true
3377     %(mmake)-uninstall_command := true
3378 endif
3380 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3383 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3386 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3388 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3389         @$(IF) ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3390             $(RM) $(%(mmake)-installflag) && \
3391             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3392             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3393             $(%(mmake)-install_command) && \
3394             $(TOUCH) $@ -r $^; \
3395         fi
3397 $(%(mmake)-pkgdir)/.files-touched:
3398         %mkdirs_q $(%(mmake)-pkgdir)
3399         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3400         $(TOUCH) $@
3403 %(mmake)-uninstall :
3404         $(%(mmake)-uninstall_command)
3407 %(mmake)-configure : $(%(mmake)-configflag)
3409 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3410 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3411         @$(RM) $@
3412         %mkdirs_q $(%(mmake)-pkgdir)
3413         @$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3414         @cd $(%(mmake)-pkgdir) && \
3415         find . -name config.cache -exec $(RM) '{}' \; && \
3416         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3417         $(TOUCH) $@
3420 %(mmake)-clean : %(mmake)-uninstall
3421         @$(RM) $(%(mmake)-pkgdir)
3422 %end
3423 #------------------------------------------------------------------------------
3426 #------------------------------------------------------------------------------
3427 # Build an imported source tree which uses cmake 
3429 # Arguments:
3431 #     - mmake           = the meta make target.
3432 #     - package         = name of the package to be built.
3433 #     - srcdir          = the location of the unpacked source code. Defaults
3434 #                         to $(SRCDIR)/$(CURDIR).
3435 #     - prefix          = the target directory. Must be an absolute path of the
3436 #                         host system. Defaults to $(AROS_CONTRIB).
3437 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3438 #                         Defaults to the value of the prefix option.
3439 #     - extraoptions    = additional options for the cmake script.
3440 #     - usecppflags     = enable the use of cpp flags. some external cmake
3441 #                         scripts will not set their own cppflags if it is already
3442 #                         set, so this allows them to be disabled (unless you can provide
3443 #                         all the options they would need)
3444 #     - cppflags        = preprocessor flags.
3445 #     - cflags          = flags to use with the C compiler.
3446 #     - cxxflags        = flags to use with the C++ compiler.
3447 #     - installoptions    = additional options for the install step.
3450 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3451     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3452     usecppflags=yes cppflags=$(CPPFLAGS) cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3454 ifneq (%(prefix),)
3455     %(mmake)-prefix := %(prefix)
3456 else
3457     %(mmake)-prefix := $(AROS_CONTRIB)
3458 endif
3460 ifneq (%(aros_prefix),)
3461     %(mmake)-aros_prefix := %(aros_prefix)
3462 else
3463     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3464 endif
3466 ifeq (%(compiler),host)
3467     BD_LDFLAGS   := $(strip -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS))
3468     BD_CFLAGS := $(strip $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include)
3469     BD_CXXFLAGS := $(strip $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include)
3470     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3471     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)"
3472     ifeq (%(usecppflags),yes)
3473         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3474     endif
3475     %(mmake)-cmake_opts += -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3476     ifeq (%(package),)
3477         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3478     else
3479         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3480     endif
3481 else
3482     BD_LDFLAGS   := %(ldflags)
3483     BD_CFLAGS := %(cflags) 
3484     BD_CXXFLAGS := %(cxxflags)
3485     BD_CPPFLAGS := %(cppflags)
3486     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3487     ifeq (%(usecppflags),yes)
3488         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3489     endif
3490     %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))" -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3491     ifeq (%(package),)
3492         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3493     else
3494         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3495     endif
3496 endif
3497 ifneq (%(gendir),)
3498     ifeq (%(package),)
3499         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3500     else
3501         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3502     endif
3503 endif
3505 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3506 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3508 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3510 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3512 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3515 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3517 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3518         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3519             $(RM)  $(%(mmake)-installflag) && \
3520             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3521             cd $(%(mmake)-pkgdir) && \
3522             cmake %(installoptions) -P cmake_install.cmake && \
3523             $(TOUCH) $@ -r $^; \
3524         fi
3526 $(%(mmake)-pkgdir)/.files-touched:
3527         %mkdirs_q $(%(mmake)-pkgdir)
3528         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3529         $(TOUCH) $@
3532 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3534 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3535 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3536         $(RM) $@
3537         %mkdirs_q $(%(mmake)-pkgdir)
3538         cd $(%(mmake)-pkgdir) && \
3539         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3540         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3541         $(TOUCH) $@
3544 %(mmake)-clean : %(mmake)-uninstall
3545         @$(RM) $(%(mmake)-pkgdir)
3546 %end
3547 #------------------------------------------------------------------------------
3550 #------------------------------------------------------------------------------
3551 # Given an archive name, patches names and locations where to find them, fetch
3552 # the archive and the patches from any of those locations, unpack the archive
3553 # and then apply the patches.
3555 # Locations currently supported are http and ftp sites, plus local filesystem
3556 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3557 # the fetch.sh script needs to be modified, since this macro relies on that script.
3559 # Arguments:
3561 #     - mmake           = mmaketarget
3562 #     - archive_origins = list of locations where to find the archive. They are tried
3563 #                         in sequence, until the archive is found and fetching it 
3564 #                         succeeded. If not specified, the current directory is assumed.
3565 #     - archive         = the archive name. Mandatory.
3566 #     - suffixes        = a list of suffixes to append to the package name plus the
3567 #                         version. Each one of them is tried until a matching archive is
3568 #                         found. They are appended to patches and these are tried the
3569 #                         same way as packages are.
3570 #     - location        = the local directory where to put the fetched archive and patches.
3571 #                         If not specified, the directory specified by destination is used.
3572 #     - destination     = the directory to unpack the archive to.
3573 #                         If not specified, the current directory is assumed.
3574 #     - patches_origins = list of locations where to find the patches. They are tried
3575 #                         in sequence, until a patch is found and fetching it 
3576 #                         succeeded. If not specified, the current directory is assumed.
3577 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3578 #                         patch_name[:[patch_subdir][:patch_opt]].
3580 #                             - patch_name   = the name of the patch file
3581 #                             - patch_subdir = the directory within \destination\ where to
3582 #                                              apply the patch.
3583 #                             - patch_opt    = any options to pass to the `patch' command
3584 #                                              when applying the patch.
3585 #                         
3586 #                         The patch_subdir and patch_opt fields are optional.
3588 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3589     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3591 .PHONY: %(mmake)
3593 ifneq (%(location),)
3594     %(mmake)-location := %(location)
3595 else
3596     %(mmake)-location := %(destination)
3597 endif
3600 %(mmake) :
3601         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3602         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3603 %end
3604 #------------------------------------------------------------------------------
3607 #------------------------------------------------------------------------------
3608 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3609 # unpatched source tree and runs diff against this and a previously fetched and possibly
3610 # patched tree. Depending on what happens after patching during a normal build it might
3611 # give best results if the new patch is created directly after fetch.
3613 # Arguments:
3615 #     - mmake       = mmaketarget
3616 #     - archive     = archive base name
3617 #     - srcdir      = the top level directory the package is unpacked to, useful if
3618 #                     an archive unpacks to a directory other than its name suggests.
3619 #                     this should not be deeper than a single path element.
3620 #     - suffixes    = a list of suffixes to append to the the package name plus the
3621 #                     version. Each one of them is tried until a matching archive is
3622 #                     found.
3623 #     - destination = the directory to unpack the archive to.
3624 #     - excludes    = diff patterns to exclude files or directories from the patch
3626 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3628 .PHONY: %(mmake)
3630 ifneq (%(excludes),)
3631     %(mmake)-exclude := -X ./exclude.patterns
3632 endif
3634 ifneq (%(srcdir),)
3635     %(mmake)-srcdir := %(srcdir)
3636 else
3637     %(mmake)-srcdir := %(archive)
3638 endif
3640 #MM- %(mmake) : %(mmake)-diff
3641 #MM- %(mmake)-quick : %(mmake)-diff
3644 %(mmake)-diff:
3645         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3646         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3647         cd %(destination)/tmp ; \
3648         $(FOR) f in %(excludes) ; do \
3649             $(ECHO) $$f >> ./exclude.patterns ; \
3650         done ; \
3651         diff -ruN $(%(mmake)-exclude) \
3652             $(%(mmake)-srcdir) \
3653             $(%(mmake)-srcdir).aros \
3654             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3655         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3656         $(RM) %(destination)/tmp
3657 %end
3658 #------------------------------------------------------------------------------
3661 #------------------------------------------------------------------------------
3662 # Joins the features of %fetch and %build_with_configure.
3664 # If a patch is provided, it *must* be named the following way:
3666 #    <package name>-<version number>-aros.diff
3668 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3669 # CD'ing into the archive's extracted directory.
3671 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3672 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3673 # to make that patch fully comprehensive.
3675 # Arguments:
3677 #    - mmake            = the meta make target.
3678 #    - package          = the GNU package name, sans version and archive format suffixes.
3679 #    - subpackage       = ???
3680 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3681 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3682 #    - version          = the package's version number, or otherwise any other version string.
3683 #                         It gets appended to the package name to form the basename of the archive.
3684 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3685 #                         version. Each one of them is tried until a matching archive is found.
3686 #                         Defaults to "tar.bz2 tar.gz".
3687 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3688 #    - builddir         = override the location we expect to run configure/make in.
3689 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3690 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3691 #                         fetched or not. Default to no.
3692 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3693 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3694 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3695 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3696 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3697 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3698 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3699 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3700 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3701 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3702 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3703 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3704 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3705 #    - nix              = same meaning as the one for the %build_with_configure macro.
3706 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3707 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3709 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3710     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3711     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3712     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3713     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="$(ISA_FLAGS)" targetisaflags="$(ISA_FLAGS)"
3715 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3716 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3717 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3718 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3720 %(mmake)-archbase  := %(package)-%(version)
3722 ifeq (%(compiler),host)
3723     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3724 else
3725     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3726 endif
3728 ifeq (%(prefix),)
3729     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3730 else
3731     %(mmake)-prefix := %(prefix)
3732 endif
3734 ifneq (%(subpackage),)
3735     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3736 else
3737     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3738 endif
3740 ifneq (%(srcdir),)
3741     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3742 else
3743     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3744 endif
3746 ifneq (%(builddir),)
3747     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3748 else
3749     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3750 endif
3752 ifeq (%(patch),yes)
3753     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3754 else
3755     %(mmake)-%(subpackage)-patches_specs := ::
3756 endif
3758 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3759     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3760     archive_origins=". %(package_repo)" \
3761     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3763 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3764     archive=$(%(mmake)-%(subpackage)-archbase) \
3765     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3766     suffixes="%(suffixes)" \
3767     destination=$(%(mmake)-portdir)
3769 #MM- %(mmake) : %(mmake)-%(subpackage)
3771 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3773 %(mmake)-%(subpackage)-package-basename := \
3774     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3776 ifneq (%(create_pkg),no)
3777     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3778 endif
3780 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3781      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3782      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3783      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix)  aros_prefix="%(aros_prefix)" \
3784      preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) %(mmake)-%(subpackage)-make-package" \
3785      extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3786      buildflags=%(buildflags) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag) hostisaflags=%(hostisaflags) targetisaflags=%(targetisaflags)
3788 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3789 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3792 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3794 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3795 #that $^ and $@ have exactly the same mtime, and in that case make tries
3796 #to rebuild $@ again, which would fail because the directory where
3797 #the package got installed would not exist anymore. 
3798 #We work this around by using an if statement to manually check the mtimes.
3799 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3800         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -s $@; then \
3801             $(RM) $@ ; \
3802             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3803             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3804             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3805             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3806             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3807             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3808         fi
3809 %end
3810 #------------------------------------------------------------------------------
3813 #------------------------------------------------------------------------------
3814 # Joins the features of %fetch and %build_with_configure, taking advantage of
3815 # the naming scheme of GNU packages. GNU packages names are in the form
3817 #     <package name>-<version number>.<archive format suffix>
3819 # If a patch is provided, it *must* be named the following way:
3821 #    <package name>-<version number>-aros.diff
3823 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3824 # CD'ing into the archive's extracted directory.
3826 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3827 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3828 # to make that patch fully comprehensive.
3830 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3832 # Arguments:
3834 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3836 #    - prefix           = defaults to $(GNUDIR).
3837 #    - aros_prefix      = defaults to /GNU.
3839 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3840     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3841     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall= \
3842     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3843     nix=yes gnuflags=yes nlsflag=yes xflag=yes
3845 GNU_REPOSITORY := gnu://
3847 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3848     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3849     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3850     patch="%(patch)" patch_repo="%(patch_repo)" \
3851     prefix="%(prefix)" aros_prefix="%(aros_prefix)" \
3852     extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3853     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
3854     nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
3856 %end
3857 #------------------------------------------------------------------------------
3860 #------------------------------------------------------------------------------
3861 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3862 # that the package is a "Developer" package, and as such it needs to be placed
3863 # under the $(AROS_DEVELOPER) directory, as a default. 
3865 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3866 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3867 # "mmake" argument, because the metatarget is implicitely defined as
3869 #     #MM- development-%(package)
3871 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3872     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3873     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall= \
3874     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3875     nix=yes gnuflags=yes nlsflag=yes xflag=yes
3877 #MM- development : development-%(package)
3880 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3881    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3882    package_repo="%(package_repo)" \
3883    patch="%(patch)" patch_repo="%(patch_repo)" \
3884    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" \
3885    extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3886    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3887    nix=%(nix) gnuflags=%(gnuflags) nlsflag=%(nlsflag) xflag=%(xflag)
3890 postinstall-%(package)-delete-la-files:
3891         $(RM) %(prefix)/lib/*.la
3893 %end
3894 #------------------------------------------------------------------------------
3896 # Builds a kickstart package in PKG format
3898 # Arguments:
3900 #    - mmake   = target name
3901 #    - file    = destination file name with path
3903 # Other arguments are self-explanatory
3905 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3906     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3908 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3909 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3910 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3911 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3912 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3913 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3915 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3916 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3917 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3918 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3919 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3920 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3922 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3923     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3924 PKG_DIR   := $(dir %(file))
3927 %(mmake) : %(file)
3930 %(mmake)-quick : %(file)
3932 %(file): $(PKG_FILES) | $(PKG_DIR)
3933         @$(ECHO) Packaging $@...
3934         @$(SRCDIR)/tools/package/pkg c $@ $^
3936 %compress_file mmake="%(mmake)" file="%(file)"
3938 GLOB_MKDIRS += $(PKG_DIR)
3940 %end
3942 #------------------------------------------------------------------------------
3943 # Compresses %(file) with a gzip.
3944 # Good in conjunction with for example %build_prog
3946 %define compress_file mmake=/A file=/A
3948 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3951 %(mmake)-gz-quick : %(file).gz
3953 %(file).gz: %(file)
3954         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3955         @gzip -9 -f $^
3957 %end
3959 #------------------------------------------------------------------------------
3960 # Links a kickstart module in ELF format
3961 # Arguments are similar to make_package
3963 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3964     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3966 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3967 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3968 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3969 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3970 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3971 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3973 ifeq (%(startup),)
3974     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3975 else
3976     KOBJ_STARTUP := %(startup)
3977 endif
3979 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3981 TMP_LDFLAGS := %(ldflags)
3983 # Make a list of the lib files this program depends on.
3984 # In LDFLAGS remove white space between -L and directory
3985 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3986 # Filter out only the libdirs and remove -L
3987 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3988 # Add trailing /
3989 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3990 # Add normal linklib path
3991 TMP_DIRS += $(AROS_LIB)/
3992 # add lib and .a to static linklib names
3993 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3994 # search for the linklibs in the given path, ignore ones not found
3995 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3996     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3999 TMP_DIRS += $(dir %(file))
4000 ifneq (%(map),)
4001     TMP_LDFLAGS += $(GENMAP) %(map)
4002     TMP_DIRS    += $(dir %(map))
4003 endif
4005 #MM %(mmake) : %(deps)
4008 %(mmake) : %(file)
4011 %(mmake)-quick : %(file)
4013 %(file): KOBJS := $(KOBJS)
4014 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
4015                     -static -nosysbase -Wl,-Ur
4016 %(file): LDLIBS := $(addprefix -l, %(uselibs))
4017 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
4018         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
4019         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
4020 ifeq ($(DEBUG),yes)
4021         @$(STRIP) $@ --only-keep-debug -o $@.dbg
4022 endif
4023         @$(STRIP) $@
4024 ifeq ($(DEBUG),yes)
4025         @$(OBJCOPY) --add-gnu-debuglink=$@.dbg $@
4026 endif
4028 %compress_file mmake="%(mmake)" file="%(file)"
4030 GLOB_MKDIRS += $(TMP_DIRS)
4032 %end
4034 #------------------------------------------------------------------------------
4035 # Generate generic rules for a subtarget
4037 %define subtarget parentmmake= mmake=/A mmbase=MM-
4038 #%(mmbase) %(parentmmake) : %(mmake)
4039 #%(mmbase) %(parentmmake)-includes : %(mmake)-includes
4040 #%(mmbase) %(parentmmake)-quick : %(mmake)-quick
4041 %end
4043 #------------------------------------------------------------------------------
4044 # Create a target directory
4046 %define directorytarget mmake=/A directory=  icontarget= mmbase=MM-
4048 %(mmake)-makedir ::
4049     %mkdirs_q %(directory)
4051 #%(mmbase) %(mmake) : %(mmake)-makedir
4052 %end