only generate the stubs/includes one time, not repeatedly for every target file in...
[AROS.git] / config / make.tmpl
blobedebefdb3a51e9fbff7e56ef4358e133090147ff
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 .PHONY : $(MODNAME).$(MODTYPE)-genfiles
1220 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1221 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1222 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1223 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1224                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1227 TMP_DEPS := $(GENMODULE)
1228 TMP_OPTS :=
1230 ifneq (%(conffile),)
1231     ifeq ($(dir %(conffile)),./)
1232         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1233         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1234     else
1235         TMP_OPTS += -c %(conffile)
1236         TMP_DEPS += %(conffile)
1237     endif 
1238 else
1239     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1240     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1241 endif
1242 ifneq (%(modsuffix),)
1243     TMP_OPTS += -s %(modsuffix)
1244 endif
1245 ifneq (%(targetdir),)
1246     TMP_OPTS += -d %(targetdir)
1247     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1248     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1249 endif
1250 ifneq (%(stubdir),)
1251     TMP_OPTS += -l %(stubdir)
1252     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1253     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1254     TMP_TARGETDIRS += %(stubdir)
1255 else
1256 ifneq (%(targetdir),)
1257     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1258 endif
1259 endif
1261 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1262 ifneq ($(TMP_TARGETDIRS),)
1263 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1264 endif
1266 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1267 $(TMP_TARGETS) : MODNAME := %(modname)
1268 $(TMP_TARGETS) : MODTYPE := %(modtype)
1269 $(TMP_TARGETS) : $(TMP_DEPS) $(MODNAME).$(MODTYPE)-genfiles
1270 $(MODNAME).$(MODTYPE)-genfiles:
1271         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1272 ifneq (%(conffile),lib.conf)
1273         @$(IF) $(TEST) -f lib.conf; then \
1274           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1275         fi
1276 endif
1277         @$(IF) $(TEST) -f libdefs.h; then \
1278           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1279         fi
1280         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1281 %end
1282 #------------------------------------------------------------------------------
1285 #------------------------------------------------------------------------------
1286 # Generate the support files for compiling a module. This includes include
1287 # files and source files.
1288 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1289     targetdir= conffile=
1291 ifneq ($(%(modname)_INCLUDES),)
1293 .PHONY : $(MODNAME).$(MODTYPE)-includes
1295 TMP_TARGETS := $(%(modname)_INCLUDES)
1297 TMP_DEPS := $(GENMODULE)
1298 TMP_OPTS :=
1300 ifneq (%(conffile),)
1301     ifeq ($(dir %(conffile)),./)
1302         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1303         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1304     else
1305         TMP_OPTS += -c %(conffile)
1306         TMP_DEPS += %(conffile)
1307     endif 
1308 else
1309     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1310     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1311 endif
1312 ifneq (%(modsuffix),)
1313     TMP_OPTS += -s %(modsuffix)
1314 endif
1315 ifneq (%(targetdir),)
1316     TMP_OPTS += -d %(targetdir)
1317     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1318 endif
1320 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1321 $(TMP_TARGETS) : MODNAME := %(modname)
1322 $(TMP_TARGETS) : MODTYPE := %(modtype)
1323 $(TMP_TARGETS) : $(TMP_DEPS) $(MODNAME).$(MODTYPE)-genincludes
1324 $(MODNAME).$(MODTYPE)-genincludes:
1325         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1326         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1327 endif
1328 %end
1329 #------------------------------------------------------------------------------
1331 #------------------------------------------------------------------------------
1332 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1333 # 'start' is an optional starting address
1334 # 'ldflags' is optional additional flags for the linker
1335 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1337 BD_OUTDIR := $(dir %(file))
1338 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1339 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1340 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1341 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1342 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1343 BD_OBJS += %(objs)
1345 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1347 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1348         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1349         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1350         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1352 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1353     GLOB_MKDIRS += $(BD_OUTDIR)
1354 endif
1356 %end
1358 #------------------------------------------------------------------------------
1359 # Common rules for all makefiles
1360 %define common
1361 # Delete generated makefiles
1363 clean ::
1364         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1366 include $(SRCDIR)/config/make.tail
1368 BDID := $(BDTARGETID)
1369 %end
1370 #------------------------------------------------------------------------------
1371       
1373 #############################################################################
1374 #############################################################################
1375 ##                                                                         ##
1376 ## Here are the mmakefile build macros. These are macros that takes care   ##
1377 ## of everything to go from the sources to the generated target. Also all  ##
1378 ## intermediate files and directories that are needed are created by these ##
1379 ## rules.                                                                  ##
1380 ##                                                                         ##
1381 #############################################################################
1382 #############################################################################
1384 #------------------------------------------------------------------------------
1385 # Build a program
1386 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1387     objcfiles= \
1388     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1389     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1390     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1391     includedir= libdir= \
1392     compiler=target linker= lto=$(TARGET_LTO)
1394 .PHONY : %(mmake)
1396 BD_PROGNAME  := %(progname)
1397 BD_OBJDIR    := %(objdir)
1398 BD_TARGETDIR := %(targetdir)
1399 BD_LINKER    := %(linker)
1401 # If not supplied, linker is equal to compiler
1402 ifeq ($(BD_LINKER),)
1403     BD_LINKER := %(compiler)
1404 endif
1406 BD_FILES     := %(files)
1407 BD_OBJCFILES := %(objcfiles)
1408 BD_ASMFILES  := %(asmfiles)
1409 BD_CXXFILES := %(cxxfiles)
1411 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1412 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1413 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1415 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1416 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1417 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1419 BD_CFLAGS    := %(cflags)
1420 BD_CXXFLAGS := %(cxxflags)
1421 BD_CPPFLAGS :=  %(cppflags)
1422 ifeq (%(lto),yes)
1423 ifeq (%(compiler),target)
1424 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1425 BD_CXXFLAGS := $(LTO_BINARY_CFLAGS) $(BD_CXXFLAGS)
1426 endif
1427 endif
1428 ifneq (%(includedir),)
1429 BD_CFLAGS    += -I%(includedir)
1430 BD_CXXFLAGS += -I%(includedir)
1431 endif
1432 BD_AFLAGS    := %(aflags)
1433 ifneq (%(includedir),)
1434 BD_AFLAGS    += -I%(includedir)
1435 endif
1436 BD_DFLAGS    := %(dflags)
1437 BD_DXXFLAGS := %(dxxflags)
1438 BD_LDFLAGS   := %(ldflags)
1439 ifneq (%(libdir),)
1440 BD_LDFLAGS   += -L%(libdir)
1441 endif
1444 %(mmake)-quick : %(mmake)
1446 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1447 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1449 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1450 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1451     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1452 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1453     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1454 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1455     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1456 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1457     aflags=$(BD_AFLAGS)
1459 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1460     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1461     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1462     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1463     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1465 endif
1467 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1469 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1470 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1471 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1473 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1475 %(mmake)-clean ::
1476         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1477         @$(RM) $(FILES)
1479 %end
1480 #------------------------------------------------------------------------------
1483 #------------------------------------------------------------------------------
1484 # Build programs, for every C file an executable will be built with the same
1485 # name as the C file
1486 %define build_progs mmake=/A files=/A nix=no \
1487     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1488     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1489     includedir= libdir= \
1490     compiler=target \
1491     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1493 .PHONY : %(mmake)
1495 BD_OBJDIR    := %(objdir)
1496 BD_TARGETDIR := %(targetdir)
1498 BD_FILES     := %(files)
1499 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1500 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1501 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1503 BD_CFLAGS    := %(cflags)
1504 ifeq (%(lto),yes)
1505 ifeq (%(compiler),target)
1506 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1507 endif
1508 endif
1509 ifneq (%(includedir),)
1510     BD_CFLAGS += -I%(includedir)
1511 endif
1512 BD_CPPFLAGS := %(cppflags)
1513 BD_DFLAGS    := %(dflags)
1514 BD_LDFLAGS   := %(ldflags)
1515 ifneq (%(libdir),)
1516     BD_LDFLAGS += -L%(libdir)
1517 endif
1520 %(mmake)-quick : %(mmake)
1522 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1523 %(mmake) : $(BD_EXES)
1525 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1526 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1527     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1529 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1530     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1531     ldflags=$(BD_LDFLAGS) \
1532     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1533     usestartup="%(usestartup)" detach="%(detach)" \
1534      cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1536 endif
1538 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1540 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1541 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1542 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1544 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1546 %(mmake)-clean ::
1547         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1548         @$(RM) $(FILES)
1550 %end
1551 #------------------------------------------------------------------------------
1554 #------------------------------------------------------------------------------
1555 # Build a module.
1556 # This is a bare version: It just compiles and links the given files. It is
1557 # assumed that all needed boiler plate code is in the files. This should only
1558 # be used for compiling external code. For AROS code use %build_module
1559 %define build_module_simple mmake=/A modname=/A modtype=/A \
1560     files="$(basename $(call WILDCARD, *.c))" \
1561     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) \
1562     objdir=$(OBJDIR) moduledir= \
1563     uselibs= usehostlibs= compiler=target lto=$(TARGET_LTO)
1565 # Define metamake targets and their dependencies
1566 #MM %(mmake) : core-linklibs includes-generate-deps
1567 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1568 #MM %(mmake)-kobj-quick
1569 #MM %(mmake)-quick
1570 #MM %(mmake)-clean
1572 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1574 .PHONY : $(BD_ALLTARGETS)
1576 ifeq (%(modname),)
1577 $(error using %build_module_simple: modname may not be empty)
1578 endif
1579 ifeq (%(modtype),)
1580 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1581 endif
1583 # Default values for variables and arguments
1584 BD_DEFLINKLIBNAME := %(modname)
1585 BD_DEFDFLAGS := %(cflags)
1586 ifeq (%(lto),yes)
1587 ifeq (%(compiler),target)
1588 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(BD_DEFDFLAGS)
1589 endif
1590 endif
1591 BD_DEFDXXFLAGS := %(dxxflags)
1592 OBJDIR ?= $(GENDIR)/$(CURDIR)
1593 BD_MODDIR := %(moduledir)
1594 ifeq ($(BD_MODDIR),)
1595   ifeq (%(modtype),library)
1596     BD_MODDIR  := $(AROS_LIBRARIES)
1597   endif
1598   ifeq (%(modtype),gadget)
1599     BD_MODDIR  := $(AROS_GADGETS)
1600   endif
1601   ifeq (%(modtype),datatype)
1602     BD_MODDIR  := $(AROS_DATATYPES)
1603   endif
1604   ifeq (%(modtype),handler)
1605     BD_MODDIR  := $(AROS_FS)
1606   endif
1607   ifeq (%(modtype),device)
1608     BD_MODDIR  := $(AROS_DEVS)
1609   endif
1610   ifeq (%(modtype),resource)
1611     BD_MODDIR  := $(AROS_RESOURCES)
1612   endif
1613   ifeq (%(modtype),hook)
1614     BD_MODDIR  := $(AROS_RESOURCES)
1615   endif
1616   ifeq (%(modtype),mui)
1617     BD_MODDIR  := $(AROS_CLASSES)/Zune
1618   endif
1619   ifeq (%(modtype),mcc)
1620     BD_MODDIR  := $(AROS_CLASSES)/Zune
1621   endif
1622   ifeq (%(modtype),mcp)
1623     BD_MODDIR  := $(AROS_CLASSES)/Zune
1624   endif
1625   ifeq (%(modtype),usbclass)
1626     BD_MODDIR  := $(AROS_CLASSES)/USB
1627   endif
1628   ifeq (%(modtype),hidd)
1629     BD_MODDIR  := $(AROS_DRIVERS)
1630   endif
1631   ifeq (%(modtype),printer)
1632     BD_MODDIR  := $(AROS_PRINTERS)
1633   endif
1634 endif
1635 ifeq ($(BD_MODDIR),)
1636   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1637 endif
1639 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1640 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1641 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1643 %rule_compile_multi \
1644     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1645     cflags="$(BD_DEFDFLAGS)" cppflags="%(cppflags)" dflags="%(dflags)" \
1646     compiler="%(compiler)"
1648 # Handlers use dash instead of dot in their names
1649 ifeq (%(modtype),handler)
1650 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1651 else
1652 ifeq (%(modtype),printer)
1653 BD_MODULE := $(BD_MODDIR)/%(modname)
1654 else
1655 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1656 endif
1657 endif
1658 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1660 %(mmake)-quick : %(mmake)
1661 %(mmake)-kobj-quick : $(BD_KOBJ)
1662 %(mmake)       : $(BD_MODULE)
1663 %(mmake)-kobj  : $(BD_KOBJ)
1665 # The module is linked from all the compiled .o files
1666 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1668 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1669 # This breaks con-handler build. Here we work around this
1670 ifeq (%(modname),con)
1671     BD_ERR := $(notdir $(BD_MODULE)).err
1672 else
1673     BD_ERR := %(modname).err
1674 endif
1676 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1677                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1678                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1679                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1681 # Link kernel object file
1682 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1684 # Make these symbols local
1685 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1686             UtilityBase ExpansionBase KeymapBase KernelBase
1688 BD_SYMBOLS := $(BD_KBASE)
1690 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1691 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1692 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1693 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1694 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1695 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1696         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1697         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1698         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1701 ## Dependency fine-tuning
1703 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1704 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1706 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1707 $(BD_MODULE) : | $(BD_MODDIR)
1708 $(BD_KOBJ) : | $(KOBJSDIR)
1709 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1711 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1712 %(mmake)-clean ::
1713         @$(ECHO) "Cleaning up for module %(modname)"
1714         @$(RM) $(FILES)
1715 %end
1716 #------------------------------------------------------------------------------
1719 #------------------------------------------------------------------------------
1720 # Build a module - core routine
1721 # Explanation of this macro is done in the developer's manual
1722 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1723   files="$(basename $(call WILDCARD, *.c))" \
1724   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1725   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1726   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1727   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1728   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1729   includedir= libdir= \
1730   build_abi= build_library=
1732 # We will employ a terrifying, but unavoidable, hack here.
1733 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1734 # ignores GNU Make ifeq() statements, but will process any #MM
1735 # headed lines in the file.
1737 # So, to make the following #MM lines conditional on whether we want
1738 # to build the ABI, Library, or both, we define build_abi= and 
1739 # build_library as 'M' to enable, or '' to disable, which allows genmf
1740 # to do the following conversions:
1742 #  #%(build_abi)M includes-foo: foo-include
1743 #    becomes, when build_abi=M
1744 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1745 #    but, when build_abi= ...
1746 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1748 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1750 # Define metamake targets and their dependencies
1751 #MM %(mmake)
1752 #MM %(mmake)-quick
1753 #MM %(mmake)-makefile
1754 #MM %(mmake)-clean
1756 # ABI targets:
1757 #M%(build_abi)- includes-all : %(mmake)-includes
1758 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1759 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1760 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1761 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1762 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1763 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1764 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1765 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1766 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1767 #M%(build_abi) %(mmake)-includes-quick
1768 #M%(build_abi) %(mmake)-includes-dirs
1769 #M%(build_abi) %(mmake)-fd
1771 # Library targets
1772 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1773 #%(build_library)M %(mmake)-kobj-quick : 
1775 # Library with ABI targets:
1776 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1777 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1779 # All MetaMake targets defined by this macro
1780 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1782 ifeq (%(build_library),M)
1783 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1784 endif
1786 ifeq (%(build_abi),M)
1787 BD_ALLTARGETS += %(mmake)-includes \
1788                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1789                  %(mmake)-linklib %(mmake)-fd
1790 endif
1792 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1794 ifeq (%(modname),)
1795 $(error using %build_module: modname may not be empty)
1796 endif
1797 ifeq (%(modtype),)
1798 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1799 endif
1801 # Default values for variables and arguments
1802 BD_DEFLINKLIBNAME := %(modname)
1803 BD_DEFDFLAGS := %(cflags)
1804 BD_DEFDXXFLAGS := %(cxxflags)
1805 BD_DEFCPPFLAGS := %(cppflags)
1806 ifeq (%(lto),yes)
1807 ifeq (%(compiler),target)
1808 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDFLAGS)
1809 BD_DEFDXXFLAGS := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDXXFLAGS)
1810 endif
1811 endif
1812 ifneq (%(includedir),)
1813     BD_DEFDFLAGS += -I%(includedir)
1814     BD_DEFDXXFLAGS += -I%(includedir)
1815 endif
1816 OBJDIR ?= $(GENDIR)/$(CURDIR)
1818 ## Create genmodule include Makefile for the module
1820 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1822 %rule_genmodule_makefile \
1823     modname="%(modname)" modtype="%(modtype)" \
1824     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1825     conffile="%(conffile)"
1827 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1829 GLOB_MKDIRS += %(objdir)
1831 # Do not parse these statements if metatarget is not appropriate
1832 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1834 # suppress makes warning that the Makefile doesnt yet exist
1835 # on early passes (it will generate the file as needed though)
1836 # when we include it.
1837 -include %(objdir)/Makefile.%(modname)%(modtype)
1839 BD_DEFMODDIR := $(%(modname)_MODDIR)
1840 ifeq (%(archspecific),yes)
1841 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1842 endif
1845 ## include files generation
1847 ifneq (%(includedir),)
1848 BD_INCDIR    := %(includedir)
1849 else
1850 BD_INCDIR    := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
1851 endif
1852 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1853 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1855 ifeq (%(build_abi),M)
1856 %(mmake)-includes-quick : %(mmake)-includes
1857 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1858     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1859     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1861 ifneq ($(%(modname)_INCLUDES),)
1862 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1863                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1864                          conffile="%(conffile)"
1866 %rule_copy_diff_multi \
1867     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1868     stampfile="%(objdir)/%(modname)_geninc"
1870 %rule_copy_diff_multi \
1871     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1872     stampfile="%(objdir)/%(modname)_incs"
1874 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1876 TMP%(modname)_INCDIRS := \
1877     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1878     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1879     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1880 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1882 endif
1884 endif
1886 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1887     modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1888     conffile="%(conffile)" version="%(version)"
1890 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1891 $(BD_DEFLIBDEFSINC) :
1892         @$(ECHO) "Generating $@"
1893         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1895 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1896 GLOB_MKDIRS += %(objdir)/include
1898 ## Extra genmodule src files generation
1899 ## 
1900 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1901     modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1902     conffile="%(conffile)"
1904 GLOB_MKDIRS += %(objdir)/linklib
1906 ifeq (%(build_abi),M)
1907 ## Create FD file
1908 ifeq (%(includedir),)
1909 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/fd
1910 else
1911 BD_FDDIR := %(includedir)/../fd
1912 endif
1913 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1915 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1916     modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1918 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1920 GLOB_MKDIRS += $(BD_FDDIR)
1921 endif
1923 ## Compilation
1925 BD_FILES      := %(files)
1926 BD_CXXFILES := %(cxxfiles)
1928 BD_LIBFILES := %(linklibfiles)
1930 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1932 BD_FILEMATCH = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
1933 BD_MATCHARCH = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call BD_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
1934 BD_FILTERARCH = $(filter-out $(call BD_MATCHARCH,$(1),$(2)),$(2))
1935 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1936 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1938 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1939 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1940 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1941 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1942 BD_NARCHFILES := $(call BD_FILTERARCH,$(BD_ARCHFILES),$(BD_FILES))
1943 BD_NLIBARCHFILES := $(call BD_FILTERARCH,$(BD_LIBARCHFILES),$(BD_LIBFILES))
1944 BD_ARCHNLIBFILES := $(call BD_FILTERARCH,$(BD_LIBFILES),$(BD_LIBARCHFILES))
1946 BD_COMMONCFLAGS=-I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1947 BD_CFLAGS        := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_CFLAGS)
1948 BD_LINKLIBCFLAGS := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBCFLAGS)
1949 BD_CXXFLAGS      := %(cxxflags) $(BD_COMMONCFLAGS) $(%(modname)_CXXFLAGS)
1950 ifeq (%(lto),yes)
1951 ifeq (%(compiler),target)
1952 BD_LTOFLAGS=$(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH)
1953 BD_CFLAGS        := $(BD_LTOFLAGS) $(BD_CFLAGS)
1954 BD_LINKLIBCFLAGS := $(BD_LTOFLAGS) $(BD_LINKLIBCFLAGS)
1955 BD_CXXFLAGS      := $(BD_LTOFLAGS) $(BD_CXXFLAGS)
1956 endif
1957 endif
1958 ifneq (%(includedir),)
1959 BD_CFLAGS        += -I%(includedir)
1960 BD_LINKLIBCFLAGS += -I%(includedir)
1961 BD_CXXFLAGS      += -I%(includedir)
1962 endif
1963 BD_CPPFLAGS      := %(cppflags)
1964 BD_DFLAGS        := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_DFLAGS)
1965 BD_LINKLIBDFLAGS := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBDFLAGS)
1966 BD_DXXFLAGS      := %(dxxflags) $(BD_COMMONCFLAGS) $(%(modname)_DXXFLAGS)
1968 ifeq (%(modtype),library)
1969     BD_LIBSUFFIX := 
1970 else
1971     BD_LIBSUFFIX := .%(modtype)
1972 endif
1974 ifeq (%(libdir),)
1975 BD_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
1976 else
1977 BD_LIBDIR := %(libdir)
1978 endif
1980 ifeq (%(build_abi),M)
1981 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
1982 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
1983 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1984     BD_LINKLIB :=
1985 else
1986     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1987     ifneq (%(modname),%(linklibname))
1988         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1989     endif
1990 endif
1991 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1993 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
1994 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
1995 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1996     BD_RELLINKLIB :=
1997 else
1998     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1999     ifneq (%(modname),%(linklibname))
2000         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
2001     endif
2002 endif
2003 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
2004 endif
2006 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
2007 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
2008                  %(linklibobjs)
2009 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
2010                  %(linklibobjs)
2011 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
2012 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
2014 BD_CCFILES := $(BD_NARCHFILES)
2015 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
2016 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2017 BD_LINKLIBCCGENFILES := $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2019 %rule_compile_cxx_multi \
2020     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2021     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) \
2022     compiler="%(compiler)"
2023 %rule_compile_multi \
2024     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
2025     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) \
2026     compiler="%(compiler)"
2027 %rule_compile_multi \
2028     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
2029     cflags=$(BD_CFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
2030     compiler="%(compiler)"
2031 %rule_compile_multi \
2032     basenames=$(BD_NLIBARCHFILES) targetdir="%(objdir)/linklib" \
2033     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2034     compiler="%(compiler)"
2035 %rule_compile_multi \
2036     basenames=$(BD_LINKLIBCCGENFILES) srcdir="%(objdir)/linklib" targetdir="%(objdir)/linklib" \
2037     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2038     compiler="%(compiler)"
2040 ifneq ($(BD_LINKLIBAFILES),)
2041 %rule_assemble_multi \
2042     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
2043 endif
2045 ## Linking
2047 ifeq (%(modsuffix),)
2048 BD_SUFFIX := %(modtype)
2049 else
2050 BD_SUFFIX := %(modsuffix)
2051 endif
2053 ifeq (%(build_library),M)
2054 # Handlers use dash instead of dot in their names
2055 ifeq ($(BD_SUFFIX),handler)
2056 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2057 else
2058 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2059 endif
2060 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2061 else
2062 BD_MODULE :=
2063 BD_KOBJ   :=
2064 endif
2066 %(mmake)-quick      : %(mmake)
2067 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2068 ifeq (%(build_library),M)
2069 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2070 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2071 endif
2072 ifeq (%(build_abi),M)
2073 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2074 endif
2076 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2077            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2079 ifeq (%(nostartup),yes)
2080 # Handlers always have entry point
2081 ifneq (%(modtype),handler)
2082 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2083 endif
2084 endif
2086 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2087 # This breaks con-handler build. Here we work around this
2088 ifeq (%(modname),con)
2089     BD_ERR := $(notdir $(BD_MODULE)).err
2090 else
2091     BD_ERR := %(modname).err
2092 endif
2094 ifeq (%(build_library),M)
2095 # The module is linked from all the compiled .o files
2096 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2097                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2098                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2099                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2100 endif
2102 ifeq (%(build_abi),M)
2103 # Link static lib
2104 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2105 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2106 ifneq ($(BD_LINKLIB),)
2107 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2108 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2109 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2110 endif
2112 $(BD_LINKLIB) : | $(BD_LIBDIR)
2113 GLOB_MKDIRS += $(BD_LIBDIR)
2114 endif
2116 ifneq ($(BD_RELLINKLIB),)
2117 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2118 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2119 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2120 endif
2122 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2123 GLOB_MKDIRS += $(BD_LIBDIR)
2124 endif
2125 endif
2127 ifeq (%(build_library),M)
2128 # Link kernel object file
2129 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2131 # Make these symbols local
2132 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2133             UtilityBase ExpansionBase KeymapBase KernelBase
2135 BD_SYMBOLS := $(BD_KBASE)
2137 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2138 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2139 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2140 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2141 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2142 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2143         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2144         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2145         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2146 endif
2148 ## Dependency fine-tuning
2150 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2152 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2154 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2155 $(BD_MODULE) : | %(prefix)/%(moduledir)
2156 $(BD_KOBJ)   : | $(KOBJSDIR)
2157 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2159 # Some include files need to be generated before the .c can be parsed.
2160 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2162 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2163     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2164 $(BD_DEPS) : $(BD_DFILE_DEPS)
2165 endif
2167 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2168     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2169     %(objdir)/Makefile.%(modname)%(modtype) \
2170     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2171     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2172     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2173     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2174     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2175     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2176     $(BD_ENDOBJS)
2177 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2178 %(mmake)-clean ::
2179         @$(ECHO) "Cleaning up for module %(modname)"
2180         @$(RM) $(FILES)
2182 endif # $(TARGET) in $(BD_ALLTARGETS)
2183 %end
2184 #------------------------------------------------------------------------------
2186 #------------------------------------------------------------------------------
2187 # Build a module - ABI and library
2188 # Explanation of this macro is done in the developer's manual
2189 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2190   files="$(basename $(call WILDCARD, *.c))" \
2191   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2192   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2193   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2194   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2195   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2196   includedir= libdir=
2198 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2199    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2200    files="%(files)" cxxfiles="%(cxxfiles)" \
2201    linklibname="%(linklibname)" \
2202    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2203    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2204    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2205    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2206    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2207    includedir="%(includedir)" libdir="%(libdir)" \
2208    build_abi=M build_library=M
2210 %end
2211 #------------------------------------------------------------------------------
2214 #------------------------------------------------------------------------------
2215 # Build a module skeleton ABI
2216 # This is a stripped-down version of build_module, it only creates include
2217 # files and the linklibs.
2218 # This is used when for plugins or classes with the same API, but no actual
2219 # implementation here.
2220 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2221   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2222   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2223   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2224   compiler=target nostartup=yes archspecific=no \
2225   includedir= libdir=
2227 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2228   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2229   linklibname="%(linklibname)" \
2230   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2231   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2232   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2233   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2234   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2235   includedir="%(includedir)" libdir="%(libdir)" \
2236   build_abi=M build_library=
2238 %end
2239 #------------------------------------------------------------------------------
2241 #------------------------------------------------------------------------------
2242 # Build a module library - no includes nor linklibs
2243 # Explanation of this macro is done in the developer's manual
2244 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2245   files="$(basename $(call WILDCARD, *.c))" \
2246   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2247   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2248   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2249   uselibs= usehostlibs= \
2250   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2251   includedir= libdir=
2253 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2254    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2255    files="%(files)" cxxfiles="%(cxxfiles)" \
2256    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2257    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2258    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2259    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2260   includedir="%(includedir)" libdir="%(libdir)" \
2261    build_abi= build_library=M
2263 %end
2264 #------------------------------------------------------------------------------
2268 #------------------------------------------------------------------------------
2269 # Build a linklib.
2270 # - mmake is the mmaketarget
2271 # - libname is the baselibname e.g. lib%(libname).a will be created
2272 # - files are the C source files to include in the lib. The list of files
2273 #   has to be given without the .c suffix
2274 # - cxxfiles are C++ source files without suffix.
2275 #   NB: files will be matched in the order .cpp > .cxx > .cc
2276 # - asmfiles are the asm files to include in the lib. The list of files has to
2277 #   be given without the .s suffix
2278 # - objs additional object to link into the linklib. The objects have to be
2279 #   given with full absolute path and the .o suffix.
2280 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2281 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2282 # - cflags are the flags to compile the source (default $(CFLAGS))
2283 # - dflags are the flags used during makedepend (default equal to cflags)
2284 # - aflags are the flags used during assembling (default $(AFLAGS))
2285 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2286   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2287   includedir= \
2288   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2289   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2291 # assign and generate the local variables used in this macro
2292 BD_LIBNAME    := %(libname)
2293 BD_LINKLIB    := %(libdir)/lib%(libname).a
2295 BD_FILES      := %(files)
2296 BD_ASMFILES   := %(asmfiles)
2297 BD_CXXFILES := %(cxxfiles)
2299 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2300 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2301 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2303 BD_OBJS       := $(BD_ARCHOBJS) \
2304                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2305                  %(objs)
2306 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2308 BD_CFLAGS    := %(cflags)
2309 BD_CXXFLAGS := %(cxxflags)
2310 ifeq (%(lto),yes)
2311 ifeq (%(compiler),target)
2312 BD_CFLAGS    := $(LTO_CFLAGS) $(BD_CFLAGS)
2313 BD_CXXFLAGS := $(LTO_CFLAGS) $(BD_CXXFLAGS)
2314 endif
2315 endif
2316 ifneq (%(includedir),)
2317 BD_CFLAGS    += -I%(includedir)
2318 BD_CXXFLAGS += -I%(includedir)
2319 endif
2320 BD_CPPFLAGS := %(cppflags)
2321 BD_AFLAGS    := %(aflags)
2322 BD_DFLAGS    := %(dflags)
2323 BD_DXXFLAGS := %(dxxflags)
2325 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2328 %(mmake)-quick : %(mmake)
2330 #MM %(mmake) : includes-generate-deps
2331 %(mmake) : $(BD_LINKLIB)
2333 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2335 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2336     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS)
2337 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2338     compiler="%(compiler)" cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS)
2339 %rule_assemble basename=% targetdir="%(objdir)" \
2340     aflags=$(BD_AFLAGS)
2342 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2343 endif
2345 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2347 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2348 $(BD_LINKLIB) : | %(libdir)
2349 GLOB_MKDIRS += %(objdir) %(libdir)
2351 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2353 %(mmake)-clean ::
2354         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2355         @$(RM) $(FILES)
2357 %end
2358 #------------------------------------------------------------------------------
2361 #------------------------------------------------------------------------------
2362 # Build catalogs.
2363 # - mmake is the mmaketarget
2364 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2365 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2366 # - subdir is the destination subdirectory of the catalogs
2367 # - name is the name of the destination catalog, without the .catalog suffix
2368 # - source is the path to the generated source code file
2369 # - dir is the base destination directory (default $(AROS_CATALOGS))
2370 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2371 # - srcdir is the directory in which the *.cd and *.ct files are searched
2373 %define build_catalogs mmake=/A name=/A subdir=/A \
2374  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2375  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2377 ifeq (%(description),)
2378 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2379 else
2380 BD_DESC := %(description)
2381 endif
2383 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2385 ifeq (%(catalogs),)
2386 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2387 else
2388 BD_LNGS := %(catalogs)
2389 endif
2391 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2392 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2395 %(mmake) : $(BD_OBJS) %(source)
2397 $(BD_OBJS) : | $(BD_DIRS)
2398 GLOB_MKDIRS += $(BD_DIRS)
2400 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2401         @$(ECHO) "Creating   %(name) catalog for language $*."
2402         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2404 ifneq (%(source),)
2405 %(source) : BD_DESC := $(BD_DESC)
2406 %(source) : BD_SRC := $(BD_SRC)
2407 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2408         @$(ECHO) "Creating   %(name) catalog source file $@"
2409         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2410 endif
2412 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2414 %(mmake)-clean ::
2415         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2416         @$(RM) $(FILES)
2418 .PHONY: %(mmake) %(mmake)-clean
2420 %end
2421 #-----------------------------------------------------------------------------
2424 #-----------------------------------------------------------------------------
2425 # Build icons.
2426 # - mmake is the mmaketarget
2427 # - icons is a list of icon base names (i.e. without the .info suffix)
2428 # - dir is the destination directory
2429 # - srcdir is where *.png and *.info.src are sought
2430 #-----------------------------------------------------------------------------
2432 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2434 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2437 %(mmake) : $(BD_OBJS)
2439 ifeq (%(image),)
2441 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2442         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2443         @$(ILBMTOICON) $+ $@
2445 else
2447 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2448         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2449         @$(ILBMTOICON) $+ $@
2451 endif
2453 $(BD_OBJS) : | %(dir)
2454 GLOB_MKDIRS += %(dir)
2456 %(mmake)-clean : FILES := $(BD_OBJS)
2458 %(mmake)-clean ::
2459         @$(RM) $(FILES)
2461 .PHONY: %(mmake) %(mmake)-clean
2463 %end
2464 #-----------------------------------------------------------------------------
2467 #------------------------------------------------------------------------------
2468 # Compile files for an arch-specific replacement of code for a module
2469 # - files: the basenames of the C files to compile.
2470 # - asmfiles: the basenames of the asm files to assemble.
2471 # - mainmmake: the mmake of the module in the main directory to compile these
2472 #   arch specific files for.
2473 # - maindir: the object directory for the main module
2474 # - arch: the arch for which to compile these files. It can have the form
2475 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2476 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2477 # - dflags: the flags used during creation of dependency file. If not specified
2478 #   the same value as cflags will be used
2479 # - aflags: the flags used during assembling
2480 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2481 #   the target compiler is used
2482 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2483 cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2485 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2486     $(error no files or asmfiles given)
2487 endif
2489 ifneq (%(cxxfiles),)
2490     $(error cxx support is TODO)
2491 endif
2493 %buildid targets="%(mainmmake)-%(arch)"
2495 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2496 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2497 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2498 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2499 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2500 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2501 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2502 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2503 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2504 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2505 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2506 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2507 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2508 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2509 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2511 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2513 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2514 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2515 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2516 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2517 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2518 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2519 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2520 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2522 ifneq (%(modulename),)
2523 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2524 endif
2526 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2527     BD_TARGET := %(mainmmake)-%(arch)-quick
2528 else
2529     BD_TARGET := %(mainmmake)-%(arch)
2530 endif
2533 ifeq ($(TARGET),$(BD_TARGET))
2534 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2535 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2536 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2537 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2538 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2539 endif
2541 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2542 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2545 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2548 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2550 ifeq ($(findstring %(compiler),host kernel target),)
2551     $(error unknown compiler %(compiler))
2552 endif
2553 ifneq (%(modulename),)
2554 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2555 else
2556 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) %(cppflags)
2557 endif
2558 ifeq (%(compiler),target)
2559 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
2560 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
2561 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2562 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2563 endif
2564 ifeq (%(compiler),host)
2565 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2566 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2567 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2568 endif
2569 ifeq (%(compiler),kernel)
2570 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
2571 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
2572 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2573 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2574 endif
2576 ifeq ($(TARGET),$(BD_TARGET))
2577 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2578         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2579 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2580         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2581 endif
2583 ifeq (%(dflags),)
2584 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2585 else
2586 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags) %(cppflags)
2587 endif
2588 ifeq ($(TARGET),$(BD_TARGET))
2589 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2590         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2592 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2593         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2594 endif
2596 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2598 ifeq ($(TARGET),$(BD_TARGET))
2599 $(BD_OBJDIR$(BDID))/%.o : %.s
2600         %assemble_q
2601 $(BD_OBJDIR$(BDID))/%.o : %.S
2602         %assemble_q
2603 endif
2605 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2606 %end
2607 #------------------------------------------------------------------------------
2610 #------------------------------------------------------------------------------
2611 # generate asm files from c files (for debugging purposes)
2612 %define ctoasm_q
2613 %.s : %.c
2614         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2615         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2616 %end
2617 #------------------------------------------------------------------------------
2620 #------------------------------------------------------------------------------
2621 # Copy files from one directory to another.
2623 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2625 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2627 GLOB_MKDIRS += %(dst)
2629 .PHONY : %(mmake)
2632 %(mmake) : | %(dst) 
2633         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2635 %end
2636 #------------------------------------------------------------------------------
2639 #------------------------------------------------------------------------------
2640 # Copy a directory recursively to another place, preserving the original 
2641 # hierarchical structure
2643 # src: the source directory whose content will be copied.
2644 # dst: the directories where to copy src's content. If not existing, they will be made.
2645 # excludefiles: files which must not be copied. Path must be relative to src.
2647 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2649 .PHONY : %(mmake)
2652 %(mmake) :
2653         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2655 %end
2656 #------------------------------------------------------------------------------
2659 #------------------------------------------------------------------------------
2660 #   Copy include files into the includes directories. There are currently
2661 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2662 #   for building tools that need to run on the host system $(GENINCDIR). The
2663 #   $(GENINCDIR) path must not contain any references to the C runtime
2664 #   library header files.
2666 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2667     dir= compiler=target includedir=$(AROS_INCLUDES)
2669 ifeq ($(findstring %(compiler),host kernel target),)
2670 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2671 endif
2673 ifneq (%(dir),)
2674 TMP_DIR := %(dir)
2675 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2676 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2677 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2678 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2679 ifeq ($(TMP_DIRFIRST),/)
2680 BD_INC_PATH := %(dir)/
2681 else
2682 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2683 endif
2684 else
2685 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2686 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2687 endif
2689 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2690         @$(CP) $< $@
2692 ifeq (%(compiler),target)
2694 ifneq (%(dir),)
2695 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2696 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2697 else
2698 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2699 endif
2701 BD_INCL_FILES += $(BD_INCL_FILES2)
2703 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2704         @$(CP) $< $@
2705 endif
2708 %(mmake) : $(BD_INCL_FILES)
2710 .PHONY: %(mmake)
2712 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2713 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2714 %end
2715 #------------------------------------------------------------------------------
2718 #------------------------------------------------------------------------------
2719 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2720 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2721 STUBS_MEM := $(addsuffix .o,$(STUBS))
2722 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2723 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2724 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2726 #MM- linklibs : hidd-%(hidd)-stubs
2727 #MM- %(parenttarget): hidd-%(hidd)-stubs
2728 #MM hidd-%(hidd)-stubs : includes includes-copy
2729 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2731 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2732         %mklib_q from=$^
2734 $(STUBS_OBJ) : $(STUBS_SRC) 
2735         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT)" opt="%(cflags) %(cppflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2737 $(STUBS_DEP) : $(STUBS_SRC)
2738         %mkdepend_q flags="%(dflags) %(cppflags)"
2740 setup ::
2741         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2744 clean ::
2745         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2747 DEPS := $(DEPS) $(STUBS_DEP)
2749 %end
2750 #------------------------------------------------------------------------------
2753 #------------------------------------------------------------------------------
2754 # Build an imported source tree which uses the configure script from the
2755 # autoconf package.  This rule will try to "integrate" the produced files as
2756 # much as possible in the AROS build, for example by putting libraries in the
2757 # standard library directory, includes in the standard include directory, and
2758 # so on. You can however override this behaviour.
2760 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2761 # be %(bindir) (or its deduced value) when running "make install", and
2762 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2763 # configure script some more parameters whose value depends upon the PROGDIR
2764 # env var, so that the program gets all its stuff installed in the proper place
2765 # when building it, but when running it from inside AROS it can also find that
2766 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2767 # the configuration parameters set when running ./configure
2769 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2770 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2771 # to the name which has to follow it.
2773 # Arguments:
2775 #     - mmake           = the meta make target.
2776 #     - package         = name of the package to be built.
2777 #     - srcdir          = the location of the unpacked source code. Defaults
2778 #                         to $(SRCDIR)/$(CURDIR).
2779 #     - prefix          = the target directory. Must be an absolute path of the
2780 #                         host system. Defaults to $(AROS_CONTRIB).
2781 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2782 #                         Defaults to the value of the prefix option.
2783 #     - extraoptions    = additional options for the configure script.
2784 #     - usecppflags      = enable the use of cpp flags. some external configure
2785 #                         scripts will not set their own cppflags if it is already
2786 #                         set, so this allows them to be disabled (unless you can provide
2787 #                         all the options they would need)
2788 #     - extracppflags      = additional preprocessor flags.
2789 #     - extracflags     = additional flags to use with the C compiler.
2790 #     - extracxxflags   = additional flags to use with the C++ compiler.
2791 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2792 #                         Defaults to the value of the nix argument.
2793 #     - nix             = enable u*nix path handling, i.e. a path like
2794 #                         /progdir//./file will be translated to
2795 #                         progdir:file during run-time. Defaults to no.
2796 #     - compiler        = target, host or kernel. Defaults to target.
2797 #     - install_target  = the command used for installing. Defaults to install. Leave
2798 #                         it empty if you want to suppress installing.
2799 #     - preconfigure    = a metatarget which is executed before configure is called.
2800 #     - postconfigure   = a metatarget which is executed after configure is called.
2801 #     - postinstall     = a metatarget which is executed after installing.
2802 #     - install_env     = set additional options for installing.
2803 #     - use_build_env   = if yes the configuration environment is used for
2804 #                         installing, too. Defaults to no.
2806 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2807 # like this:
2809 # if nix_dir_layout
2810 #    --prefix = $(aros_prefix)
2811 #    progdir = $(aros_prefix)/bin
2812 # else
2813 #    if nix
2814 #        --prefix = /PROGDIR
2815 #        --bindir = /PROGDIR
2816 #        --sbindir = /PROGDIR
2817 #        --libdir = /LIB
2818 #        --includedir = /INCLUDE
2819 #        --oldincludedir = /INCLUDE   
2820 #    else
2821 #        --prefix = $(aros_prefix)
2822 #    endif
2824 #    progdir = $(aros_prefix)
2826 #    # Install options
2827 #    bindir = $(prefix)
2828 #    sbindir = $(prefix)
2829 #    libdir = $(AROS_LIB)
2830 #    includedir = $(AROS_INCLUDES)
2831 #    oldincludedir = $(AROS_INCLUDES)
2832 # endif
2835 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
2836     prefix= gendir= basedir=$(CURDIR) extraoptions= \
2837     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
2838     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
2839     install_target=install preconfigure= postconfigure= postinstall= \
2840     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes
2842 ifneq (%(prefix),)
2843     %(mmake)-prefix := %(prefix)
2844 else
2845     %(mmake)-prefix := $(AROS_CONTRIB)
2846 endif
2848 ifneq (%(aros_prefix),)
2849     %(mmake)-aros_prefix := %(aros_prefix)
2850 else
2851     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2852 endif
2854 BD_NIXFLAG ?= -nix
2856 ifeq (%(nix),yes)
2857     %(mmake)-nix    := $(BD_NIXFLAG)
2858     %(mmake)-volpfx := /
2859     %(mmake)-volsfx := /
2860     
2861     ifeq (%(nix_dir_layout),)
2862         %(mmake)-nix_dir_layout := yes
2863     endif
2864 else
2865     %(mmake)-volsfx := :
2866     
2867     ifeq (%(nix_dir_layout),)
2868         %(mmake)-nix_dir_layout := no
2869     endif
2870 endif
2872 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2874 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2875         exec_prefix=$(%(mmake)-prefix) %(install_env)
2877 # Check if chosen compiler is valid
2878 ifeq ($(findstring %(compiler),host target kernel),)
2879   $(error unknown compiler %(compiler))
2880 endif
2882 # Set legacy 'host' variable based on chosen compiler
2883 ifeq (%(compiler),host)
2884     host := yes
2885     ifeq (%(basedir),)
2886         %(mmake)-pkgbasedir := $(HOSTGENDIR)
2887     else
2888         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
2889     endif
2890 else
2891     host := no
2892     ifeq (%(basedir),)
2893         %(mmake)-pkgbasedir := $(GENDIR)
2894     else
2895         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
2896     endif
2897 endif
2898 ifneq (%(gendir),)
2899     ifeq (%(basedir),)
2900         %(mmake)-pkgbasedir := %(gendir)
2901     else
2902         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
2903     endif
2904 endif
2906 ifeq (%(package),)
2907     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
2908 else
2909     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
2910 endif
2912 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2913 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2915 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2916     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2917     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2918 else
2919     ifeq (%(nix),yes)
2920         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2921         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2922     else
2923         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2924     endif
2926     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2927     
2928     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2929         sbindir=$(%(mmake)-prefix) \
2930         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2931         oldincludedir=$(AROS_INCLUDES) %(install_env)
2932 endif
2934 ifneq ($(DEBUG),yes)
2935     %(mmake)-s_flag = -s
2936 endif
2938 # Set up build environment, and options for configure script
2939 ifeq (%(compiler),host)
2940     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2941     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2942     # since that won't get picked up during configure.
2943     # We also cannot pass in the compiler including std flags so we need to use
2944     # the "plain" host compiler.
2945     %(mmake)-cfg-env := %(config_env_extra) \
2946         CPP="$(HOST_CPP)" \
2947         CXXCPP="$(HOST_CPP)" \
2948         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2949         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2950         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2951         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2952         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2953         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2954         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2955         TARGET_AS="$(TARGET_AS)" \
2956         OBJCOPY="$(OBJCOPY)" \
2957         TARGET_RANLIB="$(RANLIB)" \
2958         TARGET_STRIP="$(STRIP_PLAIN)" \
2959         TARGET_NM="$(NM_PLAIN)" \
2960         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2961 endif
2962 ifeq (%(compiler),target)
2963     %(mmake)-cfg-env := %(config_env_extra) \
2964         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
2965         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
2966     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2967         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2968         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2969         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2970         LD="$(strip $(TARGET_LD))"
2971 ifeq (%(crossbuild),yes)
2972     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
2973         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
2974 ifeq (%(usecppflags),yes)
2975     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2976 endif
2977 else
2978     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2979         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
2980 ifeq (%(usecppflags),yes)
2981     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2982 endif
2983 endif
2984     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2985         CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
2986         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
2987         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
2988         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
2989         LD_FOR_BUILD="$(strip $(HOST_LD))" \
2990         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))" \
2991         CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2992         CFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2993         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2994         CXXFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2995         LD_FOR_HOST="$(strip $(TARGET_LD))" \
2996         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2997         CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2998         CFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2999         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3000         CXXFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3001         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3002         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3003         AR="$(strip $(AR_PLAIN))" \
3004         AS="$(strip $(TARGET_AS))" \
3005         OBJCOPY="$(strip $(OBJCOPY))" \
3006         RANLIB="$(strip $(RANLIB))" \
3007         STRIP="$(strip $(STRIP_PLAIN))" \
3008         TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3009         TARGET_CFLAGS="$(strip $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3010         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3011         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3012         TARGET_AS="$(strip $(TARGET_AS))" \
3013         TARGET_RANLIB="$(strip $(RANLIB))" \
3014         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3015         TARGET_NM="$(strip $(NM_PLAIN))"
3016 ifeq (%(buildflags),yes)
3017     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3018     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3019     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3020 endif
3021 ifeq (%(gnuflags),yes)
3022     %(mmake)-config_opts += --without-pic --disable-shared
3023     %(mmake)-config_opts += --disable-nls --without-x
3024 endif
3025 endif
3026 ifeq (%(compiler),kernel)
3027     %(mmake)-cfg-env := %(config_env_extra) \
3028         CPP="$(KERNEL_CPP)" \
3029         CXXCPP="$(KERNEL_CPP)" \
3030         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
3031         CFLAGS="$(strip $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3032         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
3033         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3034 ifeq (%(usecppflags),yes)
3035     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3036 endif
3037     %(mmake)-cfg-env += AS="$(KERNEL_AS)" \
3038         CC_FOR_BUILD="$(HOST_DEF_CC)" \
3039         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3040         CXX_FOR_BUILD="$(HOST_CXX)" \
3041         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3042         RANLIB="$(RANLIB)" \
3043         TARGET_RANLIB="$(RANLIB)" \
3044         TARGET_STRIP="$(STRIP_PLAIN)" \
3045         TARGET_NM="$(NM_PLAIN)"
3046 ifeq (%(buildflags),yes)
3047     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3048     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3049     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3050 endif
3051 ifeq (%(gnuflags),yes)
3052     %(mmake)-config_opts += --without-pic --disable-shared
3053     %(mmake)-config_opts += --disable-nls --without-x
3054 endif
3055 endif
3057 ifeq (%(use_build_env),yes)
3058     BUILD_ENV := $(%(mmake)-cfg-env)
3059 endif
3061 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3062 # in an ideal world, we would depend on the files in the source directory,
3063 # so we could copy them when they change. unfortunately filenames with
3064 # spaces causes problems with this
3065 $(%(mmake)-pkgdir)/.local-copy:
3066         %mkdirs_q $(%(mmake)-pkgdir)
3067         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3068         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3070 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3072     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3073 else
3074     %(mmake)-cfg-srcdir=%(srcdir)
3075 endif
3076 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3078 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3080 # When building for the host, we don't need to build the
3081 # linklibs - this is especially true when building the
3082 # crosstool toolchain on 'foreign' architectures (such as
3083 # building PPC on x86)
3085 #MM- %(mmake)-host : setup includes %(mmake)-quick
3086 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3087 #MM- %(mmake): %(mmake)-%(compiler)
3089 # Using -j1 in install_command may result in a warning but finally
3090 # it does its job. make install for gcc does not work reliably for -jN
3091 # where N > 1.
3092 ifneq (%(install_target),)
3093     %(mmake)-install_command = \
3094         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3095         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3096         $(%(mmake)-make-env) %(install_target) -j1
3098     %(mmake)-uninstall_command = \
3099     $(RM) $(%(mmake)-installflag) && \
3100     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3101     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3102 else
3103     %(mmake)-install_command   := true
3104     %(mmake)-uninstall_command := true
3105 endif
3107 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3110 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3113 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3115 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3116         @$(IF) ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3117             $(RM) $(%(mmake)-installflag) && \
3118             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3119             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3120             $(%(mmake)-install_command) && \
3121             $(TOUCH) $@ -r $^; \
3122         fi
3124 $(%(mmake)-pkgdir)/.files-touched:
3125         %mkdirs_q $(%(mmake)-pkgdir)
3126         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3127         $(TOUCH) $@
3130 %(mmake)-uninstall :
3131         $(%(mmake)-uninstall_command)
3134 %(mmake)-configure : $(%(mmake)-configflag)
3136 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3137 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3138         @$(RM) $@
3139         %mkdirs_q $(%(mmake)-pkgdir)
3140         @$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3141         @cd $(%(mmake)-pkgdir) && \
3142         find . -name config.cache -exec $(RM) '{}' \; && \
3143         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3144         $(TOUCH) $@
3147 %(mmake)-clean : %(mmake)-uninstall
3148         @$(RM) $(%(mmake)-pkgdir)
3149 %end
3150 #------------------------------------------------------------------------------
3153 #------------------------------------------------------------------------------
3154 # Build an imported source tree which uses cmake 
3156 # Arguments:
3158 #     - mmake           = the meta make target.
3159 #     - package         = name of the package to be built.
3160 #     - srcdir          = the location of the unpacked source code. Defaults
3161 #                         to $(SRCDIR)/$(CURDIR).
3162 #     - prefix          = the target directory. Must be an absolute path of the
3163 #                         host system. Defaults to $(AROS_CONTRIB).
3164 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3165 #                         Defaults to the value of the prefix option.
3166 #     - extraoptions    = additional options for the cmake script.
3167 #     - usecppflags     = enable the use of cpp flags. some external cmake
3168 #                         scripts will not set their own cppflags if it is already
3169 #                         set, so this allows them to be disabled (unless you can provide
3170 #                         all the options they would need)
3171 #     - cppflags        = preprocessor flags.
3172 #     - cflags          = flags to use with the C compiler.
3173 #     - cxxflags        = flags to use with the C++ compiler.
3174 #     - installoptions    = additional options for the install step.
3177 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3178     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3179     usecppflags=yes cppflags=$(CPPFLAGS) cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3181 ifneq (%(prefix),)
3182     %(mmake)-prefix := %(prefix)
3183 else
3184     %(mmake)-prefix := $(AROS_CONTRIB)
3185 endif
3187 ifneq (%(aros_prefix),)
3188     %(mmake)-aros_prefix := %(aros_prefix)
3189 else
3190     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3191 endif
3193 ifeq (%(compiler),host)
3194     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3195     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3196     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3197     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3198     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3199     ifeq (%(usecppflags),yes)
3200         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3201     endif
3202     %(mmake)-cmake_opts += -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))"
3203     ifeq (%(package),)
3204         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3205     else
3206         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3207     endif
3208 else
3209     BD_LDFLAGS   := %(ldflags)
3210     BD_CFLAGS := %(cflags) 
3211     BD_CXXFLAGS := %(cxxflags)
3212     BD_CPPFLAGS := %(cppflags)
3213     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3214     ifeq (%(usecppflags),yes)
3215         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3216     endif
3217     %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))" -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3218     ifeq (%(package),)
3219         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3220     else
3221         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3222     endif
3223 endif
3224 ifneq (%(gendir),)
3225     ifeq (%(package),)
3226         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3227     else
3228         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3229     endif
3230 endif
3232 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3233 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3235 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3237 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3239 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3242 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3244 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3245         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3246             $(RM)  $(%(mmake)-installflag) && \
3247             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3248             cd $(%(mmake)-pkgdir) && \
3249             cmake %(installoptions) -P cmake_install.cmake && \
3250             $(TOUCH) $@ -r $^; \
3251         fi
3253 $(%(mmake)-pkgdir)/.files-touched:
3254         %mkdirs_q $(%(mmake)-pkgdir)
3255         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3256         $(TOUCH) $@
3259 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3261 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3262 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3263         $(RM) $@
3264         %mkdirs_q $(%(mmake)-pkgdir)
3265         cd $(%(mmake)-pkgdir) && \
3266         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3267         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3268         $(TOUCH) $@
3271 %(mmake)-clean : %(mmake)-uninstall
3272         @$(RM) $(%(mmake)-pkgdir)
3273 %end
3274 #------------------------------------------------------------------------------
3277 #------------------------------------------------------------------------------
3278 # Given an archive name, patches names and locations where to find them, fetch
3279 # the archive and the patches from any of those locations, unpack the archive
3280 # and then apply the patches.
3282 # Locations currently supported are http and ftp sites, plus local filesystem
3283 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3284 # the fetch.sh script needs to be modified, since this macro relies on that script.
3286 # Arguments:
3288 #     - mmake           = mmaketarget
3289 #     - archive_origins = list of locations where to find the archive. They are tried
3290 #                         in sequence, until the archive is found and fetching it 
3291 #                         succeeded. If not specified, the current directory is assumed.
3292 #     - archive         = the archive name. Mandatory.
3293 #     - suffixes        = a list of suffixes to append to the package name plus the
3294 #                         version. Each one of them is tried until a matching archive is
3295 #                         found. They are appended to patches and these are tried the
3296 #                         same way as packages are.
3297 #     - location        = the local directory where to put the fetched archive and patches.
3298 #                         If not specified, the directory specified by destination is used.
3299 #     - destination     = the directory to unpack the archive to.
3300 #                         If not specified, the current directory is assumed.
3301 #     - patches_origins = list of locations where to find the patches. They are tried
3302 #                         in sequence, until a patch is found and fetching it 
3303 #                         succeeded. If not specified, the current directory is assumed.
3304 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3305 #                         patch_name[:[patch_subdir][:patch_opt]].
3307 #                             - patch_name   = the name of the patch file
3308 #                             - patch_subdir = the directory within \destination\ where to
3309 #                                              apply the patch.
3310 #                             - patch_opt    = any options to pass to the `patch' command
3311 #                                              when applying the patch.
3312 #                         
3313 #                         The patch_subdir and patch_opt fields are optional.
3315 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3316     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3318 .PHONY: %(mmake)
3320 ifneq (%(location),)
3321     %(mmake)-location := %(location)
3322 else
3323     %(mmake)-location := %(destination)
3324 endif
3327 %(mmake) :
3328         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3329         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3330 %end
3331 #------------------------------------------------------------------------------
3334 #------------------------------------------------------------------------------
3335 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3336 # unpatched source tree and runs diff against this and a previously fetched and possibly
3337 # patched tree. Depending on what happens after patching during a normal build it might
3338 # give best results if the new patch is created directly after fetch.
3340 # Arguments:
3342 #     - mmake       = mmaketarget
3343 #     - archive     = archive base name
3344 #     - srcdir      = the top level directory the package is unpacked to, useful if
3345 #                     an archive unpacks to a directory other than its name suggests.
3346 #                     this should not be deeper than a single path element.
3347 #     - suffixes    = a list of suffixes to append to the the package name plus the
3348 #                     version. Each one of them is tried until a matching archive is
3349 #                     found.
3350 #     - destination = the directory to unpack the archive to.
3351 #     - excludes    = diff patterns to exclude files or directories from the patch
3353 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3355 .PHONY: %(mmake)
3357 ifneq (%(excludes),)
3358     %(mmake)-exclude := -X ./exclude.patterns
3359 endif
3361 ifneq (%(srcdir),)
3362     %(mmake)-srcdir := %(srcdir)
3363 else
3364     %(mmake)-srcdir := %(archive)
3365 endif
3367 #MM- %(mmake) : %(mmake)-diff
3368 #MM- %(mmake)-quick : %(mmake)-diff
3371 %(mmake)-diff:
3372         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3373         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3374         cd %(destination)/tmp ; \
3375         $(FOR) f in %(excludes) ; do \
3376             $(ECHO) $$f >> ./exclude.patterns ; \
3377         done ; \
3378         diff -ruN $(%(mmake)-exclude) \
3379             $(%(mmake)-srcdir) \
3380             $(%(mmake)-srcdir).aros \
3381             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3382         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3383         $(RM) %(destination)/tmp
3384 %end
3385 #------------------------------------------------------------------------------
3388 #------------------------------------------------------------------------------
3389 # Joins the features of %fetch and %build_with_configure.
3391 # If a patch is provided, it *must* be named the following way:
3393 #    <package name>-<version number>-aros.diff
3395 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3396 # CD'ing into the archive's extracted directory.
3398 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3399 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3400 # to make that patch fully comprehensive.
3402 # Arguments:
3404 #    - mmake            = the meta make target.
3405 #    - package          = the GNU package name, sans version and archive format suffixes.
3406 #    - subpackage       = ???
3407 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3408 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3409 #    - version          = the package's version number, or otherwise any other version string.
3410 #                         It gets appended to the package name to form the basename of the archive.
3411 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3412 #                         version. Each one of them is tried until a matching archive is found.
3413 #                         Defaults to "tar.bz2 tar.gz".
3414 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3415 #    - builddir         = override the location we expect to run configure/make in.
3416 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3417 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3418 #                         fetched or not. Default to no.
3419 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3420 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3421 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3422 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3423 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3424 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3425 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3426 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3427 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3428 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3429 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3430 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3431 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3432 #    - nix              = same meaning as the one for the %build_with_configure macro.
3433 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3434 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3436 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3437     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3438     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3439     extraoptions=  usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3440     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no buildflags=yes gnuflags=yes
3442 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3443 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3444 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3445 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3447 %(mmake)-archbase  := %(package)-%(version)
3449 ifeq (%(compiler),host)
3450     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3451 else
3452     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3453 endif
3455 ifeq (%(prefix),)
3456     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3457 else
3458     %(mmake)-prefix := %(prefix)
3459 endif
3461 ifneq (%(subpackage),)
3462     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3463 else
3464     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3465 endif
3467 ifneq (%(srcdir),)
3468     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3469 else
3470     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3471 endif
3473 ifneq (%(builddir),)
3474     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3475 else
3476     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3477 endif
3479 ifeq (%(patch),yes)
3480     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3481 else
3482     %(mmake)-%(subpackage)-patches_specs := ::
3483 endif
3485 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3486     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3487     archive_origins=". %(package_repo)" \
3488     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3490 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3491     archive=$(%(mmake)-%(subpackage)-archbase) \
3492     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3493     suffixes="%(suffixes)" \
3494     destination=$(%(mmake)-portdir)
3496 #MM- %(mmake) : %(mmake)-%(subpackage)
3498 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3500 %(mmake)-%(subpackage)-package-basename := \
3501     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3503 ifneq (%(create_pkg),no)
3504     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3505 endif
3507 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3508      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3509      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3510      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3511      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3512      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" buildflags=%(buildflags) gnuflags=%(gnuflags)
3514 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3515 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3518 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3520 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3521 #that $^ and $@ have exactly the same mtime, and in that case make tries
3522 #to rebuild $@ again, which would fail because the directory where
3523 #the package got installed would not exist anymore. 
3524 #We work this around by using an if statement to manually check the mtimes.
3525 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3526         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -f $@; then \
3527             $(RM) $@ ; \
3528             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3529             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3530             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3531             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3532             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3533             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3534         fi
3535 %end
3536 #------------------------------------------------------------------------------
3539 #------------------------------------------------------------------------------
3540 # Joins the features of %fetch and %build_with_configure, taking advantage of
3541 # the naming scheme of GNU packages. GNU packages names are in the form
3543 #     <package name>-<version number>.<archive format suffix>
3545 # If a patch is provided, it *must* be named the following way:
3547 #    <package name>-<version number>-aros.diff
3549 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3550 # CD'ing into the archive's extracted directory.
3552 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3553 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3554 # to make that patch fully comprehensive.
3556 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3558 # Arguments:
3560 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3562 #    - prefix           = defaults to $(GNUDIR).
3563 #    - aros_prefix      = defaults to /GNU.
3565 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3566     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3567     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3568     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracppflags= extracxxflags="$(OPTIMIZATION_CFLAGS)"
3570 GNU_REPOSITORY := gnu://
3572 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3573     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3574     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3575     patch="%(patch)" patch_repo="%(patch_repo)" \
3576     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3577     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=%(nix)
3579 %end
3580 #------------------------------------------------------------------------------
3583 #------------------------------------------------------------------------------
3584 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3585 # that the package is a "Developer" package, and as such it needs to be placed
3586 # under the $(AROS_DEVELOPER) directory, as a default. 
3588 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3589 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3590 # "mmake" argument, because the metatarget is implicitely defined as
3592 #     #MM- development-%(package)
3594 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3595     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3596     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3597     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracppflags= extracxxflags="$(OPTIMIZATION_CFLAGS)"
3599 #MM- development : development-%(package)
3602 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3603    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3604    package_repo="%(package_repo)" \
3605    patch="%(patch)" patch_repo="%(patch_repo)" \
3606    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3607    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" nix=%(nix)
3610 postinstall-%(package)-delete-la-files:
3611         $(RM) %(prefix)/lib/*.la
3613 %end
3614 #------------------------------------------------------------------------------
3616 # Builds a kickstart package in PKG format
3618 # Arguments:
3620 #    - mmake   = target name
3621 #    - file    = destination file name with path
3623 # Other arguments are self-explanatory
3625 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3626     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3628 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3629 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3630 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3631 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3632 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3633 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3635 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3636 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3637 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3638 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3639 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3640 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3642 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3643     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3644 PKG_DIR   := $(dir %(file))
3647 %(mmake) : %(file)
3650 %(mmake)-quick : %(file)
3652 %(file): $(PKG_FILES) | $(PKG_DIR)
3653         @$(ECHO) Packaging $@...
3654         @$(SRCDIR)/tools/package/pkg c $@ $^
3656 %compress_file mmake="%(mmake)" file="%(file)"
3658 GLOB_MKDIRS += $(PKG_DIR)
3660 %end
3662 #------------------------------------------------------------------------------
3663 # Compresses %(file) with a gzip.
3664 # Good in conjunction with for example %build_prog
3666 %define compress_file mmake=/A file=/A
3668 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3671 %(mmake)-gz-quick : %(file).gz
3673 %(file).gz: %(file)
3674         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3675         @gzip -9 -f $^
3677 %end
3679 #------------------------------------------------------------------------------
3680 # Links a kickstart module in ELF format
3681 # Arguments are similar to make_package
3683 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3684     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3686 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3687 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3688 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3689 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3690 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3691 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3693 ifeq (%(startup),)
3694     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3695 else
3696     KOBJ_STARTUP := %(startup)
3697 endif
3699 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3701 TMP_LDFLAGS := %(ldflags)
3703 # Make a list of the lib files this program depends on.
3704 # In LDFLAGS remove white space between -L and directory
3705 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3706 # Filter out only the libdirs and remove -L
3707 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3708 # Add trailing /
3709 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3710 # Add normal linklib path
3711 TMP_DIRS += $(AROS_LIB)/
3712 # add lib and .a to static linklib names
3713 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3714 # search for the linklibs in the given path, ignore ones not found
3715 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3716     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3719 TMP_DIRS += $(dir %(file))
3720 ifneq (%(map),)
3721     TMP_LDFLAGS += $(GENMAP) %(map)
3722     TMP_DIRS    += $(dir %(map))
3723 endif
3725 #MM %(mmake) : %(deps)
3728 %(mmake) : %(file)
3731 %(mmake)-quick : %(file)
3733 %(file): KOBJS := $(KOBJS)
3734 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3735                     -static -nosysbase -Wl,-Ur
3736 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3737 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3738         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3739         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3740 ifeq ($(DEBUG),yes)
3741         @$(STRIP) $@ --only-keep-debug -o $@.dbg
3742 endif
3743         @$(STRIP) $@
3745 %compress_file mmake="%(mmake)" file="%(file)"
3747 GLOB_MKDIRS += $(TMP_DIRS)
3749 %end