export the kernel cpp flags
[AROS.git] / config / make.tmpl
blobb3d3c08a5bfb15a0718e197bf4e260319e5d2a7d
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) $(CPPFLAGS)" from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                         $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                         $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51                 else \
52                         $(NOP) ; \
53                 fi ; \
54         else \
55                 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57                 exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd="$(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) cppflags=$(CPPFLAGS) targetdir=
873 ifeq (%(targetdir),)
874 %(basename).o : AFLAGS := %(aflags)
875 %(basename).o : CPPFLAGS := %(cppflags)
876 %(basename).o : %(basename).s
877         %assemble_q
878 %(basename).o : %(basename).S
879         %assemble_q
881 else
882 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
883 %(targetdir)/$(notdir %(basename)).o : CPPFLAGS := %(cppflags)
884 %(targetdir)/$(notdir %(basename)).o : %(basename).s
885         %assemble_q
886 %(targetdir)/$(notdir %(basename)).o : %(basename).S
887         %assemble_q
889 endif
890 %end
891 #------------------------------------------------------------------------------
894 #------------------------------------------------------------------------------
895 # Generate a rule to assemble multiple source files to an object file. The
896 # generated file will be put in the object directory with the directory part
897 # of the source file stripped off.
898 # options
899 # - basenames: the basenames of the files to compile. The names may include
900 #   relative or absolute path names. No wildcard is allowed
901 # - aflags (default $(AFLAGS)): the flags to use for assembly
902 # - targetdir: the directory to put the .o file and the .d file. By default
903 #   it is put in the same directory as the .c file. When targetdir is not
904 #   empty, path names will be stripped from the file names so that all files
905 #   are in that dir and not in subdirectories.
906 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A aflags=$(AFLAGS) cppflags=$(CPPFLAGS) targetdir= suffix=.s
908 ifeq (%(targetdir),)
909 TMP_TARGETS := $(addsuffix .o,%(basenames))
910 TMP_WILDCARD := %
911 else
912 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
913 TMP_WILDCARD := %(targetdir)/%
915 # Be sure that all .s files are generated
916 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
918 # Be sure that all .c files are found
919 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
920 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
921 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
922 ifneq ($(TMP_DIRS),)
923     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
924     vpath %%(suffix) $(TMP_DIRS)
925 endif
927 endif
929 BD_ASSEMBLER ?= %(cmd)
931 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
933 $(TMP_TARGETS) : AFLAGS := %(aflags)
934 $(TMP_TARGETS) : CPPFLAGS := %(cppflags)
935 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
936         %assemble_q cmd=$(TMP_CMD)
937 %end
938 #------------------------------------------------------------------------------
941 #------------------------------------------------------------------------------
942 # Link %(objs) to %(prog) using the libraries in %(uselibs)
943 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
944     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
946 TMP_EXTRA_LDFLAGS := 
947 TMP_EXTRA_LIBS :=
948 ifeq (%(nix),yes)
949     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
950 endif
951 ifeq (%(usestartup),no)
952     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
953 endif
954 ifeq (%(detach),yes)
955     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
956 endif
958 # Make a list of the lib files this program depends on.
959 # In LDFLAGS remove white space between -L and directory
960 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
961 # Filter out only the libdirs and remove -L
962 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
963 # Add trailing /
964 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
965 # Add normal linklib path
966 TMP_DIRS += $(AROS_LIB)/
967 # add lib and .a to static linklib names
968 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
969 ifeq (%(usestartup),yes)
970     TMP_LIBS += startup.o
971 endif
972 ifeq (%(detach),yes)
973     TMP_LIBS += detach.o
974 endif
975 # search for the linklibs in the given path, ignore ones not found
976 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
977     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
980 %(prog) : OBJDIR := %(objdir)
981 %(prog) : OBJS := %(objs)
982 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
983 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
984 %(prog) : %(objs) $(TMP_DEPLIBS)
985         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
986 %end
987 #------------------------------------------------------------------------------
990 #------------------------------------------------------------------------------
991 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
992 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
993 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
994     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
995     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
997 TMP_EXTRA_LDFLAGS := 
998 TMP_EXTRA_LIBS :=
999 ifeq (%(nix),yes)
1000     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1001 endif
1002 ifeq (%(usestartup),no)
1003     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1004 endif
1005 ifeq (%(detach),yes)
1006     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1007 endif
1009 # Make a list of the lib files the programs depend on.
1010 # In LDFLAGS remove white space between -L and directory
1011 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1012 # Filter out only the libdirs and remove -L
1013 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1014 # Add trailing /
1015 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1016 # Add normal linklib path
1017 TMP_DIRS += $(AROS_LIB)/
1018 # add lib and .a to static linklib names
1019 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1020 # search for the linklibs in the given path, ignore ones not found
1021 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1022     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1024 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1026 $(TMP_PROGS) : OBJDIR := %(objdir)
1027 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1028 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1029 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1030         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1031 %end
1032 #------------------------------------------------------------------------------
1035 #------------------------------------------------------------------------------
1036 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1037 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1039 ifeq (%(linker),target)
1040 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1041 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1042 endif
1043 ifeq (%(linker),host)
1044 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1045 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1046 endif
1047 ifeq (%(linker),kernel)
1048 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1049 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1050 endif
1052 %(libdir)/lib%(libname).a : %(objs)
1053         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1054 %end
1055 #------------------------------------------------------------------------------
1057 #------------------------------------------------------------------------------
1058 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1059 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1060 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1061     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1063 TMP_LDFLAGS  := %(ldflags)
1064 # Make a list of the lib files the programs depend on.
1065 # In LDFLAGS remove white space between -L and directory
1066 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1067 # Filter out only the libdirs and remove -L
1068 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1069 # Add trailing /
1070 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1071 # Add normal linklib path
1072 TMP_DIRS += $(AROS_LIB)/
1073 # add lib and .a to static linklib names
1074 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1075 # search for the linklibs in the given path, ignore ones not found
1076 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1077     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1080 %(module) : LIB_NAMES := %(uselibs)
1081 %(module) : OBJS := %(objs)
1082 %(module) : ENDTAG := %(endobj)
1083 %(module) : ERR := %(err)
1084 %(module) : OBJDIR := %(objdir)
1085 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1086 ifeq (%(usehostlibs),)
1087 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1088 else
1089 # Warning: the -L/usr/lib here can result in modules
1090 # linking against host libs instead of AROS libs (e.g stdc++) !!
1091 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1092                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1093 endif 
1094 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1095         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1097 %end
1098 #------------------------------------------------------------------------------
1101 #------------------------------------------------------------------------------
1102 # Generate the libdefs.h include file for a module.
1103 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1105 TMP_TARGET := %(modname)_libdefs.h
1106 TMP_DEPS := $(GENMODULE)
1107 TMP_OPTS := 
1108 ifneq (%(conffile),)
1109     ifeq ($(dir %(conffile)),./)
1110         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1111         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1112     else
1113         TMP_OPTS += -c %(conffile)
1114         TMP_DEPS += %(conffile)
1115     endif 
1116 else
1117     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1118     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1119 endif
1120 ifneq (%(modsuffix),)
1121     TMP_OPTS += -s %(modsuffix)
1122 endif
1123 ifneq (%(targetdir),)
1124     TMP_OPTS += -d %(targetdir)
1125     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1126 endif
1127 ifneq (%(version),)
1128     TMP_OPTS += -v %(version)
1129 endif
1131 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1132 $(TMP_TARGET) : MODNAME := %(modname)
1133 $(TMP_TARGET) : MODTYPE := %(modtype)
1134 $(TMP_TARGET) : $(TMP_DEPS)
1135         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1136         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1137 %end
1138 #------------------------------------------------------------------------------
1140 #------------------------------------------------------------------------------
1141 # Generate the _lib.fd file for a module.
1142 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1144 TMP_TARGET := %(modname)_lib.fd
1145 TMP_DEPS := $(GENMODULE)
1146 TMP_OPTS := 
1147 ifneq (%(conffile),)
1148     ifeq ($(dir %(conffile)),./)
1149         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1150         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1151     else
1152         TMP_OPTS += -c %(conffile)
1153         TMP_DEPS += %(conffile)
1154     endif 
1155 else
1156     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1157     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1158 endif
1159 ifneq (%(modsuffix),)
1160     TMP_OPTS += -s %(modsuffix)
1161 endif
1162 ifneq (%(targetdir),)
1163     TMP_OPTS += -d %(targetdir)
1164     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1165 endif
1167 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1168 $(TMP_TARGET) : MODNAME := %(modname)
1169 $(TMP_TARGET) : MODTYPE := %(modtype)
1170 $(TMP_TARGET) : $(TMP_DEPS)
1171         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1172         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1173 %end
1174 #------------------------------------------------------------------------------
1176 #------------------------------------------------------------------------------
1177 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1178 # generated file in this Makefile
1179 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1180     targetdir=
1182 TMP_TARGET := Makefile.%(modname)%(modtype)
1183 TMP_DEPS := $(GENMODULE)
1184 TMP_OPTS := 
1185 ifneq (%(conffile),)
1186     ifeq ($(dir %(conffile)),./)
1187         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1188         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1189     else
1190         TMP_OPTS += -c %(conffile)
1191         TMP_DEPS += %(conffile)
1192     endif 
1193 else
1194     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1195     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1196 endif
1197 ifneq (%(modsuffix),)
1198     TMP_OPTS += -s %(modsuffix)
1199 endif
1200 ifneq (%(targetdir),)
1201     TMP_OPTS += -d %(targetdir)
1202     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1203 endif
1205 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1206 $(TMP_TARGET) : MODNAME := %(modname)
1207 $(TMP_TARGET) : MODTYPE := %(modtype)
1208 $(TMP_TARGET) : $(TMP_DEPS)
1209         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1210 %end
1211 #------------------------------------------------------------------------------
1214 #------------------------------------------------------------------------------
1215 # Generate the support files for compiling a module. This includes include
1216 # files and source files. This rule has to be preceeded by
1217 # %rule_genmodule_makefile
1218 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= stubdir= \
1219     conffile=
1221 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1222 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1223 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1224 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1225                $(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     TMP_GENFILEFLAG=$(TMP_TARGETDIR)/.%(modname).%(modtype)-genfiles
1250 else
1251     TMP_GENFILEFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-genfiles
1252 endif
1253 ifneq (%(stubdir),)
1254     TMP_OPTS += -l %(stubdir)
1255     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1256     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1257     TMP_TARGETDIRS += %(stubdir)
1258 else
1259 ifneq (%(targetdir),)
1260     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1261 endif
1262 endif
1264 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1265 ifneq ($(TMP_TARGETDIRS),)
1266 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1267 endif
1269 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENFILEFLAG)
1271 $(TMP_GENFILEFLAG) : OPTS := $(TMP_OPTS)
1272 $(TMP_GENFILEFLAG) : MODNAME := %(modname)
1273 $(TMP_GENFILEFLAG) : MODTYPE := %(modtype)
1274 $(TMP_GENFILEFLAG) : $(TMP_DEPS)
1275         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1276 ifneq (%(conffile),lib.conf)
1277         @$(IF) $(TEST) -f lib.conf; then \
1278           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1279         fi
1280 endif
1281         @$(IF) $(TEST) -f libdefs.h; then \
1282           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1283         fi
1284         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1285         @$(TOUCH) $@
1286 %end
1287 #------------------------------------------------------------------------------
1290 #------------------------------------------------------------------------------
1291 # Generate the support files for compiling a module. This includes include
1292 # files and source files.
1293 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1294     targetdir= conffile=
1296 ifneq ($(%(modname)_INCLUDES),)
1298 TMP_TARGETS := $(%(modname)_INCLUDES)
1300 TMP_DEPS := $(GENMODULE)
1301 TMP_OPTS :=
1303 ifneq (%(conffile),)
1304     ifeq ($(dir %(conffile)),./)
1305         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1306         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1307     else
1308         TMP_OPTS += -c %(conffile)
1309         TMP_DEPS += %(conffile)
1310     endif 
1311 else
1312     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1313     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1314 endif
1315 ifneq (%(modsuffix),)
1316     TMP_OPTS += -s %(modsuffix)
1317 endif
1318 ifneq (%(targetdir),)
1319     TMP_OPTS += -d %(targetdir)
1320     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1321     TMP_GENINCFLAG=%(targetdir)/.%(modname).%(modtype)-includes
1322 else
1323     TMP_GENINCFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-includes
1324 endif
1326 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENINCFLAG)
1328 $(TMP_GENINCFLAG) : OPTS := $(TMP_OPTS)
1329 $(TMP_GENINCFLAG) : MODNAME := %(modname)
1330 $(TMP_GENINCFLAG) : MODTYPE := %(modtype)
1331 $(TMP_GENINCFLAG) : $(TMP_DEPS)
1332         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1333         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1334         @$(TOUCH) $@
1335 endif
1336 %end
1337 #------------------------------------------------------------------------------
1339 #------------------------------------------------------------------------------
1340 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1341 # 'start' is an optional starting address
1342 # 'ldflags' is optional additional flags for the linker
1343 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1345 BD_OUTDIR := $(dir %(file))
1346 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1347 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1348 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1349 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1350 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1351 BD_OBJS += %(objs)
1353 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1355 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1356         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1357         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1358         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1360 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1361     GLOB_MKDIRS += $(BD_OUTDIR)
1362 endif
1364 %end
1366 #------------------------------------------------------------------------------
1367 # Common rules for all makefiles
1368 %define common
1369 # Delete generated makefiles
1371 clean ::
1372         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1374 include $(SRCDIR)/config/make.tail
1376 BDID := $(BDTARGETID)
1377 %end
1378 #------------------------------------------------------------------------------
1379       
1381 #############################################################################
1382 #############################################################################
1383 ##                                                                         ##
1384 ## Here are the mmakefile build macros. These are macros that takes care   ##
1385 ## of everything to go from the sources to the generated target. Also all  ##
1386 ## intermediate files and directories that are needed are created by these ##
1387 ## rules.                                                                  ##
1388 ##                                                                         ##
1389 #############################################################################
1390 #############################################################################
1392 #------------------------------------------------------------------------------
1393 # Build a program
1394 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1395     objcfiles= \
1396     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1397     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1398     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1399     includedir= libdir= \
1400     compiler=target linker= lto=$(TARGET_LTO)
1402 .PHONY : %(mmake)
1404 BD_PROGNAME  := %(progname)
1405 BD_OBJDIR    := %(objdir)
1406 BD_TARGETDIR := %(targetdir)
1407 BD_LINKER    := %(linker)
1409 # If not supplied, linker is equal to compiler
1410 ifeq ($(BD_LINKER),)
1411     BD_LINKER := %(compiler)
1412 endif
1414 BD_FILES     := %(files)
1415 BD_OBJCFILES := %(objcfiles)
1416 BD_ASMFILES  := %(asmfiles)
1417 BD_CXXFILES := %(cxxfiles)
1419 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1420 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1421 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1423 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1424 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1425 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1427 BD_CFLAGS    := %(cflags)
1428 BD_CXXFLAGS := %(cxxflags)
1429 BD_CPPFLAGS :=  %(cppflags)
1430 ifeq (%(lto),yes)
1431 ifeq (%(compiler),target)
1432 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1433 BD_CXXFLAGS := $(LTO_BINARY_CFLAGS) $(BD_CXXFLAGS)
1434 endif
1435 endif
1436 ifneq (%(includedir),)
1437 BD_CFLAGS    += -I%(includedir)
1438 BD_CXXFLAGS += -I%(includedir)
1439 endif
1440 BD_AFLAGS    := %(aflags)
1441 ifneq (%(includedir),)
1442 BD_AFLAGS    += -I%(includedir)
1443 endif
1444 BD_DFLAGS    := %(dflags)
1445 BD_DXXFLAGS := %(dxxflags)
1446 BD_LDFLAGS   := %(ldflags)
1447 ifneq (%(libdir),)
1448 BD_LDFLAGS   += -L%(libdir)
1449 endif
1452 %(mmake)-quick : %(mmake)
1454 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1455 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1457 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1458 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1459     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1460 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1461     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1462 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1463     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1464 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1465     aflags=$(BD_AFLAGS)
1467 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1468     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1469     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1470     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1471     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1473 endif
1475 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1477 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1478 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1479 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1481 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1483 %(mmake)-clean ::
1484         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1485         @$(RM) $(FILES)
1487 %end
1488 #------------------------------------------------------------------------------
1491 #------------------------------------------------------------------------------
1492 # Build programs, for every C file an executable will be built with the same
1493 # name as the C file
1494 %define build_progs mmake=/A files=/A nix=no \
1495     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1496     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1497     includedir= libdir= \
1498     compiler=target \
1499     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1501 .PHONY : %(mmake)
1503 BD_OBJDIR    := %(objdir)
1504 BD_TARGETDIR := %(targetdir)
1506 BD_FILES     := %(files)
1507 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1508 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1509 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1511 BD_CFLAGS    := %(cflags)
1512 ifeq (%(lto),yes)
1513 ifeq (%(compiler),target)
1514 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1515 endif
1516 endif
1517 ifneq (%(includedir),)
1518     BD_CFLAGS += -I%(includedir)
1519 endif
1520 BD_CPPFLAGS := %(cppflags)
1521 BD_DFLAGS    := %(dflags)
1522 BD_LDFLAGS   := %(ldflags)
1523 ifneq (%(libdir),)
1524     BD_LDFLAGS += -L%(libdir)
1525 endif
1528 %(mmake)-quick : %(mmake)
1530 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1531 %(mmake) : $(BD_EXES)
1533 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1534 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1535     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1537 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1538     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1539     ldflags=$(BD_LDFLAGS) \
1540     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1541     usestartup="%(usestartup)" detach="%(detach)" \
1542      cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1544 endif
1546 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1548 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1549 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1550 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1552 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1554 %(mmake)-clean ::
1555         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1556         @$(RM) $(FILES)
1558 %end
1559 #------------------------------------------------------------------------------
1562 #------------------------------------------------------------------------------
1563 # Build a module.
1564 # This is a bare version: It just compiles and links the given files. It is
1565 # assumed that all needed boiler plate code is in the files. This should only
1566 # be used for compiling external code. For AROS code use %build_module
1567 %define build_module_simple mmake=/A modname=/A modtype=/A \
1568     files="$(basename $(call WILDCARD, *.c))" \
1569     cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) \
1570     objdir=$(OBJDIR) moduledir= \
1571     uselibs= usehostlibs= compiler=target lto=$(TARGET_LTO)
1573 # Define metamake targets and their dependencies
1574 #MM %(mmake) : core-linklibs includes-generate-deps
1575 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1576 #MM %(mmake)-kobj-quick
1577 #MM %(mmake)-quick
1578 #MM %(mmake)-clean
1580 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1582 .PHONY : $(BD_ALLTARGETS)
1584 ifeq (%(modname),)
1585 $(error using %build_module_simple: modname may not be empty)
1586 endif
1587 ifeq (%(modtype),)
1588 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1589 endif
1591 # Default values for variables and arguments
1592 BD_DEFLINKLIBNAME := %(modname)
1593 BD_DEFDFLAGS := %(cflags)
1594 ifeq (%(lto),yes)
1595 ifeq (%(compiler),target)
1596 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(BD_DEFDFLAGS)
1597 endif
1598 endif
1599 BD_DEFDXXFLAGS := %(dxxflags)
1600 OBJDIR ?= $(GENDIR)/$(CURDIR)
1601 BD_MODDIR := %(moduledir)
1602 ifeq ($(BD_MODDIR),)
1603   ifeq (%(modtype),library)
1604     BD_MODDIR  := $(AROS_LIBRARIES)
1605   endif
1606   ifeq (%(modtype),gadget)
1607     BD_MODDIR  := $(AROS_GADGETS)
1608   endif
1609   ifeq (%(modtype),datatype)
1610     BD_MODDIR  := $(AROS_DATATYPES)
1611   endif
1612   ifeq (%(modtype),handler)
1613     BD_MODDIR  := $(AROS_FS)
1614   endif
1615   ifeq (%(modtype),device)
1616     BD_MODDIR  := $(AROS_DEVS)
1617   endif
1618   ifeq (%(modtype),resource)
1619     BD_MODDIR  := $(AROS_RESOURCES)
1620   endif
1621   ifeq (%(modtype),hook)
1622     BD_MODDIR  := $(AROS_RESOURCES)
1623   endif
1624   ifeq (%(modtype),mui)
1625     BD_MODDIR  := $(AROS_CLASSES)/Zune
1626   endif
1627   ifeq (%(modtype),mcc)
1628     BD_MODDIR  := $(AROS_CLASSES)/Zune
1629   endif
1630   ifeq (%(modtype),mcp)
1631     BD_MODDIR  := $(AROS_CLASSES)/Zune
1632   endif
1633   ifeq (%(modtype),usbclass)
1634     BD_MODDIR  := $(AROS_CLASSES)/USB
1635   endif
1636   ifeq (%(modtype),hidd)
1637     BD_MODDIR  := $(AROS_DRIVERS)
1638   endif
1639   ifeq (%(modtype),printer)
1640     BD_MODDIR  := $(AROS_PRINTERS)
1641   endif
1642 endif
1643 ifeq ($(BD_MODDIR),)
1644   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1645 endif
1647 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1648 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1649 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1651 %rule_compile_multi \
1652     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1653     cflags="$(BD_DEFDFLAGS)" cppflags="%(cppflags)" dflags="%(dflags)" \
1654     compiler="%(compiler)"
1656 # Handlers use dash instead of dot in their names
1657 ifeq (%(modtype),handler)
1658 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1659 else
1660 ifeq (%(modtype),printer)
1661 BD_MODULE := $(BD_MODDIR)/%(modname)
1662 else
1663 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1664 endif
1665 endif
1666 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1668 %(mmake)-quick : %(mmake)
1669 %(mmake)-kobj-quick : $(BD_KOBJ)
1670 %(mmake)       : $(BD_MODULE)
1671 %(mmake)-kobj  : $(BD_KOBJ)
1673 # The module is linked from all the compiled .o files
1674 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1676 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1677 # This breaks con-handler build. Here we work around this
1678 ifeq (%(modname),con)
1679     BD_ERR := $(notdir $(BD_MODULE)).err
1680 else
1681     BD_ERR := %(modname).err
1682 endif
1684 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1685                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1686                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1687                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1689 # Link kernel object file
1690 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1692 # Make these symbols local
1693 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1694             UtilityBase ExpansionBase KeymapBase KernelBase
1696 BD_SYMBOLS := $(BD_KBASE)
1698 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1699 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1700 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1701 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1702 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1703 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1704         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1705         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1706         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1709 ## Dependency fine-tuning
1711 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1712 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1714 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1715 $(BD_MODULE) : | $(BD_MODDIR)
1716 $(BD_KOBJ) : | $(KOBJSDIR)
1717 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1719 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1720 %(mmake)-clean ::
1721         @$(ECHO) "Cleaning up for module %(modname)"
1722         @$(RM) $(FILES)
1723 %end
1724 #------------------------------------------------------------------------------
1727 #------------------------------------------------------------------------------
1728 # Build a module - core routine
1729 # Explanation of this macro is done in the developer's manual
1730 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1731   files="$(basename $(call WILDCARD, *.c))" \
1732   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1733   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1734   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1735   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1736   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1737   includedir= libdir= \
1738   build_abi= build_library=
1740 # We will employ a terrifying, but unavoidable, hack here.
1741 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1742 # ignores GNU Make ifeq() statements, but will process any #MM
1743 # headed lines in the file.
1745 # So, to make the following #MM lines conditional on whether we want
1746 # to build the ABI, Library, or both, we define build_abi= and 
1747 # build_library as 'M' to enable, or '' to disable, which allows genmf
1748 # to do the following conversions:
1750 #  #%(build_abi)M includes-foo: foo-include
1751 #    becomes, when build_abi=M
1752 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1753 #    but, when build_abi= ...
1754 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1756 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1758 # Define metamake targets and their dependencies
1759 #MM %(mmake)
1760 #MM %(mmake)-quick
1761 #MM %(mmake)-makefile
1762 #MM %(mmake)-clean
1764 # ABI targets:
1765 #M%(build_abi)- includes-all : %(mmake)-includes
1766 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1767 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1768 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1769 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1770 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1771 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1772 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1773 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1774 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1775 #M%(build_abi) %(mmake)-includes-quick
1776 #M%(build_abi) %(mmake)-includes-dirs
1777 #M%(build_abi) %(mmake)-fd
1779 # Library targets
1780 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1781 #%(build_library)M %(mmake)-kobj-quick : 
1783 # Library with ABI targets:
1784 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1785 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1787 # All MetaMake targets defined by this macro
1788 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1790 ifeq (%(build_library),M)
1791 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1792 endif
1794 ifeq (%(build_abi),M)
1795 BD_ALLTARGETS += %(mmake)-includes \
1796                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1797                  %(mmake)-linklib %(mmake)-fd
1798 endif
1800 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1802 ifeq (%(modname),)
1803 $(error using %build_module: modname may not be empty)
1804 endif
1805 ifeq (%(modtype),)
1806 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1807 endif
1809 # Default values for variables and arguments
1810 BD_DEFLINKLIBNAME := %(modname)
1811 BD_DEFDFLAGS := %(cflags)
1812 BD_DEFDXXFLAGS := %(cxxflags)
1813 BD_DEFCPPFLAGS := %(cppflags)
1814 ifeq (%(lto),yes)
1815 ifeq (%(compiler),target)
1816 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDFLAGS)
1817 BD_DEFDXXFLAGS := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDXXFLAGS)
1818 endif
1819 endif
1820 ifneq (%(includedir),)
1821     BD_DEFDFLAGS += -I%(includedir)
1822     BD_DEFDXXFLAGS += -I%(includedir)
1823 endif
1824 OBJDIR ?= $(GENDIR)/$(CURDIR)
1826 ## Create genmodule include Makefile for the module
1828 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1830 %rule_genmodule_makefile \
1831     modname="%(modname)" modtype="%(modtype)" \
1832     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1833     conffile="%(conffile)"
1835 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1837 GLOB_MKDIRS += %(objdir)
1839 # Do not parse these statements if metatarget is not appropriate
1840 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1842 # suppress makes warning that the Makefile doesnt yet exist
1843 # on early passes (it will generate the file as needed though)
1844 # when we include it.
1845 -include %(objdir)/Makefile.%(modname)%(modtype)
1847 BD_DEFMODDIR := $(%(modname)_MODDIR)
1848 ifeq (%(archspecific),yes)
1849 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1850 endif
1853 ## include files generation
1855 ifneq (%(includedir),)
1856 BD_INCDIR    := %(includedir)
1857 else
1858 BD_INCDIR    := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
1859 endif
1860 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1861 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1863 ifeq (%(build_abi),M)
1864 %(mmake)-includes-quick : %(mmake)-includes
1865 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1866     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1867     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1869 ifneq ($(%(modname)_INCLUDES),)
1870 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1871                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1872                          conffile="%(conffile)"
1874 %rule_copy_diff_multi \
1875     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1876     stampfile="%(objdir)/%(modname)_geninc"
1878 %rule_copy_diff_multi \
1879     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1880     stampfile="%(objdir)/%(modname)_incs"
1882 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1884 TMP%(modname)_INCDIRS := \
1885     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1886     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1887     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1888 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1890 endif
1892 endif
1894 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1895     modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1896     conffile="%(conffile)" version="%(version)"
1898 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1899 $(BD_DEFLIBDEFSINC) :
1900         @$(ECHO) "Generating $@"
1901         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1903 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1904 GLOB_MKDIRS += %(objdir)/include
1906 ## Extra genmodule src files generation
1907 ## 
1908 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1909     modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1910     conffile="%(conffile)"
1912 GLOB_MKDIRS += %(objdir)/linklib
1914 ifeq (%(build_abi),M)
1915 ## Create FD file
1916 ifeq (%(includedir),)
1917 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/fd
1918 else
1919 BD_FDDIR := %(includedir)/../fd
1920 endif
1921 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1923 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1924     modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1926 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1928 GLOB_MKDIRS += $(BD_FDDIR)
1929 endif
1931 ## Compilation
1933 BD_FILES      := %(files)
1934 BD_CXXFILES := %(cxxfiles)
1936 BD_LIBFILES := %(linklibfiles)
1938 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1940 BD_FILEMATCH = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
1941 BD_MATCHARCH = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call BD_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
1942 BD_FILTERARCH = $(filter-out $(call BD_MATCHARCH,$(1),$(2)),$(2))
1943 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1944 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1946 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1947 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1948 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1949 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1950 BD_NARCHFILES := $(call BD_FILTERARCH,$(BD_ARCHFILES),$(BD_FILES))
1951 BD_NLIBARCHFILES := $(call BD_FILTERARCH,$(BD_LIBARCHFILES),$(BD_LIBFILES))
1952 BD_ARCHNLIBFILES := $(call BD_FILTERARCH,$(BD_LIBFILES),$(BD_LIBARCHFILES))
1954 BD_COMMONCFLAGS=-I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1955 BD_CFLAGS        := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_CFLAGS)
1956 BD_LINKLIBCFLAGS := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBCFLAGS)
1957 BD_CXXFLAGS      := %(cxxflags) $(BD_COMMONCFLAGS) $(%(modname)_CXXFLAGS)
1958 ifeq (%(lto),yes)
1959 ifeq (%(compiler),target)
1960 BD_LTOFLAGS=$(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH)
1961 BD_CFLAGS        := $(BD_LTOFLAGS) $(BD_CFLAGS)
1962 BD_LINKLIBCFLAGS := $(BD_LTOFLAGS) $(BD_LINKLIBCFLAGS)
1963 BD_CXXFLAGS      := $(BD_LTOFLAGS) $(BD_CXXFLAGS)
1964 endif
1965 endif
1966 ifneq (%(includedir),)
1967 BD_CFLAGS        += -I%(includedir)
1968 BD_LINKLIBCFLAGS += -I%(includedir)
1969 BD_CXXFLAGS      += -I%(includedir)
1970 endif
1971 BD_CPPFLAGS      := %(cppflags)
1972 BD_DFLAGS        := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_DFLAGS)
1973 BD_LINKLIBDFLAGS := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBDFLAGS)
1974 BD_DXXFLAGS      := %(dxxflags) $(BD_COMMONCFLAGS) $(%(modname)_DXXFLAGS)
1976 ifeq (%(modtype),library)
1977     BD_LIBSUFFIX := 
1978 else
1979     BD_LIBSUFFIX := .%(modtype)
1980 endif
1982 ifeq (%(libdir),)
1983 BD_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
1984 else
1985 BD_LIBDIR := %(libdir)
1986 endif
1988 ifeq (%(build_abi),M)
1989 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
1990 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
1991 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1992     BD_LINKLIB :=
1993 else
1994     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1995     ifneq (%(modname),%(linklibname))
1996         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1997     endif
1998 endif
1999 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
2001 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
2002 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
2003 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
2004     BD_RELLINKLIB :=
2005 else
2006     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
2007     ifneq (%(modname),%(linklibname))
2008         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
2009     endif
2010 endif
2011 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
2012 endif
2014 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
2015 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
2016                  %(linklibobjs)
2017 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
2018                  %(linklibobjs)
2019 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
2020 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
2022 BD_CCFILES := $(BD_NARCHFILES)
2023 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
2024 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2025 BD_LINKLIBCCGENFILES := $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2027 %rule_compile_cxx_multi \
2028     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2029     cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS) \
2030     compiler="%(compiler)"
2031 %rule_compile_multi \
2032     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
2033     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) \
2034     compiler="%(compiler)"
2035 %rule_compile_multi \
2036     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
2037     cflags=$(BD_CFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
2038     compiler="%(compiler)"
2039 %rule_compile_multi \
2040     basenames=$(BD_NLIBARCHFILES) targetdir="%(objdir)/linklib" \
2041     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2042     compiler="%(compiler)"
2043 %rule_compile_multi \
2044     basenames=$(BD_LINKLIBCCGENFILES) srcdir="%(objdir)/linklib" targetdir="%(objdir)/linklib" \
2045     cflags=$(BD_LINKLIBCFLAGS) cppflags="$(BD_CPPFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2046     compiler="%(compiler)"
2048 ifneq ($(BD_LINKLIBAFILES),)
2049 %rule_assemble_multi \
2050     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
2051 endif
2053 ## Linking
2055 ifeq (%(modsuffix),)
2056 BD_SUFFIX := %(modtype)
2057 else
2058 BD_SUFFIX := %(modsuffix)
2059 endif
2061 ifeq (%(build_library),M)
2062 # Handlers use dash instead of dot in their names
2063 ifeq ($(BD_SUFFIX),handler)
2064 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2065 else
2066 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2067 endif
2068 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2069 else
2070 BD_MODULE :=
2071 BD_KOBJ   :=
2072 endif
2074 %(mmake)-quick      : %(mmake)
2075 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2076 ifeq (%(build_library),M)
2077 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2078 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2079 endif
2080 ifeq (%(build_abi),M)
2081 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2082 endif
2084 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2085            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2087 ifeq (%(nostartup),yes)
2088 # Handlers always have entry point
2089 ifneq (%(modtype),handler)
2090 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2091 endif
2092 endif
2094 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2095 # This breaks con-handler build. Here we work around this
2096 ifeq (%(modname),con)
2097     BD_ERR := $(notdir $(BD_MODULE)).err
2098 else
2099     BD_ERR := %(modname).err
2100 endif
2102 ifeq (%(build_library),M)
2103 # The module is linked from all the compiled .o files
2104 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2105                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2106                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2107                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2108 endif
2110 ifeq (%(build_abi),M)
2111 # Link static lib
2112 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2113 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2114 ifneq ($(BD_LINKLIB),)
2115 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2116 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2117 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2118 endif
2120 $(BD_LINKLIB) : | $(BD_LIBDIR)
2121 GLOB_MKDIRS += $(BD_LIBDIR)
2122 endif
2124 ifneq ($(BD_RELLINKLIB),)
2125 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2126 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2127 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2128 endif
2130 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2131 GLOB_MKDIRS += $(BD_LIBDIR)
2132 endif
2133 endif
2135 ifeq (%(build_library),M)
2136 # Link kernel object file
2137 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2139 # Make these symbols local
2140 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2141             UtilityBase ExpansionBase KeymapBase KernelBase
2143 BD_SYMBOLS := $(BD_KBASE)
2145 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2146 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2147 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2148 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2149 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2150 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2151         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2152         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2153         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2154 endif
2156 ## Dependency fine-tuning
2158 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2160 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2162 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2163 $(BD_MODULE) : | %(prefix)/%(moduledir)
2164 $(BD_KOBJ)   : | $(KOBJSDIR)
2165 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2167 # Some include files need to be generated before the .c can be parsed.
2168 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2170 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2171     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2172 $(BD_DEPS) : $(BD_DFILE_DEPS)
2173 endif
2175 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2176     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2177     %(objdir)/Makefile.%(modname)%(modtype) \
2178     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2179     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2180     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2181     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2182     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2183     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2184     $(BD_ENDOBJS)
2185 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2186 %(mmake)-clean ::
2187         @$(ECHO) "Cleaning up for module %(modname)"
2188         @$(RM) $(FILES)
2190 endif # $(TARGET) in $(BD_ALLTARGETS)
2191 %end
2192 #------------------------------------------------------------------------------
2194 #------------------------------------------------------------------------------
2195 # Build a module - ABI and library
2196 # Explanation of this macro is done in the developer's manual
2197 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2198   files="$(basename $(call WILDCARD, *.c))" \
2199   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2200   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2201   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2202   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2203   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2204   includedir= libdir=
2206 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2207    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2208    files="%(files)" cxxfiles="%(cxxfiles)" \
2209    linklibname="%(linklibname)" \
2210    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2211    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2212    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2213    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2214    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2215    includedir="%(includedir)" libdir="%(libdir)" \
2216    build_abi=M build_library=M
2218 %end
2219 #------------------------------------------------------------------------------
2222 #------------------------------------------------------------------------------
2223 # Build a module skeleton ABI
2224 # This is a stripped-down version of build_module, it only creates include
2225 # files and the linklibs.
2226 # This is used when for plugins or classes with the same API, but no actual
2227 # implementation here.
2228 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2229   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2230   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2231   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2232   compiler=target nostartup=yes archspecific=no \
2233   includedir= libdir=
2235 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2236   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2237   linklibname="%(linklibname)" \
2238   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2239   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2240   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2241   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2242   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2243   includedir="%(includedir)" libdir="%(libdir)" \
2244   build_abi=M build_library=
2246 %end
2247 #------------------------------------------------------------------------------
2249 #------------------------------------------------------------------------------
2250 # Build a module library - no includes nor linklibs
2251 # Explanation of this macro is done in the developer's manual
2252 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2253   files="$(basename $(call WILDCARD, *.c))" \
2254   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2255   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2256   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2257   uselibs= usehostlibs= \
2258   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2259   includedir= libdir=
2261 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2262    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2263    files="%(files)" cxxfiles="%(cxxfiles)" \
2264    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2265    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2266    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2267    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2268   includedir="%(includedir)" libdir="%(libdir)" \
2269    build_abi= build_library=M
2271 %end
2272 #------------------------------------------------------------------------------
2276 #------------------------------------------------------------------------------
2277 # Build a linklib.
2278 # - mmake is the mmaketarget
2279 # - libname is the baselibname e.g. lib%(libname).a will be created
2280 # - files are the C source files to include in the lib. The list of files
2281 #   has to be given without the .c suffix
2282 # - cxxfiles are C++ source files without suffix.
2283 #   NB: files will be matched in the order .cpp > .cxx > .cc
2284 # - asmfiles are the asm files to include in the lib. The list of files has to
2285 #   be given without the .s suffix
2286 # - objs additional object to link into the linklib. The objects have to be
2287 #   given with full absolute path and the .o suffix.
2288 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2289 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2290 # - cflags are the flags to compile the source (default $(CFLAGS))
2291 # - dflags are the flags used during makedepend (default equal to cflags)
2292 # - aflags are the flags used during assembling (default $(AFLAGS))
2293 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2294   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2295   includedir= \
2296   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2297   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2299 # assign and generate the local variables used in this macro
2300 BD_LIBNAME    := %(libname)
2301 BD_LINKLIB    := %(libdir)/lib%(libname).a
2303 BD_FILES      := %(files)
2304 BD_ASMFILES   := %(asmfiles)
2305 BD_CXXFILES := %(cxxfiles)
2307 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2308 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2309 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2311 BD_OBJS       := $(BD_ARCHOBJS) \
2312                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2313                  %(objs)
2314 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2316 BD_CFLAGS    := %(cflags)
2317 BD_CXXFLAGS := %(cxxflags)
2318 ifeq (%(lto),yes)
2319 ifeq (%(compiler),target)
2320 BD_CFLAGS    := $(LTO_CFLAGS) $(BD_CFLAGS)
2321 BD_CXXFLAGS := $(LTO_CFLAGS) $(BD_CXXFLAGS)
2322 endif
2323 endif
2324 ifneq (%(includedir),)
2325 BD_CFLAGS    += -I%(includedir)
2326 BD_CXXFLAGS += -I%(includedir)
2327 endif
2328 BD_CPPFLAGS := %(cppflags)
2329 BD_AFLAGS    := %(aflags)
2330 BD_DFLAGS    := %(dflags)
2331 BD_DXXFLAGS := %(dxxflags)
2333 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2336 %(mmake)-quick : %(mmake)
2338 #MM %(mmake) : includes-generate-deps
2339 %(mmake) : $(BD_LINKLIB)
2341 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2343 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2344     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) cppflags=$(BD_CPPFLAGS) dxxflags=$(BD_DXXFLAGS)
2345 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2346     compiler="%(compiler)" cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS)
2347 %rule_assemble basename=% targetdir="%(objdir)" \
2348     aflags=$(BD_AFLAGS)
2350 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2351 endif
2353 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2355 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2356 $(BD_LINKLIB) : | %(libdir)
2357 GLOB_MKDIRS += %(objdir) %(libdir)
2359 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2361 %(mmake)-clean ::
2362         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2363         @$(RM) $(FILES)
2365 %end
2366 #------------------------------------------------------------------------------
2369 #------------------------------------------------------------------------------
2370 # Build catalogs.
2371 # - mmake is the mmaketarget
2372 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2373 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2374 # - subdir is the destination subdirectory of the catalogs
2375 # - name is the name of the destination catalog, without the .catalog suffix
2376 # - source is the path to the generated source code file
2377 # - dir is the base destination directory (default $(AROS_CATALOGS))
2378 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2379 # - srcdir is the directory in which the *.cd and *.ct files are searched
2381 %define build_catalogs mmake=/A name=/A subdir=/A \
2382  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2383  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2385 ifeq (%(description),)
2386 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2387 else
2388 BD_DESC := %(description)
2389 endif
2391 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2393 ifeq (%(catalogs),)
2394 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2395 else
2396 BD_LNGS := %(catalogs)
2397 endif
2399 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2400 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2403 %(mmake) : $(BD_OBJS) %(source)
2405 $(BD_OBJS) : | $(BD_DIRS)
2406 GLOB_MKDIRS += $(BD_DIRS)
2408 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2409         @$(ECHO) "Creating   %(name) catalog for language $*."
2410         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2412 ifneq (%(source),)
2413 %(source) : BD_DESC := $(BD_DESC)
2414 %(source) : BD_SRC := $(BD_SRC)
2415 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2416         @$(ECHO) "Creating   %(name) catalog source file $@"
2417         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2418 endif
2420 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2422 %(mmake)-clean ::
2423         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2424         @$(RM) $(FILES)
2426 .PHONY: %(mmake) %(mmake)-clean
2428 %end
2429 #-----------------------------------------------------------------------------
2432 #-----------------------------------------------------------------------------
2433 # Build icons.
2434 # - mmake is the mmaketarget
2435 # - icons is a list of icon base names (i.e. without the .info suffix)
2436 # - dir is the destination directory
2437 # - srcdir is where *.png and *.info.src are sought
2438 #-----------------------------------------------------------------------------
2440 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2442 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2445 %(mmake) : $(BD_OBJS)
2447 ifeq (%(image),)
2449 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2450         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2451         @$(ILBMTOICON) $+ $@
2453 else
2455 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2456         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2457         @$(ILBMTOICON) $+ $@
2459 endif
2461 $(BD_OBJS) : | %(dir)
2462 GLOB_MKDIRS += %(dir)
2464 %(mmake)-clean : FILES := $(BD_OBJS)
2466 %(mmake)-clean ::
2467         @$(RM) $(FILES)
2469 .PHONY: %(mmake) %(mmake)-clean
2471 %end
2472 #-----------------------------------------------------------------------------
2475 #------------------------------------------------------------------------------
2476 # Compile files for an arch-specific replacement of code for a module
2477 # - files: the basenames of the C files to compile.
2478 # - asmfiles: the basenames of the asm files to assemble.
2479 # - mainmmake: the mmake of the module in the main directory to compile these
2480 #   arch specific files for.
2481 # - maindir: the object directory for the main module
2482 # - arch: the arch for which to compile these files. It can have the form
2483 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2484 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2485 # - dflags: the flags used during creation of dependency file. If not specified
2486 #   the same value as cflags will be used
2487 # - aflags: the flags used during assembling
2488 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2489 #   the target compiler is used
2490 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2491 cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2493 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2494     $(error no files or asmfiles given)
2495 endif
2497 ifneq (%(cxxfiles),)
2498     $(error cxx support is TODO)
2499 endif
2501 %buildid targets="%(mainmmake)-%(arch)"
2503 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2504 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2505 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2506 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2507 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2508 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2509 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2510 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2511 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2512 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2513 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2514 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2515 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2516 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2517 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2519 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2521 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2522 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2523 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2524 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2525 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2526 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2527 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2528 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2530 ifneq (%(modulename),)
2531 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2532 endif
2534 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2535     BD_TARGET := %(mainmmake)-%(arch)-quick
2536 else
2537     BD_TARGET := %(mainmmake)-%(arch)
2538 endif
2541 ifeq ($(TARGET),$(BD_TARGET))
2542 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2543 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2544 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2545 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2546 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2547 endif
2549 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2550 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2553 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2556 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2558 ifeq ($(findstring %(compiler),host kernel target),)
2559     $(error unknown compiler %(compiler))
2560 endif
2561 ifneq (%(modulename),)
2562 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2563 else
2564 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) %(cppflags)
2565 endif
2566 ifeq (%(compiler),target)
2567 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
2568 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
2569 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2570 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2571 endif
2572 ifeq (%(compiler),host)
2573 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2574 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2575 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2576 endif
2577 ifeq (%(compiler),kernel)
2578 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
2579 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
2580 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2581 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2582 endif
2584 ifeq ($(TARGET),$(BD_TARGET))
2585 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2586         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2587 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2588         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2589 endif
2591 ifeq (%(dflags),)
2592 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID)) %(cppflags)
2593 else
2594 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags) %(cppflags)
2595 endif
2596 ifeq ($(TARGET),$(BD_TARGET))
2597 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2598         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2600 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2601         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2602 endif
2604 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2605 $(BD_ASMOBJS$(BDID)) : CPPFLAGS:=%(cppflags)
2607 ifeq ($(TARGET),$(BD_TARGET))
2608 $(BD_OBJDIR$(BDID))/%.o : %.s
2609         %assemble_q
2610 $(BD_OBJDIR$(BDID))/%.o : %.S
2611         %assemble_q
2612 endif
2614 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2615 %end
2616 #------------------------------------------------------------------------------
2619 #------------------------------------------------------------------------------
2620 # generate asm files from c files (for debugging purposes)
2621 %define ctoasm_q
2622 %.s : %.c
2623         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2624         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2625 %end
2626 #------------------------------------------------------------------------------
2629 #------------------------------------------------------------------------------
2630 # Copy files from one directory to another.
2632 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2634 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2636 GLOB_MKDIRS += %(dst)
2638 .PHONY : %(mmake)
2641 %(mmake) : | %(dst) 
2642         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2644 %end
2645 #------------------------------------------------------------------------------
2648 #------------------------------------------------------------------------------
2649 # Copy a directory recursively to another place, preserving the original 
2650 # hierarchical structure
2652 # src: the source directory whose content will be copied.
2653 # dst: the directories where to copy src's content. If not existing, they will be made.
2654 # excludefiles: files which must not be copied. Path must be relative to src.
2656 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2658 .PHONY : %(mmake)
2661 %(mmake) :
2662         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2664 %end
2665 #------------------------------------------------------------------------------
2668 #------------------------------------------------------------------------------
2669 #   Copy include files into the includes directories. There are currently
2670 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2671 #   for building tools that need to run on the host system $(GENINCDIR). The
2672 #   $(GENINCDIR) path must not contain any references to the C runtime
2673 #   library header files.
2675 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2676     dir= compiler=target includedir=$(AROS_INCLUDES)
2678 ifeq ($(findstring %(compiler),host kernel target),)
2679 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2680 endif
2682 ifneq (%(dir),)
2683 TMP_DIR := %(dir)
2684 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2685 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2686 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2687 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2688 ifeq ($(TMP_DIRFIRST),/)
2689 BD_INC_PATH := %(dir)/
2690 else
2691 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2692 endif
2693 else
2694 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2695 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2696 endif
2698 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2699         @$(CP) $< $@
2701 ifeq (%(compiler),target)
2703 ifneq (%(dir),)
2704 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2705 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2706 else
2707 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2708 endif
2710 BD_INCL_FILES += $(BD_INCL_FILES2)
2712 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2713         @$(CP) $< $@
2714 endif
2717 %(mmake) : $(BD_INCL_FILES)
2719 .PHONY: %(mmake)
2721 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2722 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2723 %end
2724 #------------------------------------------------------------------------------
2727 #------------------------------------------------------------------------------
2728 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2729 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2730 STUBS_MEM := $(addsuffix .o,$(STUBS))
2731 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2732 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2733 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2735 #MM- linklibs : hidd-%(hidd)-stubs
2736 #MM- %(parenttarget): hidd-%(hidd)-stubs
2737 #MM hidd-%(hidd)-stubs : includes includes-copy
2738 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2740 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2741         %mklib_q from=$^
2743 $(STUBS_OBJ) : $(STUBS_SRC) 
2744         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT)" opt="%(cflags) %(cppflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2746 $(STUBS_DEP) : $(STUBS_SRC)
2747         %mkdepend_q flags="%(dflags) %(cppflags)"
2749 setup ::
2750         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2753 clean ::
2754         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2756 DEPS := $(DEPS) $(STUBS_DEP)
2758 %end
2759 #------------------------------------------------------------------------------
2762 #------------------------------------------------------------------------------
2763 # Build an imported source tree which uses the configure script from the
2764 # autoconf package.  This rule will try to "integrate" the produced files as
2765 # much as possible in the AROS build, for example by putting libraries in the
2766 # standard library directory, includes in the standard include directory, and
2767 # so on. You can however override this behaviour.
2769 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2770 # be %(bindir) (or its deduced value) when running "make install", and
2771 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2772 # configure script some more parameters whose value depends upon the PROGDIR
2773 # env var, so that the program gets all its stuff installed in the proper place
2774 # when building it, but when running it from inside AROS it can also find that
2775 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2776 # the configuration parameters set when running ./configure
2778 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2779 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2780 # to the name which has to follow it.
2782 # Arguments:
2784 #     - mmake           = the meta make target.
2785 #     - package         = name of the package to be built.
2786 #     - srcdir          = the location of the unpacked source code. Defaults
2787 #                         to $(SRCDIR)/$(CURDIR).
2788 #     - prefix          = the target directory. Must be an absolute path of the
2789 #                         host system. Defaults to $(AROS_CONTRIB).
2790 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2791 #                         Defaults to the value of the prefix option.
2792 #     - extraoptions    = additional options for the configure script.
2793 #     - usecppflags      = enable the use of cpp flags. some external configure
2794 #                         scripts will not set their own cppflags if it is already
2795 #                         set, so this allows them to be disabled (unless you can provide
2796 #                         all the options they would need)
2797 #     - extracppflags      = additional preprocessor flags.
2798 #     - extracflags     = additional flags to use with the C compiler.
2799 #     - extracxxflags   = additional flags to use with the C++ compiler.
2800 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2801 #                         Defaults to the value of the nix argument.
2802 #     - nix             = enable u*nix path handling, i.e. a path like
2803 #                         /progdir//./file will be translated to
2804 #                         progdir:file during run-time. Defaults to no.
2805 #     - compiler        = target, host or kernel. Defaults to target.
2806 #     - install_target  = the command used for installing. Defaults to install. Leave
2807 #                         it empty if you want to suppress installing.
2808 #     - preconfigure    = a metatarget which is executed before configure is called.
2809 #     - postconfigure   = a metatarget which is executed after configure is called.
2810 #     - postinstall     = a metatarget which is executed after installing.
2811 #     - install_env     = set additional options for installing.
2812 #     - use_build_env   = if yes the configuration environment is used for
2813 #                         installing, too. Defaults to no.
2815 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2816 # like this:
2818 # if nix_dir_layout
2819 #    --prefix = $(aros_prefix)
2820 #    progdir = $(aros_prefix)/bin
2821 # else
2822 #    if nix
2823 #        --prefix = /PROGDIR
2824 #        --bindir = /PROGDIR
2825 #        --sbindir = /PROGDIR
2826 #        --libdir = /LIB
2827 #        --includedir = /INCLUDE
2828 #        --oldincludedir = /INCLUDE   
2829 #    else
2830 #        --prefix = $(aros_prefix)
2831 #    endif
2833 #    progdir = $(aros_prefix)
2835 #    # Install options
2836 #    bindir = $(prefix)
2837 #    sbindir = $(prefix)
2838 #    libdir = $(AROS_LIB)
2839 #    includedir = $(AROS_INCLUDES)
2840 #    oldincludedir = $(AROS_INCLUDES)
2841 # endif
2844 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
2845     prefix= gendir= basedir=$(CURDIR) extraoptions= \
2846     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
2847     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
2848     install_target=install preconfigure= postconfigure= postinstall= \
2849     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes
2851 ifneq (%(prefix),)
2852     %(mmake)-prefix := %(prefix)
2853 else
2854     %(mmake)-prefix := $(AROS_CONTRIB)
2855 endif
2857 ifneq (%(aros_prefix),)
2858     %(mmake)-aros_prefix := %(aros_prefix)
2859 else
2860     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2861 endif
2863 BD_NIXFLAG ?= -nix
2865 ifeq (%(nix),yes)
2866     %(mmake)-nix    := $(BD_NIXFLAG)
2867     %(mmake)-volpfx := /
2868     %(mmake)-volsfx := /
2869     
2870     ifeq (%(nix_dir_layout),)
2871         %(mmake)-nix_dir_layout := yes
2872     endif
2873 else
2874     %(mmake)-volsfx := :
2875     
2876     ifeq (%(nix_dir_layout),)
2877         %(mmake)-nix_dir_layout := no
2878     endif
2879 endif
2881 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2883 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2884         exec_prefix=$(%(mmake)-prefix) %(install_env)
2886 # Check if chosen compiler is valid
2887 ifeq ($(findstring %(compiler),host target kernel),)
2888   $(error unknown compiler %(compiler))
2889 endif
2891 # Set legacy 'host' variable based on chosen compiler
2892 ifeq (%(compiler),host)
2893     host := yes
2894     ifeq (%(basedir),)
2895         %(mmake)-pkgbasedir := $(HOSTGENDIR)
2896     else
2897         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
2898     endif
2899 else
2900     host := no
2901     ifeq (%(basedir),)
2902         %(mmake)-pkgbasedir := $(GENDIR)
2903     else
2904         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
2905     endif
2906 endif
2907 ifneq (%(gendir),)
2908     ifeq (%(basedir),)
2909         %(mmake)-pkgbasedir := %(gendir)
2910     else
2911         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
2912     endif
2913 endif
2915 ifeq (%(package),)
2916     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
2917 else
2918     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
2919 endif
2921 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2922 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2924 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2925     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2926     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2927 else
2928     ifeq (%(nix),yes)
2929         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2930         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2931     else
2932         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2933     endif
2935     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2936     
2937     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2938         sbindir=$(%(mmake)-prefix) \
2939         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2940         oldincludedir=$(AROS_INCLUDES) %(install_env)
2941 endif
2943 ifneq ($(DEBUG),yes)
2944     %(mmake)-s_flag = -s
2945 endif
2947 # Set up build environment, and options for configure script
2948 ifeq (%(compiler),host)
2949     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2950     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2951     # since that won't get picked up during configure.
2952     # We also cannot pass in the compiler including std flags so we need to use
2953     # the "plain" host compiler.
2954     %(mmake)-cfg-env := %(config_env_extra) \
2955         CPP="$(HOST_CPP)" \
2956         CXXCPP="$(HOST_CPP)" \
2957         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2958         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2959         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2960         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2961         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2962         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2963         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2964         TARGET_AS="$(TARGET_AS)" \
2965         OBJCOPY="$(OBJCOPY)" \
2966         TARGET_RANLIB="$(RANLIB)" \
2967         TARGET_STRIP="$(STRIP_PLAIN)" \
2968         TARGET_NM="$(NM_PLAIN)" \
2969         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2970 endif
2971 ifeq (%(compiler),target)
2972     %(mmake)-cfg-env := %(config_env_extra) \
2973         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
2974         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
2975     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2976         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2977         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2978         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2979         LD="$(strip $(TARGET_LD))"
2980 ifeq (%(crossbuild),yes)
2981     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
2982         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
2983 ifeq (%(usecppflags),yes)
2984     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2985 endif
2986 else
2987     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2988         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
2989 ifeq (%(usecppflags),yes)
2990     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
2991 endif
2992 endif
2993     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2994         CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
2995         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
2996         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
2997         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
2998         LD_FOR_BUILD="$(strip $(HOST_LD))" \
2999         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))" \
3000         CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3001         CFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3002         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3003         CXXFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3004         LD_FOR_HOST="$(strip $(TARGET_LD))" \
3005         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3006         CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3007         CFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3008         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3009         CXXFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3010         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3011         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3012         AR="$(strip $(AR_PLAIN))" \
3013         AS="$(strip $(TARGET_AS))" \
3014         OBJCOPY="$(strip $(OBJCOPY))" \
3015         RANLIB="$(strip $(RANLIB))" \
3016         STRIP="$(strip $(STRIP_PLAIN))" \
3017         TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3018         TARGET_CFLAGS="$(strip $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3019         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3020         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3021         TARGET_AS="$(strip $(TARGET_AS))" \
3022         TARGET_RANLIB="$(strip $(RANLIB))" \
3023         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3024         TARGET_NM="$(strip $(NM_PLAIN))"
3025 ifeq (%(buildflags),yes)
3026     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3027     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3028     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3029 endif
3030 ifeq (%(gnuflags),yes)
3031     %(mmake)-config_opts += --without-pic --disable-shared
3032     %(mmake)-config_opts += --disable-nls --without-x
3033 endif
3034 endif
3035 ifeq (%(compiler),kernel)
3036     %(mmake)-cfg-env := %(config_env_extra) \
3037         CPP="$(KERNEL_CPP)" \
3038         CXXCPP="$(KERNEL_CPP)" \
3039         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
3040         CFLAGS="$(strip $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3041         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
3042         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3043 ifeq (%(usecppflags),yes)
3044     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3045 endif
3046     %(mmake)-cfg-env += AS="$(KERNEL_AS)" \
3047         CC_FOR_BUILD="$(HOST_DEF_CC)" \
3048         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3049         CXX_FOR_BUILD="$(HOST_CXX)" \
3050         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3051         RANLIB="$(RANLIB)" \
3052         TARGET_RANLIB="$(RANLIB)" \
3053         TARGET_STRIP="$(STRIP_PLAIN)" \
3054         TARGET_NM="$(NM_PLAIN)"
3055 ifeq (%(buildflags),yes)
3056     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3057     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3058     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3059 endif
3060 ifeq (%(gnuflags),yes)
3061     %(mmake)-config_opts += --without-pic --disable-shared
3062     %(mmake)-config_opts += --disable-nls --without-x
3063 endif
3064 endif
3066 ifeq (%(use_build_env),yes)
3067     BUILD_ENV := $(%(mmake)-cfg-env)
3068 endif
3070 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3071 # in an ideal world, we would depend on the files in the source directory,
3072 # so we could copy them when they change. unfortunately filenames with
3073 # spaces causes problems with this
3074 $(%(mmake)-pkgdir)/.local-copy:
3075         %mkdirs_q $(%(mmake)-pkgdir)
3076         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3077         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3079 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3081     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3082 else
3083     %(mmake)-cfg-srcdir=%(srcdir)
3084 endif
3085 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3087 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3089 # When building for the host, we don't need to build the
3090 # linklibs - this is especially true when building the
3091 # crosstool toolchain on 'foreign' architectures (such as
3092 # building PPC on x86)
3094 #MM- %(mmake)-host : setup includes %(mmake)-quick
3095 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3096 #MM- %(mmake): %(mmake)-%(compiler)
3098 # Using -j1 in install_command may result in a warning but finally
3099 # it does its job. make install for gcc does not work reliably for -jN
3100 # where N > 1.
3101 ifneq (%(install_target),)
3102     %(mmake)-install_command = \
3103         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3104         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3105         $(%(mmake)-make-env) %(install_target) -j1
3107     %(mmake)-uninstall_command = \
3108     $(RM) $(%(mmake)-installflag) && \
3109     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3110     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3111 else
3112     %(mmake)-install_command   := true
3113     %(mmake)-uninstall_command := true
3114 endif
3116 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3119 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3122 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3124 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3125         @$(IF) ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3126             $(RM) $(%(mmake)-installflag) && \
3127             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3128             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3129             $(%(mmake)-install_command) && \
3130             $(TOUCH) $@ -r $^; \
3131         fi
3133 $(%(mmake)-pkgdir)/.files-touched:
3134         %mkdirs_q $(%(mmake)-pkgdir)
3135         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3136         $(TOUCH) $@
3139 %(mmake)-uninstall :
3140         $(%(mmake)-uninstall_command)
3143 %(mmake)-configure : $(%(mmake)-configflag)
3145 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3146 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3147         @$(RM) $@
3148         %mkdirs_q $(%(mmake)-pkgdir)
3149         @$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3150         @cd $(%(mmake)-pkgdir) && \
3151         find . -name config.cache -exec $(RM) '{}' \; && \
3152         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3153         $(TOUCH) $@
3156 %(mmake)-clean : %(mmake)-uninstall
3157         @$(RM) $(%(mmake)-pkgdir)
3158 %end
3159 #------------------------------------------------------------------------------
3162 #------------------------------------------------------------------------------
3163 # Build an imported source tree which uses cmake 
3165 # Arguments:
3167 #     - mmake           = the meta make target.
3168 #     - package         = name of the package to be built.
3169 #     - srcdir          = the location of the unpacked source code. Defaults
3170 #                         to $(SRCDIR)/$(CURDIR).
3171 #     - prefix          = the target directory. Must be an absolute path of the
3172 #                         host system. Defaults to $(AROS_CONTRIB).
3173 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3174 #                         Defaults to the value of the prefix option.
3175 #     - extraoptions    = additional options for the cmake script.
3176 #     - usecppflags     = enable the use of cpp flags. some external cmake
3177 #                         scripts will not set their own cppflags if it is already
3178 #                         set, so this allows them to be disabled (unless you can provide
3179 #                         all the options they would need)
3180 #     - cppflags        = preprocessor flags.
3181 #     - cflags          = flags to use with the C compiler.
3182 #     - cxxflags        = flags to use with the C++ compiler.
3183 #     - installoptions    = additional options for the install step.
3186 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3187     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3188     usecppflags=yes cppflags=$(CPPFLAGS) cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3190 ifneq (%(prefix),)
3191     %(mmake)-prefix := %(prefix)
3192 else
3193     %(mmake)-prefix := $(AROS_CONTRIB)
3194 endif
3196 ifneq (%(aros_prefix),)
3197     %(mmake)-aros_prefix := %(aros_prefix)
3198 else
3199     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3200 endif
3202 ifeq (%(compiler),host)
3203     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3204     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3205     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3206     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3207     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3208     ifeq (%(usecppflags),yes)
3209         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3210     endif
3211     %(mmake)-cmake_opts += -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))"
3212     ifeq (%(package),)
3213         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3214     else
3215         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3216     endif
3217 else
3218     BD_LDFLAGS   := %(ldflags)
3219     BD_CFLAGS := %(cflags) 
3220     BD_CXXFLAGS := %(cxxflags)
3221     BD_CPPFLAGS := %(cppflags)
3222     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3223     ifeq (%(usecppflags),yes)
3224         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3225     endif
3226     %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))" -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3227     ifeq (%(package),)
3228         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3229     else
3230         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3231     endif
3232 endif
3233 ifneq (%(gendir),)
3234     ifeq (%(package),)
3235         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3236     else
3237         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3238     endif
3239 endif
3241 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3242 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3244 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3246 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3248 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3251 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3253 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3254         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3255             $(RM)  $(%(mmake)-installflag) && \
3256             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3257             cd $(%(mmake)-pkgdir) && \
3258             cmake %(installoptions) -P cmake_install.cmake && \
3259             $(TOUCH) $@ -r $^; \
3260         fi
3262 $(%(mmake)-pkgdir)/.files-touched:
3263         %mkdirs_q $(%(mmake)-pkgdir)
3264         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3265         $(TOUCH) $@
3268 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3270 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3271 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3272         $(RM) $@
3273         %mkdirs_q $(%(mmake)-pkgdir)
3274         cd $(%(mmake)-pkgdir) && \
3275         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3276         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3277         $(TOUCH) $@
3280 %(mmake)-clean : %(mmake)-uninstall
3281         @$(RM) $(%(mmake)-pkgdir)
3282 %end
3283 #------------------------------------------------------------------------------
3286 #------------------------------------------------------------------------------
3287 # Given an archive name, patches names and locations where to find them, fetch
3288 # the archive and the patches from any of those locations, unpack the archive
3289 # and then apply the patches.
3291 # Locations currently supported are http and ftp sites, plus local filesystem
3292 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3293 # the fetch.sh script needs to be modified, since this macro relies on that script.
3295 # Arguments:
3297 #     - mmake           = mmaketarget
3298 #     - archive_origins = list of locations where to find the archive. They are tried
3299 #                         in sequence, until the archive is found and fetching it 
3300 #                         succeeded. If not specified, the current directory is assumed.
3301 #     - archive         = the archive name. Mandatory.
3302 #     - suffixes        = a list of suffixes to append to the package name plus the
3303 #                         version. Each one of them is tried until a matching archive is
3304 #                         found. They are appended to patches and these are tried the
3305 #                         same way as packages are.
3306 #     - location        = the local directory where to put the fetched archive and patches.
3307 #                         If not specified, the directory specified by destination is used.
3308 #     - destination     = the directory to unpack the archive to.
3309 #                         If not specified, the current directory is assumed.
3310 #     - patches_origins = list of locations where to find the patches. They are tried
3311 #                         in sequence, until a patch is found and fetching it 
3312 #                         succeeded. If not specified, the current directory is assumed.
3313 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3314 #                         patch_name[:[patch_subdir][:patch_opt]].
3316 #                             - patch_name   = the name of the patch file
3317 #                             - patch_subdir = the directory within \destination\ where to
3318 #                                              apply the patch.
3319 #                             - patch_opt    = any options to pass to the `patch' command
3320 #                                              when applying the patch.
3321 #                         
3322 #                         The patch_subdir and patch_opt fields are optional.
3324 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3325     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3327 .PHONY: %(mmake)
3329 ifneq (%(location),)
3330     %(mmake)-location := %(location)
3331 else
3332     %(mmake)-location := %(destination)
3333 endif
3336 %(mmake) :
3337         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3338         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3339 %end
3340 #------------------------------------------------------------------------------
3343 #------------------------------------------------------------------------------
3344 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3345 # unpatched source tree and runs diff against this and a previously fetched and possibly
3346 # patched tree. Depending on what happens after patching during a normal build it might
3347 # give best results if the new patch is created directly after fetch.
3349 # Arguments:
3351 #     - mmake       = mmaketarget
3352 #     - archive     = archive base name
3353 #     - srcdir      = the top level directory the package is unpacked to, useful if
3354 #                     an archive unpacks to a directory other than its name suggests.
3355 #                     this should not be deeper than a single path element.
3356 #     - suffixes    = a list of suffixes to append to the the package name plus the
3357 #                     version. Each one of them is tried until a matching archive is
3358 #                     found.
3359 #     - destination = the directory to unpack the archive to.
3360 #     - excludes    = diff patterns to exclude files or directories from the patch
3362 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3364 .PHONY: %(mmake)
3366 ifneq (%(excludes),)
3367     %(mmake)-exclude := -X ./exclude.patterns
3368 endif
3370 ifneq (%(srcdir),)
3371     %(mmake)-srcdir := %(srcdir)
3372 else
3373     %(mmake)-srcdir := %(archive)
3374 endif
3376 #MM- %(mmake) : %(mmake)-diff
3377 #MM- %(mmake)-quick : %(mmake)-diff
3380 %(mmake)-diff:
3381         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3382         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3383         cd %(destination)/tmp ; \
3384         $(FOR) f in %(excludes) ; do \
3385             $(ECHO) $$f >> ./exclude.patterns ; \
3386         done ; \
3387         diff -ruN $(%(mmake)-exclude) \
3388             $(%(mmake)-srcdir) \
3389             $(%(mmake)-srcdir).aros \
3390             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3391         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3392         $(RM) %(destination)/tmp
3393 %end
3394 #------------------------------------------------------------------------------
3397 #------------------------------------------------------------------------------
3398 # Joins the features of %fetch and %build_with_configure.
3400 # If a patch is provided, it *must* be named the following way:
3402 #    <package name>-<version number>-aros.diff
3404 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3405 # CD'ing into the archive's extracted directory.
3407 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3408 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3409 # to make that patch fully comprehensive.
3411 # Arguments:
3413 #    - mmake            = the meta make target.
3414 #    - package          = the GNU package name, sans version and archive format suffixes.
3415 #    - subpackage       = ???
3416 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3417 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3418 #    - version          = the package's version number, or otherwise any other version string.
3419 #                         It gets appended to the package name to form the basename of the archive.
3420 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3421 #                         version. Each one of them is tried until a matching archive is found.
3422 #                         Defaults to "tar.bz2 tar.gz".
3423 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3424 #    - builddir         = override the location we expect to run configure/make in.
3425 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3426 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3427 #                         fetched or not. Default to no.
3428 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3429 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3430 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3431 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3432 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3433 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3434 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3435 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3436 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3437 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3438 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3439 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3440 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3441 #    - nix              = same meaning as the one for the %build_with_configure macro.
3442 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3443 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3445 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3446     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3447     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3448     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3449     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no buildflags=yes gnuflags=yes
3451 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3452 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3453 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3454 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3456 %(mmake)-archbase  := %(package)-%(version)
3458 ifeq (%(compiler),host)
3459     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3460 else
3461     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3462 endif
3464 ifeq (%(prefix),)
3465     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3466 else
3467     %(mmake)-prefix := %(prefix)
3468 endif
3470 ifneq (%(subpackage),)
3471     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3472 else
3473     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3474 endif
3476 ifneq (%(srcdir),)
3477     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3478 else
3479     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3480 endif
3482 ifneq (%(builddir),)
3483     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3484 else
3485     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3486 endif
3488 ifeq (%(patch),yes)
3489     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3490 else
3491     %(mmake)-%(subpackage)-patches_specs := ::
3492 endif
3494 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3495     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3496     archive_origins=". %(package_repo)" \
3497     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3499 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3500     archive=$(%(mmake)-%(subpackage)-archbase) \
3501     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3502     suffixes="%(suffixes)" \
3503     destination=$(%(mmake)-portdir)
3505 #MM- %(mmake) : %(mmake)-%(subpackage)
3507 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3509 %(mmake)-%(subpackage)-package-basename := \
3510     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3512 ifneq (%(create_pkg),no)
3513     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3514 endif
3516 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3517      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3518      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3519      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3520      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3521      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" buildflags=%(buildflags) gnuflags=%(gnuflags)
3523 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3524 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3527 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3529 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3530 #that $^ and $@ have exactly the same mtime, and in that case make tries
3531 #to rebuild $@ again, which would fail because the directory where
3532 #the package got installed would not exist anymore. 
3533 #We work this around by using an if statement to manually check the mtimes.
3534 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3535         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -f $@; then \
3536             $(RM) $@ ; \
3537             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3538             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3539             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3540             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3541             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3542             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3543         fi
3544 %end
3545 #------------------------------------------------------------------------------
3548 #------------------------------------------------------------------------------
3549 # Joins the features of %fetch and %build_with_configure, taking advantage of
3550 # the naming scheme of GNU packages. GNU packages names are in the form
3552 #     <package name>-<version number>.<archive format suffix>
3554 # If a patch is provided, it *must* be named the following way:
3556 #    <package name>-<version number>-aros.diff
3558 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3559 # CD'ing into the archive's extracted directory.
3561 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3562 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3563 # to make that patch fully comprehensive.
3565 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3567 # Arguments:
3569 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3571 #    - prefix           = defaults to $(GNUDIR).
3572 #    - aros_prefix      = defaults to /GNU.
3574 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3575     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3576     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3577     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3579 GNU_REPOSITORY := gnu://
3581 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3582     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3583     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3584     patch="%(patch)" patch_repo="%(patch_repo)" \
3585     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3586     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=%(nix)
3588 %end
3589 #------------------------------------------------------------------------------
3592 #------------------------------------------------------------------------------
3593 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3594 # that the package is a "Developer" package, and as such it needs to be placed
3595 # under the $(AROS_DEVELOPER) directory, as a default. 
3597 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3598 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3599 # "mmake" argument, because the metatarget is implicitely defined as
3601 #     #MM- development-%(package)
3603 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3604     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3605     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3606     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3608 #MM- development : development-%(package)
3611 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3612    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3613    package_repo="%(package_repo)" \
3614    patch="%(patch)" patch_repo="%(patch_repo)" \
3615    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3616    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" nix=%(nix)
3619 postinstall-%(package)-delete-la-files:
3620         $(RM) %(prefix)/lib/*.la
3622 %end
3623 #------------------------------------------------------------------------------
3625 # Builds a kickstart package in PKG format
3627 # Arguments:
3629 #    - mmake   = target name
3630 #    - file    = destination file name with path
3632 # Other arguments are self-explanatory
3634 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3635     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3637 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3638 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3639 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3640 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3641 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3642 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3644 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3645 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3646 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3647 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3648 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3649 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3651 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3652     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3653 PKG_DIR   := $(dir %(file))
3656 %(mmake) : %(file)
3659 %(mmake)-quick : %(file)
3661 %(file): $(PKG_FILES) | $(PKG_DIR)
3662         @$(ECHO) Packaging $@...
3663         @$(SRCDIR)/tools/package/pkg c $@ $^
3665 %compress_file mmake="%(mmake)" file="%(file)"
3667 GLOB_MKDIRS += $(PKG_DIR)
3669 %end
3671 #------------------------------------------------------------------------------
3672 # Compresses %(file) with a gzip.
3673 # Good in conjunction with for example %build_prog
3675 %define compress_file mmake=/A file=/A
3677 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3680 %(mmake)-gz-quick : %(file).gz
3682 %(file).gz: %(file)
3683         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3684         @gzip -9 -f $^
3686 %end
3688 #------------------------------------------------------------------------------
3689 # Links a kickstart module in ELF format
3690 # Arguments are similar to make_package
3692 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3693     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3695 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3696 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3697 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3698 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3699 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3700 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3702 ifeq (%(startup),)
3703     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3704 else
3705     KOBJ_STARTUP := %(startup)
3706 endif
3708 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3710 TMP_LDFLAGS := %(ldflags)
3712 # Make a list of the lib files this program depends on.
3713 # In LDFLAGS remove white space between -L and directory
3714 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3715 # Filter out only the libdirs and remove -L
3716 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3717 # Add trailing /
3718 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3719 # Add normal linklib path
3720 TMP_DIRS += $(AROS_LIB)/
3721 # add lib and .a to static linklib names
3722 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3723 # search for the linklibs in the given path, ignore ones not found
3724 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3725     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3728 TMP_DIRS += $(dir %(file))
3729 ifneq (%(map),)
3730     TMP_LDFLAGS += $(GENMAP) %(map)
3731     TMP_DIRS    += $(dir %(map))
3732 endif
3734 #MM %(mmake) : %(deps)
3737 %(mmake) : %(file)
3740 %(mmake)-quick : %(file)
3742 %(file): KOBJS := $(KOBJS)
3743 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3744                     -static -nosysbase -Wl,-Ur
3745 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3746 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3747         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3748         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3749 ifeq ($(DEBUG),yes)
3750         @$(STRIP) $@ --only-keep-debug -o $@.dbg
3751 endif
3752         @$(STRIP) $@
3754 %compress_file mmake="%(mmake)" file="%(file)"
3756 GLOB_MKDIRS += $(TMP_DIRS)
3758 %end