make sure and pass the kernel ldflags when linking
[AROS.git] / config / make.tmpl
blob1f47549d3bcd4765fee9a738a8272033bfb2ba8f
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_CFLAGS)" 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) 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) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(from) -o %(to) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(opt) %(libs)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(opt) %(libs)" 1>&2 ; \
76             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
77             exit 1 ; \
78         fi; \
79         %(strip) %(to)
80 %end
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd=$(AROS_CC) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(ldflags) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
98             cat %(objdir)/%(err); \
99             exit 1; \
100         fi
102         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
103         @$(STRIP) $@
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the library
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
112         @%(ar) %(to) %(from)
113         @%(ranlib) %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121         %mkdir_q dir="$(dir %(to))"
122         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
124 %end
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
148 ##                                                                         ##
149 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
150 ## mmakefile. They consist of one or more full makefile rules.             ##
151 ## In general the files generated in these macros are also defined as      ##
152 ## make targets so that they can be used as a dependency in other rules    ##
153 ##                                                                         ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
160 BDID := $(BDID)_
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
163 endif
164 %end
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
171 %(to) : %(from)
172         @$(CP) $< $@
173 %end
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
181 # present.
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185         @$(CP) $< $@
186 %end
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by 
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197     stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207         @for f in $(FILES); do \
208              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
210              fi ; \
211         done
212         @$(TOUCH) $@
213 %end
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
219 # be displayed.
220 # Restriction: at the moment when using a non-empty target dir %(from) may
221 # not have 
222 %define rule_join to=/A from=/A text=
224 %(to) : %(from)
225 ifneq (%(text),)
226         @$(ECHO) %(text)
227 endif
228         @$(CAT) $^ >$@
229 %end
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean 
238 %define include_deps deps=$(DEPS)/M  depstargets=
239 ifneq (%(deps),)
240   ifneq (%(depstargets),)
241     ifneq ($(findstring $(TARGET),%(depstargets)),)
242       -include %(deps)
243     endif
244   else
245     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
246       -include %(deps)
247     endif
248   endif
249 endif
250 %end
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default. 
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
263 %end
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
272 # options
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 #   the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 #   it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
281 ifeq (%(targetdir),)
282   TMP_TARGETBASE := %(basename)
283 else
284   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
285 endif
287 # Adjust compiler flags to suit C
288 TMP_CFLAGS := %(cflags)
289 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
291 ifeq ($(findstring %(compiler),host kernel target),)
292   $(error unknown compiler %(compiler))
293 endif
294 ifeq (%(compiler),target)
295 BD_LINK := $(TARGET_CC)
296 BD_STRIP := $(TARGET_STRIP)
297 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
298 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
303 endif
304 ifeq (%(compiler),host)
305 BD_LINK := $(HOST_CC)
306 BD_STRIP := $(HOST_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
313 endif
314 ifeq (%(compiler),kernel)
315 BD_LINK := $(KERNEL_CC) $(KERNEL_LDFLAGS)
316 BD_STRIP := $(ECHO) >/dev/null
317 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
318 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
319 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
320 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
321 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
322 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
323 endif
325 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
326 $(TMP_TARGETBASE).o : %(basename).c
327         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
329 ifeq (%(dflags),)
330   ifeq (%(nix),yes)
331     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
332   else
333     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
334   endif
335 else
336   ifeq (%(nix),yes)
337     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
338   else
339     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
340   endif
341 endif
342 $(TMP_TARGETBASE).d : %(basename).c
343         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
344 %end
345 #------------------------------------------------------------------------------
348 #------------------------------------------------------------------------------
349 # Generate a rule to compile a C++ source file to an object file and generate
350 # the dependency file. Basename may contain a directory part, then the source
351 # file has to be in that directory. The generated file will be put in the
352 # object directory without the directory.
353 # options
354 # - basename: the basename of the file to compile. Use % for a wildcard rule
355 # - cflags (default $(CFLAGS)): the C flags to use for compilation
356 # - dflags: the flags used during creation of dependency file. If not specified
357 #   the same value as cflags will be used
358 # - targetdir: the directory to put the .o file and the .d file. By default
359 #   it is put in the same directory as the .c file
360 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
362 ifeq (%(targetdir),)
363   TMP_TARGETBASE := %(basename)
364 else
365   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
366 endif
368 # Adjust compiler flags to suit C++
369 TMP_CXXFLAGS := %(cflags)
370 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include 
371 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
373 ifeq ($(findstring %(compiler),host kernel target),)
374   $(error unknown compiler %(compiler))
375 endif
376 ifeq (%(compiler),target)
377 BD_LINK := $(AROS_CXX)
378 BD_STRIP := $(TARGET_STRIP)
379 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
380 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
385 endif
386 ifeq (%(compiler),host)
387 BD_LINK := $(HOST_CXX)
388 BD_STRIP := $(HOST_STRIP)
389 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
390 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
391 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
392 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
393 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
394 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
395 endif
396 ifeq (%(compiler),kernel)
397 BD_LINK := $(KERNEL_CXX) $(KERNEL_LDFLAGS)
398 BD_STRIP := $(ECHO) >/dev/null
399 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
400 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
401 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
402 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
403 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
404 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
405 endif
407 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
408 $(TMP_TARGETBASE).o : %(basename).cpp
409         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
411 ifeq (%(dflags),)
412   ifeq (%(nix),yes)
413     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
414   else
415     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
416   endif
417 else
418   ifeq (%(nix),yes)
419     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
420   else
421     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
422   endif
423 endif
424 $(TMP_TARGETBASE).d : %(basename).cpp
425         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
426 %end
427 #------------------------------------------------------------------------------
430 #------------------------------------------------------------------------------
431 # Generate a rule to compile multiple C source files to an object file and
432 # generate the corresponding dependency files. The generated file will be put
433 # in the object directory without the directory part of the source file.
434 # options
435 # - basenames: the basenames of the files to compile. The names may include
436 #   relative or absolute path names. No wildcard is allowed
437 # - cflags (default $(CFLAGS)): the C flags to use for compilation
438 # - dflags: the flags used during creation of dependency file. If not specified
439 #   the same value as cflags will be used
440 # - targetdir: the directory to put the .o file and the .d file. By default
441 #   it is put in the same directory as the .c file. When targetdir is not
442 #   empty, path names will be stripped from the file names so that all files
443 #   are in that dir and not in subdirectories.
444 # - compiler (default target): compiler to use, target, kernel or host
445 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
446     compiler=target
448 ifeq (%(targetdir),)
449 TMP_TARGETS := $(addsuffix .o,%(basenames))
450 TMP_DTARGETS := $(addsuffix .d,%(basenames))
451 TMP_WILDCARD := %
452 else
453 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
454 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
455 TMP_WILDCARD := %(targetdir)/%
457 # Be sure that all .c files are generated
458 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
460 # Be sure that all .c files are found
461 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
462 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
463 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
464 ifneq ($(TMP_DIRS),)
465     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
466     vpath %.c $(TMP_DIRS)
467 endif
469 endif
471 ifeq ($(findstring %(compiler),host kernel target),)
472   $(error unknown compiler %(compiler))
473 endif
474 ifeq (%(compiler),target)
475 BD_LINK := $(TARGET_CC)
476 BD_STRIP := $(TARGET_STRIP)
477 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
478 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
479 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
480 endif
481 ifeq (%(compiler),host)
482 BD_LINK := $(HOST_CC)
483 BD_STRIP := $(HOST_STRIP)
484 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
485 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
486 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
487 endif
488 ifeq (%(compiler),kernel)
489 BD_LINK := $(KERNEL_CC) $(KERNEL_LDFLAGS)
490 BD_STRIP := $(ECHO) >/dev/null
491 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
492 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
493 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
494 endif
496 $(TMP_TARGETS) : CFLAGS := %(cflags)
497 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
498         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
500 ifeq (%(dflags),)
501 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
502 else
503 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
504 endif
505 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
506         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
507 %end
508 #------------------------------------------------------------------------------
511 #------------------------------------------------------------------------------
512 # Generate a rule to compile multiple C++ source files to an object file and
513 # generate the corresponding dependency files. The generated file will be put
514 # in the object directory without the directory part of the source file.
515 # options
516 # - basenames: the basenames of the files to compile. The names may include
517 #   relative or absolute path names. No wildcard is allowed. basenames will be 
518 #   matched to supported AROS_CXXEXTS.
519 # - cflags (default $(CFLAGS)): the C flags to use for compilation
520 # - dflags: the flags used during creation of dependency file. If not specified
521 #   the same value as cflags will be used
522 # - targetdir: the directory to put the .o file and the .d file. By default
523 #   it is put in the same directory as the .c file. When targetdir is not
524 #   empty, path names will be stripped from the file names so that all files
525 #   are in that dir and not in subdirectories.
526 # - compiler (default target): compiler to use, target, kernel or host
527 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
528     targetdir= compiler=target
530 # Adjust compiler flags to suit C++
531 TMP_CXXFLAGS := %(cflags)
532 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
533 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include
535 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
536 ifneq ($(TMP_CXXABSBASENAMES),)
537 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
539 # Identify the "real" c++ files from the passed in basenames
540 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
542 ifeq (%(targetdir),)
543   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
544   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
545   TMP_WILDCARD := %
546 else
547   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
548   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
549   TMP_WILDCARD := %(targetdir)/%
551   # Be sure that all source files are generated
552   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
553 endif
555 ifeq ($(findstring %(compiler),host kernel target),)
556   $(error unknown compiler %(compiler))
557 endif
558 ifeq (%(compiler),target)
559   BD_LINK := $(AROS_CXX)
560   BD_STRIP := $(TARGET_STRIP)
561   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_CFLAGS)
562   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
563   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
564 endif
565 ifeq (%(compiler),host)
566   BD_LINK := $(HOST_CXX)
567   BD_STRIP := $(TARGET_STRIP)
568   TMP_CXXCMD:=$(HOST_CXX)
569   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
570   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
571 endif
572 ifeq (%(compiler),kernel)
573   BD_LINK := $(KERNEL_CXX) $(KERNEL_LDFLAGS)
574   BD_STRIP := $(ECHO) >/dev/null
575   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
576   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
577   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
578 endif
580 ifeq (%(dflags),)
581   TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
582 else
583   ifeq (%(dflags),%(cflags))
584     TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
585   else
586     TMP_CXXDFLAGS:=%(dflags)
587   endif
588 endif
590 define cxx_multi_recipe_template
591  $(1).o : $(2)
592         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
594  $(1).d : $(2)
595         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
596 endef
597 ifeq (%(targetdir),)
598   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
599 else
600   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
601 endif
602 endif
603 %end
604 #------------------------------------------------------------------------------
607 #------------------------------------------------------------------------------
608 # Generate a rule to compile an ObjC source file to an object file and generate
609 # the dependency file. Basename may contain a directory part, then the source
610 # file has to be in that directory. The generated file will be put in the
611 # object directory without the directory.
612 # options
613 # - basename: the basename of the file to compile. Use % for a wildcard rule
614 # - cflags (default $(CFLAGS)): the C flags to use for compilation
615 # - dflags: the flags used during creation of dependency file. If not specified
616 #   the same value as cflags will be used
617 # - targetdir: the directory to put the .o file and the .d file. By default
618 #   it is put in the same directory as the .m file
619 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
621 ifeq (%(targetdir),)
622   TMP_TARGETBASE := %(basename)
623 else
624   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
625 endif
627 # Adjust compiler flags to suit ObjC
628 TMP_OBJCFLAGS := %(cflags)
629 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
630 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
632 # Define the use of cross compiler
633 ifeq ($(TARGET_OBJC),)
634   TMP_CC := $(TARGET_CC)
635 else
636   TMP_CC := $(TARGET_OBJC)
637 endif
639 ifeq ($(findstring %(compiler),host kernel target),)
640   $(error unknown compiler %(compiler))
641 endif
642 ifeq (%(compiler),target)
643 BD_LINK := $(TMP_CC)
644 BD_STRIP := $(TARGET_STRIP)
645 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_CFLAGS)
646 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_CFLAGS)
647 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
648 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
649 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
650 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
651 endif
652 ifeq (%(compiler),host)
653 BD_LINK := $(HOST_CC)
654 BD_STRIP := $(HOST_STRIP)
655 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
656 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
657 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
658 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
659 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
660 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
661 endif
662 ifeq (%(compiler),kernel)
663 BD_LINK := $(KERNEL_CC) $(KERNEL_LDFLAGS)
664 BD_STRIP := $(ECHO) >/dev/null
665 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
666 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
667 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
668 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
669 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
670 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
671 endif
673 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
674 $(TMP_TARGETBASE).o : %(basename).m
675         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
677 ifeq (%(dflags),)
678   ifeq (%(nix),yes)
679     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
680   else
681     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
682   endif
683 else
684   ifeq (%(nix),yes)
685     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
686   else
687     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
688   endif
689 endif
690 $(TMP_TARGETBASE).d : %(basename).m
691         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
692 %end
693 #------------------------------------------------------------------------------
695 #------------------------------------------------------------------------------
696 # Generate a rule to compile multiple ObjC source files to an object file and
697 # generate the corresponding dependency files. The generated file will be put
698 # in the object directory without the directory part of the source file.
699 # options
700 # - basenames: the basenames of the files to compile. The names may include
701 #   relative or absolute path names. No wildcard is allowed
702 # - cflags (default $(CFLAGS)): the C flags to use for compilation
703 # - dflags: the flags used during creation of dependency file. If not specified
704 #   the same value as cflags will be used
705 # - targetdir: the directory to put the .o file and the .d file. By default
706 #   it is put in the same directory as the .m file. When targetdir is not
707 #   empty, path names will be stripped from the file names so that all files
708 #   are in that dir and not in subdirectories.
709 # - compiler (default target): compiler to use, target, kernel or host
710 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
711     targetdir= compiler=target
713 # Adjust compiler flags to suit ObjC
714 TMP_OBJCFLAGS := %(cflags)
715 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
716 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
718 ifeq (%(targetdir),)
719   TMP_TARGETS := $(addsuffix .o,%(basenames))
720   TMP_DTARGETS := $(addsuffix .d,%(basenames))
721   TMP_WILDCARD := %
722 else
723   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
724   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
725   TMP_WILDCARD := %(targetdir)/%
727   # Be sure that all .m files are generated
728   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
730   # Be sure that all .m files are found
731   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
732   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
733   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
734   ifneq ($(TMP_DIRS),)
735     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
736     vpath %.m $(TMP_DIRS)
737   endif
738 endif
740 # Define the use of cross compiler
741 ifeq ($(TARGET_OBJC),)
742   TMP_CC := $(TARGET_CC)
743 else
744   TMP_CC := $(TARGET_OBJC)
745 endif
747 ifeq ($(findstring %(compiler),host kernel target),)
748   $(error unknown compiler %(compiler))
749 endif
750 ifeq (%(compiler),target)
751   BD_LINK := $(TMP_CC)
752   BD_STRIP := $(TARGET_STRIP)
753   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
754   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
755   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
756 endif
757 ifeq (%(compiler),host)
758   BD_LINK := $(HOST_OBJC)
759   BD_STRIP := $(HOST_STRIP)
760   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
761   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
762   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
763 endif
764 ifeq (%(compiler),kernel)
765   BD_LINK := $(KERNEL_OBJC) $(KERNEL_LDFLAGS)
766   BD_STRIP := $(ECHO) >/dev/null
767   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
768   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
769   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
770 endif
772 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
773 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
774         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
776 ifeq (%(dflags),)
777   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
778 else
779   ifeq (%(dflags),%(cflags))
780     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
781   else
782     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
783   endif
784 endif
785 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
786         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
787 %end
788 #------------------------------------------------------------------------------
791 #------------------------------------------------------------------------------
792 # Make an alias from one arch specific build to another arch.
793 # arguments:
794 # - mainmmake: the mmake of the module in the main tree
795 # - arch: the current arch
796 # - alias: the alias to which this should point
797 %define rule_archalias mainmmake=\A arch=\A alias=\A
799 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
800 %end
801 #------------------------------------------------------------------------------
804 #------------------------------------------------------------------------------
805 # Generate a rule to assemble a source file to an object file. Basename may
806 # contain a directory part, then the source file has to be in that directory.
807 # The generated file will be put in the object directory without the directory.
808 # options
809 # - basename: the basename of the file to compile. Use % for a wildcard rule
810 # - flags (default $(AFLAGS)): the asm flags to use for assembling
811 # - targetdir: the directory to put the .o file in. By default it is put in the
812 #   same directory as the .s file
813 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
815 ifeq (%(targetdir),)
816 %(basename).o : AFLAGS := %(aflags)
817 %(basename).o : %(basename).s
818         %assemble_q
819 %(basename).o : %(basename).S
820         %assemble_q
822 else
823 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
824 %(targetdir)/$(notdir %(basename)).o : %(basename).s
825         %assemble_q
826 %(targetdir)/$(notdir %(basename)).o : %(basename).S
827         %assemble_q
829 endif
830 %end
831 #------------------------------------------------------------------------------
834 #------------------------------------------------------------------------------
835 # Generate a rule to assemble multiple source files to an object file. The
836 # generated file will be put in the object directory with the directory part
837 # of the source file stripped off.
838 # options
839 # - basenames: the basenames of the files to compile. The names may include
840 #   relative or absolute path names. No wildcard is allowed
841 # - aflags (default $(AFLAGS)): the flags to use for assembly
842 # - targetdir: the directory to put the .o file and the .d file. By default
843 #   it is put in the same directory as the .c file. When targetdir is not
844 #   empty, path names will be stripped from the file names so that all files
845 #   are in that dir and not in subdirectories.
846 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
848 ifeq (%(targetdir),)
849 TMP_TARGETS := $(addsuffix .o,%(basenames))
850 TMP_WILDCARD := %
851 else
852 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
853 TMP_WILDCARD := %(targetdir)/%
855 # Be sure that all .s files are generated
856 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
858 # Be sure that all .c files are found
859 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
860 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
861 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
862 ifneq ($(TMP_DIRS),)
863     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
864     vpath %%(suffix) $(TMP_DIRS)
865 endif
867 endif
869 ifeq ($(findstring %(compiler),host kernel target),)
870   $(error unknown compiler %(compiler))
871 endif
872 ifeq (%(compiler),target)
873 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
874 endif
875 ifeq (%(compiler),host)
876 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
877 endif
878 ifeq (%(compiler),kernel)
879 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
880 endif
882 $(TMP_TARGETS) : AFLAGS := %(aflags)
883 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
884         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
885 %end
886 #------------------------------------------------------------------------------
889 #------------------------------------------------------------------------------
890 # Link %(objs) to %(prog) using the libraries in %(uselibs)
891 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
892     usehostlibs= usestartup=yes detach=no nix=no cmd=$(AROS_CC) strip=$(TARGET_STRIP)
894 TMP_EXTRA_LDFLAGS := 
895 TMP_EXTRA_LIBS :=
896 ifeq (%(nix),yes)
897     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
898 endif
899 ifeq (%(usestartup),no)
900     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
901 endif
902 ifeq (%(detach),yes)
903     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
904 endif
906 # Make a list of the lib files this program depends on.
907 # In LDFLAGS remove white space between -L and directory
908 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
909 # Filter out only the libdirs and remove -L
910 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
911 # Add trailing /
912 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
913 # Add normal linklib path
914 TMP_DIRS += $(AROS_LIB)/
915 # add lib and .a to static linklib names
916 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
917 ifeq (%(usestartup),yes)
918     TMP_LIBS += startup.o
919 endif
920 ifeq (%(detach),yes)
921     TMP_LIBS += detach.o
922 endif
923 # search for the linklibs in the given path, ignore ones not found
924 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
925     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
928 %(prog) : OBJS := %(objs)
929 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
930 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
931 %(prog) : %(objs) $(TMP_DEPLIBS)
932         %link_q cmd=%(cmd) strip=%(strip) from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
933 %end
934 #------------------------------------------------------------------------------
937 #------------------------------------------------------------------------------
938 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
939 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
940 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
941     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
942     usestartup=yes detach=no cmd=$(AROS_CC) strip=$(TARGET_STRIP)
944 TMP_EXTRA_LDFLAGS := 
945 TMP_EXTRA_LIBS :=
946 ifeq (%(nix),yes)
947     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
948 endif
949 ifeq (%(usestartup),no)
950     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
951 endif
952 ifeq (%(detach),yes)
953     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
954 endif
956 # Make a list of the lib files the programs depend on.
957 # In LDFLAGS remove white space between -L and directory
958 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
959 # Filter out only the libdirs and remove -L
960 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
961 # Add trailing /
962 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
963 # Add normal linklib path
964 TMP_DIRS += $(AROS_LIB)/
965 # add lib and .a to static linklib names
966 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
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)))) \
971 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
973 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
974 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
975 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
976         %link_q cmd=%(cmd) strip=%(strip) from=$< opt=$(LDFLAGS) libs=$(LIBS)
977 %end
978 #------------------------------------------------------------------------------
981 #------------------------------------------------------------------------------
982 # Link the %(objs) to the library %(libdir)/lib%(libname).a
983 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
985 ifeq (%(linker),target)
986 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
987 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
988 endif
989 ifeq (%(linker),host)
990 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
991 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
992 endif
993 ifeq (%(linker),kernel)
994 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
995 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
996 endif
998 %(libdir)/lib%(libname).a : %(objs)
999         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1000 %end
1001 #------------------------------------------------------------------------------
1003 #------------------------------------------------------------------------------
1004 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1005 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1006 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1007     cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
1009 TMP_LDFLAGS  := %(ldflags)
1010 # Make a list of the lib files the programs depend on.
1011 # In LDFLAGS remove white space between -L and directory
1012 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1013 # Filter out only the libdirs and remove -L
1014 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1015 # Add trailing /
1016 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1017 # Add normal linklib path
1018 TMP_DIRS += $(AROS_LIB)/
1019 # add lib and .a to static linklib names
1020 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1021 # search for the linklibs in the given path, ignore ones not found
1022 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1023     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1026 %(module) : LIB_NAMES := %(uselibs)
1027 %(module) : OBJS := %(objs)
1028 %(module) : ENDTAG := %(endobj)
1029 %(module) : ERR := %(err)
1030 %(module) : OBJDIR := %(objdir)
1031 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1032 ifeq (%(usehostlibs),)
1033 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1034 else
1035 # Warning: the -L/usr/lib here can result in modules
1036 # linking against host libs instead of AROS libs (e.g stdc++) !!
1037 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1038                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1039 endif 
1040 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1041         %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS)"
1043 %end
1044 #------------------------------------------------------------------------------
1047 #------------------------------------------------------------------------------
1048 # Generate the libdefs.h include file for a module.
1049 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1051 TMP_TARGET := %(modname)_libdefs.h
1052 TMP_DEPS := $(GENMODULE)
1053 TMP_OPTS := 
1054 ifneq (%(conffile),)
1055     ifeq ($(dir %(conffile)),./)
1056         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1057         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1058     else
1059         TMP_OPTS += -c %(conffile)
1060         TMP_DEPS += %(conffile)
1061     endif 
1062 else
1063     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1064     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1065 endif
1066 ifneq (%(modsuffix),)
1067     TMP_OPTS += -s %(modsuffix)
1068 endif
1069 ifneq (%(targetdir),)
1070     TMP_OPTS += -d %(targetdir)
1071     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1072 endif
1073 ifneq (%(version),)
1074     TMP_OPTS += -v %(version)
1075 endif
1077 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1078 $(TMP_TARGET) : MODNAME := %(modname)
1079 $(TMP_TARGET) : MODTYPE := %(modtype)
1080 $(TMP_TARGET) : $(TMP_DEPS)
1081         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1082         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1083 %end
1084 #------------------------------------------------------------------------------
1086 #------------------------------------------------------------------------------
1087 # Generate the _lib.fd file for a module.
1088 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1090 TMP_TARGET := %(modname)_lib.fd
1091 TMP_DEPS := $(GENMODULE)
1092 TMP_OPTS := 
1093 ifneq (%(conffile),)
1094     ifeq ($(dir %(conffile)),./)
1095         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1096         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1097     else
1098         TMP_OPTS += -c %(conffile)
1099         TMP_DEPS += %(conffile)
1100     endif 
1101 else
1102     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1103     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1104 endif
1105 ifneq (%(modsuffix),)
1106     TMP_OPTS += -s %(modsuffix)
1107 endif
1108 ifneq (%(targetdir),)
1109     TMP_OPTS += -d %(targetdir)
1110     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1111 endif
1113 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1114 $(TMP_TARGET) : MODNAME := %(modname)
1115 $(TMP_TARGET) : MODTYPE := %(modtype)
1116 $(TMP_TARGET) : $(TMP_DEPS)
1117         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1118         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1119 %end
1120 #------------------------------------------------------------------------------
1122 #------------------------------------------------------------------------------
1123 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1124 # generated file in this Makefile
1125 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1126     targetdir=
1128 TMP_TARGET := Makefile.%(modname)%(modtype)
1129 TMP_DEPS := $(GENMODULE)
1130 TMP_OPTS := 
1131 ifneq (%(conffile),)
1132     ifeq ($(dir %(conffile)),./)
1133         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1134         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1135     else
1136         TMP_OPTS += -c %(conffile)
1137         TMP_DEPS += %(conffile)
1138     endif 
1139 else
1140     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1141     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1142 endif
1143 ifneq (%(modsuffix),)
1144     TMP_OPTS += -s %(modsuffix)
1145 endif
1146 ifneq (%(targetdir),)
1147     TMP_OPTS += -d %(targetdir)
1148     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1149 endif
1151 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1152 $(TMP_TARGET) : MODNAME := %(modname)
1153 $(TMP_TARGET) : MODTYPE := %(modtype)
1154 $(TMP_TARGET) : $(TMP_DEPS)
1155         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1156 %end
1157 #------------------------------------------------------------------------------
1160 #------------------------------------------------------------------------------
1161 # Generate the support files for compiling a module. This includes include
1162 # files and source files. This rule has to be preceeded by
1163 # %rule_genmodule_makefile
1164 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1165     conffile=
1167 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1168                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1169 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1170                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1172 TMP_DEPS := $(GENMODULE)
1173 TMP_OPTS :=
1175 ifneq (%(conffile),)
1176     ifeq ($(dir %(conffile)),./)
1177         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1178         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1179     else
1180         TMP_OPTS += -c %(conffile)
1181         TMP_DEPS += %(conffile)
1182     endif 
1183 else
1184     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1185     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1186 endif
1187 ifneq (%(modsuffix),)
1188     TMP_OPTS += -s %(modsuffix)
1189 endif
1190 ifneq (%(targetdir),)
1191     TMP_OPTS += -d %(targetdir)
1192     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1193     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1194 endif
1196 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1197 $(TMP_TARGETS) : MODNAME := %(modname)
1198 $(TMP_TARGETS) : MODTYPE := %(modtype)
1199 $(TMP_TARGETS) : $(TMP_DEPS)
1200         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1201 ifneq (%(conffile),lib.conf)
1202         @$(IF) $(TEST) -f lib.conf; then \
1203           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1204         fi
1205 endif
1206         @$(IF) $(TEST) -f libdefs.h; then \
1207           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1208         fi
1209         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1210 %end
1211 #------------------------------------------------------------------------------
1214 #------------------------------------------------------------------------------
1215 # Generate the support files for compiling a module. This includes include
1216 # files and source files.
1217 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1218     targetdir= conffile=
1220 ifneq ($(%(modname)_INCLUDES),)
1221 TMP_TARGETS := $(%(modname)_INCLUDES)
1223 TMP_DEPS := $(GENMODULE)
1224 TMP_OPTS :=
1226 ifneq (%(conffile),)
1227     ifeq ($(dir %(conffile)),./)
1228         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1229         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1230     else
1231         TMP_OPTS += -c %(conffile)
1232         TMP_DEPS += %(conffile)
1233     endif 
1234 else
1235     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1236     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1237 endif
1238 ifneq (%(modsuffix),)
1239     TMP_OPTS += -s %(modsuffix)
1240 endif
1241 ifneq (%(targetdir),)
1242     TMP_OPTS += -d %(targetdir)
1243     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1244 endif
1246 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1247 $(TMP_TARGETS) : MODNAME := %(modname)
1248 $(TMP_TARGETS) : MODTYPE := %(modtype)
1249 $(TMP_TARGETS) : $(TMP_DEPS)
1250         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1251         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1252 endif
1253 %end
1254 #------------------------------------------------------------------------------
1256 #------------------------------------------------------------------------------
1257 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1258 # 'start' is an optional starting address
1259 # 'ldflags' is optional additional flags for the linker
1260 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1262 BD_OUTDIR := $(dir %(file))
1263 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1264 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1265 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1266 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1267 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1268 BD_OBJS += %(objs)
1270 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1272 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1273         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1274         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1275         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1277 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1278     GLOB_MKDIRS += $(BD_OUTDIR)
1279 endif
1281 %end
1283 #------------------------------------------------------------------------------
1284 # Common rules for all makefiles
1285 %define common
1286 # Delete generated makefiles
1288 clean ::
1289         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1291 include $(SRCDIR)/config/make.tail
1293 BDID := $(BDTARGETID)
1294 %end
1295 #------------------------------------------------------------------------------
1296       
1298 #############################################################################
1299 #############################################################################
1300 ##                                                                         ##
1301 ## Here are the mmakefile build macros. These are macros that takes care   ##
1302 ## of everything to go from the sources to the generated target. Also all  ##
1303 ## intermediate files and directories that are needed are created by these ##
1304 ## rules.                                                                  ##
1305 ##                                                                         ##
1306 #############################################################################
1307 #############################################################################
1309 #------------------------------------------------------------------------------
1310 # Build a program
1311 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1312     objcfiles= \
1313     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1314     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1315     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1316     compiler=target linker=
1318 .PHONY : %(mmake)
1320 BD_PROGNAME  := %(progname)
1321 BD_OBJDIR    := %(objdir)
1322 BD_TARGETDIR := %(targetdir)
1323 BD_LINKER    := %(linker)
1325 # If not supplied, linker is equal to compiler
1326 ifeq ($(BD_LINKER),)
1327     BD_LINKER := %(compiler)
1328 endif
1330 BD_FILES     := %(files)
1331 BD_OBJCFILES := %(objcfiles)
1332 BD_ASMFILES  := %(asmfiles)
1333 BD_CXXFILES := %(cxxfiles)
1335 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1336 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1337 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1339 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1340 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1341 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1343 BD_CFLAGS    := %(cflags)
1344 BD_AFLAGS    := %(aflags)
1345 BD_DFLAGS    := %(dflags)
1346 BD_LDFLAGS   := %(ldflags)
1349 %(mmake)-quick : %(mmake)
1351 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1352 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1354 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1355 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1356     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1357 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1358     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1359 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1360     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1361 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1362     aflags=$(BD_AFLAGS) compiler=%(compiler)
1364 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1365     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1366     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1367     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1368      cmd=$(BD_LINK) strip=$(BD_STRIP)
1370 endif
1372 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1374 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1375 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1376 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1378 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1380 %(mmake)-clean ::
1381         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1382         @$(RM) $(FILES)
1384 %end
1385 #------------------------------------------------------------------------------
1388 #------------------------------------------------------------------------------
1389 # Build programs, for every C file an executable will be built with the same
1390 # name as the C file
1391 %define build_progs mmake=/A files=/A nix=no \
1392     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1393     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1394     uselibs= usehostlibs= usestartup=yes detach=no
1396 .PHONY : %(mmake)
1398 BD_OBJDIR    := %(objdir)
1399 BD_TARGETDIR := %(targetdir)
1401 BD_FILES     := %(files)
1402 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1403 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1404 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1406 BD_CFLAGS    := %(cflags)
1407 BD_DFLAGS    := %(dflags)
1408 BD_LDFLAGS   := %(ldflags)
1411 %(mmake)-quick : %(mmake)
1413 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1414 %(mmake) : $(BD_EXES)
1416 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1417 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1418     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1420 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1421     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1422     ldflags=$(BD_LDFLAGS) \
1423     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1424     usestartup="%(usestartup)" detach="%(detach)" \
1425      cmd=$(BD_LINK) strip=$(BD_STRIP)
1427 endif
1429 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1431 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1432 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1433 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1435 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1437 %(mmake)-clean ::
1438         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1439         @$(RM) $(FILES)
1441 %end
1442 #------------------------------------------------------------------------------
1445 #------------------------------------------------------------------------------
1446 # Build a module.
1447 # This is a bare version: It just compiles and links the given files. It is
1448 # assumed that all needed boiler plate code is in the files. This should only
1449 # be used for compiling external code. For AROS code use %build_module
1450 %define build_module_simple mmake=/A modname=/A modtype=/A \
1451     files="$(basename $(call WILDCARD, *.c))" \
1452     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1453     objdir=$(OBJDIR) moduledir= \
1454     uselibs= usehostlibs= compiler=target
1456 # Define metamake targets and their dependencies
1457 #MM %(mmake) : core-linklibs includes-generate-deps
1458 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1459 #MM %(mmake)-kobj-quick
1460 #MM %(mmake)-quick
1461 #MM %(mmake)-clean
1463 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1465 .PHONY : $(BD_ALLTARGETS)
1467 ifeq (%(modname),)
1468 $(error using %build_module_simple: modname may not be empty)
1469 endif
1470 ifeq (%(modtype),)
1471 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1472 endif
1474 # Default values for variables and arguments
1475 BD_DEFLINKLIBNAME := %(modname)
1476 BD_DEFDFLAGS := %(cflags)
1477 OBJDIR ?= $(GENDIR)/$(CURDIR)
1478 BD_MODDIR := %(moduledir)
1479 ifeq ($(BD_MODDIR),)
1480   ifeq (%(modtype),library)
1481     BD_MODDIR  := $(AROS_LIBRARIES)
1482   endif
1483   ifeq (%(modtype),gadget)
1484     BD_MODDIR  := $(AROS_GADGETS)
1485   endif
1486   ifeq (%(modtype),datatype)
1487     BD_MODDIR  := $(AROS_DATATYPES)
1488   endif
1489   ifeq (%(modtype),handler)
1490     BD_MODDIR  := $(AROS_FS)
1491   endif
1492   ifeq (%(modtype),device)
1493     BD_MODDIR  := $(AROS_DEVS)
1494   endif
1495   ifeq (%(modtype),resource)
1496     BD_MODDIR  := $(AROS_RESOURCES)
1497   endif
1498   ifeq (%(modtype),hook)
1499     BD_MODDIR  := $(AROS_RESOURCES)
1500   endif
1501   ifeq (%(modtype),mui)
1502     BD_MODDIR  := $(AROS_CLASSES)/Zune
1503   endif
1504   ifeq (%(modtype),mcc)
1505     BD_MODDIR  := $(AROS_CLASSES)/Zune
1506   endif
1507   ifeq (%(modtype),mcp)
1508     BD_MODDIR  := $(AROS_CLASSES)/Zune
1509   endif
1510   ifeq (%(modtype),usbclass)
1511     BD_MODDIR  := $(AROS_CLASSES)/USB
1512   endif
1513   ifeq (%(modtype),hidd)
1514     BD_MODDIR  := $(AROS_DRIVERS)
1515   endif
1516   ifeq (%(modtype),printer)
1517     BD_MODDIR  := $(AROS_PRINTERS)
1518   endif
1519 endif
1520 ifeq ($(BD_MODDIR),)
1521   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1522 endif
1524 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1525 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1526 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1528 %rule_compile_multi \
1529     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1530     cflags="%(cflags)" dflags="%(dflags)" \
1531     compiler=%(compiler)
1533 # Handlers use dash instead of dot in their names
1534 ifeq (%(modtype),handler)
1535 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1536 else
1537 ifeq (%(modtype),printer)
1538 BD_MODULE := $(BD_MODDIR)/%(modname)
1539 else
1540 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1541 endif
1542 endif
1543 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1545 %(mmake)-quick : %(mmake)
1546 %(mmake)-kobj-quick : $(BD_KOBJ)
1547 %(mmake)       : $(BD_MODULE)
1548 %(mmake)-kobj  : $(BD_KOBJ)
1550 # The module is linked from all the compiled .o files
1551 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1553 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1554 # This breaks con-handler build. Here we work around this
1555 ifeq (%(modname),con)
1556     BD_ERR := $(notdir $(BD_MODULE)).err
1557 else
1558     BD_ERR := %(modname).err
1559 endif
1561 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1562                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1563                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1564                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1566 # Link kernel object file
1567 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1569 # Make these symbols local
1570 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1571             UtilityBase ExpansionBase KeymapBase KernelBase
1573 BD_SYMBOLS := $(BD_KBASE)
1575 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1576 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1577 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1578 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1579 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1580 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1581         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1582         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1583         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1586 ## Dependency fine-tuning
1588 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1589 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1591 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1592 $(BD_MODULE) : | $(BD_MODDIR)
1593 $(BD_KOBJ) : | $(KOBJSDIR)
1594 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1596 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1597 %(mmake)-clean ::
1598         @$(ECHO) "Cleaning up for module %(modname)"
1599         @$(RM) $(FILES)
1600 %end
1601 #------------------------------------------------------------------------------
1604 #------------------------------------------------------------------------------
1605 # Build a module - core routine
1606 # Explanation of this macro is done in the developer's manual
1607 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1608   files="$(basename $(call WILDCARD, *.c))" \
1609   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1610   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1611   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1612   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1613   compiler=target nostartup=yes archspecific=no \
1614   build_abi= build_library=
1616 # We will employ a terrifying, but unavoidable, hack here.
1617 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1618 # ignores GNU Make ifeq() statements, but will process any #MM
1619 # headed lines in the file.
1621 # So, to make the following #MM lines conditional on whether we want
1622 # to build the ABI, Library, or both, we define build_abi= and 
1623 # build_library as 'M' to enable, or '' to disable, which allows genmf
1624 # to do the following conversions:
1626 #  #%(build_abi)M includes-foo: foo-include
1627 #    becomes, when build_abi=M
1628 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1629 #    but, when build_abi= ...
1630 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1632 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1634 # Define metamake targets and their dependencies
1635 #MM %(mmake)
1636 #MM %(mmake)-quick
1637 #MM %(mmake)-makefile
1638 #MM %(mmake)-clean
1640 # ABI targets:
1641 #M%(build_abi)- includes-all : %(mmake)-includes
1642 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1643 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1644 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1645 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1646 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1647 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1648 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1649 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1650 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1651 #M%(build_abi) %(mmake)-includes-quick
1652 #M%(build_abi) %(mmake)-includes-dirs
1653 #M%(build_abi) %(mmake)-fd
1655 # Library targets
1656 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1657 #%(build_library)M %(mmake)-kobj-quick : 
1659 # Library with ABI targets:
1660 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1661 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1663 # All MetaMake targets defined by this macro
1664 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1666 ifeq (%(build_library),M)
1667 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1668 endif
1670 ifeq (%(build_abi),M)
1671 BD_ALLTARGETS += %(mmake)-includes \
1672                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1673                  %(mmake)-linklib %(mmake)-fd
1674 endif
1676 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1678 ifeq (%(modname),)
1679 $(error using %build_module: modname may not be empty)
1680 endif
1681 ifeq (%(modtype),)
1682 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1683 endif
1685 # Default values for variables and arguments
1686 BD_DEFLINKLIBNAME := %(modname)
1687 BD_DEFDFLAGS := %(cflags)
1688 OBJDIR ?= $(GENDIR)/$(CURDIR)
1690 ## Create genmodule include Makefile for the module
1692 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1694 %rule_genmodule_makefile \
1695     modname=%(modname) modtype=%(modtype) \
1696     modsuffix=%(modsuffix) targetdir=%(objdir) \
1697     conffile=%(conffile)
1699 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1701 GLOB_MKDIRS += %(objdir)
1703 # Do not parse these statements if metatarget is not appropriate
1704 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1706 include %(objdir)/Makefile.%(modname)%(modtype)
1708 BD_DEFMODDIR := $(%(modname)_MODDIR)
1709 ifeq (%(archspecific),yes)
1710 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1711 endif
1714 ## include files generation
1716 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1717 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1718 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1720 ifeq (%(build_abi),M)
1721 %(mmake)-includes-quick : %(mmake)-includes
1722 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1723     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1724     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1726 ifneq ($(%(modname)_INCLUDES),)
1727 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1728                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1729                          conffile=%(conffile)
1731 %rule_copy_diff_multi \
1732     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1733     stampfile=%(objdir)/%(modname)_geninc
1735 %rule_copy_diff_multi \
1736     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1737     stampfile=%(objdir)/%(modname)_incs
1739 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1741 TMP%(modname)_INCDIRS := \
1742     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1743     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1744     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1745 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1747 endif
1749 endif
1751 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1752                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1753                            conffile=%(conffile) version=%(version)
1755 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1756 $(BD_DEFLIBDEFSINC) :
1757         @$(ECHO) "Generating $@"
1758         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1760 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1761 GLOB_MKDIRS += %(objdir)/include
1763 ## Extra genmodule src files generation
1764 ## 
1765 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1766                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1767                       conffile=%(conffile)
1770 ifeq (%(build_abi),M)
1771 ## Create FD file
1772 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1773 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1775 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1776                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1778 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1780 GLOB_MKDIRS += $(BD_FDDIR)
1781 endif
1783 ## Compilation
1785 BD_FILES      := %(files)
1786 BD_CXXFILES := %(cxxfiles)
1788 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1790 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1791 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1793 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1794 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1795 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1797 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1798 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1800 ifeq (%(modtype),library)
1801     BD_LIBSUFFIX := 
1802 else
1803     BD_LIBSUFFIX := .%(modtype)
1804 endif
1806 ifeq (%(build_abi),M)
1807 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1808 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1809 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1810     BD_LINKLIB :=
1811 else
1812     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1813     ifneq (%(modname),%(linklibname))
1814         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1815     endif
1816 endif
1817 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1819 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1820 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1821 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1822     BD_RELLINKLIB :=
1823 else
1824     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1825     ifneq (%(modname),%(linklibname))
1826         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1827     endif
1828 endif
1829 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1830 endif
1832 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1833 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1834     $(BD_RELLINKLIBCFILES)
1836 %rule_compile_cxx_multi \
1837     basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1838     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1839     compiler=%(compiler)
1840 %rule_compile_multi \
1841     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1842     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1843     compiler=%(compiler)
1844 %rule_compile_multi \
1845     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1846     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1847     compiler=%(compiler)
1849 ifneq ($(BD_LINKLIBAFILES),)
1850 %rule_assemble_multi \
1851     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1852 endif
1854 ## Linking
1856 ifeq (%(modsuffix),)
1857 BD_SUFFIX := %(modtype)
1858 else
1859 BD_SUFFIX := %(modsuffix)
1860 endif
1862 ifeq (%(build_library),M)
1863 # Handlers use dash instead of dot in their names
1864 ifeq ($(BD_SUFFIX),handler)
1865 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1866 else
1867 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1868 endif
1869 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1870 else
1871 BD_MODULE :=
1872 BD_KOBJ   :=
1873 endif
1875 %(mmake)-quick      : %(mmake)
1876 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1877 ifeq (%(build_library),M)
1878 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1879 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1880 endif
1881 ifeq (%(build_abi),M)
1882 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1883 endif
1885 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1886            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1888 ifeq (%(nostartup),yes)
1889 # Handlers always have entry point
1890 ifneq (%(modtype),handler)
1891 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1892 endif
1893 endif
1895 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1896 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1897                  %(linklibobjs)
1898 BD_RELLINKLIBOBJS \
1899               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1900                  %(linklibobjs)
1902 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1903 # This breaks con-handler build. Here we work around this
1904 ifeq (%(modname),con)
1905     BD_ERR := $(notdir $(BD_MODULE)).err
1906 else
1907     BD_ERR := %(modname).err
1908 endif
1910 ifeq (%(build_library),M)
1911 # The module is linked from all the compiled .o files
1912 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1913                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1914                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1915                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1916 endif
1918 ifeq (%(build_abi),M)
1919 # Link static lib
1920 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1921 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1922 ifneq ($(BD_LINKLIB),)
1923 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1924 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1925 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1926 endif
1928 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1929 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1930 endif
1932 ifneq ($(BD_RELLINKLIB),)
1933 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1934 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1935 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1936 endif
1938 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1939 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1940 endif
1941 endif
1943 ifeq (%(build_library),M)
1944 # Link kernel object file
1945 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1947 # Make these symbols local
1948 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1949             UtilityBase ExpansionBase KeymapBase KernelBase
1951 BD_SYMBOLS := $(BD_KBASE)
1953 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1954 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1955 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1956 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1957 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1958 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1959         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1960         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1961         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1962 endif
1964 ## Dependency fine-tuning
1966 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1968 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1970 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1971 $(BD_MODULE) : | %(prefix)/%(moduledir)
1972 $(BD_KOBJ)   : | $(KOBJSDIR)
1973 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1975 # Some include files need to be generated before the .c can be parsed.
1976 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
1978 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1979     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1980 $(BD_DEPS) : $(BD_DFILE_DEPS)
1981 endif
1983 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1984     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1985     %(objdir)/Makefile.%(modname)%(modtype) \
1986     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1987     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1988     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1989     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1990     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1991     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1992     $(BD_ENDOBJS)
1993 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1994 %(mmake)-clean ::
1995         @$(ECHO) "Cleaning up for module %(modname)"
1996         @$(RM) $(FILES)
1998 endif # $(TARGET) in $(BD_ALLTARGETS)
1999 %end
2000 #------------------------------------------------------------------------------
2002 #------------------------------------------------------------------------------
2003 # Build a module - ABI and library
2004 # Explanation of this macro is done in the developer's manual
2005 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2006   files="$(basename $(call WILDCARD, *.c))" \
2007   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2008   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2009   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2010   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2011   compiler=target nostartup=yes archspecific=no
2013 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2014    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2015    files="%(files)" cxxfiles="%(cxxfiles)" \
2016    linklibname="%(linklibname)" \
2017    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2018    cflags="%(cflags)" dflags="%(dflags)" \
2019    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2020    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2021    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2022    build_abi=M build_library=M
2024 %end
2025 #------------------------------------------------------------------------------
2028 #------------------------------------------------------------------------------
2029 # Build a module skeleton ABI
2030 # This is a stripped-down version of build_module, it only creates include
2031 # files and the linklibs.
2032 # This is used when for plugins or classes with the same API, but no actual
2033 # implementation here.
2034 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2035   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2036   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2037   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2038   compiler=target nostartup=yes archspecific=no
2040 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2041   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2042   linklibname="%(linklibname)" \
2043   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2044   cflags="%(cflags)" dflags="%(dflags)" \
2045   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2046   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2047   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2048   build_abi=M build_library=
2050 %end
2051 #------------------------------------------------------------------------------
2053 #------------------------------------------------------------------------------
2054 # Build a module library - no includes nor linklibs
2055 # Explanation of this macro is done in the developer's manual
2056 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2057   files="$(basename $(call WILDCARD, *.c))" \
2058   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2059   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2060   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2061   uselibs= usehostlibs= \
2062   compiler=target nostartup=yes archspecific=no
2064 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2065    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2066    files="%(files)" cxxfiles="%(cxxfiles)" \
2067    cflags="%(cflags)" dflags="%(dflags)" \
2068    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2069    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2070    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2071    build_abi= build_library=M
2073 %end
2074 #------------------------------------------------------------------------------
2078 #------------------------------------------------------------------------------
2079 # Build a linklib.
2080 # - mmake is the mmaketarget
2081 # - libname is the baselibname e.g. lib%(libname).a will be created
2082 # - files are the C source files to include in the lib. The list of files
2083 #   has to be given without the .c suffix
2084 # - cxxfiles are C++ source files without suffix.
2085 #   NB: files will be matched in the order .cpp > .cxx > .cc
2086 # - asmfiles are the asm files to include in the lib. The list of files has to
2087 #   be given without the .s suffix
2088 # - objs additional object to link into the linklib. The objects have to be
2089 #   given with full absolute path and the .o suffix.
2090 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2091 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2092 # - cflags are the flags to compile the source (default $(CFLAGS))
2093 # - dflags are the flags use during makedepend (default equal to cflags)
2094 # - aflags are the flags use during assembling (default $(AFLAGS))
2095 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2096 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2097   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2098   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2099   aflags=$(AFLAGS) compiler=target
2101 # assign and generate the local variables used in this macro
2102 BD_LIBNAME    := %(libname)
2103 BD_LINKLIB    := %(libdir)/lib%(libname).a
2105 BD_FILES      := %(files)
2106 BD_ASMFILES   := %(asmfiles)
2107 BD_CXXFILES := %(cxxfiles)
2109 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2110 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2111 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2113 BD_OBJS       := $(BD_ARCHOBJS) \
2114                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2115                  %(objs)
2116 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2118 BD_CFLAGS    := %(cflags)
2119 BD_AFLAGS    := %(aflags)
2120 BD_DFLAGS    := %(dflags)
2122 .PHONY : %(mmake) %(mmake)-clean
2124 #MM %(mmake) : includes-generate-deps
2125 %(mmake) : $(BD_LINKLIB)
2127 ifeq ($(TARGET),%(mmake))
2129 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2130     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2131 %rule_compile_multi basenames=$(BD_FILES) targetdir=%(objdir) \
2132     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2133 %rule_assemble basename=% targetdir=%(objdir) \
2134     aflags=$(BD_AFLAGS)
2136 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2137 endif
2139 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2141 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2142 $(BD_LINKLIB) : | %(libdir)
2143 GLOB_MKDIRS += %(objdir) %(libdir)
2145 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2147 %(mmake)-clean ::
2148         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2149         @$(RM) $(FILES)
2151 %end
2152 #------------------------------------------------------------------------------
2155 #------------------------------------------------------------------------------
2156 # Build catalogs.
2157 # - mmake is the mmaketarget
2158 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2159 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2160 # - subdir is the destination subdirectory of the catalogs
2161 # - name is the name of the destination catalog, without the .catalog suffix
2162 # - source is the path to the generated source code file
2163 # - dir is the base destination directory (default $(AROS_CATALOGS))
2164 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2165 # - srcdir is the directory in which the *.cd and *.ct files are searched
2167 %define build_catalogs mmake=/A name=/A subdir=/A \
2168  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2169  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2171 ifeq (%(description),)
2172 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2173 else
2174 BD_DESC := %(description)
2175 endif
2177 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2179 ifeq (%(catalogs),)
2180 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2181 else
2182 BD_LNGS := %(catalogs)
2183 endif
2185 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2186 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2189 %(mmake) : $(BD_OBJS) %(source)
2191 $(BD_OBJS) : | $(BD_DIRS)
2192 GLOB_MKDIRS += $(BD_DIRS)
2194 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2195         @$(ECHO) "Creating   %(name) catalog for language $*."
2196         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2198 ifneq (%(source),)
2199 %(source) : BD_DESC := $(BD_DESC)
2200 %(source) : BD_SRC := $(BD_SRC)
2201 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2202         @$(ECHO) "Creating   %(name) catalog source file $@"
2203         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2204 endif
2206 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2208 %(mmake)-clean ::
2209         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2210         @$(RM) $(FILES)
2212 .PHONY: %(mmake) %(mmake)-clean
2214 %end
2215 #-----------------------------------------------------------------------------
2218 #-----------------------------------------------------------------------------
2219 # Build icons.
2220 # - mmake is the mmaketarget
2221 # - icons is a list of icon base names (ie. without the .info suffix)
2222 # - dir is the destination directory
2223 # - srcdir is where *.png and *.info.src are searched
2224 #-----------------------------------------------------------------------------
2226 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2228 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2231 %(mmake) : $(BD_OBJS)
2233 ifeq (%(image),)
2235 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2236         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2237         @$(ILBMTOICON) $+ $@
2239 else
2241 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2242         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2243         @$(ILBMTOICON) $+ $@
2245 endif
2247 $(BD_OBJS) : | %(dir)
2248 GLOB_MKDIRS += %(dir)
2250 %(mmake)-clean : FILES := $(BD_OBJS)
2252 %(mmake)-clean ::
2253         @$(RM) $(FILES)
2255 .PHONY: %(mmake) %(mmake)-clean
2257 %end
2258 #-----------------------------------------------------------------------------
2261 #------------------------------------------------------------------------------
2262 # Compile files for an arch-specific replacement of code for a module
2263 # - files: the basenames of the C files to compile.
2264 # - asmfiles: the basenames of the asm files to assemble.
2265 # - mainmmake: the mmake of the module in the main directory to compile these
2266 #   arch specific files for.
2267 # - maindir: the object directory for the main module
2268 # - arch: the arch for which to compile these files. It can have the form
2269 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2270 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2271 # - dflags: the flags used during creation of dependency file. If not specified
2272 #   the same value as cflags will be used
2273 # - aflags: the flags used during assembling
2274 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2275 #   the target compiler is used
2276 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2277 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2279 ifeq (%(files) %(asmfiles),)
2280   $(error no files or asmfiles given)
2281 endif
2283 %buildid targets="%(mainmmake)-%(arch)"
2285 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2286 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2287 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2288 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2289 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2290 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2291 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2292 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2293 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2294 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2295 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2296 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2297 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2298 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2299 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2301 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2303 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2304 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2305 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2306 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2307 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2309 ifneq (%(modulename),)
2310 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2311 endif
2313 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2314     BD_TARGET := %(mainmmake)-%(arch)-quick
2315 else
2316     BD_TARGET := %(mainmmake)-%(arch)
2317 endif
2320 ifeq ($(TARGET),$(BD_TARGET))
2321 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2322 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2323 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2324 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2325 endif
2327 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2328 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2331 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2334 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2336 ifeq ($(findstring %(compiler),host kernel target),)
2337   $(error unknown compiler %(compiler))
2338 endif
2339 ifeq (%(compiler),target)
2340 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2341 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2342 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2343 endif
2344 ifeq (%(compiler),host)
2345 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2346 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2347 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2348 endif
2349 ifeq (%(compiler),kernel)
2350 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2351 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2352 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2353 endif
2354 ifneq (%(modulename),)
2355 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2356 else
2357 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2358 endif
2359 ifeq ($(TARGET),$(BD_TARGET))
2360 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2361         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2362 endif
2364 ifeq (%(dflags),)
2365 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2366 else
2367 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2368 endif
2369 ifeq ($(TARGET),$(BD_TARGET))
2370 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2371         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2372 endif
2374 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2376 ifeq ($(TARGET),$(BD_TARGET))
2377 $(BD_OBJDIR$(BDID))/%.o : %.s
2378         %assemble_q opt=$(AFLAGS)
2379 $(BD_OBJDIR$(BDID))/%.o : %.S
2380         %assemble_q opt=$(AFLAGS)
2381 endif
2383 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2384 %end
2385 #------------------------------------------------------------------------------
2388 #------------------------------------------------------------------------------
2389 # generate asm files from c files (for debugging purposes)
2390 %define ctoasm_q
2391 %.s : %.c
2392         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2393         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2394 %end
2395 #------------------------------------------------------------------------------
2398 #------------------------------------------------------------------------------
2399 # Copy files from one directory to another.
2401 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2403 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2405 GLOB_MKDIRS += %(dst)
2407 .PHONY : %(mmake)
2410 %(mmake) : | %(dst) 
2411         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2413 %end
2414 #------------------------------------------------------------------------------
2417 #------------------------------------------------------------------------------
2418 # Copy a directory recursively to another place, preserving the original 
2419 # hierarchical structure
2421 # src: the source directory whose content will be copied.
2422 # dst: the directories where to copy src's content. If not existing, they will be made.
2423 # excludefiles: files which must not be copied. Path must be relative to src.
2425 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2427 .PHONY : %(mmake)
2430 %(mmake) :
2431         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2433 %end
2434 #------------------------------------------------------------------------------
2437 #------------------------------------------------------------------------------
2438 #   Copy include files into the includes directories. There are currently
2439 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2440 #   for building tools that need to run on the host system $(GENINCDIR). The
2441 #   $(GENINCDIR) path must not contain any references to the C runtime
2442 #   library header files.
2444 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2445     dir= compiler=target
2447 ifeq ($(findstring %(compiler),host kernel target),)
2448 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2449 endif
2451 ifneq (%(dir),)
2452 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2453 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2454 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2455 else
2456 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2457 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2458 endif
2460 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2461         @$(CP) $< $@
2464 ifeq (%(compiler),target)
2466 ifneq (%(dir),)
2467 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2468 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2469 else
2470 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2471 endif
2473 BD_INCL_FILES += $(BD_INCL_FILES2)
2475 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2476         @$(CP) $< $@
2477 endif
2480 %(mmake) : $(BD_INCL_FILES)
2482 .PHONY: %(mmake)
2484 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2485 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2486 %end
2487 #------------------------------------------------------------------------------
2490 #------------------------------------------------------------------------------
2491 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2492 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2493 STUBS_MEM := $(addsuffix .o,$(STUBS))
2494 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2495 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2496 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2498 #MM- linklibs : hidd-%(hidd)-stubs
2499 #MM- %(parenttarget): hidd-%(hidd)-stubs
2500 #MM hidd-%(hidd)-stubs : includes includes-copy
2501 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2503 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2504         %mklib_q from=$^
2506 $(STUBS_OBJ) : $(STUBS_SRC) 
2507         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2509 $(STUBS_DEP) : $(STUBS_SRC)
2510         %mkdepend_q flags=%(dflags)
2512 setup ::
2513         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2516 clean ::
2517         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2519 DEPS := $(DEPS) $(STUBS_DEP)
2521 %end
2522 #------------------------------------------------------------------------------
2525 #------------------------------------------------------------------------------
2526 # Build an imported source tree which uses the configure script from the
2527 # autoconf package.  This rule will try to "integrate" the produced files as
2528 # much as possible in the AROS build, for example by putting libraries in the
2529 # standard library directory, includes in the standard include directory, and
2530 # so on. You can however override this behaviour.
2532 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2533 # be %(bindir) (or its deduced value) when running "make install", and
2534 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2535 # configure script some more parameters whose value depends upon the PROGDIR
2536 # env var, so that the program gets all its stuff installed in the proper place
2537 # when building it, but when running it from inside AROS it can also find that
2538 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2539 # the configuration parameters set when running ./configure
2541 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2542 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2543 # to the name which has to follow it.
2545 # Arguments:
2547 #     - mmake           = the meta make target.
2548 #     - package         = name of the package to be built.
2549 #     - srcdir          = the location of the unpacked source code. Defaults
2550 #                         to $(SRCDIR)/$(CURDIR).
2551 #     - prefix          = the target directory. Must be an absolute path of the
2552 #                         host system. Defaults to $(AROS_CONTRIB).
2553 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2554 #                         Defaults to the value of the prefix option.
2555 #     - extraoptions    = additional options for the configure script.
2556 #     - extracflags     = additional flags which are used for both C and C++.
2557 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2558 #                         Defaults to the value of the nix argument.
2559 #     - nix             = enable u*nix path handling, i.e. a path like
2560 #                         /progdir//./file will be translated to
2561 #                         progdir:file during run-time. Defaults to no.
2562 #     - compiler        = target, host or kernel. Defaults to target.
2563 #     - install_target  = the command used for installing. Defaults to install. Leave
2564 #                         it empty if you want to suppress installing.
2565 #     - preconfigure    = a metatarget which is executed before configure is called.
2566 #     - postconfigure   = a metatarget which is executed after configure is called.
2567 #     - postinstall     = a metatarget which is executed after installing.
2568 #     - install_env     = set additional options for installing.
2569 #     - use_build_env   = if yes the configuration environment is used for
2570 #                         installing, too. Defaults to no.
2572 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2573 # like this:
2575 # if nix_dir_layout
2576 #    --prefix = $(aros_prefix)
2577 #    progdir = $(aros_prefix)/bin
2578 # else
2579 #    if nix
2580 #        --prefix = /PROGDIR
2581 #        --bindir = /PROGDIR
2582 #        --sbindir = /PROGDIR
2583 #        --libdir = /LIB
2584 #        --includedir = /INCLUDE
2585 #        --oldincludedir = /INCLUDE   
2586 #    else
2587 #        --prefix = $(aros_prefix)
2588 #    endif
2590 #    progdir = $(aros_prefix)
2592 #    # Install options
2593 #    bindir = $(prefix)
2594 #    sbindir = $(prefix)
2595 #    libdir = $(AROS_LIB)
2596 #    includedir = $(AROS_INCLUDES)
2597 #    oldincludedir = $(AROS_INCLUDES)
2598 # endif
2601 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2602     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2603     install_target=install preconfigure= postconfigure= postinstall= \
2604     install_env= use_build_env=no
2606 ifneq (%(prefix),)
2607     %(mmake)-prefix := %(prefix)
2608 else
2609     %(mmake)-prefix := $(AROS_CONTRIB)
2610 endif
2612 ifneq (%(aros_prefix),)
2613     %(mmake)-aros_prefix := %(aros_prefix)
2614 else
2615     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2616 endif
2618 ifeq (%(nix),yes)
2619     %(mmake)-nix    := -nix
2620     %(mmake)-volpfx := /
2621     %(mmake)-volsfx := /
2622     
2623     ifeq (%(nix_dir_layout),)
2624         %(mmake)-nix_dir_layout := yes
2625     endif
2626 else
2627     %(mmake)-volsfx := :
2628     
2629     ifeq (%(nix_dir_layout),)
2630         %(mmake)-nix_dir_layout := no
2631     endif
2632 endif
2634 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2636 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2637         exec_prefix=$(%(mmake)-prefix) %(install_env)
2639 # Check if chosen compiler is valid
2640 ifeq ($(findstring %(compiler),host target kernel),)
2641   $(error unknown compiler %(compiler))
2642 endif
2644 # Set legacy 'host' variable based on chosen compiler
2645 ifeq (%(compiler),host)
2646     host := yes
2647     ifeq (%(package),)
2648         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2649     else
2650         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2651     endif
2652 else
2653     host := no
2654     ifeq (%(package),)
2655         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2656     else
2657         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2658     endif
2659 endif
2660 ifneq (%(gendir),)
2661     ifeq (%(package),)
2662         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2663     else
2664         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2665     endif
2666 endif
2668 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2669 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2671 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2672     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2673     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2674 else
2675     ifeq (%(nix),yes)
2676         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2677         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2678     else
2679         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2680     endif
2682     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2683     
2684     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2685         sbindir=$(%(mmake)-prefix) \
2686         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2687         oldincludedir=$(AROS_INCLUDES) %(install_env)
2688 endif
2690 ifneq ($(DEBUG),yes)
2691     %(mmake)-s_flag = -s
2692 endif
2694 # Set up build environment, and options for configure script
2695 ifeq (%(compiler),host)
2696     CONFIG_ENV := \
2697         CPP="$(HOST_CPP)" \
2698         CXXCPP="$(HOST_CPP)" \
2699         CC="$(HOST_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2700         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2701         LDFLAGS="-L$(CROSSTOOLSDIR)/lib" \
2702         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2703         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2704         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2705         TARGET_NM="$(NM_PLAIN)"
2706 endif
2707 ifeq (%(compiler),target)
2708     CONFIG_ENV := \
2709         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2710         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2711         CFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2712         CXXFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2713         CPP="$(TARGET_CPP)" \
2714         CXXCPP="$(TARGET_CPP)" \
2715         CC="$(TARGET_CC) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2716         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2717         LDFLAGS="-L$(AROS_DEVELOPMENT)/lib" \
2718         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2719         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2720         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2721         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2722         TARGET_NM="$(NM_PLAIN)" \
2723         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2724         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2725     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2726         --host=$(AROS_TARGET_CPU)-aros\
2727         --target=$(AROS_TARGET_CPU)-aros\
2728         --disable-nls\
2729         --without-x --without-pic --disable-shared
2730 endif
2731 ifeq (%(compiler),kernel)
2732     CONFIG_ENV := \
2733         CPP="$(KERNEL_CPP)" \
2734         CXXCPP="$(KERNEL_CPP)" \
2735         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2736         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2737         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2738         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2739         TARGET_NM="$(NM_PLAIN)"
2740     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2741         --host=$(AROS_TARGET_CPU)-aros\
2742         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2743         --without-x --without-pic --disable-shared
2744 endif
2746 ifeq (%(use_build_env),yes)
2747     BUILD_ENV := $(CONFIG_ENV)
2748 endif
2751 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2753 # When building for the host, we don't need to build the
2754 # linklibs - this is especially true when building the
2755 # crosstool toolchain on 'foreign' architectures (such as
2756 # building PPC on x86)
2758 #MM- %(mmake)-host : setup includes %(mmake)-quick
2759 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2760 #MM- %(mmake): %(mmake)-%(compiler)
2762 # Using -j1 in install_command may result in a warning but finally
2763 # it does its job. make install for gcc does not work reliably for -jN
2764 # where N > 1.
2765 ifneq (%(install_target),)
2766     %(mmake)-install_command = \
2767         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2768         -C $(%(mmake)-pkgdir) %(install_target) -j1
2770     %(mmake)-uninstall_command = \
2771     $(RM) $(%(mmake)-installflag) && \
2772     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2773     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2774 else
2775     %(mmake)-install_command   := true
2776     %(mmake)-uninstall_command := true
2777 endif
2779 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2782 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2784 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2785         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2786             $(RM)  $(%(mmake)-installflag) && \
2787             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2788              -C $(%(mmake)-pkgdir) && \
2789             $(%(mmake)-install_command) && \
2790             $(TOUCH) $@ -r $^; \
2791         fi
2793 $(%(mmake)-pkgdir)/.files-touched:
2794         %mkdirs_q $(%(mmake)-pkgdir)
2795         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2796         $(TOUCH) $@
2799 %(mmake)-uninstall :
2800         $(%(mmake)-uninstall_command)
2803 %(mmake)-configure : $(%(mmake)-configflag)
2805 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2806 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2807         $(RM) $@
2808         %mkdirs_q $(%(mmake)-pkgdir)
2809         cd $(%(mmake)-pkgdir) && \
2810         find . -name config.cache -exec $(RM) '{}' \; && \
2811         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2812             %(extraoptions) && \
2813         $(TOUCH) $@
2816 %(mmake)-clean : %(mmake)-uninstall
2817         @$(RM) $(%(mmake)-pkgdir)
2818 %end
2819 #------------------------------------------------------------------------------
2822 #------------------------------------------------------------------------------
2823 # Given an archive name, patches names and locations where to find them, fetch
2824 # the archive and the patches from any of those locations, unpack the archive
2825 # and then apply the patches.
2827 # Locations currently supported are http and ftp sites, plus local filesystem
2828 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2829 # the fetch.sh script needs to be modified, since this macro relies on that script.
2831 # Arguments:
2833 #     - mmake           = mmaketarget
2834 #     - archive_origins = list of locations where to find the archive. They are tried
2835 #                         in sequence, until the archive is found and fetching it 
2836 #                         succeeded. If not specified, the current directory is assumed.
2837 #     - archive         = the archive name. Mandatory.
2838 #     - suffixes        = a list of suffixes to append to the the package name plus the
2839 #                         version. Each one of them is tried until a matching archive is
2840 #                         found. They are appended to patches and these are tried the
2841 #                         same way as packages are.
2842 #     - location        = the local directory where to put the fetched archive and patches.
2843 #                         If not specified, the directory specified by destination is used.
2844 #     - destination     = the directory to unpack the archive to.
2845 #                         If not specified, the current directory is assumed.
2846 #     - patches_origins = list of locations where to find the patches. They are tried
2847 #                         in sequence, until a patch is found and fetching it 
2848 #                         succeeded. If not specified, the current directory is assumed.
2849 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2850 #                         patch_name[:[patch_subdir][:patch_opt]].
2852 #                             - patch_name   = the name of the patch file
2853 #                             - patch_subdir = the directory within \destination\ where to
2854 #                                              apply the patch.
2855 #                             - patch_opt    = any options to pass to the `patch' command
2856 #                                              when applying the patch.
2857 #                         
2858 #                         The patch_subdir and patch_opt fields are optional.
2860 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2861     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2863 .PHONY: %(mmake)
2865 ifneq (%(location),)
2866     %(mmake)-location := %(location)
2867 else
2868     %(mmake)-location := %(destination)
2869 endif
2872 %(mmake) :
2873         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2874         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2875 %end
2876 #------------------------------------------------------------------------------
2879 #------------------------------------------------------------------------------
2880 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2881 # unpatched source tree and runs diff against this and a previously fetched and possibly
2882 # patched tree. Depending on what happens after patching during a normal build it might
2883 # give best results if the new patch is created directly after fetch.
2885 # Arguments:
2887 #     - mmake       = mmaketarget
2888 #     - archive     = archive base name
2889 #     - srcdir      = the top level directory the package is unpacked to, useful if
2890 #                     an archive unpacks to a directory other than its name suggests.
2891 #                     this should not be deeper than a single path element.
2892 #     - suffixes    = a list of suffixes to append to the the package name plus the
2893 #                     version. Each one of them is tried until a matching archive is
2894 #                     found.
2895 #     - destination = the directory to unpack the archive to.
2896 #     - excludes    = diff patterns to exclude files or directories from the patch
2898 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2900 .PHONY: %(mmake)
2902 ifneq (%(excludes),)
2903     %(mmake)-exclude := -X ./exclude.patterns
2904 endif
2906 ifneq (%(srcdir),)
2907     %(mmake)-srcdir := %(srcdir)
2908 else
2909     %(mmake)-srcdir := %(archive)
2910 endif
2913 %(mmake):
2914         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2915         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2916         cd %(destination)/tmp ; \
2917         $(FOR) f in %(excludes) ; do \
2918             $(ECHO) $$f >> ./exclude.patterns ; \
2919         done ; \
2920         diff -ruN $(%(mmake)-exclude) \
2921             $(%(mmake)-srcdir) \
2922             $(%(mmake)-srcdir).aros \
2923             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2924         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2925         $(RM) %(destination)/tmp
2926 %end
2927 #------------------------------------------------------------------------------
2930 #------------------------------------------------------------------------------
2931 # Joins the features of %fetch and %build_with_configure.
2933 # If a patch is provided, it *must* be named the following way:
2935 #    <package name>-<version number>-aros.diff
2937 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2938 # CD'ing into the archive's extracted directory.
2940 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2941 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2942 # to make that patch fully comprehensive.
2944 # Arguments:
2946 #    - mmake            = the meta make target.
2947 #    - package          = the GNU package name, sans version and archive format suffixes.
2948 #    - subpackage       = ???
2949 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2950 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2951 #    - version          = the package's version number, or otherwise any other version string.
2952 #                         It gets appended to the package name to form the basename of the archive.
2953 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2954 #                         version. Each one of them is tried until a matching archive is found.
2955 #                         Defaults to "tar.bz2 tar.gz".
2956 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
2957 #    - builddir         = override the location we expect to run configure/make in.
2958 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2959 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2960 #                         fetched or not. Default to no.
2961 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2962 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2963 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2964 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2965 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2966 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2967 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2968 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2969 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2970 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2971 #    - nix              = same meaning as the one for the %build_with_configure macro.
2972 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
2973 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
2975 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2976     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
2977     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2978     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2980 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2981 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2982 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2983 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2985 %(mmake)-archbase  := %(package)-%(version)
2987 ifeq (%(compiler),host)
2988     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2989 else
2990     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2991 endif
2993 ifeq (%(prefix),)
2994     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2995 else
2996     %(mmake)-prefix := %(prefix)
2997 endif
2999 ifneq (%(subpackage),)
3000     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3001 else
3002     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3003 endif
3005 ifneq (%(srcdir),)
3006     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3007 else
3008     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3009 endif
3011 ifneq (%(builddir),)
3012     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3013 else
3014     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3015 endif
3017 ifeq (%(patch),yes)
3018     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3019 else
3020     %(mmake)-%(subpackage)-patches_specs := ::
3021 endif
3023 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3024     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3025     archive_origins=". %(package_repo)" \
3026     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3028 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3029     archive=$(%(mmake)-%(subpackage)-archbase) \
3030     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3031     suffixes="%(suffixes)" \
3032     destination=$(%(mmake)-portdir)
3034 #MM- %(mmake) : %(mmake)-%(subpackage)
3036 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3038 %(mmake)-%(subpackage)-package-basename := \
3039     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3041 ifneq (%(create_pkg),no)
3042     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3043 endif
3045 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3046      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3047      install_env=%(install_env) use_build_env=%(use_build_env) \
3048      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3049      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3050      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3052 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3053 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3056 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3058 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3059 #that $^ and $@ have exactly the same mtime, and in that case make tries
3060 #to rebuild $@ again, which would fail because the directory where
3061 #the package got installed would not exist anymore. 
3062 #We work this around by using an if statement to manually check the mtimes.
3063 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3064         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3065         $(RM) $@ ; \
3066         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3067         mkdir -p "$(DISTDIR)/Packages" ; \
3068         mkdir -p "$(%(mmake)-prefix)" ; \
3069         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3070         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3071         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3072     fi
3073 %end
3074 #------------------------------------------------------------------------------
3077 #------------------------------------------------------------------------------
3078 # Joins the features of %fetch and %build_with_configure, taking advantage of
3079 # the naming scheme of GNU packages. GNU packages names are in the form
3081 #     <package name>-<version number>.<archive format suffix>
3083 # If a patch is provided, it *must* be named the following way:
3085 #    <package name>-<version number>-aros.diff
3087 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3088 # CD'ing into the archive's extracted directory.
3090 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3091 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3092 # to make that patch fully comprehensive.
3094 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3096 # Arguments:
3098 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3100 #    - prefix           = defaults to $(GNUDIR).
3101 #    - aros_prefix      = defaults to /GNU.
3103 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3104     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3105     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3107 GNU_REPOSITORY := gnu://
3109 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3110     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3111     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3112     patch="%(patch)" patch_repo="%(patch_repo)" \
3113     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3114     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3116 %end
3117 #------------------------------------------------------------------------------
3120 #------------------------------------------------------------------------------
3121 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3122 # that the package is a "Development" package, and as such it needs to be placed
3123 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3125 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3126 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3127 # "mmake" argument, because the metatarget is implicitely defined as
3129 #     #MM- development-%(package)
3131 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3132     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3133     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3135 #MM- development : development-%(package)
3138 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3139    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3140    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3141    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3142    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3145 postinstall-%(package)-delete-la-files:
3146         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3148 %end
3149 #------------------------------------------------------------------------------
3151 # Builds a kickstart package in PKG format
3153 # Arguments:
3155 #    - mmake   = target name
3156 #    - file    = destination file name with path
3158 # Other arguments are self-explanatory
3160 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3161     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3163 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3164 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3165 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3166 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3167 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3168 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3170 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3171 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3172 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3173 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3174 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3175 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3177 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3178     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3179 PKG_DIR   := $(dir %(file))
3182 %(mmake) : %(file)
3185 %(mmake)-quick : %(file)
3187 %(file): $(PKG_FILES) | $(PKG_DIR)
3188         @$(ECHO) Packaging $@...
3189         @$(SRCDIR)/tools/package/pkg c $@ $^
3191 %compress_file mmake=%(mmake) file=%(file)
3193 GLOB_MKDIRS += $(PKG_DIR)
3195 %end
3197 #------------------------------------------------------------------------------
3198 # Compresses %(file) with a gzip.
3199 # Good in conjunction with for example %build_prog
3201 %define compress_file mmake=/A file=/A
3203 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3206 %(mmake)-gz-quick : %(file).gz
3208 %(file).gz: %(file)
3209         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3210         @gzip -9 -f $^
3212 %end
3214 #------------------------------------------------------------------------------
3215 # Links a kickstart module in ELF format
3216 # Arguments are similar to make_package
3218 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3219     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3221 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3222 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3223 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3224 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3225 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3226 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3228 ifeq (%(startup),)
3229     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3230 else
3231     KOBJ_STARTUP := %(startup)
3232 endif
3234 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3236 TMP_LDFLAGS := %(ldflags)
3238 # Make a list of the lib files this program depends on.
3239 # In LDFLAGS remove white space between -L and directory
3240 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3241 # Filter out only the libdirs and remove -L
3242 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3243 # Add trailing /
3244 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3245 # Add normal linklib path
3246 TMP_DIRS += $(AROS_LIB)/
3247 # add lib and .a to static linklib names
3248 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3249 # search for the linklibs in the given path, ignore ones not found
3250 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3251     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3254 TMP_DIRS += $(dir %(file))
3255 ifneq (%(map),)
3256     TMP_LDFLAGS += $(GENMAP) %(map)
3257     TMP_DIRS    += $(dir %(map))
3258 endif
3260 #MM %(mmake) : %(deps)
3263 %(mmake) : %(file)
3266 %(mmake)-quick : %(file)
3268 %(file): KOBJS := $(KOBJS)
3269 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3270                     -static -nosysbase -Wl,-Ur
3271 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3272 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3273         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3274         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3275         @$(STRIP) $@
3277 %compress_file mmake=%(mmake) file=%(file)
3279 GLOB_MKDIRS += $(TMP_DIRS)
3281 %end