make sure kernel/host code also receives USER_ flags...
[AROS.git] / config / make.tmpl
blob07707776871553f00d9a210294cd2e927e946d2f
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)" 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) -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) -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) -c %(from) -o %(to)" 1>&2 ; \
36                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37                 exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd="$(CC) $(TARGET_SYSROOT)" opt=$(AFLAGS) from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                         $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                         $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51                 else \
52                         $(NOP) ; \
53                 fi ; \
54         else \
55                 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57                 exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP) objdir=$(GENDIR)/$(CURDIR)
66         @$(eval LINKTARGET=%(to))
67         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$(LINKTARGET))..."
68         @$(eval LINKTMPFILE=%(objdir)/$(notdir $(LINKTARGET)))
69         @$(IF) %(cmd) %(from) -o $(LINKTMPFILE) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
70                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
71                                 $(ECHO) "$(LINKTARGET): %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" >> $(GENDIR)/errors ; \
72                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
73                 else \
74                         $(NOP) ; \
75                 fi ; \
76                 $(CP) $(LINKTMPFILE) $(LINKTARGET) ; \
77         else \
78                 $(ECHO) "Link failed: %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" 1>&2 ; \
79                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
80                 exit 1 ; \
81         fi; \
82         %(strip) $(LINKTARGET)
83 %end
84 #------------------------------------------------------------------------------
87 #-------------------------------------------------------------------------
88 # Link a module based upon a number of arguments and the standard $(LIBS)
89 # and $(DEPLIBS) make variables.
91 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
92         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
93         @$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
94                 $(GENMAP) %(objdir)/%(module).map \
95                 %(objs) %(libs) %(ldflags) %(endtag) \
96                 -o $@ 2>&1 > %(objdir)/%(err); \
97         then \
98                 cat %(objdir)/%(err); \
99         else \
100                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
101                 cat %(objdir)/%(err); \
102                 exit 1; \
103         fi
105         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
106         @$(STRIP) $@
107 %end
108 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the library
113 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
114         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
115         @%(ar) %(to) %(from)
116         @%(ranlib) %(to)
117 %end
118 #------------------------------------------------------------------------------
121 #------------------------------------------------------------------------------
122 # Create the dependency file %(to) for %(from)
123 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
124         %mkdir_q dir="$(dir %(to))"
125         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
126         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
127 %end
128 #------------------------------------------------------------------------------
131 #------------------------------------------------------------------------------
132 # Create one directory without any output
133 %define mkdir_q dir=.
134         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
135 %end
136 #------------------------------------------------------------------------------
139 #------------------------------------------------------------------------------
140 # Create several directories without any output
141 %define mkdirs_q dirs=/M
142         @$(FOR) dir in %(dirs) ; do \
143             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
144         done
145 %end
146 #------------------------------------------------------------------------------
149 #############################################################################
150 #############################################################################
151 ##                                                                         ##
152 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
153 ## mmakefile. They consist of one or more full makefile rules.             ##
154 ## In general the files generated in these macros are also defined as      ##
155 ## make targets so that they can be used as a dependency in other rules    ##
156 ##                                                                         ##
157 #############################################################################
158 #############################################################################
160 #------------------------------------------------------------------------------
161 # Generate a unique id for each of the %build... rules
162 %define buildid targets=/A
163 BDID := $(BDID)_
164 ifneq ($(filter $(TARGET),%(targets)),)
165 BDTARGETID := $(BDID)
166 endif
167 %end
168 #------------------------------------------------------------------------------
171 #------------------------------------------------------------------------------
172 # Copy file %(from) to %(to) in a makefile rule
173 %define rule_copy from=/A to=/A
174 %(to) : %(from)
175         @$(CP) $< $@
176 %end
177 #------------------------------------------------------------------------------
180 #------------------------------------------------------------------------------
181 # Copy the files %(files) to %(targetdir). For each file in %(files),
182 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
183 # appropriate subdirs are not generated by this rule so they have to be
184 # present.
185 %define rule_copy_multi files=/A targetdir=/A srcdir=.
187 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
188         @$(CP) $< $@
189 %end
190 #------------------------------------------------------------------------------
193 #------------------------------------------------------------------------------
194 # Copy the files %(files) to %(targetdir). For each file in %(files),
195 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
196 # %(stampfile) is used to keep track of when the last time the comparison has
197 # been done. The targetdir and the appropriate subdirs are not generated by 
198 # this rule so they have to be present.
199 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
200     stampfile=$(TMP_SRCDIR)/.copy_stamp
202 TMP_SRCDIR := %(srcdir)
204 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
206 %(stampfile) : COPYSRCDIR := %(srcdir)
207 %(stampfile) : TGTDIR := %(targetdir)
208 %(stampfile) : FILES := %(files)
209 %(stampfile) : $(addprefix %(srcdir)/,%(files))
210         @for f in $(FILES); do \
211              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
212                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
213              fi ; \
214         done
215         @$(TOUCH) $@
216 %end
217 #------------------------------------------------------------------------------
220 #------------------------------------------------------------------------------
221 # Will join all the files in %(from) to %(to). When text is specified it will
222 # be displayed.
223 # Restriction: at the moment when using a non-empty target dir %(from) may
224 # not have 
225 %define rule_join to=/A from=/A text=
227 %(to) : %(from)
228 ifneq (%(text),)
229         @$(ECHO) %(text)
230 endif
231         @$(CAT) $^ >$@
232 %end
233 #------------------------------------------------------------------------------
236 #------------------------------------------------------------------------------
237 # Include the dependency files and add some internal rules
238 # When depstargets is provided the depencies will only be included when one of
239 # these targets is the $(TARGET). Otherwise the dependencies will only be
240 # included when the $(TARGET) is not for setup or clean 
241 %define include_deps deps=$(DEPS)/M  depstargets=
242 ifneq (%(deps),)
243   ifneq (%(depstargets),)
244     ifneq ($(findstring $(TARGET),%(depstargets)),)
245       -include %(deps)
246     endif
247   else
248     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
249       -include %(deps)
250     endif
251   endif
252 endif
253 %end
254 #------------------------------------------------------------------------------
257 #------------------------------------------------------------------------------
258 # Create the directories %(dirs). The creation will be done by adding rules to
259 # the %(setuptarget) make target with setup as the default. 
260 %define rule_makedirs dirs=/A setuptarget=setup
262 %(setuptarget) :: %(dirs)
264 GLOB_MKDIRS += %(dirs)
266 %end
267 #------------------------------------------------------------------------------
270 #------------------------------------------------------------------------------
271 # Generate a rule to compile a C source file to an object file and generate
272 # the dependency file. Basename may contain a directory part, then the source
273 # file has to be in that directory. The generated file will be put in the
274 # object directory without the directory.
275 # options
276 # - basename: the basename of the file to compile. Use % for a wildcard rule
277 # - cflags (default $(CFLAGS)): the C flags to use for compilation
278 # - dflags: the flags used during creation of dependency file. If not specified
279 #   the same value as cflags will be used
280 # - targetdir: the directory to put the .o file and the .d file. By default
281 #   it is put in the same directory as the .c file
282 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
284 BD_NIXFLAG ?= -nix
286 ifeq (%(targetdir),)
287   TMP_TARGETBASE := %(basename)
288 else
289   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
290 endif
292 # Adjust compiler flags to suit C
293 TMP_CFLAGS := %(cflags)
294 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
295 ifeq (%(dflags),)
296   TMP_DFLAGS := %(cflags)
297 else
298   TMP_DFLAGS := %(dflags)
299 endif
301 ifeq ($(findstring %(compiler),host kernel target),)
302   $(error unknown compiler %(compiler))
303 endif
304 ifeq (%(compiler),target)
305 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
306 BD_STRIP ?= $(TARGET_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
309 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TMP_CFLAGS)
310 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_DFLAGS)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
313 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
315 endif
316 ifeq (%(compiler),host)
317 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
318 BD_STRIP ?= $(HOST_STRIP)
319 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
320 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
321 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS) $(USER_CFLAGS) 
322 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS) $(USER_CFLAGS) 
323 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
324 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
325 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
326 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
327 endif
328 ifeq (%(compiler),kernel)
329 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
330 BD_STRIP ?= $(ECHO) >/dev/null
331 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
332 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
333 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS) $(USER_CFLAGS) 
334 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS) $(USER_CFLAGS) 
335 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
336 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
337 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
338 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
339 endif
341 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
342 $(TMP_TARGETBASE).o : %(basename).c
343         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
345 ifeq (%(nix),yes)
346   $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
347 endif
348 $(TMP_TARGETBASE).d : %(basename).c
349         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
350 %end
351 #------------------------------------------------------------------------------
354 #------------------------------------------------------------------------------
355 # Generate a rule to compile a C++ source file to an object file and generate
356 # the dependency file. Basename may contain a directory part, then the source
357 # file has to be in that directory. The generated file will be put in the
358 # object directory without the directory.
359 # options
360 # - basename: the basename of the file to compile. Use % for a wildcard rule
361 # - cflags (default $(CFLAGS)): the C flags to use for compilation
362 # - dflags: the flags used during creation of dependency file. If not specified
363 #   the same value as cflags will be used
364 # - targetdir: the directory to put the .o file and the .d file. By default
365 #   it is put in the same directory as the .c file
366 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
368 ifneq (%(basename),)
369 BD_NIXFLAG ?= -nix
370 ifeq (%(targetdir),)
371   TMP_TARGETBASE := %(basename)
372 else
373   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
374 endif
376 # Adjust compiler flags to suit C++
377 TMP_CXXFLAGS := %(cxxflags)
378 ifeq (%(dxxflags),)
379   TMP_DXXFLAGS := %(cxxflags)
380 else
381   TMP_DXXFLAGS := %(dxxflags)
382 endif
384 ifeq ($(findstring %(compiler),host kernel target),)
385   $(error unknown compiler %(compiler))
386 endif
387 ifeq (%(compiler),target)
388 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
389 BD_STRIP ?= $(TARGET_STRIP)
390 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
391 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
392 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TMP_CXXFLAGS)
393 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TMP_DXXFLAGS)
394 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
395 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
396 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
397 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
398 endif
399 ifeq (%(compiler),host)
400 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
401 BD_STRIP ?= $(HOST_STRIP)
402 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
403 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
404 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS) $(USER_CXXFLAGS) 
405 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS) $(USER_CXXFLAGS) 
406 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
407 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
408 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
409 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
410 endif
411 ifeq (%(compiler),kernel)
412 KERNEL_CXX ?= $(KERNEL_CC)
413 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
414 BD_STRIP ?= $(ECHO) >/dev/null
415 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
416 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
417 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS) $(USER_CXXFLAGS) 
418 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS) $(USER_CXXFLAGS) 
419 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
420 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
421 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
422 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
423 endif
425 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
426 $(TMP_TARGETBASE).o : %(basename).cpp
427         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
429 ifeq (%(nix),yes)
430   $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
431 endif
432 $(TMP_TARGETBASE).d : %(basename).cpp
433         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DXXFLAGS)
435 endif
437 %end
438 #------------------------------------------------------------------------------
441 #------------------------------------------------------------------------------
442 # Generate a rule to compile an ObjC source file to an object file and generate
443 # the dependency file. Basename may contain a directory part, then the source
444 # file has to be in that directory. The generated file will be put in the
445 # object directory without the directory.
446 # options
447 # - basename: the basename of the file to compile. Use % for a wildcard rule
448 # - cflags (default $(CFLAGS)): the C flags to use for compilation
449 # - dflags: the flags used during creation of dependency file. If not specified
450 #   the same value as cflags will be used
451 # - targetdir: the directory to put the .o file and the .d file. By default
452 #   it is put in the same directory as the .m file
453 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
455 ifneq (%(basename),)
456 BD_NIXFLAG ?= -nix
457 ifeq (%(targetdir),)
458   TMP_TARGETBASE := %(basename)
459 else
460   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
461 endif
463 # Adjust compiler flags to suit ObjC
464 TMP_OBJCFLAGS := %(cflags)
465 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
466 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
467 ifeq (%(dflags),)
468   TMP_OBJCDFLAGS := %(cflags)
469 else
470   TMP_OBJCDFLAGS := %(dflags)
471 endif
473 # Define the use of cross compiler
474 ifeq ($(TARGET_OBJC),)
475   TMP_CC := $(TARGET_CC)
476 else
477   TMP_CC := $(TARGET_OBJC)
478 endif
480 ifeq ($(findstring %(compiler),host kernel target),)
481   $(error unknown compiler %(compiler))
482 endif
483 ifeq (%(compiler),target)
484 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
485 BD_STRIP ?= $(TARGET_STRIP)
486 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
487 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
488 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS)
489 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
490 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
491 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
492 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
493 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
494 endif
495 ifeq (%(compiler),host)
496 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
497 BD_STRIP ?= $(HOST_STRIP)
498 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
499 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
500 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS) $(USER_CFLAGS)
501 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS) $(USER_CFLAGS)
502 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
503 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
504 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
505 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
506 endif
507 ifeq (%(compiler),kernel)
508 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
509 BD_STRIP ?= $(ECHO) >/dev/null
510 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
511 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
512 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS) $(USER_CFLAGS)
513 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS) $(USER_CFLAGS)
514 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
515 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
516 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
517 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
518 endif
520 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
521 $(TMP_TARGETBASE).o : %(basename).m
522         %compile_q cmd=$(TMP_CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
524 ifeq (%(nix),yes)
525   $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
526 endif
527 $(TMP_TARGETBASE).d : %(basename).m
528         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_OBJCDFLAGS)
530 endif
532 %end
533 #------------------------------------------------------------------------------
536 #------------------------------------------------------------------------------
537 # Generate a rule to compile multiple C source files to an object file and
538 # generate the corresponding dependency files. The generated file will be put
539 # in the object directory without the directory part of the source file.
540 # options
541 # - basenames: the basenames of the files to compile. The names may include
542 #   relative or absolute path names. No wildcard is allowed
543 # - cflags (default $(CFLAGS)): the C flags to use for compilation
544 # - dflags: the flags used during creation of dependency file. If not specified
545 #   the same value as cflags will be used
546 # - targetdir: the directory to put the .o file and the .d file. By default
547 #   it is put in the same directory as the .c file. When targetdir is not
548 #   empty, path names will be stripped from the file names so that all files
549 #   are in that dir and not in subdirectories.
550 # - compiler (default target): compiler to use, target, kernel or host
551 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= srcdir= targetdir= \
552     compiler=target
554 ifeq (%(srcdir),)
555 TMP_SRCWILDCARD := %
556 else
557 TMP_SRCWILDCARD := %(srcdir)/%
558 endif
560 ifeq (%(targetdir),)
561 TMP_TARGETS := $(addsuffix .o,%(basenames))
562 TMP_DTARGETS := $(addsuffix .d,%(basenames))
563 TMP_TGTWILDCARD := %
564 else
565 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
566 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
567 TMP_TGTWILDCARD := %(targetdir)/%
569 # Be sure that all .c files are generated
570 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
572 # Be sure that all .c files are found
573 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
574 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
575 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
576 ifneq ($(TMP_DIRS),)
577     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
578     vpath %.c $(TMP_DIRS)
579 endif
581 endif
583 TMP_CFLAGS := %(cflags)
584 ifeq (%(dflags),)
585   TMP_DFLAGS := %(cflags)
586 else
587   TMP_DFLAGS := %(dflags)
588 endif
590 ifeq ($(findstring %(compiler),host kernel target),)
591   $(error unknown compiler %(compiler))
592 endif
593 ifeq (%(compiler),target)
594 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
595 BD_STRIP ?= $(TARGET_STRIP)
596 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
597 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
598 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TMP_CFLAGS)
599 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TMP_DFLAGS)
600 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
601 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
602 endif
603 ifeq (%(compiler),host)
604 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
605 BD_STRIP ?= $(HOST_STRIP)
606 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
607 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
608 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS) $(USER_CFLAGS)
609 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS) $(USER_CFLAGS)
610 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
611 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
612 endif
613 ifeq (%(compiler),kernel)
614 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
615 BD_STRIP ?= $(ECHO) >/dev/null
616 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
617 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
618 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS) $(USER_CFLAGS)
619 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS) $(USER_CFLAGS)
620 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
621 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
622 endif
624 $(TMP_TARGETS) : CFLAGS := %(TMP_CFLAGS)
625 $(TMP_TARGETS) : $(TMP_TGTWILDCARD).o : $(TMP_SRCWILDCARD).c
626         %compile_q cmd=$(CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
628 $(TMP_DTARGETS) : $(TMP_TGTWILDCARD).d : $(TMP_SRCWILDCARD).c
629         %mkdepend_q cc=$(CMD) flags=$(TMP_DFLAGS)
630 %end
631 #------------------------------------------------------------------------------
634 #------------------------------------------------------------------------------
635 # Generate a rule to compile multiple C++ source files to an object file and
636 # generate the corresponding dependency files. The generated file will be put
637 # in the object directory without the directory part of the source file.
638 # options
639 # - basenames: the basenames of the files to compile. The names may include
640 #   relative or absolute path names. No wildcard is allowed. basenames will be 
641 #   matched to supported AROS_CXXEXTS.
642 # - cflags (default $(CFLAGS)): the C flags to use for compilation
643 # - dflags: the flags used during creation of dependency file. If not specified
644 #   the same value as cflags will be used
645 # - targetdir: the directory to put the .o file and the .d file. By default
646 #   it is put in the same directory as the .c file. When targetdir is not
647 #   empty, path names will be stripped from the file names so that all files
648 #   are in that dir and not in subdirectories.
649 # - compiler (default target): compiler to use, target, kernel or host
650 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) dxxflags= \
651     targetdir= compiler=target
653 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
655 ifneq ($(TMP_CXXABSBASENAMES),)
657 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
659 # Identify the "real" c++ files from the passed in basenames
660 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
662 ifeq (%(targetdir),)
663   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
664   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
665   TMP_WILDCARD := %
666 else
667   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
668   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
669   TMP_WILDCARD := %(targetdir)/%
671   # Be sure that all source files are generated
672   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
673 endif
675 # Adjust compiler flags to suit C++
676 TMP_CXXFLAGS := %(cxxflags)
677 ifeq (%(dxxflags),)
678   TMP_DXXFLAGS := %(cxxflags)
679 else
680   TMP_DXXFLAGS := %(dxxflags)
681 endif
683 ifeq ($(findstring %(compiler),host kernel target),)
684   $(error unknown compiler %(compiler))
685 endif
686 ifeq (%(compiler),host)
687   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
688   BD_STRIP ?= $(HOST_STRIP)
689   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
690   TMP_CXXCMD:=$(HOST_CXX)
691   TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS) $(USER_CXXFLAGS) 
692   TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS) $(USER_CXXFLAGS) 
693   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
694   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
695 endif
696 ifeq (%(compiler),target)
697   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
698   BD_STRIP ?= $(TARGET_STRIP)
699   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
700   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
701   TMP_CXXFLAGS := $(TMP_CXXFLAGS)
702   TMP_DXXFLAGS := $(TMP_DXXFLAGS)
703   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
704   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
705 endif
706 ifeq (%(compiler),kernel)
707   KERNEL_CXX ?= $(KERNEL_CC)
708   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
709   BD_STRIP ?= $(ECHO) >/dev/null
710   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
711   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
712   TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS) $(USER_CXXFLAGS) 
713   TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS) $(USER_CXXFLAGS) 
714   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
715   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
716 endif
718 define cxx_multi_recipe_template
719  $(1).o : $(2)
720         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
722  $(1).d : $(2)
723         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
724 endef
725 ifeq (%(targetdir),)
726   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
727 else
728   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
729 endif
731 endif
733 %end
734 #------------------------------------------------------------------------------
737 #------------------------------------------------------------------------------
738 # Generate a rule to compile multiple ObjC source files to an object file and
739 # generate the corresponding dependency files. The generated file will be put
740 # in the object directory without the directory part of the source file.
741 # options
742 # - basenames: the basenames of the files to compile. The names may include
743 #   relative or absolute path names. No wildcard is allowed
744 # - cflags (default $(CFLAGS)): the C flags to use for compilation
745 # - dflags: the flags used during creation of dependency file. If not specified
746 #   the same value as cflags will be used
747 # - targetdir: the directory to put the .o file and the .d file. By default
748 #   it is put in the same directory as the .m file. When targetdir is not
749 #   empty, path names will be stripped from the file names so that all files
750 #   are in that dir and not in subdirectories.
751 # - compiler (default target): compiler to use, target, kernel or host
752 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
753     targetdir= compiler=target
755 ifneq (%(basenames),)
757 ifeq (%(targetdir),)
758   TMP_TARGETS := $(addsuffix .o,%(basenames))
759   TMP_DTARGETS := $(addsuffix .d,%(basenames))
760   TMP_WILDCARD := %
761 else
762   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
763   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
764   TMP_WILDCARD := %(targetdir)/%
766   # Be sure that all .m files are generated
767   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
769   # Be sure that all .m files are found
770   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
771   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
772   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
773   ifneq ($(TMP_DIRS),)
774     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
775     vpath %.m $(TMP_DIRS)
776   endif
777 endif
779 # Define the use of cross compiler
780 ifeq ($(TARGET_OBJC),)
781   TMP_CC := $(TARGET_CC)
782 else
783   TMP_CC := $(TARGET_OBJC)
784 endif
786 # Adjust compiler flags to suit ObjC
787 TMP_OBJCFLAGS := %(cflags)
788 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
789 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
790 ifeq (%(dflags),)
791   TMP_OBJCDFLAGS := %(cflags)
792 else
793   TMP_OBJCDFLAGS := %(dflags)
794 endif
796 ifeq ($(findstring %(compiler),host kernel target),)
797   $(error unknown compiler %(compiler))
798 endif
799 ifeq (%(compiler),target)
800   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
801   BD_STRIP ?= $(TARGET_STRIP)
802   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
803   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
804   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS)
805   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
806   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
807   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
808 endif
809 ifeq (%(compiler),host)
810   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
811   BD_STRIP ?= $(HOST_STRIP)
812   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
813   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
814   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS) $(USER_CFLAGS) 
815   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS) $(USER_CFLAGS) 
816   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
817   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
818 endif
819 ifeq (%(compiler),kernel)
820   KERNEL_OBJC ?= $(KERNEL_CC)
821   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
822   BD_STRIP ?= $(ECHO) >/dev/null
823   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
824   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
825   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS) $(USER_CFLAGS) 
826   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS) $(USER_CFLAGS) 
827   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
828   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
829 endif
831 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
832 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
833         %compile_q cmd=$(CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
835 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
836         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
838 endif
840 %end
841 #------------------------------------------------------------------------------
844 #------------------------------------------------------------------------------
845 # Make an alias from one arch specific build to another arch.
846 # arguments:
847 # - mainmmake: the mmake of the module in the main tree
848 # - arch: the current arch
849 # - alias: the alias to which this should point
850 %define rule_archalias mainmmake=\A arch=\A alias=\A
852 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
853 %end
854 #------------------------------------------------------------------------------
857 #------------------------------------------------------------------------------
858 # Generate a rule to assemble a source file to an object file. Basename may
859 # contain a directory part, then the source file has to be in that directory.
860 # The generated file will be put in the object directory without the directory.
861 # options
862 # - basename: the basename of the file to compile. Use % for a wildcard rule
863 # - flags (default $(AFLAGS)): the asm flags to use for assembling
864 # - targetdir: the directory to put the .o file in. By default it is put in the
865 #   same directory as the .s file
866 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
868 ifeq (%(targetdir),)
869 %(basename).o : AFLAGS := %(aflags)
870 %(basename).o : %(basename).s
871         %assemble_q
872 %(basename).o : %(basename).S
873         %assemble_q
875 else
876 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
877 %(targetdir)/$(notdir %(basename)).o : %(basename).s
878         %assemble_q
879 %(targetdir)/$(notdir %(basename)).o : %(basename).S
880         %assemble_q
882 endif
883 %end
884 #------------------------------------------------------------------------------
887 #------------------------------------------------------------------------------
888 # Generate a rule to assemble multiple source files to an object file. The
889 # generated file will be put in the object directory with the directory part
890 # of the source file stripped off.
891 # options
892 # - basenames: the basenames of the files to compile. The names may include
893 #   relative or absolute path names. No wildcard is allowed
894 # - aflags (default $(AFLAGS)): the flags to use for assembly
895 # - targetdir: the directory to put the .o file and the .d file. By default
896 #   it is put in the same directory as the .c file. When targetdir is not
897 #   empty, path names will be stripped from the file names so that all files
898 #   are in that dir and not in subdirectories.
899 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
901 ifeq (%(targetdir),)
902 TMP_TARGETS := $(addsuffix .o,%(basenames))
903 TMP_WILDCARD := %
904 else
905 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
906 TMP_WILDCARD := %(targetdir)/%
908 # Be sure that all .s files are generated
909 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
911 # Be sure that all .c files are found
912 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
913 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
914 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
915 ifneq ($(TMP_DIRS),)
916     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
917     vpath %%(suffix) $(TMP_DIRS)
918 endif
920 endif
922 BD_ASSEMBLER ?= %(cmd)
924 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
926 $(TMP_TARGETS) : AFLAGS := %(aflags)
927 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
928         %assemble_q cmd=$(TMP_CMD)
929 %end
930 #------------------------------------------------------------------------------
933 #------------------------------------------------------------------------------
934 # Link %(objs) to %(prog) using the libraries in %(uselibs)
935 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
936     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
938 TMP_EXTRA_LDFLAGS := 
939 TMP_EXTRA_LIBS :=
940 ifeq (%(nix),yes)
941     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
942 endif
943 ifeq (%(usestartup),no)
944     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
945 endif
946 ifeq (%(detach),yes)
947     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
948 endif
950 # Make a list of the lib files this program depends on.
951 # In LDFLAGS remove white space between -L and directory
952 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
953 # Filter out only the libdirs and remove -L
954 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
955 # Add trailing /
956 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
957 # Add normal linklib path
958 TMP_DIRS += $(AROS_LIB)/
959 # add lib and .a to static linklib names
960 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
961 ifeq (%(usestartup),yes)
962     TMP_LIBS += startup.o
963 endif
964 ifeq (%(detach),yes)
965     TMP_LIBS += detach.o
966 endif
967 # search for the linklibs in the given path, ignore ones not found
968 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
969     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
972 %(prog) : OBJDIR := %(objdir)
973 %(prog) : OBJS := %(objs)
974 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
975 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
976 %(prog) : %(objs) $(TMP_DEPLIBS)
977         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
978 %end
979 #------------------------------------------------------------------------------
982 #------------------------------------------------------------------------------
983 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
984 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
985 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
986     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
987     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
989 TMP_EXTRA_LDFLAGS := 
990 TMP_EXTRA_LIBS :=
991 ifeq (%(nix),yes)
992     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
993 endif
994 ifeq (%(usestartup),no)
995     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
996 endif
997 ifeq (%(detach),yes)
998     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
999 endif
1001 # Make a list of the lib files the programs depend on.
1002 # In LDFLAGS remove white space between -L and directory
1003 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1004 # Filter out only the libdirs and remove -L
1005 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1006 # Add trailing /
1007 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1008 # Add normal linklib path
1009 TMP_DIRS += $(AROS_LIB)/
1010 # add lib and .a to static linklib names
1011 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1012 # search for the linklibs in the given path, ignore ones not found
1013 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1014     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1016 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1018 $(TMP_PROGS) : OBJDIR := %(objdir)
1019 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1020 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1021 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1022         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1023 %end
1024 #------------------------------------------------------------------------------
1027 #------------------------------------------------------------------------------
1028 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1029 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1031 ifeq (%(linker),target)
1032 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1033 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1034 endif
1035 ifeq (%(linker),host)
1036 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1037 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1038 endif
1039 ifeq (%(linker),kernel)
1040 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1041 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1042 endif
1044 %(libdir)/lib%(libname).a : %(objs)
1045         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1046 %end
1047 #------------------------------------------------------------------------------
1049 #------------------------------------------------------------------------------
1050 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1051 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1052 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1053     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1055 TMP_LDFLAGS  := %(ldflags)
1056 # Make a list of the lib files the programs depend on.
1057 # In LDFLAGS remove white space between -L and directory
1058 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1059 # Filter out only the libdirs and remove -L
1060 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1061 # Add trailing /
1062 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1063 # Add normal linklib path
1064 TMP_DIRS += $(AROS_LIB)/
1065 # add lib and .a to static linklib names
1066 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1067 # search for the linklibs in the given path, ignore ones not found
1068 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1069     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1072 %(module) : LIB_NAMES := %(uselibs)
1073 %(module) : OBJS := %(objs)
1074 %(module) : ENDTAG := %(endobj)
1075 %(module) : ERR := %(err)
1076 %(module) : OBJDIR := %(objdir)
1077 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1078 ifeq (%(usehostlibs),)
1079 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1080 else
1081 # Warning: the -L/usr/lib here can result in modules
1082 # linking against host libs instead of AROS libs (e.g stdc++) !!
1083 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1084                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1085 endif 
1086 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1087         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1089 %end
1090 #------------------------------------------------------------------------------
1093 #------------------------------------------------------------------------------
1094 # Generate the libdefs.h include file for a module.
1095 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1097 TMP_TARGET := %(modname)_libdefs.h
1098 TMP_DEPS := $(GENMODULE)
1099 TMP_OPTS := 
1100 ifneq (%(conffile),)
1101     ifeq ($(dir %(conffile)),./)
1102         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1103         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1104     else
1105         TMP_OPTS += -c %(conffile)
1106         TMP_DEPS += %(conffile)
1107     endif 
1108 else
1109     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1110     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1111 endif
1112 ifneq (%(modsuffix),)
1113     TMP_OPTS += -s %(modsuffix)
1114 endif
1115 ifneq (%(targetdir),)
1116     TMP_OPTS += -d %(targetdir)
1117     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1118 endif
1119 ifneq (%(version),)
1120     TMP_OPTS += -v %(version)
1121 endif
1123 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1124 $(TMP_TARGET) : MODNAME := %(modname)
1125 $(TMP_TARGET) : MODTYPE := %(modtype)
1126 $(TMP_TARGET) : $(TMP_DEPS)
1127         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1128         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1129 %end
1130 #------------------------------------------------------------------------------
1132 #------------------------------------------------------------------------------
1133 # Generate the _lib.fd file for a module.
1134 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1136 TMP_TARGET := %(modname)_lib.fd
1137 TMP_DEPS := $(GENMODULE)
1138 TMP_OPTS := 
1139 ifneq (%(conffile),)
1140     ifeq ($(dir %(conffile)),./)
1141         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1142         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1143     else
1144         TMP_OPTS += -c %(conffile)
1145         TMP_DEPS += %(conffile)
1146     endif 
1147 else
1148     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1149     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1150 endif
1151 ifneq (%(modsuffix),)
1152     TMP_OPTS += -s %(modsuffix)
1153 endif
1154 ifneq (%(targetdir),)
1155     TMP_OPTS += -d %(targetdir)
1156     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1157 endif
1159 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1160 $(TMP_TARGET) : MODNAME := %(modname)
1161 $(TMP_TARGET) : MODTYPE := %(modtype)
1162 $(TMP_TARGET) : $(TMP_DEPS)
1163         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1164         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1165 %end
1166 #------------------------------------------------------------------------------
1168 #------------------------------------------------------------------------------
1169 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1170 # generated file in this Makefile
1171 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1172     targetdir=
1174 TMP_TARGET := Makefile.%(modname)%(modtype)
1175 TMP_DEPS := $(GENMODULE)
1176 TMP_OPTS := 
1177 ifneq (%(conffile),)
1178     ifeq ($(dir %(conffile)),./)
1179         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1180         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1181     else
1182         TMP_OPTS += -c %(conffile)
1183         TMP_DEPS += %(conffile)
1184     endif 
1185 else
1186     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1187     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1188 endif
1189 ifneq (%(modsuffix),)
1190     TMP_OPTS += -s %(modsuffix)
1191 endif
1192 ifneq (%(targetdir),)
1193     TMP_OPTS += -d %(targetdir)
1194     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1195 endif
1197 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1198 $(TMP_TARGET) : MODNAME := %(modname)
1199 $(TMP_TARGET) : MODTYPE := %(modtype)
1200 $(TMP_TARGET) : $(TMP_DEPS)
1201         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1202 %end
1203 #------------------------------------------------------------------------------
1206 #------------------------------------------------------------------------------
1207 # Generate the support files for compiling a module. This includes include
1208 # files and source files. This rule has to be preceeded by
1209 # %rule_genmodule_makefile
1210 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= stubdir= \
1211     conffile=
1213 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1214 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1215 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1216 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1217                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1220 TMP_DEPS := $(GENMODULE)
1221 TMP_OPTS :=
1223 ifneq (%(conffile),)
1224     ifeq ($(dir %(conffile)),./)
1225         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1226         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1227     else
1228         TMP_OPTS += -c %(conffile)
1229         TMP_DEPS += %(conffile)
1230     endif 
1231 else
1232     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1233     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1234 endif
1235 ifneq (%(modsuffix),)
1236     TMP_OPTS += -s %(modsuffix)
1237 endif
1238 ifneq (%(targetdir),)
1239     TMP_OPTS += -d %(targetdir)
1240     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1241     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1242 endif
1243 ifneq (%(stubdir),)
1244     TMP_OPTS += -l %(stubdir)
1245     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1246     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1247     TMP_TARGETDIRS += %(stubdir)
1248 else
1249 ifneq (%(targetdir),)
1250     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1251 endif
1252 endif
1254 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1255 ifneq ($(TMP_TARGETDIRS),)
1256 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1257 endif
1259 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1260 $(TMP_TARGETS) : MODNAME := %(modname)
1261 $(TMP_TARGETS) : MODTYPE := %(modtype)
1262 $(TMP_TARGETS) : $(TMP_DEPS)
1263         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1264 ifneq (%(conffile),lib.conf)
1265         @$(IF) $(TEST) -f lib.conf; then \
1266           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1267         fi
1268 endif
1269         @$(IF) $(TEST) -f libdefs.h; then \
1270           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1271         fi
1272         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1273 %end
1274 #------------------------------------------------------------------------------
1277 #------------------------------------------------------------------------------
1278 # Generate the support files for compiling a module. This includes include
1279 # files and source files.
1280 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1281     targetdir= conffile=
1283 ifneq ($(%(modname)_INCLUDES),)
1284 TMP_TARGETS := $(%(modname)_INCLUDES)
1286 TMP_DEPS := $(GENMODULE)
1287 TMP_OPTS :=
1289 ifneq (%(conffile),)
1290     ifeq ($(dir %(conffile)),./)
1291         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1292         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1293     else
1294         TMP_OPTS += -c %(conffile)
1295         TMP_DEPS += %(conffile)
1296     endif 
1297 else
1298     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1299     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1300 endif
1301 ifneq (%(modsuffix),)
1302     TMP_OPTS += -s %(modsuffix)
1303 endif
1304 ifneq (%(targetdir),)
1305     TMP_OPTS += -d %(targetdir)
1306     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1307 endif
1309 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1310 $(TMP_TARGETS) : MODNAME := %(modname)
1311 $(TMP_TARGETS) : MODTYPE := %(modtype)
1312 $(TMP_TARGETS) : $(TMP_DEPS)
1313         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1314         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1315 endif
1316 %end
1317 #------------------------------------------------------------------------------
1319 #------------------------------------------------------------------------------
1320 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1321 # 'start' is an optional starting address
1322 # 'ldflags' is optional additional flags for the linker
1323 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1325 BD_OUTDIR := $(dir %(file))
1326 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1327 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1328 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1329 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1330 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1331 BD_OBJS += %(objs)
1333 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1335 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1336         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1337         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1338         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1340 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1341     GLOB_MKDIRS += $(BD_OUTDIR)
1342 endif
1344 %end
1346 #------------------------------------------------------------------------------
1347 # Common rules for all makefiles
1348 %define common
1349 # Delete generated makefiles
1351 clean ::
1352         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1354 include $(SRCDIR)/config/make.tail
1356 BDID := $(BDTARGETID)
1357 %end
1358 #------------------------------------------------------------------------------
1359       
1361 #############################################################################
1362 #############################################################################
1363 ##                                                                         ##
1364 ## Here are the mmakefile build macros. These are macros that takes care   ##
1365 ## of everything to go from the sources to the generated target. Also all  ##
1366 ## intermediate files and directories that are needed are created by these ##
1367 ## rules.                                                                  ##
1368 ##                                                                         ##
1369 #############################################################################
1370 #############################################################################
1372 #------------------------------------------------------------------------------
1373 # Build a program
1374 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1375     objcfiles= \
1376     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1377     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1378     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1379     includedir= libdir= \
1380     compiler=target linker= lto=$(TARGET_LTO)
1382 .PHONY : %(mmake)
1384 BD_PROGNAME  := %(progname)
1385 BD_OBJDIR    := %(objdir)
1386 BD_TARGETDIR := %(targetdir)
1387 BD_LINKER    := %(linker)
1389 # If not supplied, linker is equal to compiler
1390 ifeq ($(BD_LINKER),)
1391     BD_LINKER := %(compiler)
1392 endif
1394 BD_FILES     := %(files)
1395 BD_OBJCFILES := %(objcfiles)
1396 BD_ASMFILES  := %(asmfiles)
1397 BD_CXXFILES := %(cxxfiles)
1399 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1400 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1401 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1403 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1404 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1405 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1407 BD_CFLAGS    := %(cflags)
1408 BD_CXXFLAGS := %(cxxflags)
1409 ifeq (%(lto),yes)
1410 ifeq (%(compiler),target)
1411 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1412 BD_CXXFLAGS := $(LTO_BINARY_CFLAGS) $(BD_CXXFLAGS)
1413 endif
1414 endif
1415 ifneq (%(includedir),)
1416 BD_CFLAGS    += -I%(includedir)
1417 BD_CXXFLAGS += -I%(includedir)
1418 endif
1419 BD_AFLAGS    := %(aflags)
1420 ifneq (%(includedir),)
1421 BD_AFLAGS    += -I%(includedir)
1422 endif
1423 BD_DFLAGS    := %(dflags)
1424 BD_DXXFLAGS := %(dxxflags)
1425 BD_LDFLAGS   := %(ldflags)
1426 ifneq (%(libdir),)
1427 BD_LDFLAGS   += -L%(libdir)
1428 endif
1431 %(mmake)-quick : %(mmake)
1433 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1434 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1436 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1437 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1438     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1439 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1440     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1441 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1442     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1443 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1444     aflags=$(BD_AFLAGS)
1446 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1447     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1448     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1449     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1450     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1452 endif
1454 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1456 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1457 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1458 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1460 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1462 %(mmake)-clean ::
1463         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1464         @$(RM) $(FILES)
1466 %end
1467 #------------------------------------------------------------------------------
1470 #------------------------------------------------------------------------------
1471 # Build programs, for every C file an executable will be built with the same
1472 # name as the C file
1473 %define build_progs mmake=/A files=/A nix=no \
1474     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1475     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1476     includedir= libdir= \
1477     compiler=target \
1478     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1480 .PHONY : %(mmake)
1482 BD_OBJDIR    := %(objdir)
1483 BD_TARGETDIR := %(targetdir)
1485 BD_FILES     := %(files)
1486 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1487 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1488 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1490 BD_CFLAGS    := %(cflags)
1491 ifeq (%(lto),yes)
1492 ifeq (%(compiler),target)
1493 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1494 endif
1495 endif
1496 ifneq (%(includedir),)
1497     BD_CFLAGS += -I%(includedir)
1498 endif
1499 BD_DFLAGS    := %(dflags)
1500 BD_LDFLAGS   := %(ldflags)
1501 ifneq (%(libdir),)
1502     BD_LDFLAGS += -L%(libdir)
1503 endif
1506 %(mmake)-quick : %(mmake)
1508 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1509 %(mmake) : $(BD_EXES)
1511 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1512 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1513     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1515 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1516     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1517     ldflags=$(BD_LDFLAGS) \
1518     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1519     usestartup="%(usestartup)" detach="%(detach)" \
1520      cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1522 endif
1524 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1526 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1527 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1528 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1530 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1532 %(mmake)-clean ::
1533         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1534         @$(RM) $(FILES)
1536 %end
1537 #------------------------------------------------------------------------------
1540 #------------------------------------------------------------------------------
1541 # Build a module.
1542 # This is a bare version: It just compiles and links the given files. It is
1543 # assumed that all needed boiler plate code is in the files. This should only
1544 # be used for compiling external code. For AROS code use %build_module
1545 %define build_module_simple mmake=/A modname=/A modtype=/A \
1546     files="$(basename $(call WILDCARD, *.c))" \
1547     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1548     objdir=$(OBJDIR) moduledir= \
1549     uselibs= usehostlibs= compiler=target lto=$(TARGET_LTO)
1551 # Define metamake targets and their dependencies
1552 #MM %(mmake) : core-linklibs includes-generate-deps
1553 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1554 #MM %(mmake)-kobj-quick
1555 #MM %(mmake)-quick
1556 #MM %(mmake)-clean
1558 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1560 .PHONY : $(BD_ALLTARGETS)
1562 ifeq (%(modname),)
1563 $(error using %build_module_simple: modname may not be empty)
1564 endif
1565 ifeq (%(modtype),)
1566 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1567 endif
1569 # Default values for variables and arguments
1570 BD_DEFLINKLIBNAME := %(modname)
1571 BD_DEFDFLAGS := %(cflags)
1572 ifeq (%(lto),yes)
1573 ifeq (%(compiler),target)
1574 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(BD_DEFDFLAGS)
1575 endif
1576 endif
1577 BD_DEFDXXFLAGS := %(dxxflags)
1578 OBJDIR ?= $(GENDIR)/$(CURDIR)
1579 BD_MODDIR := %(moduledir)
1580 ifeq ($(BD_MODDIR),)
1581   ifeq (%(modtype),library)
1582     BD_MODDIR  := $(AROS_LIBRARIES)
1583   endif
1584   ifeq (%(modtype),gadget)
1585     BD_MODDIR  := $(AROS_GADGETS)
1586   endif
1587   ifeq (%(modtype),datatype)
1588     BD_MODDIR  := $(AROS_DATATYPES)
1589   endif
1590   ifeq (%(modtype),handler)
1591     BD_MODDIR  := $(AROS_FS)
1592   endif
1593   ifeq (%(modtype),device)
1594     BD_MODDIR  := $(AROS_DEVS)
1595   endif
1596   ifeq (%(modtype),resource)
1597     BD_MODDIR  := $(AROS_RESOURCES)
1598   endif
1599   ifeq (%(modtype),hook)
1600     BD_MODDIR  := $(AROS_RESOURCES)
1601   endif
1602   ifeq (%(modtype),mui)
1603     BD_MODDIR  := $(AROS_CLASSES)/Zune
1604   endif
1605   ifeq (%(modtype),mcc)
1606     BD_MODDIR  := $(AROS_CLASSES)/Zune
1607   endif
1608   ifeq (%(modtype),mcp)
1609     BD_MODDIR  := $(AROS_CLASSES)/Zune
1610   endif
1611   ifeq (%(modtype),usbclass)
1612     BD_MODDIR  := $(AROS_CLASSES)/USB
1613   endif
1614   ifeq (%(modtype),hidd)
1615     BD_MODDIR  := $(AROS_DRIVERS)
1616   endif
1617   ifeq (%(modtype),printer)
1618     BD_MODDIR  := $(AROS_PRINTERS)
1619   endif
1620 endif
1621 ifeq ($(BD_MODDIR),)
1622   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1623 endif
1625 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1626 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1627 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1629 %rule_compile_multi \
1630     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1631     cflags="$(BD_DEFDFLAGS)" dflags="%(dflags)" \
1632     compiler="%(compiler)"
1634 # Handlers use dash instead of dot in their names
1635 ifeq (%(modtype),handler)
1636 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1637 else
1638 ifeq (%(modtype),printer)
1639 BD_MODULE := $(BD_MODDIR)/%(modname)
1640 else
1641 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1642 endif
1643 endif
1644 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1646 %(mmake)-quick : %(mmake)
1647 %(mmake)-kobj-quick : $(BD_KOBJ)
1648 %(mmake)       : $(BD_MODULE)
1649 %(mmake)-kobj  : $(BD_KOBJ)
1651 # The module is linked from all the compiled .o files
1652 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1654 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1655 # This breaks con-handler build. Here we work around this
1656 ifeq (%(modname),con)
1657     BD_ERR := $(notdir $(BD_MODULE)).err
1658 else
1659     BD_ERR := %(modname).err
1660 endif
1662 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1663                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1664                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1665                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1667 # Link kernel object file
1668 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1670 # Make these symbols local
1671 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1672             UtilityBase ExpansionBase KeymapBase KernelBase
1674 BD_SYMBOLS := $(BD_KBASE)
1676 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1677 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1678 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1679 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1680 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1681 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1682         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1683         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1684         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1687 ## Dependency fine-tuning
1689 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1690 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1692 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1693 $(BD_MODULE) : | $(BD_MODDIR)
1694 $(BD_KOBJ) : | $(KOBJSDIR)
1695 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1697 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1698 %(mmake)-clean ::
1699         @$(ECHO) "Cleaning up for module %(modname)"
1700         @$(RM) $(FILES)
1701 %end
1702 #------------------------------------------------------------------------------
1705 #------------------------------------------------------------------------------
1706 # Build a module - core routine
1707 # Explanation of this macro is done in the developer's manual
1708 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1709   files="$(basename $(call WILDCARD, *.c))" \
1710   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1711   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1712   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1713   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1714   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1715   includedir= libdir= \
1716   build_abi= build_library=
1718 # We will employ a terrifying, but unavoidable, hack here.
1719 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1720 # ignores GNU Make ifeq() statements, but will process any #MM
1721 # headed lines in the file.
1723 # So, to make the following #MM lines conditional on whether we want
1724 # to build the ABI, Library, or both, we define build_abi= and 
1725 # build_library as 'M' to enable, or '' to disable, which allows genmf
1726 # to do the following conversions:
1728 #  #%(build_abi)M includes-foo: foo-include
1729 #    becomes, when build_abi=M
1730 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1731 #    but, when build_abi= ...
1732 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1734 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1736 # Define metamake targets and their dependencies
1737 #MM %(mmake)
1738 #MM %(mmake)-quick
1739 #MM %(mmake)-makefile
1740 #MM %(mmake)-clean
1742 # ABI targets:
1743 #M%(build_abi)- includes-all : %(mmake)-includes
1744 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1745 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1746 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1747 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1748 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1749 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1750 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1751 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1752 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1753 #M%(build_abi) %(mmake)-includes-quick
1754 #M%(build_abi) %(mmake)-includes-dirs
1755 #M%(build_abi) %(mmake)-fd
1757 # Library targets
1758 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1759 #%(build_library)M %(mmake)-kobj-quick : 
1761 # Library with ABI targets:
1762 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1763 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1765 # All MetaMake targets defined by this macro
1766 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1768 ifeq (%(build_library),M)
1769 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1770 endif
1772 ifeq (%(build_abi),M)
1773 BD_ALLTARGETS += %(mmake)-includes \
1774                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1775                  %(mmake)-linklib %(mmake)-fd
1776 endif
1778 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1780 ifeq (%(modname),)
1781 $(error using %build_module: modname may not be empty)
1782 endif
1783 ifeq (%(modtype),)
1784 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1785 endif
1787 # Default values for variables and arguments
1788 BD_DEFLINKLIBNAME := %(modname)
1789 BD_DEFDFLAGS := %(cflags)
1790 BD_DEFDXXFLAGS := %(cxxflags)
1791 ifeq (%(lto),yes)
1792 ifeq (%(compiler),target)
1793 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDFLAGS)
1794 BD_DEFDXXFLAGS := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDXXFLAGS)
1795 endif
1796 endif
1797 ifneq (%(includedir),)
1798     BD_DEFDFLAGS += -I%(includedir)
1799     BD_DEFDXXFLAGS += -I%(includedir)
1800 endif
1801 OBJDIR ?= $(GENDIR)/$(CURDIR)
1803 ## Create genmodule include Makefile for the module
1805 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1807 %rule_genmodule_makefile \
1808     modname="%(modname)" modtype="%(modtype)" \
1809     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1810     conffile="%(conffile)"
1812 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1814 GLOB_MKDIRS += %(objdir)
1816 # Do not parse these statements if metatarget is not appropriate
1817 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1819 include %(objdir)/Makefile.%(modname)%(modtype)
1821 BD_DEFMODDIR := $(%(modname)_MODDIR)
1822 ifeq (%(archspecific),yes)
1823 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1824 endif
1827 ## include files generation
1829 ifneq (%(includedir),)
1830 BD_INCDIR    := %(includedir)
1831 else
1832 BD_INCDIR    := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
1833 endif
1834 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1835 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1837 ifeq (%(build_abi),M)
1838 %(mmake)-includes-quick : %(mmake)-includes
1839 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1840     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1841     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1843 ifneq ($(%(modname)_INCLUDES),)
1844 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1845                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1846                          conffile="%(conffile)"
1848 %rule_copy_diff_multi \
1849     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1850     stampfile="%(objdir)/%(modname)_geninc"
1852 %rule_copy_diff_multi \
1853     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1854     stampfile="%(objdir)/%(modname)_incs"
1856 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1858 TMP%(modname)_INCDIRS := \
1859     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1860     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1861     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1862 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1864 endif
1866 endif
1868 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1869                            modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1870                            conffile="%(conffile)" version="%(version)"
1872 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1873 $(BD_DEFLIBDEFSINC) :
1874         @$(ECHO) "Generating $@"
1875         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1877 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1878 GLOB_MKDIRS += %(objdir)/include
1880 ## Extra genmodule src files generation
1881 ## 
1882 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1883                       modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1884                       conffile="%(conffile)"
1886 GLOB_MKDIRS += %(objdir)/linklib
1888 ifeq (%(build_abi),M)
1889 ## Create FD file
1890 ifeq (%(includedir),)
1891 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/fd
1892 else
1893 BD_FDDIR := %(includedir)/../fd
1894 endif
1895 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1897 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1898                    modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1900 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1902 GLOB_MKDIRS += $(BD_FDDIR)
1903 endif
1905 ## Compilation
1907 BD_FILES      := %(files)
1908 BD_CXXFILES := %(cxxfiles)
1910 BD_LIBFILES := %(linklibfiles)
1912 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1914 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1915 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1917 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1918 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1919 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1920 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1921 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1922 BD_NLIBARCHFILES := $(filter-out $(BD_LIBARCHFILES),$(BD_LIBFILES))
1923 BD_ARCHNLIBFILES := $(filter-out $(BD_LIBFILES),$(BD_LIBARCHFILES))
1925 BD_COMMONCFLAGS=-I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1926 BD_CFLAGS        := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_CFLAGS)
1927 BD_LINKLIBCFLAGS := %(cflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBCFLAGS)
1928 BD_CXXFLAGS      := %(cxxflags) $(BD_COMMONCFLAGS) $(%(modname)_CXXFLAGS)
1929 ifeq (%(lto),yes)
1930 ifeq (%(compiler),target)
1931 BD_LTOFLAGS=$(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH)
1932 BD_CFLAGS        := $(BD_LTOFLAGS) $(BD_CFLAGS)
1933 BD_LINKLIBCFLAGS := $(BD_LTOFLAGS) $(BD_LINKLIBCFLAGS)
1934 BD_CXXFLAGS      := $(BD_LTOFLAGS) $(BD_CXXFLAGS)
1935 endif
1936 endif
1937 ifneq (%(includedir),)
1938 BD_CFLAGS        += -I%(includedir)
1939 BD_LINKLIBCFLAGS += -I%(includedir)
1940 BD_CXXFLAGS      += -I%(includedir)
1941 endif
1942 BD_DFLAGS        := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_DFLAGS)
1943 BD_LINKLIBDFLAGS := %(dflags) $(BD_COMMONCFLAGS) $(%(modname)_LINKLIBDFLAGS)
1944 BD_DXXFLAGS      := %(dxxflags) $(BD_COMMONCFLAGS) $(%(modname)_DXXFLAGS)
1946 ifeq (%(modtype),library)
1947     BD_LIBSUFFIX := 
1948 else
1949     BD_LIBSUFFIX := .%(modtype)
1950 endif
1952 ifeq (%(libdir),)
1953 BD_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
1954 else
1955 BD_LIBDIR := %(libdir)
1956 endif
1958 ifeq (%(build_abi),M)
1959 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
1960 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
1961 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1962     BD_LINKLIB :=
1963 else
1964     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1965     ifneq (%(modname),%(linklibname))
1966         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1967     endif
1968 endif
1969 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1971 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
1972 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
1973 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1974     BD_RELLINKLIB :=
1975 else
1976     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1977     ifneq (%(modname),%(linklibname))
1978         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1979     endif
1980 endif
1981 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1982 endif
1984 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1985 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
1986                  %(linklibobjs)
1987 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
1988                  %(linklibobjs)
1989 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
1990 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
1992 BD_CCFILES := $(BD_NARCHFILES)
1993 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
1994 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
1995 BD_LINKLIBCCGENFILES := $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
1997 %rule_compile_cxx_multi \
1998     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1999     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
2000     compiler="%(compiler)"
2001 %rule_compile_multi \
2002     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
2003     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
2004     compiler="%(compiler)"
2005 %rule_compile_multi \
2006     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
2007     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
2008     compiler="%(compiler)"
2009 %rule_compile_multi \
2010     basenames=$(BD_NLIBARCHFILES) targetdir="%(objdir)/linklib" \
2011     cflags="$(BD_LINKLIBCFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2012     compiler="%(compiler)"
2013 %rule_compile_multi \
2014     basenames=$(BD_LINKLIBCCGENFILES) srcdir="%(objdir)/linklib" targetdir="%(objdir)/linklib" \
2015     cflags="$(BD_LINKLIBCFLAGS) -D__AROS__" dflags=$(BD_LINKLIBDFLAGS) \
2016     compiler="%(compiler)"
2018 ifneq ($(BD_LINKLIBAFILES),)
2019 %rule_assemble_multi \
2020     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
2021 endif
2023 ## Linking
2025 ifeq (%(modsuffix),)
2026 BD_SUFFIX := %(modtype)
2027 else
2028 BD_SUFFIX := %(modsuffix)
2029 endif
2031 ifeq (%(build_library),M)
2032 # Handlers use dash instead of dot in their names
2033 ifeq ($(BD_SUFFIX),handler)
2034 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2035 else
2036 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2037 endif
2038 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2039 else
2040 BD_MODULE :=
2041 BD_KOBJ   :=
2042 endif
2044 %(mmake)-quick      : %(mmake)
2045 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2046 ifeq (%(build_library),M)
2047 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2048 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2049 endif
2050 ifeq (%(build_abi),M)
2051 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2052 endif
2054 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2055            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2057 ifeq (%(nostartup),yes)
2058 # Handlers always have entry point
2059 ifneq (%(modtype),handler)
2060 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2061 endif
2062 endif
2064 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2065 # This breaks con-handler build. Here we work around this
2066 ifeq (%(modname),con)
2067     BD_ERR := $(notdir $(BD_MODULE)).err
2068 else
2069     BD_ERR := %(modname).err
2070 endif
2072 ifeq (%(build_library),M)
2073 # The module is linked from all the compiled .o files
2074 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2075                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2076                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2077                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2078 endif
2080 ifeq (%(build_abi),M)
2081 # Link static lib
2082 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2083 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2084 ifneq ($(BD_LINKLIB),)
2085 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2086 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2087 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2088 endif
2090 $(BD_LINKLIB) : | $(BD_LIBDIR)
2091 GLOB_MKDIRS += $(BD_LIBDIR)
2092 endif
2094 ifneq ($(BD_RELLINKLIB),)
2095 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2096 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2097 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2098 endif
2100 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2101 GLOB_MKDIRS += $(BD_LIBDIR)
2102 endif
2103 endif
2105 ifeq (%(build_library),M)
2106 # Link kernel object file
2107 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2109 # Make these symbols local
2110 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2111             UtilityBase ExpansionBase KeymapBase KernelBase
2113 BD_SYMBOLS := $(BD_KBASE)
2115 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2116 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2117 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2118 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2119 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2120 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2121         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2122         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2123         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2124 endif
2126 ## Dependency fine-tuning
2128 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2130 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2132 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2133 $(BD_MODULE) : | %(prefix)/%(moduledir)
2134 $(BD_KOBJ)   : | $(KOBJSDIR)
2135 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2137 # Some include files need to be generated before the .c can be parsed.
2138 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2140 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2141     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2142 $(BD_DEPS) : $(BD_DFILE_DEPS)
2143 endif
2145 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2146     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2147     %(objdir)/Makefile.%(modname)%(modtype) \
2148     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2149     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2150     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2151     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2152     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2153     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2154     $(BD_ENDOBJS)
2155 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2156 %(mmake)-clean ::
2157         @$(ECHO) "Cleaning up for module %(modname)"
2158         @$(RM) $(FILES)
2160 endif # $(TARGET) in $(BD_ALLTARGETS)
2161 %end
2162 #------------------------------------------------------------------------------
2164 #------------------------------------------------------------------------------
2165 # Build a module - ABI and library
2166 # Explanation of this macro is done in the developer's manual
2167 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2168   files="$(basename $(call WILDCARD, *.c))" \
2169   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2170   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2171   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2172   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2173   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2174   includedir= libdir=
2176 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2177    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2178    files="%(files)" cxxfiles="%(cxxfiles)" \
2179    linklibname="%(linklibname)" \
2180    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2181    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2182    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2183    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2184    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2185    includedir="%(includedir)" libdir="%(libdir)" \
2186    build_abi=M build_library=M
2188 %end
2189 #------------------------------------------------------------------------------
2192 #------------------------------------------------------------------------------
2193 # Build a module skeleton ABI
2194 # This is a stripped-down version of build_module, it only creates include
2195 # files and the linklibs.
2196 # This is used when for plugins or classes with the same API, but no actual
2197 # implementation here.
2198 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2199   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2200   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2201   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2202   compiler=target nostartup=yes archspecific=no \
2203   includedir= libdir=
2205 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2206   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2207   linklibname="%(linklibname)" \
2208   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2209   cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2210   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2211   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2212   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2213   includedir="%(includedir)" libdir="%(libdir)" \
2214   build_abi=M build_library=
2216 %end
2217 #------------------------------------------------------------------------------
2219 #------------------------------------------------------------------------------
2220 # Build a module library - no includes nor linklibs
2221 # Explanation of this macro is done in the developer's manual
2222 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2223   files="$(basename $(call WILDCARD, *.c))" \
2224   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2225   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2226   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2227   uselibs= usehostlibs= \
2228   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2229   includedir= libdir=
2231 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2232    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2233    files="%(files)" cxxfiles="%(cxxfiles)" \
2234    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2235    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2236    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2237    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2238   includedir="%(includedir)" libdir="%(libdir)" \
2239    build_abi= build_library=M
2241 %end
2242 #------------------------------------------------------------------------------
2246 #------------------------------------------------------------------------------
2247 # Build a linklib.
2248 # - mmake is the mmaketarget
2249 # - libname is the baselibname e.g. lib%(libname).a will be created
2250 # - files are the C source files to include in the lib. The list of files
2251 #   has to be given without the .c suffix
2252 # - cxxfiles are C++ source files without suffix.
2253 #   NB: files will be matched in the order .cpp > .cxx > .cc
2254 # - asmfiles are the asm files to include in the lib. The list of files has to
2255 #   be given without the .s suffix
2256 # - objs additional object to link into the linklib. The objects have to be
2257 #   given with full absolute path and the .o suffix.
2258 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2259 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2260 # - cflags are the flags to compile the source (default $(CFLAGS))
2261 # - dflags are the flags used during makedepend (default equal to cflags)
2262 # - aflags are the flags used during assembling (default $(AFLAGS))
2263 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2264 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2265   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2266   includedir= \
2267   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2268   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2270 # assign and generate the local variables used in this macro
2271 BD_LIBNAME    := %(libname)
2272 BD_LINKLIB    := %(libdir)/lib%(libname).a
2274 BD_FILES      := %(files)
2275 BD_ASMFILES   := %(asmfiles)
2276 BD_CXXFILES := %(cxxfiles)
2278 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2279 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2280 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2282 BD_OBJS       := $(BD_ARCHOBJS) \
2283                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2284                  %(objs)
2285 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2287 BD_CFLAGS    := %(cflags)
2288 BD_CXXFLAGS := %(cxxflags)
2289 ifeq (%(lto),yes)
2290 ifeq (%(compiler),target)
2291 BD_CFLAGS    := $(LTO_CFLAGS) $(BD_CFLAGS)
2292 BD_CXXFLAGS := $(LTO_CFLAGS) $(BD_CXXFLAGS)
2293 endif
2294 endif
2295 ifneq (%(includedir),)
2296 BD_CFLAGS    += -I%(includedir)
2297 BD_CXXFLAGS += -I%(includedir)
2298 endif
2299 BD_AFLAGS    := %(aflags)
2300 BD_DFLAGS    := %(dflags)
2301 BD_DXXFLAGS := %(dxxflags)
2303 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2306 %(mmake)-quick : %(mmake)
2308 #MM %(mmake) : includes-generate-deps
2309 %(mmake) : $(BD_LINKLIB)
2311 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2313 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2314     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2315 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2316     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2317 %rule_assemble basename=% targetdir="%(objdir)" \
2318     aflags=$(BD_AFLAGS)
2320 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2321 endif
2323 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2325 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2326 $(BD_LINKLIB) : | %(libdir)
2327 GLOB_MKDIRS += %(objdir) %(libdir)
2329 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2331 %(mmake)-clean ::
2332         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2333         @$(RM) $(FILES)
2335 %end
2336 #------------------------------------------------------------------------------
2339 #------------------------------------------------------------------------------
2340 # Build catalogs.
2341 # - mmake is the mmaketarget
2342 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2343 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2344 # - subdir is the destination subdirectory of the catalogs
2345 # - name is the name of the destination catalog, without the .catalog suffix
2346 # - source is the path to the generated source code file
2347 # - dir is the base destination directory (default $(AROS_CATALOGS))
2348 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2349 # - srcdir is the directory in which the *.cd and *.ct files are searched
2351 %define build_catalogs mmake=/A name=/A subdir=/A \
2352  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2353  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2355 ifeq (%(description),)
2356 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2357 else
2358 BD_DESC := %(description)
2359 endif
2361 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2363 ifeq (%(catalogs),)
2364 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2365 else
2366 BD_LNGS := %(catalogs)
2367 endif
2369 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2370 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2373 %(mmake) : $(BD_OBJS) %(source)
2375 $(BD_OBJS) : | $(BD_DIRS)
2376 GLOB_MKDIRS += $(BD_DIRS)
2378 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2379         @$(ECHO) "Creating   %(name) catalog for language $*."
2380         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2382 ifneq (%(source),)
2383 %(source) : BD_DESC := $(BD_DESC)
2384 %(source) : BD_SRC := $(BD_SRC)
2385 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2386         @$(ECHO) "Creating   %(name) catalog source file $@"
2387         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2388 endif
2390 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2392 %(mmake)-clean ::
2393         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2394         @$(RM) $(FILES)
2396 .PHONY: %(mmake) %(mmake)-clean
2398 %end
2399 #-----------------------------------------------------------------------------
2402 #-----------------------------------------------------------------------------
2403 # Build icons.
2404 # - mmake is the mmaketarget
2405 # - icons is a list of icon base names (ie. without the .info suffix)
2406 # - dir is the destination directory
2407 # - srcdir is where *.png and *.info.src are searched
2408 #-----------------------------------------------------------------------------
2410 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2412 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2415 %(mmake) : $(BD_OBJS)
2417 ifeq (%(image),)
2419 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2420         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2421         @$(ILBMTOICON) $+ $@
2423 else
2425 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2426         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2427         @$(ILBMTOICON) $+ $@
2429 endif
2431 $(BD_OBJS) : | %(dir)
2432 GLOB_MKDIRS += %(dir)
2434 %(mmake)-clean : FILES := $(BD_OBJS)
2436 %(mmake)-clean ::
2437         @$(RM) $(FILES)
2439 .PHONY: %(mmake) %(mmake)-clean
2441 %end
2442 #-----------------------------------------------------------------------------
2445 #------------------------------------------------------------------------------
2446 # Compile files for an arch-specific replacement of code for a module
2447 # - files: the basenames of the C files to compile.
2448 # - asmfiles: the basenames of the asm files to assemble.
2449 # - mainmmake: the mmake of the module in the main directory to compile these
2450 #   arch specific files for.
2451 # - maindir: the object directory for the main module
2452 # - arch: the arch for which to compile these files. It can have the form
2453 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2454 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2455 # - dflags: the flags used during creation of dependency file. If not specified
2456 #   the same value as cflags will be used
2457 # - aflags: the flags used during assembling
2458 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2459 #   the target compiler is used
2460 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2461 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2463 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2464     $(error no files or asmfiles given)
2465 endif
2467 ifneq (%(cxxfiles),)
2468     $(error cxx support is TODO)
2469 endif
2471 %buildid targets="%(mainmmake)-%(arch)"
2473 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2474 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2475 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2476 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2477 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2478 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2479 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2480 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2481 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2482 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2483 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2484 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2485 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2486 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2487 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2489 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2491 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2492 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2493 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2494 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2495 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2496 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2497 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2498 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2500 ifneq (%(modulename),)
2501 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2502 endif
2504 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2505     BD_TARGET := %(mainmmake)-%(arch)-quick
2506 else
2507     BD_TARGET := %(mainmmake)-%(arch)
2508 endif
2511 ifeq ($(TARGET),$(BD_TARGET))
2512 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2513 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2514 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2515 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2516 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2517 endif
2519 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2520 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2523 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2526 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2528 ifeq ($(findstring %(compiler),host kernel target),)
2529     $(error unknown compiler %(compiler))
2530 endif
2531 ifeq (%(compiler),target)
2532 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
2533 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2534 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2535 endif
2536 ifeq (%(compiler),host)
2537 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2538 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2539 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2540 endif
2541 ifeq (%(compiler),kernel)
2542 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2543 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2544 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2545 endif
2546 ifneq (%(modulename),)
2547 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2548 else
2549 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2550 endif
2551 ifeq ($(TARGET),$(BD_TARGET))
2552 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2553         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2554 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2555         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2556 endif
2558 ifeq (%(dflags),)
2559 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2560 else
2561 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2562 endif
2563 ifeq ($(TARGET),$(BD_TARGET))
2564 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2565         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2567 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2568         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2569 endif
2571 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2573 ifeq ($(TARGET),$(BD_TARGET))
2574 $(BD_OBJDIR$(BDID))/%.o : %.s
2575         %assemble_q
2576 $(BD_OBJDIR$(BDID))/%.o : %.S
2577         %assemble_q
2578 endif
2580 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2581 %end
2582 #------------------------------------------------------------------------------
2585 #------------------------------------------------------------------------------
2586 # generate asm files from c files (for debugging purposes)
2587 %define ctoasm_q
2588 %.s : %.c
2589         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2590         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $< -c -o $@
2591 %end
2592 #------------------------------------------------------------------------------
2595 #------------------------------------------------------------------------------
2596 # Copy files from one directory to another.
2598 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2600 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2602 GLOB_MKDIRS += %(dst)
2604 .PHONY : %(mmake)
2607 %(mmake) : | %(dst) 
2608         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2610 %end
2611 #------------------------------------------------------------------------------
2614 #------------------------------------------------------------------------------
2615 # Copy a directory recursively to another place, preserving the original 
2616 # hierarchical structure
2618 # src: the source directory whose content will be copied.
2619 # dst: the directories where to copy src's content. If not existing, they will be made.
2620 # excludefiles: files which must not be copied. Path must be relative to src.
2622 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2624 .PHONY : %(mmake)
2627 %(mmake) :
2628         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2630 %end
2631 #------------------------------------------------------------------------------
2634 #------------------------------------------------------------------------------
2635 #   Copy include files into the includes directories. There are currently
2636 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2637 #   for building tools that need to run on the host system $(GENINCDIR). The
2638 #   $(GENINCDIR) path must not contain any references to the C runtime
2639 #   library header files.
2641 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2642     dir= compiler=target includedir=$(AROS_INCLUDES)
2644 ifeq ($(findstring %(compiler),host kernel target),)
2645 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2646 endif
2648 ifneq (%(dir),)
2649 TMP_DIR := %(dir)
2650 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2651 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2652 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2653 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2654 ifeq ($(TMP_DIRFIRST),/)
2655 BD_INC_PATH := %(dir)/
2656 else
2657 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2658 endif
2659 else
2660 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2661 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2662 endif
2664 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2665         @$(CP) $< $@
2667 ifeq (%(compiler),target)
2669 ifneq (%(dir),)
2670 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2671 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2672 else
2673 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2674 endif
2676 BD_INCL_FILES += $(BD_INCL_FILES2)
2678 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2679         @$(CP) $< $@
2680 endif
2683 %(mmake) : $(BD_INCL_FILES)
2685 .PHONY: %(mmake)
2687 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2688 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2689 %end
2690 #------------------------------------------------------------------------------
2693 #------------------------------------------------------------------------------
2694 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2695 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2696 STUBS_MEM := $(addsuffix .o,$(STUBS))
2697 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2698 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2699 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2701 #MM- linklibs : hidd-%(hidd)-stubs
2702 #MM- %(parenttarget): hidd-%(hidd)-stubs
2703 #MM hidd-%(hidd)-stubs : includes includes-copy
2704 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2706 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2707         %mklib_q from=$^
2709 $(STUBS_OBJ) : $(STUBS_SRC) 
2710         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2712 $(STUBS_DEP) : $(STUBS_SRC)
2713         %mkdepend_q flags="%(dflags)"
2715 setup ::
2716         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2719 clean ::
2720         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2722 DEPS := $(DEPS) $(STUBS_DEP)
2724 %end
2725 #------------------------------------------------------------------------------
2728 #------------------------------------------------------------------------------
2729 # Build an imported source tree which uses the configure script from the
2730 # autoconf package.  This rule will try to "integrate" the produced files as
2731 # much as possible in the AROS build, for example by putting libraries in the
2732 # standard library directory, includes in the standard include directory, and
2733 # so on. You can however override this behaviour.
2735 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2736 # be %(bindir) (or its deduced value) when running "make install", and
2737 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2738 # configure script some more parameters whose value depends upon the PROGDIR
2739 # env var, so that the program gets all its stuff installed in the proper place
2740 # when building it, but when running it from inside AROS it can also find that
2741 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2742 # the configuration parameters set when running ./configure
2744 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2745 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2746 # to the name which has to follow it.
2748 # Arguments:
2750 #     - mmake           = the meta make target.
2751 #     - package         = name of the package to be built.
2752 #     - srcdir          = the location of the unpacked source code. Defaults
2753 #                         to $(SRCDIR)/$(CURDIR).
2754 #     - prefix          = the target directory. Must be an absolute path of the
2755 #                         host system. Defaults to $(AROS_CONTRIB).
2756 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2757 #                         Defaults to the value of the prefix option.
2758 #     - extraoptions    = additional options for the configure script.
2759 #     - extracflags     = additional flags to use with the C compiler.
2760 #     - extracxxflags   = additional flags to use with the C++ compiler.
2761 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2762 #                         Defaults to the value of the nix argument.
2763 #     - nix             = enable u*nix path handling, i.e. a path like
2764 #                         /progdir//./file will be translated to
2765 #                         progdir:file during run-time. Defaults to no.
2766 #     - compiler        = target, host or kernel. Defaults to target.
2767 #     - install_target  = the command used for installing. Defaults to install. Leave
2768 #                         it empty if you want to suppress installing.
2769 #     - preconfigure    = a metatarget which is executed before configure is called.
2770 #     - postconfigure   = a metatarget which is executed after configure is called.
2771 #     - postinstall     = a metatarget which is executed after installing.
2772 #     - install_env     = set additional options for installing.
2773 #     - use_build_env   = if yes the configuration environment is used for
2774 #                         installing, too. Defaults to no.
2776 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2777 # like this:
2779 # if nix_dir_layout
2780 #    --prefix = $(aros_prefix)
2781 #    progdir = $(aros_prefix)/bin
2782 # else
2783 #    if nix
2784 #        --prefix = /PROGDIR
2785 #        --bindir = /PROGDIR
2786 #        --sbindir = /PROGDIR
2787 #        --libdir = /LIB
2788 #        --includedir = /INCLUDE
2789 #        --oldincludedir = /INCLUDE   
2790 #    else
2791 #        --prefix = $(aros_prefix)
2792 #    endif
2794 #    progdir = $(aros_prefix)
2796 #    # Install options
2797 #    bindir = $(prefix)
2798 #    sbindir = $(prefix)
2799 #    libdir = $(AROS_LIB)
2800 #    includedir = $(AROS_INCLUDES)
2801 #    oldincludedir = $(AROS_INCLUDES)
2802 # endif
2805 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
2806     prefix= gendir= basedir=$(CURDIR) extraoptions= \
2807     extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
2808     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
2809     install_target=install preconfigure= postconfigure= postinstall= \
2810     config_env_extra= install_env= use_build_env=no gnuflags=yes
2812 ifneq (%(prefix),)
2813     %(mmake)-prefix := %(prefix)
2814 else
2815     %(mmake)-prefix := $(AROS_CONTRIB)
2816 endif
2818 ifneq (%(aros_prefix),)
2819     %(mmake)-aros_prefix := %(aros_prefix)
2820 else
2821     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2822 endif
2824 BD_NIXFLAG ?= -nix
2826 ifeq (%(nix),yes)
2827     %(mmake)-nix    := $(BD_NIXFLAG)
2828     %(mmake)-volpfx := /
2829     %(mmake)-volsfx := /
2830     
2831     ifeq (%(nix_dir_layout),)
2832         %(mmake)-nix_dir_layout := yes
2833     endif
2834 else
2835     %(mmake)-volsfx := :
2836     
2837     ifeq (%(nix_dir_layout),)
2838         %(mmake)-nix_dir_layout := no
2839     endif
2840 endif
2842 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2844 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2845         exec_prefix=$(%(mmake)-prefix) %(install_env)
2847 # Check if chosen compiler is valid
2848 ifeq ($(findstring %(compiler),host target kernel),)
2849   $(error unknown compiler %(compiler))
2850 endif
2852 # Set legacy 'host' variable based on chosen compiler
2853 ifeq (%(compiler),host)
2854     host := yes
2855     ifeq (%(basedir),)
2856         %(mmake)-pkgbasedir := $(HOSTGENDIR)
2857     else
2858         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
2859     endif
2860 else
2861     host := no
2862     ifeq (%(basedir),)
2863         %(mmake)-pkgbasedir := $(GENDIR)
2864     else
2865         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
2866     endif
2867 endif
2868 ifneq (%(gendir),)
2869     ifeq (%(basedir),)
2870         %(mmake)-pkgbasedir := %(gendir)
2871     else
2872         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
2873     endif
2874 endif
2876 ifeq (%(package),)
2877     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
2878 else
2879     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
2880 endif
2882 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2883 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2885 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2886     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2887     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2888 else
2889     ifeq (%(nix),yes)
2890         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2891         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2892     else
2893         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2894     endif
2896     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2897     
2898     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2899         sbindir=$(%(mmake)-prefix) \
2900         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2901         oldincludedir=$(AROS_INCLUDES) %(install_env)
2902 endif
2904 ifneq ($(DEBUG),yes)
2905     %(mmake)-s_flag = -s
2906 endif
2908 # Set up build environment, and options for configure script
2909 ifeq (%(compiler),host)
2910     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2911     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2912     # since that won't get picked up during configure.
2913     # We also cannot pass in the compiler including std flags so we need to use
2914     # the "plain" host compiler.
2915     %(mmake)-cfg-env := %(config_env_extra) \
2916         CPP="$(HOST_CPP)" \
2917         CXXCPP="$(HOST_CPP)" \
2918         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2919         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2920         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2921         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2922         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2923         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2924         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2925         TARGET_AS="$(TARGET_AS)" \
2926         OBJCOPY="$(OBJCOPY)" \
2927         TARGET_RANLIB="$(RANLIB)" \
2928         TARGET_STRIP="$(STRIP_PLAIN)" \
2929         TARGET_NM="$(NM_PLAIN)" \
2930         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2931 endif
2932 ifeq (%(compiler),target)
2933     %(mmake)-cfg-env := %(config_env_extra) \
2934         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
2935         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
2936     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2937         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
2938         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2939         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2940         LD="$(strip $(TARGET_LD))"
2941 ifeq (%(crossbuild),yes)
2942     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
2943         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
2944 else
2945     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2946         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
2947 endif
2948     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2949         CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
2950         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
2951         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
2952         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
2953         LD_FOR_BUILD="$(strip $(HOST_LD))" \
2954         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))" \
2955         CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2956         CFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2957         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2958         CXXFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2959         LD_FOR_HOST="$(strip $(TARGET_LD))" \
2960         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2961         CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
2962         CFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2963         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
2964         CXXFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2965         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
2966         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
2967         AR="$(strip $(AR_PLAIN))" \
2968         AS="$(strip $(TARGET_AS))" \
2969         OBJCOPY="$(strip $(OBJCOPY))" \
2970         RANLIB="$(strip $(RANLIB))" \
2971         STRIP="$(strip $(STRIP_PLAIN))" \
2972         TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
2973         TARGET_CFLAGS="$(strip $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
2974         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
2975         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
2976         TARGET_AS="$(strip $(TARGET_AS))" \
2977         TARGET_RANLIB="$(strip $(RANLIB))" \
2978         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
2979         TARGET_NM="$(strip $(NM_PLAIN))"
2980 ifeq (%(gnuflags),yes)
2981     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2982     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) --host=$(AROS_TARGET_CPU)-aros
2983     %(mmake)-config_opts += --without-pic --disable-shared
2984     %(mmake)-config_opts += --disable-nls --without-x
2985 endif
2986 endif
2987 ifeq (%(compiler),kernel)
2988     %(mmake)-cfg-env := %(config_env_extra) \
2989         CPP="$(KERNEL_CPP)" \
2990         CXXCPP="$(KERNEL_CPP)" \
2991         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2992         CFLAGS="$(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)" \
2993         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2994         CXXFLAGS="$(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag)" \
2995         AS="$(KERNEL_AS)" \
2996         CC_FOR_BUILD="$(HOST_DEF_CC)" \
2997         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2998         CXX_FOR_BUILD="$(HOST_CXX)" \
2999         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3000         RANLIB="$(RANLIB)" \
3001         TARGET_RANLIB="$(RANLIB)" \
3002         TARGET_STRIP="$(STRIP_PLAIN)" \
3003         TARGET_NM="$(NM_PLAIN)"
3004 ifeq (%(gnuflags),yes)
3005     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
3006         --host=$(AROS_TARGET_CPU)-aros\
3007         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
3008         --without-x --without-pic --disable-shared
3009 endif
3010 endif
3012 ifeq (%(use_build_env),yes)
3013     BUILD_ENV := $(%(mmake)-cfg-env)
3014 endif
3016 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3017 # in an ideal world, we would depend on the files in the source directory,
3018 # so we could copy them when they change. unfortunately filenames with
3019 # spaces causes problems with this
3020 $(%(mmake)-pkgdir)/.local-copy:
3021         %mkdirs_q $(%(mmake)-pkgdir)
3022         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3023         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3025 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3027     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3028 else
3029     %(mmake)-cfg-srcdir=%(srcdir)
3030 endif
3031 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3033 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3035 # When building for the host, we don't need to build the
3036 # linklibs - this is especially true when building the
3037 # crosstool toolchain on 'foreign' architectures (such as
3038 # building PPC on x86)
3040 #MM- %(mmake)-host : setup includes %(mmake)-quick
3041 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3042 #MM- %(mmake): %(mmake)-%(compiler)
3044 # Using -j1 in install_command may result in a warning but finally
3045 # it does its job. make install for gcc does not work reliably for -jN
3046 # where N > 1.
3047 ifneq (%(install_target),)
3048     %(mmake)-install_command = \
3049         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3050         $(%(mmake)-make-env) %(install_target) -j1
3052     %(mmake)-uninstall_command = \
3053     $(RM) $(%(mmake)-installflag) && \
3054     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3055     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3056 else
3057     %(mmake)-install_command   := true
3058     %(mmake)-uninstall_command := true
3059 endif
3061 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3064 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3066 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3067         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3068             $(RM) $(%(mmake)-installflag) && \
3069             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3070             $(%(mmake)-install_command) && \
3071             $(TOUCH) $@ -r $^; \
3072         fi
3074 $(%(mmake)-pkgdir)/.files-touched:
3075         %mkdirs_q $(%(mmake)-pkgdir)
3076         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3077         $(TOUCH) $@
3080 %(mmake)-uninstall :
3081         $(%(mmake)-uninstall_command)
3084 %(mmake)-configure : $(%(mmake)-configflag)
3086 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3087 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3088         @$(RM) $@
3089         %mkdirs_q $(%(mmake)-pkgdir)
3090         @cd $(%(mmake)-pkgdir) && \
3091         find . -name config.cache -exec $(RM) '{}' \; && \
3092         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3093         $(TOUCH) $@
3096 %(mmake)-clean : %(mmake)-uninstall
3097         @$(RM) $(%(mmake)-pkgdir)
3098 %end
3099 #------------------------------------------------------------------------------
3102 #------------------------------------------------------------------------------
3103 # Build an imported source tree which uses cmake 
3105 # Arguments:
3107 #     - mmake           = the meta make target.
3108 #     - package         = name of the package to be built.
3109 #     - srcdir          = the location of the unpacked source code. Defaults
3110 #                         to $(SRCDIR)/$(CURDIR).
3111 #     - prefix          = the target directory. Must be an absolute path of the
3112 #                         host system. Defaults to $(AROS_CONTRIB).
3113 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3114 #                         Defaults to the value of the prefix option.
3115 #     - extraoptions    = additional options for the cmake script.
3116 #     - installoptions    = additional options for the install step.
3119 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3120     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3121     cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3123 ifneq (%(prefix),)
3124     %(mmake)-prefix := %(prefix)
3125 else
3126     %(mmake)-prefix := $(AROS_CONTRIB)
3127 endif
3129 ifneq (%(aros_prefix),)
3130     %(mmake)-aros_prefix := %(aros_prefix)
3131 else
3132     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3133 endif
3135 ifeq (%(compiler),host)
3136     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3137     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3138     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3139     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3140     ifeq (%(package),)
3141         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3142     else
3143         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3144     endif
3145 else
3146     BD_LDFLAGS   := %(ldflags)
3147     BD_CFLAGS := %(cflags)
3148     BD_CXXFLAGS := %(cxxflags)
3149     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(BD_LDFLAGS)"
3150     ifeq (%(package),)
3151         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3152     else
3153         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3154     endif
3155 endif
3156 ifneq (%(gendir),)
3157     ifeq (%(package),)
3158         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3159     else
3160         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3161     endif
3162 endif
3164 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3165 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3167 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3169 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3171 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3174 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3176 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3177         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3178             $(RM)  $(%(mmake)-installflag) && \
3179             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3180             cd $(%(mmake)-pkgdir) && \
3181             cmake %(installoptions) -P cmake_install.cmake && \
3182             $(TOUCH) $@ -r $^; \
3183         fi
3185 $(%(mmake)-pkgdir)/.files-touched:
3186         %mkdirs_q $(%(mmake)-pkgdir)
3187         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3188         $(TOUCH) $@
3191 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3193 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3194 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3195         $(RM) $@
3196         %mkdirs_q $(%(mmake)-pkgdir)
3197         cd $(%(mmake)-pkgdir) && \
3198         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3199         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3200         $(TOUCH) $@
3203 %(mmake)-clean : %(mmake)-uninstall
3204         @$(RM) $(%(mmake)-pkgdir)
3205 %end
3206 #------------------------------------------------------------------------------
3209 #------------------------------------------------------------------------------
3210 # Given an archive name, patches names and locations where to find them, fetch
3211 # the archive and the patches from any of those locations, unpack the archive
3212 # and then apply the patches.
3214 # Locations currently supported are http and ftp sites, plus local filesystem
3215 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3216 # the fetch.sh script needs to be modified, since this macro relies on that script.
3218 # Arguments:
3220 #     - mmake           = mmaketarget
3221 #     - archive_origins = list of locations where to find the archive. They are tried
3222 #                         in sequence, until the archive is found and fetching it 
3223 #                         succeeded. If not specified, the current directory is assumed.
3224 #     - archive         = the archive name. Mandatory.
3225 #     - suffixes        = a list of suffixes to append to the the package name plus the
3226 #                         version. Each one of them is tried until a matching archive is
3227 #                         found. They are appended to patches and these are tried the
3228 #                         same way as packages are.
3229 #     - location        = the local directory where to put the fetched archive and patches.
3230 #                         If not specified, the directory specified by destination is used.
3231 #     - destination     = the directory to unpack the archive to.
3232 #                         If not specified, the current directory is assumed.
3233 #     - patches_origins = list of locations where to find the patches. They are tried
3234 #                         in sequence, until a patch is found and fetching it 
3235 #                         succeeded. If not specified, the current directory is assumed.
3236 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3237 #                         patch_name[:[patch_subdir][:patch_opt]].
3239 #                             - patch_name   = the name of the patch file
3240 #                             - patch_subdir = the directory within \destination\ where to
3241 #                                              apply the patch.
3242 #                             - patch_opt    = any options to pass to the `patch' command
3243 #                                              when applying the patch.
3244 #                         
3245 #                         The patch_subdir and patch_opt fields are optional.
3247 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3248     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3250 .PHONY: %(mmake)
3252 ifneq (%(location),)
3253     %(mmake)-location := %(location)
3254 else
3255     %(mmake)-location := %(destination)
3256 endif
3259 %(mmake) :
3260         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3261         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3262 %end
3263 #------------------------------------------------------------------------------
3266 #------------------------------------------------------------------------------
3267 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3268 # unpatched source tree and runs diff against this and a previously fetched and possibly
3269 # patched tree. Depending on what happens after patching during a normal build it might
3270 # give best results if the new patch is created directly after fetch.
3272 # Arguments:
3274 #     - mmake       = mmaketarget
3275 #     - archive     = archive base name
3276 #     - srcdir      = the top level directory the package is unpacked to, useful if
3277 #                     an archive unpacks to a directory other than its name suggests.
3278 #                     this should not be deeper than a single path element.
3279 #     - suffixes    = a list of suffixes to append to the the package name plus the
3280 #                     version. Each one of them is tried until a matching archive is
3281 #                     found.
3282 #     - destination = the directory to unpack the archive to.
3283 #     - excludes    = diff patterns to exclude files or directories from the patch
3285 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3287 .PHONY: %(mmake)
3289 ifneq (%(excludes),)
3290     %(mmake)-exclude := -X ./exclude.patterns
3291 endif
3293 ifneq (%(srcdir),)
3294     %(mmake)-srcdir := %(srcdir)
3295 else
3296     %(mmake)-srcdir := %(archive)
3297 endif
3299 #MM- %(mmake) : %(mmake)-diff
3300 #MM- %(mmake)-quick : %(mmake)-diff
3303 %(mmake)-diff:
3304         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3305         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3306         cd %(destination)/tmp ; \
3307         $(FOR) f in %(excludes) ; do \
3308             $(ECHO) $$f >> ./exclude.patterns ; \
3309         done ; \
3310         diff -ruN $(%(mmake)-exclude) \
3311             $(%(mmake)-srcdir) \
3312             $(%(mmake)-srcdir).aros \
3313             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3314         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3315         $(RM) %(destination)/tmp
3316 %end
3317 #------------------------------------------------------------------------------
3320 #------------------------------------------------------------------------------
3321 # Joins the features of %fetch and %build_with_configure.
3323 # If a patch is provided, it *must* be named the following way:
3325 #    <package name>-<version number>-aros.diff
3327 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3328 # CD'ing into the archive's extracted directory.
3330 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3331 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3332 # to make that patch fully comprehensive.
3334 # Arguments:
3336 #    - mmake            = the meta make target.
3337 #    - package          = the GNU package name, sans version and archive format suffixes.
3338 #    - subpackage       = ???
3339 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3340 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3341 #    - version          = the package's version number, or otherwise any other version string.
3342 #                         It gets appended to the package name to form the basename of the archive.
3343 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3344 #                         version. Each one of them is tried until a matching archive is found.
3345 #                         Defaults to "tar.bz2 tar.gz".
3346 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3347 #    - builddir         = override the location we expect to run configure/make in.
3348 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3349 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3350 #                         fetched or not. Default to no.
3351 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3352 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3353 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3354 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3355 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3356 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3357 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3358 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3359 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3360 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3361 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3362 #    - nix              = same meaning as the one for the %build_with_configure macro.
3363 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3364 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3366 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3367     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3368     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3369     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3370     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no gnuflags=yes
3372 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3373 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3374 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3375 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3377 %(mmake)-archbase  := %(package)-%(version)
3379 ifeq (%(compiler),host)
3380     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3381 else
3382     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3383 endif
3385 ifeq (%(prefix),)
3386     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3387 else
3388     %(mmake)-prefix := %(prefix)
3389 endif
3391 ifneq (%(subpackage),)
3392     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3393 else
3394     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3395 endif
3397 ifneq (%(srcdir),)
3398     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3399 else
3400     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3401 endif
3403 ifneq (%(builddir),)
3404     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3405 else
3406     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3407 endif
3409 ifeq (%(patch),yes)
3410     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3411 else
3412     %(mmake)-%(subpackage)-patches_specs := ::
3413 endif
3415 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3416     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3417     archive_origins=". %(package_repo)" \
3418     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3420 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3421     archive=$(%(mmake)-%(subpackage)-archbase) \
3422     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3423     suffixes="%(suffixes)" \
3424     destination=$(%(mmake)-portdir)
3426 #MM- %(mmake) : %(mmake)-%(subpackage)
3428 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3430 %(mmake)-%(subpackage)-package-basename := \
3431     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3433 ifneq (%(create_pkg),no)
3434     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3435 endif
3437 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3438      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3439      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3440      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3441      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3442      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" gnuflags=%(gnuflags)
3444 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3445 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3448 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3450 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3451 #that $^ and $@ have exactly the same mtime, and in that case make tries
3452 #to rebuild $@ again, which would fail because the directory where
3453 #the package got installed would not exist anymore. 
3454 #We work this around by using an if statement to manually check the mtimes.
3455 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3456         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -f $@; then \
3457             $(RM) $@ ; \
3458             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3459             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3460             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3461             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3462             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3463             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3464         fi
3465 %end
3466 #------------------------------------------------------------------------------
3469 #------------------------------------------------------------------------------
3470 # Joins the features of %fetch and %build_with_configure, taking advantage of
3471 # the naming scheme of GNU packages. GNU packages names are in the form
3473 #     <package name>-<version number>.<archive format suffix>
3475 # If a patch is provided, it *must* be named the following way:
3477 #    <package name>-<version number>-aros.diff
3479 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3480 # CD'ing into the archive's extracted directory.
3482 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3483 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3484 # to make that patch fully comprehensive.
3486 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3488 # Arguments:
3490 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3492 #    - prefix           = defaults to $(GNUDIR).
3493 #    - aros_prefix      = defaults to /GNU.
3495 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3496     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3497     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3498     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3500 GNU_REPOSITORY := gnu://
3502 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3503     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3504     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3505     patch="%(patch)" patch_repo="%(patch_repo)" \
3506     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3507     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=%(nix)
3509 %end
3510 #------------------------------------------------------------------------------
3513 #------------------------------------------------------------------------------
3514 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3515 # that the package is a "Developer" package, and as such it needs to be placed
3516 # under the $(AROS_DEVELOPER) directory, as a default. 
3518 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3519 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3520 # "mmake" argument, because the metatarget is implicitely defined as
3522 #     #MM- development-%(package)
3524 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3525     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3526     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3527     extraoptions=  extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3529 #MM- development : development-%(package)
3532 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3533    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3534    package_repo="%(package_repo)" \
3535    patch="%(patch)" patch_repo="%(patch_repo)" \
3536    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3537    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" nix=%(nix)
3540 postinstall-%(package)-delete-la-files:
3541         $(RM) %(prefix)/lib/*.la
3543 %end
3544 #------------------------------------------------------------------------------
3546 # Builds a kickstart package in PKG format
3548 # Arguments:
3550 #    - mmake   = target name
3551 #    - file    = destination file name with path
3553 # Other arguments are self-explanatory
3555 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3556     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3558 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3559 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3560 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3561 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3562 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3563 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3565 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3566 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3567 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3568 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3569 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3570 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3572 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3573     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3574 PKG_DIR   := $(dir %(file))
3577 %(mmake) : %(file)
3580 %(mmake)-quick : %(file)
3582 %(file): $(PKG_FILES) | $(PKG_DIR)
3583         @$(ECHO) Packaging $@...
3584         @$(SRCDIR)/tools/package/pkg c $@ $^
3586 %compress_file mmake="%(mmake)" file="%(file)"
3588 GLOB_MKDIRS += $(PKG_DIR)
3590 %end
3592 #------------------------------------------------------------------------------
3593 # Compresses %(file) with a gzip.
3594 # Good in conjunction with for example %build_prog
3596 %define compress_file mmake=/A file=/A
3598 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3601 %(mmake)-gz-quick : %(file).gz
3603 %(file).gz: %(file)
3604         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3605         @gzip -9 -f $^
3607 %end
3609 #------------------------------------------------------------------------------
3610 # Links a kickstart module in ELF format
3611 # Arguments are similar to make_package
3613 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3614     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3616 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3617 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3618 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3619 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3620 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3621 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3623 ifeq (%(startup),)
3624     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3625 else
3626     KOBJ_STARTUP := %(startup)
3627 endif
3629 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3631 TMP_LDFLAGS := %(ldflags)
3633 # Make a list of the lib files this program depends on.
3634 # In LDFLAGS remove white space between -L and directory
3635 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3636 # Filter out only the libdirs and remove -L
3637 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3638 # Add trailing /
3639 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3640 # Add normal linklib path
3641 TMP_DIRS += $(AROS_LIB)/
3642 # add lib and .a to static linklib names
3643 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3644 # search for the linklibs in the given path, ignore ones not found
3645 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3646     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3649 TMP_DIRS += $(dir %(file))
3650 ifneq (%(map),)
3651     TMP_LDFLAGS += $(GENMAP) %(map)
3652     TMP_DIRS    += $(dir %(map))
3653 endif
3655 #MM %(mmake) : %(deps)
3658 %(mmake) : %(file)
3661 %(mmake)-quick : %(file)
3663 %(file): KOBJS := $(KOBJS)
3664 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3665                     -static -nosysbase -Wl,-Ur
3666 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3667 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3668         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3669         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3670         @$(STRIP) $@
3672 %compress_file mmake="%(mmake)" file="%(file)"
3674 GLOB_MKDIRS += $(TMP_DIRS)
3676 %end