build_with_configure: only provide CPPFLAGS if they are requested.
[AROS.git] / config / make.tmpl
blobc199afbea0572b3273433d977dec0d9f754360c9
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="$(TARGET_CC) $(TARGET_SYSROOT)" opt="$(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="$(CC) $(TARGET_SYSROOT)" opt=$(AFLAGS) 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="$(AROS_CC) $(TARGET_SYSROOT)" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP) objdir=$(GENDIR)/$(CURDIR)
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 %end
87 #------------------------------------------------------------------------------
90 #-------------------------------------------------------------------------
91 # Link a module based upon a number of arguments and the standard $(LIBS)
92 # and $(DEPLIBS) make variables.
94 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
95         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
96         @$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
97                 $(GENMAP) %(objdir)/%(module).map \
98                 %(objs) %(libs) %(ldflags) %(endtag) \
99                 -o $@ 2>&1 > %(objdir)/%(err); \
100         then \
101                 cat %(objdir)/%(err); \
102         else \
103                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
104                 cat %(objdir)/%(err); \
105                 exit 1; \
106         fi
107         @$(IF) $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
108         @$(IF) [ "$(DEBUG)" = "yes" ]; then \
109                 $(STRIP) $@ --only-keep-debug -o $@.dbg; \
110         fi
111         @$(STRIP) $@
112 %end
113 #------------------------------------------------------------------------------
116 #------------------------------------------------------------------------------
117 # Create the library
118 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
119         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
120         @%(ar) %(to) %(from)
121         @%(ranlib) %(to)
122 %end
123 #------------------------------------------------------------------------------
126 #------------------------------------------------------------------------------
127 # Create the dependency file %(to) for %(from)
128 %define mkdepend_q flags="$(CFLAGS) $(CPPFLAGS)" from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
129         %mkdir_q dir="$(dir %(to))"
130         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
131         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create one directory without any output
138 %define mkdir_q dir=.
139         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
140 %end
141 #------------------------------------------------------------------------------
144 #------------------------------------------------------------------------------
145 # Create several directories without any output
146 %define mkdirs_q dirs=/M
147         @$(FOR) dir in %(dirs) ; do \
148                 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
149         done
150 %end
151 #------------------------------------------------------------------------------
154 #############################################################################
155 #############################################################################
156 ##                                                                         ##
157 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
158 ## mmakefile. They consist of one or more full makefile rules.             ##
159 ## In general the files generated in these macros are also defined as      ##
160 ## make targets so that they can be used as a dependency in other rules    ##
161 ##                                                                         ##
162 #############################################################################
163 #############################################################################
165 #------------------------------------------------------------------------------
166 # Generate a unique id for each of the %build... rules
167 %define buildid targets=/A
168 BDID := $(BDID)_
169 ifneq ($(filter $(TARGET),%(targets)),)
170 BDTARGETID := $(BDID)
171 endif
172 %end
173 #------------------------------------------------------------------------------
176 #------------------------------------------------------------------------------
177 # Copy file %(from) to %(to) in a makefile rule
178 %define rule_copy from=/A to=/A
179 %(to) : %(from)
180         @$(CP) $< $@
181 %end
182 #------------------------------------------------------------------------------
185 #------------------------------------------------------------------------------
186 # Copy the files %(files) to %(targetdir). For each file in %(files),
187 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
188 # appropriate subdirs are not generated by this rule so they have to be
189 # present.
190 %define rule_copy_multi files=/A targetdir=/A srcdir=.
192 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
193         @$(CP) $< $@
194 %end
195 #------------------------------------------------------------------------------
198 #------------------------------------------------------------------------------
199 # Copy the files %(files) to %(targetdir). For each file in %(files),
200 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
201 # %(stampfile) is used to keep track of when the last time the comparison has
202 # been done. The targetdir and the appropriate subdirs are not generated by 
203 # this rule so they have to be present.
204 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
205     stampfile=$(TMP_SRCDIR)/.copy_stamp
207 TMP_SRCDIR := %(srcdir)
209 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
211 %(stampfile) : COPYSRCDIR := %(srcdir)
212 %(stampfile) : TGTDIR := %(targetdir)
213 %(stampfile) : FILES := %(files)
214 %(stampfile) : $(addprefix %(srcdir)/,%(files))
215         @for f in $(FILES); do \
216              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
217                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
218              fi ; \
219         done
220         @$(TOUCH) $@
221 %end
222 #------------------------------------------------------------------------------
225 #------------------------------------------------------------------------------
226 # Will join all the files in %(from) to %(to). When text is specified it will
227 # be displayed.
228 # Restriction: at the moment when using a non-empty target dir %(from) may
229 # not have 
230 %define rule_join to=/A from=/A text=
232 %(to) : %(from)
233 ifneq (%(text),)
234         @$(ECHO) %(text)
235 endif
236         @$(CAT) $^ >$@
237 %end
238 #------------------------------------------------------------------------------
241 #------------------------------------------------------------------------------
242 # Include the dependency files and add some internal rules
243 # When depstargets is provided the depencies will only be included when one of
244 # these targets is the $(TARGET). Otherwise the dependencies will only be
245 # included when the $(TARGET) is not for setup or clean 
246 %define include_deps deps=$(DEPS)/M  depstargets=
247 ifneq (%(deps),)
248   ifneq (%(depstargets),)
249     ifneq ($(findstring $(TARGET),%(depstargets)),)
250       -include %(deps)
251     endif
252   else
253     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
254       -include %(deps)
255     endif
256   endif
257 endif
258 %end
259 #------------------------------------------------------------------------------
262 #------------------------------------------------------------------------------
263 # Create the directories %(dirs). The creation will be done by adding rules to
264 # the %(setuptarget) make target with setup as the default. 
265 %define rule_makedirs dirs=/A setuptarget=setup
267 %(setuptarget) :: %(dirs)
269 GLOB_MKDIRS += %(dirs)
271 %end
272 #------------------------------------------------------------------------------
275 #------------------------------------------------------------------------------
276 # Generate a rule to compile a C source file to an object file and generate
277 # the dependency file. Basename may contain a directory part, then the source
278 # file has to be in that directory. The generated file will be put in the
279 # object directory without the directory.
280 # options
281 # - basename: the basename of the file to compile. Use % for a wildcard rule
282 # - cflags (default $(CFLAGS)): the C flags to use for compilation
283 # - dflags: the flags used during creation of dependency file. If not specified
284 #   the same value as cflags will be used
285 # - targetdir: the directory to put the .o file and the .d file. By default
286 #   it is put in the same directory as the .c file
287 %define rule_compile basename=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= targetdir= compiler=target
289 BD_NIXFLAG ?= -nix
291 ifeq (%(targetdir),)
292   TMP_TARGETBASE := %(basename)
293 else
294   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
295 endif
297 # Adjust compiler flags to suit C
298 TMP_CFLAGS := %(cflags) %(cppflags)
299 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
300 ifeq (%(dflags),)
301   TMP_DFLAGS := %(cflags) %(cppflags)
302 else
303   TMP_DFLAGS := %(dflags) %(cppflags)
304 endif
306 ifeq ($(findstring %(compiler),host kernel target),)
307   $(error unknown compiler %(compiler))
308 endif
309 ifeq (%(compiler),target)
310 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
311 BD_STRIP ?= $(TARGET_STRIP)
312 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
313 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
314 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
315 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_DFLAGS)
316 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
317 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
318 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
319 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
320 endif
321 ifeq (%(compiler),host)
322 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
323 BD_STRIP ?= $(HOST_STRIP)
324 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
325 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
326 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
327 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
328 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
329 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
330 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
331 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
332 endif
333 ifeq (%(compiler),kernel)
334 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
335 BD_STRIP ?= $(ECHO) >/dev/null
336 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
337 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
338 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
339 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
340 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
341 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
342 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
343 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
344 endif
346 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
347 $(TMP_TARGETBASE).o : %(basename).c
348         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
350 ifeq (%(nix),yes)
351   $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
352 endif
353 $(TMP_TARGETBASE).d : %(basename).c
354         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
355 %end
356 #------------------------------------------------------------------------------
359 #------------------------------------------------------------------------------
360 # Generate a rule to compile a C++ source file to an object file and generate
361 # the dependency file. Basename may contain a directory part, then the source
362 # file has to be in that directory. The generated file will be put in the
363 # object directory without the directory.
364 # options
365 # - basename: the basename of the file to compile. Use % for a wildcard rule
366 # - cflags (default $(CFLAGS)): the C flags to use for compilation
367 # - dflags: the flags used during creation of dependency file. If not specified
368 #   the same value as cflags will be used
369 # - targetdir: the directory to put the .o file and the .d file. By default
370 #   it is put in the same directory as the .c file
371 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) cppflags=$(CPPFLAGS) dxxflags= targetdir= compiler=target
373 ifneq (%(basename),)
374 BD_NIXFLAG ?= -nix
375 ifeq (%(targetdir),)
376   TMP_TARGETBASE := %(basename)
377 else
378   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
379 endif
381 # Adjust compiler flags to suit C++
382 TMP_CXXFLAGS := %(cxxflags) %(cppflags)
383 ifeq (%(dxxflags),)
384   TMP_DXXFLAGS := %(cxxflags) %(cppflags)
385 else
386   TMP_DXXFLAGS := %(dxxflags) %(cppflags)
387 endif
389 ifeq ($(findstring %(compiler),host kernel target),)
390   $(error unknown compiler %(compiler))
391 endif
392 ifeq (%(compiler),target)
393 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
394 BD_STRIP ?= $(TARGET_STRIP)
395 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
396 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
397 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TMP_CXXFLAGS) $(SAFETY_CFLAGS)
398 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TMP_DXXFLAGS)
399 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
400 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
401 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
402 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
403 endif
404 ifeq (%(compiler),host)
405 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
406 BD_STRIP ?= $(HOST_STRIP)
407 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
408 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
409 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS) 
410 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
411 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
412 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
413 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
414 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
415 endif
416 ifeq (%(compiler),kernel)
417 KERNEL_CXX ?= $(KERNEL_CC)
418 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
419 BD_STRIP ?= $(ECHO) >/dev/null
420 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
421 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
422 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
423 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
424 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
425 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
426 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
427 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
428 endif
430 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
431 $(TMP_TARGETBASE).o : %(basename).cpp
432         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
434 ifeq (%(nix),yes)
435   $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
436 endif
437 $(TMP_TARGETBASE).d : %(basename).cpp
438         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DXXFLAGS)
440 endif
442 %end
443 #------------------------------------------------------------------------------
446 #------------------------------------------------------------------------------
447 # Generate a rule to compile an ObjC source file to an object file and generate
448 # the dependency file. Basename may contain a directory part, then the source
449 # file has to be in that directory. The generated file will be put in the
450 # object directory without the directory.
451 # options
452 # - basename: the basename of the file to compile. Use % for a wildcard rule
453 # - cflags (default $(CFLAGS)): the C flags to use for compilation
454 # - dflags: the flags used during creation of dependency file. If not specified
455 #   the same value as cflags will be used
456 # - targetdir: the directory to put the .o file and the .d file. By default
457 #   it is put in the same directory as the .m file
458 %define rule_compile_objc basename=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= targetdir= compiler=target
460 ifneq (%(basename),)
461 BD_NIXFLAG ?= -nix
462 ifeq (%(targetdir),)
463   TMP_TARGETBASE := %(basename)
464 else
465   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
466 endif
468 # Adjust compiler flags to suit ObjC
469 TMP_OBJCFLAGS := %(cflags) %(cppflags)
470 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
471 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
472 ifeq (%(dflags),)
473   TMP_OBJCDFLAGS := %(cflags) %(cppflags)
474 else
475   TMP_OBJCDFLAGS := %(dflags) %(cppflags)
476 endif
478 # Define the use of cross compiler
479 ifeq ($(TARGET_OBJC),)
480   TMP_CC := $(TARGET_CC)
481 else
482   TMP_CC := $(TARGET_OBJC)
483 endif
485 ifeq ($(findstring %(compiler),host kernel target),)
486   $(error unknown compiler %(compiler))
487 endif
488 ifeq (%(compiler),target)
489 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
490 BD_STRIP ?= $(TARGET_STRIP)
491 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
492 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
493 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS) $(SAFETY_CFLAGS)
494 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
495 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
496 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
497 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
498 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
499 endif
500 ifeq (%(compiler),host)
501 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
502 BD_STRIP ?= $(HOST_STRIP)
503 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
504 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
505 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
506 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
507 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
508 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
509 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
510 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
511 endif
512 ifeq (%(compiler),kernel)
513 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
514 BD_STRIP ?= $(ECHO) >/dev/null
515 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
516 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
517 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
518 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
519 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
520 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
521 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
522 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
523 endif
525 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
526 $(TMP_TARGETBASE).o : %(basename).m
527         %compile_q cmd=$(TMP_CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
529 ifeq (%(nix),yes)
530   $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
531 endif
532 $(TMP_TARGETBASE).d : %(basename).m
533         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_OBJCDFLAGS)
535 endif
537 %end
538 #------------------------------------------------------------------------------
541 #------------------------------------------------------------------------------
542 # Generate a rule to compile multiple C source files to an object file and
543 # generate the corresponding dependency files. The generated file will be put
544 # in the object directory without the directory part of the source file.
545 # options
546 # - basenames: the basenames of the files to compile. The names may include
547 #   relative or absolute path names. No wildcard is allowed
548 # - cflags (default $(CFLAGS)): the C flags to use for compilation
549 # - dflags: the flags used during creation of dependency file. If not specified
550 #   the same value as cflags will be used
551 # - targetdir: the directory to put the .o file and the .d file. By default
552 #   it is put in the same directory as the .c file. When targetdir is not
553 #   empty, path names will be stripped from the file names so that all files
554 #   are in that dir and not in subdirectories.
555 # - compiler (default target): compiler to use, target, kernel or host
556 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) cppflags=$(cppflags) dflags= srcdir= targetdir= \
557     compiler=target
559 ifeq (%(srcdir),)
560 TMP_SRCWILDCARD := %
561 else
562 TMP_SRCWILDCARD := %(srcdir)/%
563 endif
565 ifeq (%(targetdir),)
566 TMP_TARGETS := $(addsuffix .o,%(basenames))
567 TMP_DTARGETS := $(addsuffix .d,%(basenames))
568 TMP_TGTWILDCARD := %
569 else
570 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
571 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
572 TMP_TGTWILDCARD := %(targetdir)/%
574 # Be sure that all .c files are generated
575 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
577 # Be sure that all .c files are found
578 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
579 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
580 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
581 ifneq ($(TMP_DIRS),)
582     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
583     vpath %.c $(TMP_DIRS)
584 endif
586 endif
588 TMP_CFLAGS := %(cflags) %(cppflags)
589 ifeq (%(dflags),)
590   TMP_DFLAGS := %(cflags) %(cppflags)
591 else
592   TMP_DFLAGS := %(dflags) %(cppflags)
593 endif
595 ifeq ($(findstring %(compiler),host kernel target),)
596   $(error unknown compiler %(compiler))
597 endif
598 ifeq (%(compiler),target)
599 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
600 BD_STRIP ?= $(TARGET_STRIP)
601 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
602 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
603 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
604 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TMP_DFLAGS)
605 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
606 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
607 endif
608 ifeq (%(compiler),host)
609 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
610 BD_STRIP ?= $(HOST_STRIP)
611 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
612 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
613 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
614 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
615 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
616 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
617 endif
618 ifeq (%(compiler),kernel)
619 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
620 BD_STRIP ?= $(ECHO) >/dev/null
621 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
622 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
623 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
624 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
625 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
626 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
627 endif
629 $(TMP_TARGETS) : CFLAGS := %(TMP_CFLAGS)
630 $(TMP_TARGETS) : $(TMP_TGTWILDCARD).o : $(TMP_SRCWILDCARD).c
631         %compile_q cmd=$(CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
633 $(TMP_DTARGETS) : $(TMP_TGTWILDCARD).d : $(TMP_SRCWILDCARD).c
634         %mkdepend_q cc=$(CMD) flags=$(TMP_DFLAGS)
635 %end
636 #------------------------------------------------------------------------------
639 #------------------------------------------------------------------------------
640 # Generate a rule to compile multiple C++ source files to an object file and
641 # generate the corresponding dependency files. The generated file will be put
642 # in the object directory without the directory part of the source file.
643 # options
644 # - basenames: the basenames of the files to compile. The names may include
645 #   relative or absolute path names. No wildcard is allowed. basenames will be 
646 #   matched to supported AROS_CXXEXTS.
647 # - cflags (default $(CFLAGS)): the C flags to use for compilation
648 # - dflags: the flags used during creation of dependency file. If not specified
649 #   the same value as cflags will be used
650 # - targetdir: the directory to put the .o file and the .d file. By default
651 #   it is put in the same directory as the .c file. When targetdir is not
652 #   empty, path names will be stripped from the file names so that all files
653 #   are in that dir and not in subdirectories.
654 # - compiler (default target): compiler to use, target, kernel or host
655 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) cppflags=$(CPPFLAGS) dxxflags= \
656     targetdir= compiler=target
658 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
660 ifneq ($(TMP_CXXABSBASENAMES),)
662 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
664 # Identify the "real" c++ files from the passed in basenames
665 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
667 ifeq (%(targetdir),)
668   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
669   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
670   TMP_WILDCARD := %
671 else
672   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
673   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
674   TMP_WILDCARD := %(targetdir)/%
676   # Be sure that all source files are generated
677   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
678 endif
680 # Adjust compiler flags to suit C++
681 TMP_CXXFLAGS := %(cxxflags) %(cppflags)
682 ifeq (%(dxxflags),)
683   TMP_DXXFLAGS := %(cxxflags) %(cppflags)
684 else
685   TMP_DXXFLAGS := %(dxxflags) %(cppflags)
686 endif
688 ifeq ($(findstring %(compiler),host kernel target),)
689   $(error unknown compiler %(compiler))
690 endif
691 ifeq (%(compiler),host)
692   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
693   BD_STRIP ?= $(HOST_STRIP)
694   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
695   TMP_CXXCMD:=$(HOST_CXX)
696   TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
697   TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
698   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
699   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
700 endif
701 ifeq (%(compiler),target)
702   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
703   BD_STRIP ?= $(TARGET_STRIP)
704   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
705   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
706   TMP_CXXFLAGS := $(TMP_CXXFLAGS) $(SAFETY_CFLAGS)
707   TMP_DXXFLAGS := $(TMP_DXXFLAGS)
708   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
709   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
710 endif
711 ifeq (%(compiler),kernel)
712   KERNEL_CXX ?= $(KERNEL_CC)
713   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
714   BD_STRIP ?= $(ECHO) >/dev/null
715   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
716   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
717   TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS) 
718   TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
719   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
720   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
721 endif
723 define cxx_multi_recipe_template
724  $(1).o : $(2)
725         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
727  $(1).d : $(2)
728         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
729 endef
730 ifeq (%(targetdir),)
731   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
732 else
733   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
734 endif
736 endif
738 %end
739 #------------------------------------------------------------------------------
742 #------------------------------------------------------------------------------
743 # Generate a rule to compile multiple ObjC source files to an object file and
744 # generate the corresponding dependency files. The generated file will be put
745 # in the object directory without the directory part of the source file.
746 # options
747 # - basenames: the basenames of the files to compile. The names may include
748 #   relative or absolute path names. No wildcard is allowed
749 # - cflags (default $(CFLAGS)): the C flags to use for compilation
750 # - dflags: the flags used during creation of dependency file. If not specified
751 #   the same value as cflags will be used
752 # - targetdir: the directory to put the .o file and the .d file. By default
753 #   it is put in the same directory as the .m file. When targetdir is not
754 #   empty, path names will be stripped from the file names so that all files
755 #   are in that dir and not in subdirectories.
756 # - compiler (default target): compiler to use, target, kernel or host
757 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= \
758     targetdir= compiler=target
760 ifneq (%(basenames),)
762 ifeq (%(targetdir),)
763   TMP_TARGETS := $(addsuffix .o,%(basenames))
764   TMP_DTARGETS := $(addsuffix .d,%(basenames))
765   TMP_WILDCARD := %
766 else
767   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
768   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
769   TMP_WILDCARD := %(targetdir)/%
771   # Be sure that all .m files are generated
772   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
774   # Be sure that all .m files are found
775   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
776   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
777   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
778   ifneq ($(TMP_DIRS),)
779     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
780     vpath %.m $(TMP_DIRS)
781   endif
782 endif
784 # Define the use of cross compiler
785 ifeq ($(TARGET_OBJC),)
786   TMP_CC := $(TARGET_CC)
787 else
788   TMP_CC := $(TARGET_OBJC)
789 endif
791 # Adjust compiler flags to suit ObjC
792 TMP_OBJCFLAGS := %(cflags) %(cppflags)
793 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
794 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
795 ifeq (%(dflags),)
796   TMP_OBJCDFLAGS := %(cflags) %(cppflags)
797 else
798   TMP_OBJCDFLAGS := %(dflags) %(cppflags)
799 endif
801 ifeq ($(findstring %(compiler),host kernel target),)
802   $(error unknown compiler %(compiler))
803 endif
804 ifeq (%(compiler),target)
805   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
806   BD_STRIP ?= $(TARGET_STRIP)
807   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
808   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
809   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS)  $(SAFETY_CFLAGS)
810   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
811   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
812   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
813 endif
814 ifeq (%(compiler),host)
815   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
816   BD_STRIP ?= $(HOST_STRIP)
817   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
818   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
819   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
820   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
821   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
822   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
823 endif
824 ifeq (%(compiler),kernel)
825   KERNEL_OBJC ?= $(KERNEL_CC)
826   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
827   BD_STRIP ?= $(ECHO) >/dev/null
828   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
829   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
830   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS) 
831   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS) 
832   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
833   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
834 endif
836 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
837 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
838         %compile_q cmd=$(CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
840 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
841         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
843 endif
845 %end
846 #------------------------------------------------------------------------------
849 #------------------------------------------------------------------------------
850 # Make an alias from one arch specific build to another arch.
851 # arguments:
852 # - mainmmake: the mmake of the module in the main tree
853 # - arch: the current arch
854 # - alias: the alias to which this should point
855 %define rule_archalias mainmmake=\A arch=\A alias=\A
857 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
858 %end
859 #------------------------------------------------------------------------------
862 #------------------------------------------------------------------------------
863 # Generate a rule to assemble a source file to an object file. Basename may
864 # contain a directory part, then the source file has to be in that directory.
865 # The generated file will be put in the object directory without the directory.
866 # options
867 # - basename: the basename of the file to compile. Use % for a wildcard rule
868 # - flags (default $(AFLAGS)): the asm flags to use for assembling
869 # - targetdir: the directory to put the .o file in. By default it is put in the
870 #   same directory as the .s file
871 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
873 ifeq (%(targetdir),)
874 %(basename).o : AFLAGS := %(aflags)
875 %(basename).o : %(basename).s
876         %assemble_q
877 %(basename).o : %(basename).S
878         %assemble_q
880 else
881 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
882 %(targetdir)/$(notdir %(basename)).o : %(basename).s
883         %assemble_q
884 %(targetdir)/$(notdir %(basename)).o : %(basename).S
885         %assemble_q
887 endif
888 %end
889 #------------------------------------------------------------------------------
892 #------------------------------------------------------------------------------
893 # Generate a rule to assemble multiple source files to an object file. The
894 # generated file will be put in the object directory with the directory part
895 # of the source file stripped off.
896 # options
897 # - basenames: the basenames of the files to compile. The names may include
898 #   relative or absolute path names. No wildcard is allowed
899 # - aflags (default $(AFLAGS)): the flags to use for assembly
900 # - targetdir: the directory to put the .o file and the .d file. By default
901 #   it is put in the same directory as the .c file. When targetdir is not
902 #   empty, path names will be stripped from the file names so that all files
903 #   are in that dir and not in subdirectories.
904 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
906 ifeq (%(targetdir),)
907 TMP_TARGETS := $(addsuffix .o,%(basenames))
908 TMP_WILDCARD := %
909 else
910 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
911 TMP_WILDCARD := %(targetdir)/%
913 # Be sure that all .s files are generated
914 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
916 # Be sure that all .c files are found
917 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
918 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
919 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
920 ifneq ($(TMP_DIRS),)
921     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
922     vpath %%(suffix) $(TMP_DIRS)
923 endif
925 endif
927 BD_ASSEMBLER ?= %(cmd)
929 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
931 $(TMP_TARGETS) : AFLAGS := %(aflags)
932 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
933         %assemble_q cmd=$(TMP_CMD)
934 %end
935 #------------------------------------------------------------------------------
938 #------------------------------------------------------------------------------
939 # Link %(objs) to %(prog) using the libraries in %(uselibs)
940 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
941     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
943 TMP_EXTRA_LDFLAGS := 
944 TMP_EXTRA_LIBS :=
945 ifeq (%(nix),yes)
946     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
947 endif
948 ifeq (%(usestartup),no)
949     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
950 endif
951 ifeq (%(detach),yes)
952     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
953 endif
955 # Make a list of the lib files this program depends on.
956 # In LDFLAGS remove white space between -L and directory
957 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
958 # Filter out only the libdirs and remove -L
959 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
960 # Add trailing /
961 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
962 # Add normal linklib path
963 TMP_DIRS += $(AROS_LIB)/
964 # add lib and .a to static linklib names
965 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
966 ifeq (%(usestartup),yes)
967     TMP_LIBS += startup.o
968 endif
969 ifeq (%(detach),yes)
970     TMP_LIBS += detach.o
971 endif
972 # search for the linklibs in the given path, ignore ones not found
973 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
974     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
977 %(prog) : OBJDIR := %(objdir)
978 %(prog) : OBJS := %(objs)
979 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
980 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
981 %(prog) : %(objs) $(TMP_DEPLIBS)
982         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
983 %end
984 #------------------------------------------------------------------------------
987 #------------------------------------------------------------------------------
988 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
989 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
990 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
991     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
992     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
994 TMP_EXTRA_LDFLAGS := 
995 TMP_EXTRA_LIBS :=
996 ifeq (%(nix),yes)
997     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
998 endif
999 ifeq (%(usestartup),no)
1000     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1001 endif
1002 ifeq (%(detach),yes)
1003     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1004 endif
1006 # Make a list of the lib files the programs depend on.
1007 # In LDFLAGS remove white space between -L and directory
1008 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1009 # Filter out only the libdirs and remove -L
1010 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1011 # Add trailing /
1012 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1013 # Add normal linklib path
1014 TMP_DIRS += $(AROS_LIB)/
1015 # add lib and .a to static linklib names
1016 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1017 # search for the linklibs in the given path, ignore ones not found
1018 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1019     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1021 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1023 $(TMP_PROGS) : OBJDIR := %(objdir)
1024 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1025 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1026 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1027         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1028 %end
1029 #------------------------------------------------------------------------------
1032 #------------------------------------------------------------------------------
1033 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1034 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1036 ifeq (%(linker),target)
1037 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1038 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1039 endif
1040 ifeq (%(linker),host)
1041 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1042 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1043 endif
1044 ifeq (%(linker),kernel)
1045 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1046 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1047 endif
1049 %(libdir)/lib%(libname).a : %(objs)
1050         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1051 %end
1052 #------------------------------------------------------------------------------
1054 #------------------------------------------------------------------------------
1055 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1056 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1057 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1058     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1060 TMP_LDFLAGS  := %(ldflags)
1061 # Make a list of the lib files the programs depend on.
1062 # In LDFLAGS remove white space between -L and directory
1063 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1064 # Filter out only the libdirs and remove -L
1065 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1066 # Add trailing /
1067 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1068 # Add normal linklib path
1069 TMP_DIRS += $(AROS_LIB)/
1070 # add lib and .a to static linklib names
1071 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1072 # search for the linklibs in the given path, ignore ones not found
1073 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1074     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1077 %(module) : LIB_NAMES := %(uselibs)
1078 %(module) : OBJS := %(objs)
1079 %(module) : ENDTAG := %(endobj)
1080 %(module) : ERR := %(err)
1081 %(module) : OBJDIR := %(objdir)
1082 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1083 ifeq (%(usehostlibs),)
1084 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1085 else
1086 # Warning: the -L/usr/lib here can result in modules
1087 # linking against host libs instead of AROS libs (e.g stdc++) !!
1088 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1089                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1090 endif 
1091 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1092         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1094 %end
1095 #------------------------------------------------------------------------------
1098 #------------------------------------------------------------------------------
1099 # Generate the libdefs.h include file for a module.
1100 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1102 TMP_TARGET := %(modname)_libdefs.h
1103 TMP_DEPS := $(GENMODULE)
1104 TMP_OPTS := 
1105 ifneq (%(conffile),)
1106     ifeq ($(dir %(conffile)),./)
1107         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1108         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1109     else
1110         TMP_OPTS += -c %(conffile)
1111         TMP_DEPS += %(conffile)
1112     endif 
1113 else
1114     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1115     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1116 endif
1117 ifneq (%(modsuffix),)
1118     TMP_OPTS += -s %(modsuffix)
1119 endif
1120 ifneq (%(targetdir),)
1121     TMP_OPTS += -d %(targetdir)
1122     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1123 endif
1124 ifneq (%(version),)
1125     TMP_OPTS += -v %(version)
1126 endif
1128 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1129 $(TMP_TARGET) : MODNAME := %(modname)
1130 $(TMP_TARGET) : MODTYPE := %(modtype)
1131 $(TMP_TARGET) : $(TMP_DEPS)
1132         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1133         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1134 %end
1135 #------------------------------------------------------------------------------
1137 #------------------------------------------------------------------------------
1138 # Generate the _lib.fd file for a module.
1139 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1141 TMP_TARGET := %(modname)_lib.fd
1142 TMP_DEPS := $(GENMODULE)
1143 TMP_OPTS := 
1144 ifneq (%(conffile),)
1145     ifeq ($(dir %(conffile)),./)
1146         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1147         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1148     else
1149         TMP_OPTS += -c %(conffile)
1150         TMP_DEPS += %(conffile)
1151     endif 
1152 else
1153     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1154     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1155 endif
1156 ifneq (%(modsuffix),)
1157     TMP_OPTS += -s %(modsuffix)
1158 endif
1159 ifneq (%(targetdir),)
1160     TMP_OPTS += -d %(targetdir)
1161     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1162 endif
1164 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1165 $(TMP_TARGET) : MODNAME := %(modname)
1166 $(TMP_TARGET) : MODTYPE := %(modtype)
1167 $(TMP_TARGET) : $(TMP_DEPS)
1168         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1169         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1170 %end
1171 #------------------------------------------------------------------------------
1173 #------------------------------------------------------------------------------
1174 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1175 # generated file in this Makefile
1176 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1177     targetdir=
1179 TMP_TARGET := Makefile.%(modname)%(modtype)
1180 TMP_DEPS := $(GENMODULE)
1181 TMP_OPTS := 
1182 ifneq (%(conffile),)
1183     ifeq ($(dir %(conffile)),./)
1184         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1185         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1186     else
1187         TMP_OPTS += -c %(conffile)
1188         TMP_DEPS += %(conffile)
1189     endif 
1190 else
1191     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1192     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1193 endif
1194 ifneq (%(modsuffix),)
1195     TMP_OPTS += -s %(modsuffix)
1196 endif
1197 ifneq (%(targetdir),)
1198     TMP_OPTS += -d %(targetdir)
1199     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1200 endif
1202 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1203 $(TMP_TARGET) : MODNAME := %(modname)
1204 $(TMP_TARGET) : MODTYPE := %(modtype)
1205 $(TMP_TARGET) : $(TMP_DEPS)
1206         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1207 %end
1208 #------------------------------------------------------------------------------
1211 #------------------------------------------------------------------------------
1212 # Generate the support files for compiling a module. This includes include
1213 # files and source files. This rule has to be preceeded by
1214 # %rule_genmodule_makefile
1215 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= stubdir= \
1216     conffile=
1218 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1219 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1220 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1221 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1222                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1225 TMP_DEPS := $(GENMODULE)
1226 TMP_OPTS :=
1228 ifneq (%(conffile),)
1229     ifeq ($(dir %(conffile)),./)
1230         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1231         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1232     else
1233         TMP_OPTS += -c %(conffile)
1234         TMP_DEPS += %(conffile)
1235     endif 
1236 else
1237     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1238     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1239 endif
1240 ifneq (%(modsuffix),)
1241     TMP_OPTS += -s %(modsuffix)
1242 endif
1243 ifneq (%(targetdir),)
1244     TMP_OPTS += -d %(targetdir)
1245     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1246     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1247 endif
1248 ifneq (%(stubdir),)
1249     TMP_OPTS += -l %(stubdir)
1250     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1251     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1252     TMP_TARGETDIRS += %(stubdir)
1253 else
1254 ifneq (%(targetdir),)
1255     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1256 endif
1257 endif
1259 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1260 ifneq ($(TMP_TARGETDIRS),)
1261 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1262 endif
1264 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1265 $(TMP_TARGETS) : MODNAME := %(modname)
1266 $(TMP_TARGETS) : MODTYPE := %(modtype)
1267 $(TMP_TARGETS) : $(TMP_DEPS)
1268         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1269 ifneq (%(conffile),lib.conf)
1270         @$(IF) $(TEST) -f lib.conf; then \
1271           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1272         fi
1273 endif
1274         @$(IF) $(TEST) -f libdefs.h; then \
1275           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1276         fi
1277         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1278 %end
1279 #------------------------------------------------------------------------------
1282 #------------------------------------------------------------------------------
1283 # Generate the support files for compiling a module. This includes include
1284 # files and source files.
1285 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1286     targetdir= conffile=
1288 ifneq ($(%(modname)_INCLUDES),)
1289 TMP_TARGETS := $(%(modname)_INCLUDES)
1291 TMP_DEPS := $(GENMODULE)
1292 TMP_OPTS :=
1294 ifneq (%(conffile),)
1295     ifeq ($(dir %(conffile)),./)
1296         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1297         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1298     else
1299         TMP_OPTS += -c %(conffile)
1300         TMP_DEPS += %(conffile)
1301     endif 
1302 else
1303     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1304     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1305 endif
1306 ifneq (%(modsuffix),)
1307     TMP_OPTS += -s %(modsuffix)
1308 endif
1309 ifneq (%(targetdir),)
1310     TMP_OPTS += -d %(targetdir)
1311     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1312 endif
1314 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1315 $(TMP_TARGETS) : MODNAME := %(modname)
1316 $(TMP_TARGETS) : MODTYPE := %(modtype)
1317 $(TMP_TARGETS) : $(TMP_DEPS)
1318         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1319         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1320 endif
1321 %end
1322 #------------------------------------------------------------------------------
1324 #------------------------------------------------------------------------------
1325 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1326 # 'start' is an optional starting address
1327 # 'ldflags' is optional additional flags for the linker
1328 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1330 BD_OUTDIR := $(dir %(file))
1331 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1332 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1333 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1334 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1335 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1336 BD_OBJS += %(objs)
1338 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1340 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1341         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1342         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1343         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1345 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1346     GLOB_MKDIRS += $(BD_OUTDIR)
1347 endif
1349 %end
1351 #------------------------------------------------------------------------------
1352 # Common rules for all makefiles
1353 %define common
1354 # Delete generated makefiles
1356 clean ::
1357         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1359 include $(SRCDIR)/config/make.tail
1361 BDID := $(BDTARGETID)
1362 %end
1363 #------------------------------------------------------------------------------
1364       
1366 #############################################################################
1367 #############################################################################
1368 ##                                                                         ##
1369 ## Here are the mmakefile build macros. These are macros that takes care   ##
1370 ## of everything to go from the sources to the generated target. Also all  ##
1371 ## intermediate files and directories that are needed are created by these ##
1372 ## rules.                                                                  ##
1373 ##                                                                         ##
1374 #############################################################################
1375 #############################################################################
1377 #------------------------------------------------------------------------------
1378 # Build a program
1379 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1380     objcfiles= \
1381     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1382     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1383     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1384     includedir= libdir= \
1385     compiler=target linker= lto=$(TARGET_LTO)
1387 .PHONY : %(mmake)
1389 BD_PROGNAME  := %(progname)
1390 BD_OBJDIR    := %(objdir)
1391 BD_TARGETDIR := %(targetdir)
1392 BD_LINKER    := %(linker)
1394 # If not supplied, linker is equal to compiler
1395 ifeq ($(BD_LINKER),)
1396     BD_LINKER := %(compiler)
1397 endif
1399 BD_FILES     := %(files)
1400 BD_OBJCFILES := %(objcfiles)
1401 BD_ASMFILES  := %(asmfiles)
1402 BD_CXXFILES := %(cxxfiles)
1404 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1405 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1406 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1408 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1409 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1410 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1412 BD_CFLAGS    := %(cflags)
1413 BD_CXXFLAGS := %(cxxflags)
1414 BD_CPPFLAGS :=  %(cppflags)
1415 ifeq (%(lto),yes)
1416 ifeq (%(compiler),target)
1417 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1418 BD_CXXFLAGS := $(LTO_BINARY_CFLAGS) $(BD_CXXFLAGS)
1419 endif
1420 endif
1421 ifneq (%(includedir),)
1422 BD_CFLAGS    += -I%(includedir)
1423 BD_CXXFLAGS += -I%(includedir)
1424 endif
1425 BD_AFLAGS    := %(aflags)
1426 ifneq (%(includedir),)
1427 BD_AFLAGS    += -I%(includedir)
1428 endif
1429 BD_DFLAGS    := %(dflags)
1430 BD_DXXFLAGS := %(dxxflags)
1431 BD_LDFLAGS   := %(ldflags)
1432 ifneq (%(libdir),)
1433 BD_LDFLAGS   += -L%(libdir)
1434 endif
1437 %(mmake)-quick : %(mmake)
1439 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1440 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1442 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1443 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1444     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1445 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1446     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1447 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1448     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1449 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1450     aflags=$(BD_AFLAGS)
1452 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1453     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1454     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1455     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1456     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1458 endif
1460 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1462 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1463 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1464 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1466 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1468 %(mmake)-clean ::
1469         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1470         @$(RM) $(FILES)
1472 %end
1473 #------------------------------------------------------------------------------
1476 #------------------------------------------------------------------------------
1477 # Build programs, for every C file an executable will be built with the same
1478 # name as the C file
1479 %define build_progs mmake=/A files=/A nix=no \
1480     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1481     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1482     includedir= libdir= \
1483     compiler=target \
1484     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1486 .PHONY : %(mmake)
1488 BD_OBJDIR    := %(objdir)
1489 BD_TARGETDIR := %(targetdir)
1491 BD_FILES     := %(files)
1492 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1493 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1494 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1496 BD_CFLAGS    := %(cflags)
1497 ifeq (%(lto),yes)
1498 ifeq (%(compiler),target)
1499 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1500 endif
1501 endif
1502 ifneq (%(includedir),)
1503     BD_CFLAGS += -I%(includedir)
1504 endif
1505 BD_CPPFLAGS := %(cppflags)
1506 BD_DFLAGS    := %(dflags)
1507 BD_LDFLAGS   := %(ldflags)
1508 ifneq (%(libdir),)
1509     BD_LDFLAGS += -L%(libdir)
1510 endif
1513 %(mmake)-quick : %(mmake)
1515 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1516 %(mmake) : $(BD_EXES)
1518 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1519 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1520     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1522 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1523     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1524     ldflags=$(BD_LDFLAGS) \
1525     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1526     usestartup="%(usestartup)" detach="%(detach)" \
1527      cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1529 endif
1531 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1533 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1534 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1535 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1537 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1539 %(mmake)-clean ::
1540         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1541         @$(RM) $(FILES)
1543 %end
1544 #------------------------------------------------------------------------------
1547 #------------------------------------------------------------------------------
1548 # Build a module.
1549 # This is a bare version: It just compiles and links the given files. It is
1550 # assumed that all needed boiler plate code is in the files. This should only
1551 # be used for compiling external code. For AROS code use %build_module
1552 %define build_module_simple mmake=/A modname=/A modtype=/A \
1553     files="$(basename $(call WILDCARD, *.c))" \
1554     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) \
1555     objdir=$(OBJDIR) moduledir= \
1556     uselibs= usehostlibs= compiler=target lto=$(TARGET_LTO)
1558 # Define metamake targets and their dependencies
1559 #MM %(mmake) : core-linklibs includes-generate-deps
1560 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1561 #MM %(mmake)-kobj-quick
1562 #MM %(mmake)-quick
1563 #MM %(mmake)-clean
1565 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1567 .PHONY : $(BD_ALLTARGETS)
1569 ifeq (%(modname),)
1570 $(error using %build_module_simple: modname may not be empty)
1571 endif
1572 ifeq (%(modtype),)
1573 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1574 endif
1576 # Default values for variables and arguments
1577 BD_DEFLINKLIBNAME := %(modname)
1578 BD_DEFDFLAGS := %(cflags)
1579 ifeq (%(lto),yes)
1580 ifeq (%(compiler),target)
1581 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(BD_DEFDFLAGS)
1582 endif
1583 endif
1584 BD_DEFDXXFLAGS := %(dxxflags)
1585 OBJDIR ?= $(GENDIR)/$(CURDIR)
1586 BD_MODDIR := %(moduledir)
1587 ifeq ($(BD_MODDIR),)
1588   ifeq (%(modtype),library)
1589     BD_MODDIR  := $(AROS_LIBRARIES)
1590   endif
1591   ifeq (%(modtype),gadget)
1592     BD_MODDIR  := $(AROS_GADGETS)
1593   endif
1594   ifeq (%(modtype),datatype)
1595     BD_MODDIR  := $(AROS_DATATYPES)
1596   endif
1597   ifeq (%(modtype),handler)
1598     BD_MODDIR  := $(AROS_FS)
1599   endif
1600   ifeq (%(modtype),device)
1601     BD_MODDIR  := $(AROS_DEVS)
1602   endif
1603   ifeq (%(modtype),resource)
1604     BD_MODDIR  := $(AROS_RESOURCES)
1605   endif
1606   ifeq (%(modtype),hook)
1607     BD_MODDIR  := $(AROS_RESOURCES)
1608   endif
1609   ifeq (%(modtype),mui)
1610     BD_MODDIR  := $(AROS_CLASSES)/Zune
1611   endif
1612   ifeq (%(modtype),mcc)
1613     BD_MODDIR  := $(AROS_CLASSES)/Zune
1614   endif
1615   ifeq (%(modtype),mcp)
1616     BD_MODDIR  := $(AROS_CLASSES)/Zune
1617   endif
1618   ifeq (%(modtype),usbclass)
1619     BD_MODDIR  := $(AROS_CLASSES)/USB
1620   endif
1621   ifeq (%(modtype),hidd)
1622     BD_MODDIR  := $(AROS_DRIVERS)
1623   endif
1624   ifeq (%(modtype),printer)
1625     BD_MODDIR  := $(AROS_PRINTERS)
1626   endif
1627 endif
1628 ifeq ($(BD_MODDIR),)
1629   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1630 endif
1632 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1633 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1634 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1636 %rule_compile_multi \
1637     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1638     cflags="$(BD_DEFDFLAGS)" cppflags="%(cppflags)" dflags="%(dflags)" \
1639     compiler="%(compiler)"
1641 # Handlers use dash instead of dot in their names
1642 ifeq (%(modtype),handler)
1643 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1644 else
1645 ifeq (%(modtype),printer)
1646 BD_MODULE := $(BD_MODDIR)/%(modname)
1647 else
1648 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1649 endif
1650 endif
1651 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1653 %(mmake)-quick : %(mmake)
1654 %(mmake)-kobj-quick : $(BD_KOBJ)
1655 %(mmake)       : $(BD_MODULE)
1656 %(mmake)-kobj  : $(BD_KOBJ)
1658 # The module is linked from all the compiled .o files
1659 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1661 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1662 # This breaks con-handler build. Here we work around this
1663 ifeq (%(modname),con)
1664     BD_ERR := $(notdir $(BD_MODULE)).err
1665 else
1666     BD_ERR := %(modname).err
1667 endif
1669 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1670                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1671                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1672                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1674 # Link kernel object file
1675 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1677 # Make these symbols local
1678 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1679             UtilityBase ExpansionBase KeymapBase KernelBase
1681 BD_SYMBOLS := $(BD_KBASE)
1683 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1684 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1685 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1686 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1687 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1688 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1689         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1690         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1691         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1694 ## Dependency fine-tuning
1696 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1697 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1699 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1700 $(BD_MODULE) : | $(BD_MODDIR)
1701 $(BD_KOBJ) : | $(KOBJSDIR)
1702 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1704 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1705 %(mmake)-clean ::
1706         @$(ECHO) "Cleaning up for module %(modname)"
1707         @$(RM) $(FILES)
1708 %end
1709 #------------------------------------------------------------------------------
1712 #------------------------------------------------------------------------------
1713 # Build a module - core routine
1714 # Explanation of this macro is done in the developer's manual
1715 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1716   files="$(basename $(call WILDCARD, *.c))" \
1717   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1718   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1719   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1720   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1721   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1722   includedir= libdir= \
1723   build_abi= build_library=
1725 # We will employ a terrifying, but unavoidable, hack here.
1726 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1727 # ignores GNU Make ifeq() statements, but will process any #MM
1728 # headed lines in the file.
1730 # So, to make the following #MM lines conditional on whether we want
1731 # to build the ABI, Library, or both, we define build_abi= and 
1732 # build_library as 'M' to enable, or '' to disable, which allows genmf
1733 # to do the following conversions:
1735 #  #%(build_abi)M includes-foo: foo-include
1736 #    becomes, when build_abi=M
1737 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1738 #    but, when build_abi= ...
1739 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1741 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1743 # Define metamake targets and their dependencies
1744 #MM %(mmake)
1745 #MM %(mmake)-quick
1746 #MM %(mmake)-makefile
1747 #MM %(mmake)-clean
1749 # ABI targets:
1750 #M%(build_abi)- includes-all : %(mmake)-includes
1751 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1752 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1753 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1754 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1755 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1756 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1757 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1758 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1759 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1760 #M%(build_abi) %(mmake)-includes-quick
1761 #M%(build_abi) %(mmake)-includes-dirs
1762 #M%(build_abi) %(mmake)-fd
1764 # Library targets
1765 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1766 #%(build_library)M %(mmake)-kobj-quick : 
1768 # Library with ABI targets:
1769 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1770 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1772 # All MetaMake targets defined by this macro
1773 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1775 ifeq (%(build_library),M)
1776 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1777 endif
1779 ifeq (%(build_abi),M)
1780 BD_ALLTARGETS += %(mmake)-includes \
1781                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1782                  %(mmake)-linklib %(mmake)-fd
1783 endif
1785 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1787 ifeq (%(modname),)
1788 $(error using %build_module: modname may not be empty)
1789 endif
1790 ifeq (%(modtype),)
1791 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1792 endif
1794 # Default values for variables and arguments
1795 BD_DEFLINKLIBNAME := %(modname)
1796 BD_DEFDFLAGS := %(cflags)
1797 BD_DEFDXXFLAGS := %(cxxflags)
1798 BD_DEFCPPFLAGS := %(cppflags)
1799 ifeq (%(lto),yes)
1800 ifeq (%(compiler),target)
1801 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDFLAGS)
1802 BD_DEFDXXFLAGS := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDXXFLAGS)
1803 endif
1804 endif
1805 ifneq (%(includedir),)
1806     BD_DEFDFLAGS += -I%(includedir)
1807     BD_DEFDXXFLAGS += -I%(includedir)
1808 endif
1809 OBJDIR ?= $(GENDIR)/$(CURDIR)
1811 ## Create genmodule include Makefile for the module
1813 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1815 %rule_genmodule_makefile \
1816     modname="%(modname)" modtype="%(modtype)" \
1817     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1818     conffile="%(conffile)"
1820 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1822 GLOB_MKDIRS += %(objdir)
1824 # Do not parse these statements if metatarget is not appropriate
1825 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1827 # suppress makes warning that the Makefile doesnt yet exist
1828 # on early passes (it will generate the file as needed though)
1829 # when we include it.
1830 -include %(objdir)/Makefile.%(modname)%(modtype)
1832 BD_DEFMODDIR := $(%(modname)_MODDIR)
1833 ifeq (%(archspecific),yes)
1834 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1835 endif
1838 ## include files generation
1840 ifneq (%(includedir),)
1841 BD_INCDIR    := %(includedir)
1842 else
1843 BD_INCDIR    := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
1844 endif
1845 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1846 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1848 ifeq (%(build_abi),M)
1849 %(mmake)-includes-quick : %(mmake)-includes
1850 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1851     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1852     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1854 ifneq ($(%(modname)_INCLUDES),)
1855 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1856                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1857                          conffile="%(conffile)"
1859 %rule_copy_diff_multi \
1860     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1861     stampfile="%(objdir)/%(modname)_geninc"
1863 %rule_copy_diff_multi \
1864     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1865     stampfile="%(objdir)/%(modname)_incs"
1867 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1869 TMP%(modname)_INCDIRS := \
1870     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1871     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1872     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1873 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1875 endif
1877 endif
1879 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1880     modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1881     conffile="%(conffile)" version="%(version)"
1883 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1884 $(BD_DEFLIBDEFSINC) :
1885         @$(ECHO) "Generating $@"
1886         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1888 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1889 GLOB_MKDIRS += %(objdir)/include
1891 ## Extra genmodule src files generation
1892 ## 
1893 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1894     modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1895     conffile="%(conffile)"
1897 GLOB_MKDIRS += %(objdir)/linklib
1899 ifeq (%(build_abi),M)
1900 ## Create FD file
1901 ifeq (%(includedir),)
1902 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/fd
1903 else
1904 BD_FDDIR := %(includedir)/../fd
1905 endif
1906 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1908 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1909     modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1911 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1913 GLOB_MKDIRS += $(BD_FDDIR)
1914 endif
1916 ## Compilation
1918 BD_FILES      := %(files)
1919 BD_CXXFILES := %(cxxfiles)
1921 BD_LIBFILES := %(linklibfiles)
1923 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1925 BD_FILEMATCH = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
1926 BD_MATCHARCH = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call BD_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
1927 BD_FILTERARCH = $(filter-out $(call BD_MATCHARCH,$(1),$(2)),$(2))
1928 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1929 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1931 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1932 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1933 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1934 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1935 BD_NARCHFILES := $(call BD_FILTERARCH,$(BD_ARCHFILES),$(BD_FILES))
1936 BD_NLIBARCHFILES := $(call BD_FILTERARCH,$(BD_LIBARCHFILES),$(BD_LIBFILES))
1937 BD_ARCHNLIBFILES := $(call BD_FILTERARCH,$(BD_LIBFILES),$(BD_LIBARCHFILES))
1939 BD_COMMONCFLAGS=-I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1940 BD_CFLAGS        := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_CFLAGS)
1941 BD_LINKLIBCFLAGS := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBCFLAGS)
1942 BD_CXXFLAGS      := %(cxxflags) $(BD_COMMONCFLAGS) $(%(modname)_CXXFLAGS)
1943 ifeq (%(lto),yes)
1944 ifeq (%(compiler),target)
1945 BD_LTOFLAGS=$(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH)
1946 BD_CFLAGS        := $(BD_LTOFLAGS) $(BD_CFLAGS)
1947 BD_LINKLIBCFLAGS := $(BD_LTOFLAGS) $(BD_LINKLIBCFLAGS)
1948 BD_CXXFLAGS      := $(BD_LTOFLAGS) $(BD_CXXFLAGS)
1949 endif
1950 endif
1951 ifneq (%(includedir),)
1952 BD_CFLAGS        += -I%(includedir)
1953 BD_LINKLIBCFLAGS += -I%(includedir)
1954 BD_CXXFLAGS      += -I%(includedir)
1955 endif
1956 BD_CPPFLAGS      := %(cppflags)
1957 BD_DFLAGS        := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_DFLAGS)
1958 BD_LINKLIBDFLAGS := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBDFLAGS)
1959 BD_DXXFLAGS      := %(dxxflags) $(BD_COMMONCFLAGS) $(%(modname)_DXXFLAGS)
1961 ifeq (%(modtype),library)
1962     BD_LIBSUFFIX := 
1963 else
1964     BD_LIBSUFFIX := .%(modtype)
1965 endif
1967 ifeq (%(libdir),)
1968 BD_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
1969 else
1970 BD_LIBDIR := %(libdir)
1971 endif
1973 ifeq (%(build_abi),M)
1974 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
1975 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
1976 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1977     BD_LINKLIB :=
1978 else
1979     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1980     ifneq (%(modname),%(linklibname))
1981         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1982     endif
1983 endif
1984 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1986 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
1987 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
1988 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1989     BD_RELLINKLIB :=
1990 else
1991     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1992     ifneq (%(modname),%(linklibname))
1993         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1994     endif
1995 endif
1996 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1997 endif
1999 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
2000 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
2001                  %(linklibobjs)
2002 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
2003                  %(linklibobjs)
2004 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
2005 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
2007 BD_CCFILES := $(BD_NARCHFILES)
2008 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
2009 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2010 BD_LINKLIBCCGENFILES := $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2012 %rule_compile_cxx_multi \
2013     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2014     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) \
2015     compiler="%(compiler)"
2016 %rule_compile_multi \
2017     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
2018     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) \
2019     compiler="%(compiler)"
2020 %rule_compile_multi \
2021     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
2022     cflags=$(BD_CFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
2023     compiler="%(compiler)"
2024 %rule_compile_multi \
2025     basenames=$(BD_NLIBARCHFILES) targetdir="%(objdir)/linklib" \
2026     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2027     compiler="%(compiler)"
2028 %rule_compile_multi \
2029     basenames=$(BD_LINKLIBCCGENFILES) srcdir="%(objdir)/linklib" targetdir="%(objdir)/linklib" \
2030     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2031     compiler="%(compiler)"
2033 ifneq ($(BD_LINKLIBAFILES),)
2034 %rule_assemble_multi \
2035     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
2036 endif
2038 ## Linking
2040 ifeq (%(modsuffix),)
2041 BD_SUFFIX := %(modtype)
2042 else
2043 BD_SUFFIX := %(modsuffix)
2044 endif
2046 ifeq (%(build_library),M)
2047 # Handlers use dash instead of dot in their names
2048 ifeq ($(BD_SUFFIX),handler)
2049 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2050 else
2051 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2052 endif
2053 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2054 else
2055 BD_MODULE :=
2056 BD_KOBJ   :=
2057 endif
2059 %(mmake)-quick      : %(mmake)
2060 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2061 ifeq (%(build_library),M)
2062 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2063 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2064 endif
2065 ifeq (%(build_abi),M)
2066 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2067 endif
2069 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2070            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2072 ifeq (%(nostartup),yes)
2073 # Handlers always have entry point
2074 ifneq (%(modtype),handler)
2075 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2076 endif
2077 endif
2079 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2080 # This breaks con-handler build. Here we work around this
2081 ifeq (%(modname),con)
2082     BD_ERR := $(notdir $(BD_MODULE)).err
2083 else
2084     BD_ERR := %(modname).err
2085 endif
2087 ifeq (%(build_library),M)
2088 # The module is linked from all the compiled .o files
2089 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2090                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2091                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2092                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2093 endif
2095 ifeq (%(build_abi),M)
2096 # Link static lib
2097 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2098 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2099 ifneq ($(BD_LINKLIB),)
2100 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2101 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2102 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2103 endif
2105 $(BD_LINKLIB) : | $(BD_LIBDIR)
2106 GLOB_MKDIRS += $(BD_LIBDIR)
2107 endif
2109 ifneq ($(BD_RELLINKLIB),)
2110 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2111 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2112 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2113 endif
2115 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2116 GLOB_MKDIRS += $(BD_LIBDIR)
2117 endif
2118 endif
2120 ifeq (%(build_library),M)
2121 # Link kernel object file
2122 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2124 # Make these symbols local
2125 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2126             UtilityBase ExpansionBase KeymapBase KernelBase
2128 BD_SYMBOLS := $(BD_KBASE)
2130 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2131 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2132 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2133 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2134 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2135 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2136         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2137         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2138         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2139 endif
2141 ## Dependency fine-tuning
2143 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2145 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2147 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2148 $(BD_MODULE) : | %(prefix)/%(moduledir)
2149 $(BD_KOBJ)   : | $(KOBJSDIR)
2150 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2152 # Some include files need to be generated before the .c can be parsed.
2153 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2155 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2156     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2157 $(BD_DEPS) : $(BD_DFILE_DEPS)
2158 endif
2160 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2161     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2162     %(objdir)/Makefile.%(modname)%(modtype) \
2163     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2164     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2165     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2166     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2167     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2168     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2169     $(BD_ENDOBJS)
2170 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2171 %(mmake)-clean ::
2172         @$(ECHO) "Cleaning up for module %(modname)"
2173         @$(RM) $(FILES)
2175 endif # $(TARGET) in $(BD_ALLTARGETS)
2176 %end
2177 #------------------------------------------------------------------------------
2179 #------------------------------------------------------------------------------
2180 # Build a module - ABI and library
2181 # Explanation of this macro is done in the developer's manual
2182 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2183   files="$(basename $(call WILDCARD, *.c))" \
2184   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2185   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2186   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2187   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2188   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2189   includedir= libdir=
2191 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2192    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2193    files="%(files)" cxxfiles="%(cxxfiles)" \
2194    linklibname="%(linklibname)" \
2195    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2196    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2197    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2198    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2199    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2200    includedir="%(includedir)" libdir="%(libdir)" \
2201    build_abi=M build_library=M
2203 %end
2204 #------------------------------------------------------------------------------
2207 #------------------------------------------------------------------------------
2208 # Build a module skeleton ABI
2209 # This is a stripped-down version of build_module, it only creates include
2210 # files and the linklibs.
2211 # This is used when for plugins or classes with the same API, but no actual
2212 # implementation here.
2213 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2214   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2215   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2216   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2217   compiler=target nostartup=yes archspecific=no \
2218   includedir= libdir=
2220 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2221   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2222   linklibname="%(linklibname)" \
2223   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2224   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2225   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2226   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2227   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2228   includedir="%(includedir)" libdir="%(libdir)" \
2229   build_abi=M build_library=
2231 %end
2232 #------------------------------------------------------------------------------
2234 #------------------------------------------------------------------------------
2235 # Build a module library - no includes nor linklibs
2236 # Explanation of this macro is done in the developer's manual
2237 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2238   files="$(basename $(call WILDCARD, *.c))" \
2239   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2240   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2241   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2242   uselibs= usehostlibs= \
2243   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2244   includedir= libdir=
2246 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2247    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2248    files="%(files)" cxxfiles="%(cxxfiles)" \
2249    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2250    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2251    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2252    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2253   includedir="%(includedir)" libdir="%(libdir)" \
2254    build_abi= build_library=M
2256 %end
2257 #------------------------------------------------------------------------------
2261 #------------------------------------------------------------------------------
2262 # Build a linklib.
2263 # - mmake is the mmaketarget
2264 # - libname is the baselibname e.g. lib%(libname).a will be created
2265 # - files are the C source files to include in the lib. The list of files
2266 #   has to be given without the .c suffix
2267 # - cxxfiles are C++ source files without suffix.
2268 #   NB: files will be matched in the order .cpp > .cxx > .cc
2269 # - asmfiles are the asm files to include in the lib. The list of files has to
2270 #   be given without the .s suffix
2271 # - objs additional object to link into the linklib. The objects have to be
2272 #   given with full absolute path and the .o suffix.
2273 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2274 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2275 # - cflags are the flags to compile the source (default $(CFLAGS))
2276 # - dflags are the flags used during makedepend (default equal to cflags)
2277 # - aflags are the flags used during assembling (default $(AFLAGS))
2278 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2279   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2280   includedir= \
2281   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2282   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2284 # assign and generate the local variables used in this macro
2285 BD_LIBNAME    := %(libname)
2286 BD_LINKLIB    := %(libdir)/lib%(libname).a
2288 BD_FILES      := %(files)
2289 BD_ASMFILES   := %(asmfiles)
2290 BD_CXXFILES := %(cxxfiles)
2292 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2293 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2294 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2296 BD_OBJS       := $(BD_ARCHOBJS) \
2297                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2298                  %(objs)
2299 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2301 BD_CFLAGS    := %(cflags)
2302 BD_CXXFLAGS := %(cxxflags)
2303 ifeq (%(lto),yes)
2304 ifeq (%(compiler),target)
2305 BD_CFLAGS    := $(LTO_CFLAGS) $(BD_CFLAGS)
2306 BD_CXXFLAGS := $(LTO_CFLAGS) $(BD_CXXFLAGS)
2307 endif
2308 endif
2309 ifneq (%(includedir),)
2310 BD_CFLAGS    += -I%(includedir)
2311 BD_CXXFLAGS += -I%(includedir)
2312 endif
2313 BD_CPPFLAGS := %(cppflags)
2314 BD_AFLAGS    := %(aflags)
2315 BD_DFLAGS    := %(dflags)
2316 BD_DXXFLAGS := %(dxxflags)
2318 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2321 %(mmake)-quick : %(mmake)
2323 #MM %(mmake) : includes-generate-deps
2324 %(mmake) : $(BD_LINKLIB)
2326 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2328 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2329     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS)
2330 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2331     compiler="%(compiler)" cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS)
2332 %rule_assemble basename=% targetdir="%(objdir)" \
2333     aflags=$(BD_AFLAGS)
2335 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2336 endif
2338 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2340 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2341 $(BD_LINKLIB) : | %(libdir)
2342 GLOB_MKDIRS += %(objdir) %(libdir)
2344 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2346 %(mmake)-clean ::
2347         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2348         @$(RM) $(FILES)
2350 %end
2351 #------------------------------------------------------------------------------
2354 #------------------------------------------------------------------------------
2355 # Build catalogs.
2356 # - mmake is the mmaketarget
2357 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2358 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2359 # - subdir is the destination subdirectory of the catalogs
2360 # - name is the name of the destination catalog, without the .catalog suffix
2361 # - source is the path to the generated source code file
2362 # - dir is the base destination directory (default $(AROS_CATALOGS))
2363 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2364 # - srcdir is the directory in which the *.cd and *.ct files are searched
2366 %define build_catalogs mmake=/A name=/A subdir=/A \
2367  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2368  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2370 ifeq (%(description),)
2371 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2372 else
2373 BD_DESC := %(description)
2374 endif
2376 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2378 ifeq (%(catalogs),)
2379 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2380 else
2381 BD_LNGS := %(catalogs)
2382 endif
2384 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2385 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2388 %(mmake) : $(BD_OBJS) %(source)
2390 $(BD_OBJS) : | $(BD_DIRS)
2391 GLOB_MKDIRS += $(BD_DIRS)
2393 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2394         @$(ECHO) "Creating   %(name) catalog for language $*."
2395         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2397 ifneq (%(source),)
2398 %(source) : BD_DESC := $(BD_DESC)
2399 %(source) : BD_SRC := $(BD_SRC)
2400 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2401         @$(ECHO) "Creating   %(name) catalog source file $@"
2402         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2403 endif
2405 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2407 %(mmake)-clean ::
2408         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2409         @$(RM) $(FILES)
2411 .PHONY: %(mmake) %(mmake)-clean
2413 %end
2414 #-----------------------------------------------------------------------------
2417 #-----------------------------------------------------------------------------
2418 # Build icons.
2419 # - mmake is the mmaketarget
2420 # - icons is a list of icon base names (i.e. without the .info suffix)
2421 # - dir is the destination directory
2422 # - srcdir is where *.png and *.info.src are sought
2423 #-----------------------------------------------------------------------------
2425 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2427 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2430 %(mmake) : $(BD_OBJS)
2432 ifeq (%(image),)
2434 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2435         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2436         @$(ILBMTOICON) $+ $@
2438 else
2440 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2441         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2442         @$(ILBMTOICON) $+ $@
2444 endif
2446 $(BD_OBJS) : | %(dir)
2447 GLOB_MKDIRS += %(dir)
2449 %(mmake)-clean : FILES := $(BD_OBJS)
2451 %(mmake)-clean ::
2452         @$(RM) $(FILES)
2454 .PHONY: %(mmake) %(mmake)-clean
2456 %end
2457 #-----------------------------------------------------------------------------
2460 #------------------------------------------------------------------------------
2461 # Compile files for an arch-specific replacement of code for a module
2462 # - files: the basenames of the C files to compile.
2463 # - asmfiles: the basenames of the asm files to assemble.
2464 # - mainmmake: the mmake of the module in the main directory to compile these
2465 #   arch specific files for.
2466 # - maindir: the object directory for the main module
2467 # - arch: the arch for which to compile these files. It can have the form
2468 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2469 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2470 # - dflags: the flags used during creation of dependency file. If not specified
2471 #   the same value as cflags will be used
2472 # - aflags: the flags used during assembling
2473 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2474 #   the target compiler is used
2475 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2476 cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2478 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2479     $(error no files or asmfiles given)
2480 endif
2482 ifneq (%(cxxfiles),)
2483     $(error cxx support is TODO)
2484 endif
2486 %buildid targets="%(mainmmake)-%(arch)"
2488 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2489 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2490 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2491 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2492 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2493 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2494 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2495 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2496 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2497 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2498 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2499 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2500 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2501 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2502 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2504 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2506 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2507 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2508 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2509 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2510 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2511 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2512 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2513 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2515 ifneq (%(modulename),)
2516 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2517 endif
2519 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2520     BD_TARGET := %(mainmmake)-%(arch)-quick
2521 else
2522     BD_TARGET := %(mainmmake)-%(arch)
2523 endif
2526 ifeq ($(TARGET),$(BD_TARGET))
2527 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2528 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2529 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2530 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2531 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2532 endif
2534 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2535 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2538 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2541 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2543 ifeq ($(findstring %(compiler),host kernel target),)
2544     $(error unknown compiler %(compiler))
2545 endif
2546 ifneq (%(modulename),)
2547 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2548 else
2549 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) %(cppflags)
2550 endif
2551 ifeq (%(compiler),target)
2552 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
2553 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
2554 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2555 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2556 endif
2557 ifeq (%(compiler),host)
2558 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2559 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2560 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2561 endif
2562 ifeq (%(compiler),kernel)
2563 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
2564 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
2565 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2566 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2567 endif
2569 ifeq ($(TARGET),$(BD_TARGET))
2570 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2571         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2572 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2573         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2574 endif
2576 ifeq (%(dflags),)
2577 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2578 else
2579 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags) %(cppflags)
2580 endif
2581 ifeq ($(TARGET),$(BD_TARGET))
2582 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2583         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2585 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2586         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2587 endif
2589 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2591 ifeq ($(TARGET),$(BD_TARGET))
2592 $(BD_OBJDIR$(BDID))/%.o : %.s
2593         %assemble_q
2594 $(BD_OBJDIR$(BDID))/%.o : %.S
2595         %assemble_q
2596 endif
2598 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2599 %end
2600 #------------------------------------------------------------------------------
2603 #------------------------------------------------------------------------------
2604 # generate asm files from c files (for debugging purposes)
2605 %define ctoasm_q
2606 %.s : %.c
2607         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2608         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2609 %end
2610 #------------------------------------------------------------------------------
2613 #------------------------------------------------------------------------------
2614 # Copy files from one directory to another.
2616 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2618 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2620 GLOB_MKDIRS += %(dst)
2622 .PHONY : %(mmake)
2625 %(mmake) : | %(dst) 
2626         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2628 %end
2629 #------------------------------------------------------------------------------
2632 #------------------------------------------------------------------------------
2633 # Copy a directory recursively to another place, preserving the original 
2634 # hierarchical structure
2636 # src: the source directory whose content will be copied.
2637 # dst: the directories where to copy src's content. If not existing, they will be made.
2638 # excludefiles: files which must not be copied. Path must be relative to src.
2640 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2642 .PHONY : %(mmake)
2645 %(mmake) :
2646         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2648 %end
2649 #------------------------------------------------------------------------------
2652 #------------------------------------------------------------------------------
2653 #   Copy include files into the includes directories. There are currently
2654 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2655 #   for building tools that need to run on the host system $(GENINCDIR). The
2656 #   $(GENINCDIR) path must not contain any references to the C runtime
2657 #   library header files.
2659 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2660     dir= compiler=target includedir=$(AROS_INCLUDES)
2662 ifeq ($(findstring %(compiler),host kernel target),)
2663 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2664 endif
2666 ifneq (%(dir),)
2667 TMP_DIR := %(dir)
2668 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2669 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2670 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2671 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2672 ifeq ($(TMP_DIRFIRST),/)
2673 BD_INC_PATH := %(dir)/
2674 else
2675 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2676 endif
2677 else
2678 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2679 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2680 endif
2682 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2683         @$(CP) $< $@
2685 ifeq (%(compiler),target)
2687 ifneq (%(dir),)
2688 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2689 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2690 else
2691 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2692 endif
2694 BD_INCL_FILES += $(BD_INCL_FILES2)
2696 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2697         @$(CP) $< $@
2698 endif
2701 %(mmake) : $(BD_INCL_FILES)
2703 .PHONY: %(mmake)
2705 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2706 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2707 %end
2708 #------------------------------------------------------------------------------
2711 #------------------------------------------------------------------------------
2712 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2713 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2714 STUBS_MEM := $(addsuffix .o,$(STUBS))
2715 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2716 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2717 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2719 #MM- linklibs : hidd-%(hidd)-stubs
2720 #MM- %(parenttarget): hidd-%(hidd)-stubs
2721 #MM hidd-%(hidd)-stubs : includes includes-copy
2722 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2724 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2725         %mklib_q from=$^
2727 $(STUBS_OBJ) : $(STUBS_SRC) 
2728         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT)" opt="%(cflags) %(cppflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2730 $(STUBS_DEP) : $(STUBS_SRC)
2731         %mkdepend_q flags="%(dflags) %(cppflags)"
2733 setup ::
2734         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2737 clean ::
2738         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2740 DEPS := $(DEPS) $(STUBS_DEP)
2742 %end
2743 #------------------------------------------------------------------------------
2746 #------------------------------------------------------------------------------
2747 # Build an imported source tree which uses the configure script from the
2748 # autoconf package.  This rule will try to "integrate" the produced files as
2749 # much as possible in the AROS build, for example by putting libraries in the
2750 # standard library directory, includes in the standard include directory, and
2751 # so on. You can however override this behaviour.
2753 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2754 # be %(bindir) (or its deduced value) when running "make install", and
2755 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2756 # configure script some more parameters whose value depends upon the PROGDIR
2757 # env var, so that the program gets all its stuff installed in the proper place
2758 # when building it, but when running it from inside AROS it can also find that
2759 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2760 # the configuration parameters set when running ./configure
2762 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2763 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2764 # to the name which has to follow it.
2766 # Arguments:
2768 #     - mmake           = the meta make target.
2769 #     - package         = name of the package to be built.
2770 #     - srcdir          = the location of the unpacked source code. Defaults
2771 #                         to $(SRCDIR)/$(CURDIR).
2772 #     - prefix          = the target directory. Must be an absolute path of the
2773 #                         host system. Defaults to $(AROS_CONTRIB).
2774 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2775 #                         Defaults to the value of the prefix option.
2776 #     - extraoptions    = additional options for the configure script.
2777 #     - extracflags     = additional flags to use with the C compiler.
2778 #     - extracxxflags   = additional flags to use with the C++ compiler.
2779 #     - usecppflags      = enable the use of cpp flags. some external configure
2780 #                         scripts will not set their own cppflags if it is already
2781 #                         set, so this allows them to be disabled (unless you can provide
2782 #                         all the options they would need)
2783 #     - extracppflags      = additional preprocessor flags.
2784 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2785 #                         Defaults to the value of the nix argument.
2786 #     - nix             = enable u*nix path handling, i.e. a path like
2787 #                         /progdir//./file will be translated to
2788 #                         progdir:file during run-time. Defaults to no.
2789 #     - compiler        = target, host or kernel. Defaults to target.
2790 #     - install_target  = the command used for installing. Defaults to install. Leave
2791 #                         it empty if you want to suppress installing.
2792 #     - preconfigure    = a metatarget which is executed before configure is called.
2793 #     - postconfigure   = a metatarget which is executed after configure is called.
2794 #     - postinstall     = a metatarget which is executed after installing.
2795 #     - install_env     = set additional options for installing.
2796 #     - use_build_env   = if yes the configuration environment is used for
2797 #                         installing, too. Defaults to no.
2799 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2800 # like this:
2802 # if nix_dir_layout
2803 #    --prefix = $(aros_prefix)
2804 #    progdir = $(aros_prefix)/bin
2805 # else
2806 #    if nix
2807 #        --prefix = /PROGDIR
2808 #        --bindir = /PROGDIR
2809 #        --sbindir = /PROGDIR
2810 #        --libdir = /LIB
2811 #        --includedir = /INCLUDE
2812 #        --oldincludedir = /INCLUDE   
2813 #    else
2814 #        --prefix = $(aros_prefix)
2815 #    endif
2817 #    progdir = $(aros_prefix)
2819 #    # Install options
2820 #    bindir = $(prefix)
2821 #    sbindir = $(prefix)
2822 #    libdir = $(AROS_LIB)
2823 #    includedir = $(AROS_INCLUDES)
2824 #    oldincludedir = $(AROS_INCLUDES)
2825 # endif
2828 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
2829     prefix= gendir= basedir=$(CURDIR) extraoptions= \
2830     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
2831     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
2832     install_target=install preconfigure= postconfigure= postinstall= \
2833     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes
2835 ifneq (%(prefix),)
2836     %(mmake)-prefix := %(prefix)
2837 else
2838     %(mmake)-prefix := $(AROS_CONTRIB)
2839 endif
2841 ifneq (%(aros_prefix),)
2842     %(mmake)-aros_prefix := %(aros_prefix)
2843 else
2844     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2845 endif
2847 BD_NIXFLAG ?= -nix
2849 ifeq (%(nix),yes)
2850     %(mmake)-nix    := $(BD_NIXFLAG)
2851     %(mmake)-volpfx := /
2852     %(mmake)-volsfx := /
2853     
2854     ifeq (%(nix_dir_layout),)
2855         %(mmake)-nix_dir_layout := yes
2856     endif
2857 else
2858     %(mmake)-volsfx := :
2859     
2860     ifeq (%(nix_dir_layout),)
2861         %(mmake)-nix_dir_layout := no
2862     endif
2863 endif
2865 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2867 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2868         exec_prefix=$(%(mmake)-prefix) %(install_env)
2870 # Check if chosen compiler is valid
2871 ifeq ($(findstring %(compiler),host target kernel),)
2872   $(error unknown compiler %(compiler))
2873 endif
2875 # Set legacy 'host' variable based on chosen compiler
2876 ifeq (%(compiler),host)
2877     host := yes
2878     ifeq (%(basedir),)
2879         %(mmake)-pkgbasedir := $(HOSTGENDIR)
2880     else
2881         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
2882     endif
2883 else
2884     host := no
2885     ifeq (%(basedir),)
2886         %(mmake)-pkgbasedir := $(GENDIR)
2887     else
2888         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
2889     endif
2890 endif
2891 ifneq (%(gendir),)
2892     ifeq (%(basedir),)
2893         %(mmake)-pkgbasedir := %(gendir)
2894     else
2895         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
2896     endif
2897 endif
2899 ifeq (%(package),)
2900     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
2901 else
2902     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
2903 endif
2905 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2906 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2908 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2909     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2910     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2911 else
2912     ifeq (%(nix),yes)
2913         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2914         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2915     else
2916         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2917     endif
2919     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2920     
2921     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2922         sbindir=$(%(mmake)-prefix) \
2923         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2924         oldincludedir=$(AROS_INCLUDES) %(install_env)
2925 endif
2927 ifneq ($(DEBUG),yes)
2928     %(mmake)-s_flag = -s
2929 endif
2931 # Set up build environment, and options for configure script
2932 ifeq (%(compiler),host)
2933     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2934     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2935     # since that won't get picked up during configure.
2936     # We also cannot pass in the compiler including std flags so we need to use
2937     # the "plain" host compiler.
2938     %(mmake)-cfg-env := %(config_env_extra) \
2939         CPP="$(HOST_CPP)" \
2940         CXXCPP="$(HOST_CPP)" \
2941         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2942         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2943         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2944         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2945         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2946         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2947         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2948         TARGET_AS="$(TARGET_AS)" \
2949         OBJCOPY="$(OBJCOPY)" \
2950         TARGET_RANLIB="$(RANLIB)" \
2951         TARGET_STRIP="$(STRIP_PLAIN)" \
2952         TARGET_NM="$(NM_PLAIN)" \
2953         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2954 endif
2955 ifeq (%(compiler),target)
2956     %(mmake)-cfg-env := %(config_env_extra) \
2957         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
2958         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
2959     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2960         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2961         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2962         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2963         LD="$(strip $(TARGET_LD))"
2964 ifeq (%(crossbuild),yes)
2965     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
2966         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
2967 ifeq (%(usecppflags),yes)
2968     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2969 endif
2970 else
2971     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2972         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
2973 ifeq (%(usecppflags),yes)
2974     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2975 endif
2976 endif
2977     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2978         CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
2979         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
2980         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
2981         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
2982         LD_FOR_BUILD="$(strip $(HOST_LD))" \
2983         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))" \
2984         CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2985         CFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2986         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2987         CXXFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2988         LD_FOR_HOST="$(strip $(TARGET_LD))" \
2989         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2990         CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2991         CFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2992         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2993         CXXFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2994         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
2995         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2996         AR="$(strip $(AR_PLAIN))" \
2997         AS="$(strip $(TARGET_AS))" \
2998         OBJCOPY="$(strip $(OBJCOPY))" \
2999         RANLIB="$(strip $(RANLIB))" \
3000         STRIP="$(strip $(STRIP_PLAIN))" \
3001         TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3002         TARGET_CFLAGS="$(strip $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3003         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3004         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3005         TARGET_AS="$(strip $(TARGET_AS))" \
3006         TARGET_RANLIB="$(strip $(RANLIB))" \
3007         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3008         TARGET_NM="$(strip $(NM_PLAIN))"
3009 ifeq (%(buildflags),yes)
3010     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3011     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3012     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3013 endif
3014 ifeq (%(gnuflags),yes)
3015     %(mmake)-config_opts += --without-pic --disable-shared
3016     %(mmake)-config_opts += --disable-nls --without-x
3017 endif
3018 endif
3019 ifeq (%(compiler),kernel)
3020     %(mmake)-cfg-env := %(config_env_extra) \
3021         CPP="$(KERNEL_CPP)" \
3022         CXXCPP="$(KERNEL_CPP)" \
3023         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
3024         CFLAGS="$(strip $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3025         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
3026         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3027 ifeq (%(usecppflags),yes)
3028     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3029 endif
3030     %(mmake)-cfg-env += AS="$(KERNEL_AS)" \
3031         CC_FOR_BUILD="$(HOST_DEF_CC)" \
3032         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3033         CXX_FOR_BUILD="$(HOST_CXX)" \
3034         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3035         RANLIB="$(RANLIB)" \
3036         TARGET_RANLIB="$(RANLIB)" \
3037         TARGET_STRIP="$(STRIP_PLAIN)" \
3038         TARGET_NM="$(NM_PLAIN)"
3039 ifeq (%(buildflags),yes)
3040     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3041     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3042     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3043 endif
3044 ifeq (%(gnuflags),yes)
3045     %(mmake)-config_opts += --without-pic --disable-shared
3046     %(mmake)-config_opts += --disable-nls --without-x
3047 endif
3048 endif
3050 ifeq (%(use_build_env),yes)
3051     BUILD_ENV := $(%(mmake)-cfg-env)
3052 endif
3054 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3055 # in an ideal world, we would depend on the files in the source directory,
3056 # so we could copy them when they change. unfortunately filenames with
3057 # spaces causes problems with this
3058 $(%(mmake)-pkgdir)/.local-copy:
3059         %mkdirs_q $(%(mmake)-pkgdir)
3060         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3061         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3063 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3065     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3066 else
3067     %(mmake)-cfg-srcdir=%(srcdir)
3068 endif
3069 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3071 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3073 # When building for the host, we don't need to build the
3074 # linklibs - this is especially true when building the
3075 # crosstool toolchain on 'foreign' architectures (such as
3076 # building PPC on x86)
3078 #MM- %(mmake)-host : setup includes %(mmake)-quick
3079 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3080 #MM- %(mmake): %(mmake)-%(compiler)
3082 # Using -j1 in install_command may result in a warning but finally
3083 # it does its job. make install for gcc does not work reliably for -jN
3084 # where N > 1.
3085 ifneq (%(install_target),)
3086     %(mmake)-install_command = \
3087         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3088         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3089         $(%(mmake)-make-env) %(install_target) -j1
3091     %(mmake)-uninstall_command = \
3092     $(RM) $(%(mmake)-installflag) && \
3093     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3094     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3095 else
3096     %(mmake)-install_command   := true
3097     %(mmake)-uninstall_command := true
3098 endif
3100 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3103 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3106 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3108 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3109         @$(IF) ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3110             $(RM) $(%(mmake)-installflag) && \
3111             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3112             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3113             $(%(mmake)-install_command) && \
3114             $(TOUCH) $@ -r $^; \
3115         fi
3117 $(%(mmake)-pkgdir)/.files-touched:
3118         %mkdirs_q $(%(mmake)-pkgdir)
3119         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3120         $(TOUCH) $@
3123 %(mmake)-uninstall :
3124         $(%(mmake)-uninstall_command)
3127 %(mmake)-configure : $(%(mmake)-configflag)
3129 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3130 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3131         @$(RM) $@
3132         %mkdirs_q $(%(mmake)-pkgdir)
3133         @$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3134         @cd $(%(mmake)-pkgdir) && \
3135         find . -name config.cache -exec $(RM) '{}' \; && \
3136         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3137         $(TOUCH) $@
3140 %(mmake)-clean : %(mmake)-uninstall
3141         @$(RM) $(%(mmake)-pkgdir)
3142 %end
3143 #------------------------------------------------------------------------------
3146 #------------------------------------------------------------------------------
3147 # Build an imported source tree which uses cmake 
3149 # Arguments:
3151 #     - mmake           = the meta make target.
3152 #     - package         = name of the package to be built.
3153 #     - srcdir          = the location of the unpacked source code. Defaults
3154 #                         to $(SRCDIR)/$(CURDIR).
3155 #     - prefix          = the target directory. Must be an absolute path of the
3156 #                         host system. Defaults to $(AROS_CONTRIB).
3157 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3158 #                         Defaults to the value of the prefix option.
3159 #     - extraoptions    = additional options for the cmake script.
3160 #     - installoptions    = additional options for the install step.
3163 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3164     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3165     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3167 ifneq (%(prefix),)
3168     %(mmake)-prefix := %(prefix)
3169 else
3170     %(mmake)-prefix := $(AROS_CONTRIB)
3171 endif
3173 ifneq (%(aros_prefix),)
3174     %(mmake)-aros_prefix := %(aros_prefix)
3175 else
3176     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3177 endif
3179 ifeq (%(compiler),host)
3180     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3181     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3182     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3183     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3184     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)" -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3185     ifeq (%(package),)
3186         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3187     else
3188         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3189     endif
3190 else
3191     BD_LDFLAGS   := %(ldflags)
3192     BD_CFLAGS := %(cflags) 
3193     BD_CXXFLAGS := %(cxxflags)
3194     BD_CPPFLAGS := %(cppflags)
3195     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(BD_LDFLAGS)"
3196     ifeq (%(package),)
3197         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3198     else
3199         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3200     endif
3201 endif
3202 ifneq (%(gendir),)
3203     ifeq (%(package),)
3204         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3205     else
3206         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3207     endif
3208 endif
3210 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3211 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3213 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3215 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3217 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3220 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3222 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3223         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3224             $(RM)  $(%(mmake)-installflag) && \
3225             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3226             cd $(%(mmake)-pkgdir) && \
3227             cmake %(installoptions) -P cmake_install.cmake && \
3228             $(TOUCH) $@ -r $^; \
3229         fi
3231 $(%(mmake)-pkgdir)/.files-touched:
3232         %mkdirs_q $(%(mmake)-pkgdir)
3233         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3234         $(TOUCH) $@
3237 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3239 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3240 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3241         $(RM) $@
3242         %mkdirs_q $(%(mmake)-pkgdir)
3243         cd $(%(mmake)-pkgdir) && \
3244         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3245         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3246         $(TOUCH) $@
3249 %(mmake)-clean : %(mmake)-uninstall
3250         @$(RM) $(%(mmake)-pkgdir)
3251 %end
3252 #------------------------------------------------------------------------------
3255 #------------------------------------------------------------------------------
3256 # Given an archive name, patches names and locations where to find them, fetch
3257 # the archive and the patches from any of those locations, unpack the archive
3258 # and then apply the patches.
3260 # Locations currently supported are http and ftp sites, plus local filesystem
3261 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3262 # the fetch.sh script needs to be modified, since this macro relies on that script.
3264 # Arguments:
3266 #     - mmake           = mmaketarget
3267 #     - archive_origins = list of locations where to find the archive. They are tried
3268 #                         in sequence, until the archive is found and fetching it 
3269 #                         succeeded. If not specified, the current directory is assumed.
3270 #     - archive         = the archive name. Mandatory.
3271 #     - suffixes        = a list of suffixes to append to the package name plus the
3272 #                         version. Each one of them is tried until a matching archive is
3273 #                         found. They are appended to patches and these are tried the
3274 #                         same way as packages are.
3275 #     - location        = the local directory where to put the fetched archive and patches.
3276 #                         If not specified, the directory specified by destination is used.
3277 #     - destination     = the directory to unpack the archive to.
3278 #                         If not specified, the current directory is assumed.
3279 #     - patches_origins = list of locations where to find the patches. They are tried
3280 #                         in sequence, until a patch is found and fetching it 
3281 #                         succeeded. If not specified, the current directory is assumed.
3282 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3283 #                         patch_name[:[patch_subdir][:patch_opt]].
3285 #                             - patch_name   = the name of the patch file
3286 #                             - patch_subdir = the directory within \destination\ where to
3287 #                                              apply the patch.
3288 #                             - patch_opt    = any options to pass to the `patch' command
3289 #                                              when applying the patch.
3290 #                         
3291 #                         The patch_subdir and patch_opt fields are optional.
3293 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3294     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3296 .PHONY: %(mmake)
3298 ifneq (%(location),)
3299     %(mmake)-location := %(location)
3300 else
3301     %(mmake)-location := %(destination)
3302 endif
3305 %(mmake) :
3306         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3307         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3308 %end
3309 #------------------------------------------------------------------------------
3312 #------------------------------------------------------------------------------
3313 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3314 # unpatched source tree and runs diff against this and a previously fetched and possibly
3315 # patched tree. Depending on what happens after patching during a normal build it might
3316 # give best results if the new patch is created directly after fetch.
3318 # Arguments:
3320 #     - mmake       = mmaketarget
3321 #     - archive     = archive base name
3322 #     - srcdir      = the top level directory the package is unpacked to, useful if
3323 #                     an archive unpacks to a directory other than its name suggests.
3324 #                     this should not be deeper than a single path element.
3325 #     - suffixes    = a list of suffixes to append to the the package name plus the
3326 #                     version. Each one of them is tried until a matching archive is
3327 #                     found.
3328 #     - destination = the directory to unpack the archive to.
3329 #     - excludes    = diff patterns to exclude files or directories from the patch
3331 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3333 .PHONY: %(mmake)
3335 ifneq (%(excludes),)
3336     %(mmake)-exclude := -X ./exclude.patterns
3337 endif
3339 ifneq (%(srcdir),)
3340     %(mmake)-srcdir := %(srcdir)
3341 else
3342     %(mmake)-srcdir := %(archive)
3343 endif
3345 #MM- %(mmake) : %(mmake)-diff
3346 #MM- %(mmake)-quick : %(mmake)-diff
3349 %(mmake)-diff:
3350         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3351         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3352         cd %(destination)/tmp ; \
3353         $(FOR) f in %(excludes) ; do \
3354             $(ECHO) $$f >> ./exclude.patterns ; \
3355         done ; \
3356         diff -ruN $(%(mmake)-exclude) \
3357             $(%(mmake)-srcdir) \
3358             $(%(mmake)-srcdir).aros \
3359             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3360         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3361         $(RM) %(destination)/tmp
3362 %end
3363 #------------------------------------------------------------------------------
3366 #------------------------------------------------------------------------------
3367 # Joins the features of %fetch and %build_with_configure.
3369 # If a patch is provided, it *must* be named the following way:
3371 #    <package name>-<version number>-aros.diff
3373 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3374 # CD'ing into the archive's extracted directory.
3376 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3377 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3378 # to make that patch fully comprehensive.
3380 # Arguments:
3382 #    - mmake            = the meta make target.
3383 #    - package          = the GNU package name, sans version and archive format suffixes.
3384 #    - subpackage       = ???
3385 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3386 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3387 #    - version          = the package's version number, or otherwise any other version string.
3388 #                         It gets appended to the package name to form the basename of the archive.
3389 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3390 #                         version. Each one of them is tried until a matching archive is found.
3391 #                         Defaults to "tar.bz2 tar.gz".
3392 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3393 #    - builddir         = override the location we expect to run configure/make in.
3394 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3395 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3396 #                         fetched or not. Default to no.
3397 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3398 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3399 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3400 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3401 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3402 #    - extracppflags      = same meaning as the one for the %build_with_configure macro.
3403 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3404 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3405 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3406 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3407 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3408 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3409 #    - nix              = same meaning as the one for the %build_with_configure macro.
3410 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3411 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3413 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3414     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3415     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3416     extraoptions=  usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3417     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no buildflags=yes gnuflags=yes
3419 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3420 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3421 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3422 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3424 %(mmake)-archbase  := %(package)-%(version)
3426 ifeq (%(compiler),host)
3427     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3428 else
3429     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3430 endif
3432 ifeq (%(prefix),)
3433     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3434 else
3435     %(mmake)-prefix := %(prefix)
3436 endif
3438 ifneq (%(subpackage),)
3439     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3440 else
3441     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3442 endif
3444 ifneq (%(srcdir),)
3445     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3446 else
3447     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3448 endif
3450 ifneq (%(builddir),)
3451     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3452 else
3453     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3454 endif
3456 ifeq (%(patch),yes)
3457     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3458 else
3459     %(mmake)-%(subpackage)-patches_specs := ::
3460 endif
3462 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3463     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3464     archive_origins=". %(package_repo)" \
3465     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3467 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3468     archive=$(%(mmake)-%(subpackage)-archbase) \
3469     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3470     suffixes="%(suffixes)" \
3471     destination=$(%(mmake)-portdir)
3473 #MM- %(mmake) : %(mmake)-%(subpackage)
3475 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3477 %(mmake)-%(subpackage)-package-basename := \
3478     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3480 ifneq (%(create_pkg),no)
3481     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3482 endif
3484 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3485      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3486      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3487      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3488      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3489      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" buildflags=%(buildflags) gnuflags=%(gnuflags)
3491 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3492 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3495 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3497 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3498 #that $^ and $@ have exactly the same mtime, and in that case make tries
3499 #to rebuild $@ again, which would fail because the directory where
3500 #the package got installed would not exist anymore. 
3501 #We work this around by using an if statement to manually check the mtimes.
3502 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3503         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -f $@; then \
3504             $(RM) $@ ; \
3505             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3506             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3507             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3508             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3509             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3510             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3511         fi
3512 %end
3513 #------------------------------------------------------------------------------
3516 #------------------------------------------------------------------------------
3517 # Joins the features of %fetch and %build_with_configure, taking advantage of
3518 # the naming scheme of GNU packages. GNU packages names are in the form
3520 #     <package name>-<version number>.<archive format suffix>
3522 # If a patch is provided, it *must* be named the following way:
3524 #    <package name>-<version number>-aros.diff
3526 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3527 # CD'ing into the archive's extracted directory.
3529 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3530 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3531 # to make that patch fully comprehensive.
3533 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3535 # Arguments:
3537 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3539 #    - prefix           = defaults to $(GNUDIR).
3540 #    - aros_prefix      = defaults to /GNU.
3542 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3543     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3544     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3545     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracppflags= extracxxflags="$(OPTIMIZATION_CFLAGS)"
3547 GNU_REPOSITORY := gnu://
3549 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3550     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3551     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3552     patch="%(patch)" patch_repo="%(patch_repo)" \
3553     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3554     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=%(nix)
3556 %end
3557 #------------------------------------------------------------------------------
3560 #------------------------------------------------------------------------------
3561 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3562 # that the package is a "Developer" package, and as such it needs to be placed
3563 # under the $(AROS_DEVELOPER) directory, as a default. 
3565 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3566 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3567 # "mmake" argument, because the metatarget is implicitely defined as
3569 #     #MM- development-%(package)
3571 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3572     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3573     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3574     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracppflags= extracxxflags="$(OPTIMIZATION_CFLAGS)"
3576 #MM- development : development-%(package)
3579 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3580    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3581    package_repo="%(package_repo)" \
3582    patch="%(patch)" patch_repo="%(patch_repo)" \
3583    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3584    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" nix=%(nix)
3587 postinstall-%(package)-delete-la-files:
3588         $(RM) %(prefix)/lib/*.la
3590 %end
3591 #------------------------------------------------------------------------------
3593 # Builds a kickstart package in PKG format
3595 # Arguments:
3597 #    - mmake   = target name
3598 #    - file    = destination file name with path
3600 # Other arguments are self-explanatory
3602 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3603     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3605 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3606 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3607 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3608 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3609 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3610 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3612 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3613 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3614 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3615 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3616 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3617 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3619 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3620     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3621 PKG_DIR   := $(dir %(file))
3624 %(mmake) : %(file)
3627 %(mmake)-quick : %(file)
3629 %(file): $(PKG_FILES) | $(PKG_DIR)
3630         @$(ECHO) Packaging $@...
3631         @$(SRCDIR)/tools/package/pkg c $@ $^
3633 %compress_file mmake="%(mmake)" file="%(file)"
3635 GLOB_MKDIRS += $(PKG_DIR)
3637 %end
3639 #------------------------------------------------------------------------------
3640 # Compresses %(file) with a gzip.
3641 # Good in conjunction with for example %build_prog
3643 %define compress_file mmake=/A file=/A
3645 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3648 %(mmake)-gz-quick : %(file).gz
3650 %(file).gz: %(file)
3651         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3652         @gzip -9 -f $^
3654 %end
3656 #------------------------------------------------------------------------------
3657 # Links a kickstart module in ELF format
3658 # Arguments are similar to make_package
3660 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3661     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3663 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3664 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3665 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3666 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3667 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3668 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3670 ifeq (%(startup),)
3671     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3672 else
3673     KOBJ_STARTUP := %(startup)
3674 endif
3676 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3678 TMP_LDFLAGS := %(ldflags)
3680 # Make a list of the lib files this program depends on.
3681 # In LDFLAGS remove white space between -L and directory
3682 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3683 # Filter out only the libdirs and remove -L
3684 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3685 # Add trailing /
3686 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3687 # Add normal linklib path
3688 TMP_DIRS += $(AROS_LIB)/
3689 # add lib and .a to static linklib names
3690 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3691 # search for the linklibs in the given path, ignore ones not found
3692 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3693     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3696 TMP_DIRS += $(dir %(file))
3697 ifneq (%(map),)
3698     TMP_LDFLAGS += $(GENMAP) %(map)
3699     TMP_DIRS    += $(dir %(map))
3700 endif
3702 #MM %(mmake) : %(deps)
3705 %(mmake) : %(file)
3708 %(mmake)-quick : %(file)
3710 %(file): KOBJS := $(KOBJS)
3711 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3712                     -static -nosysbase -Wl,-Ur
3713 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3714 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3715         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3716         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3717 ifeq ($(DEBUG),yes)
3718         @$(STRIP) $@ --only-keep-debug -o $@.dbg
3719 endif
3720         @$(STRIP) $@
3722 %compress_file mmake="%(mmake)" file="%(file)"
3724 GLOB_MKDIRS += $(TMP_DIRS)
3726 %end