Added support for compiling C++ files. It isn't included for all
[AROS.git] / config / make.tmpl
blob3318a053f7e7f8b365563988944ece265b2ab88d
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 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling  $(CURDIR)/$(notdir %(from))"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         %(strip) %(to)
70 %end
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
121 %end
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128         @$(FOR) dir in %(dirs) ; do \
129             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
130         done
131 %end
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
137 ##                                                                         ##
138 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
139 ## mmakefile. They consist of one or more full makefile rules.             ##
140 ## In general the files generated in these macros are also defined as      ##
141 ## make targets so that they can be used as a dependency in other rules    ##
142 ##                                                                         ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
149 BDID := $(BDID)_
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
152 endif
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
160 %(to) : %(from)
161         @$(CP) $< $@
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
170 # present.
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
174         @$(CP) $< $@
175 %end
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by 
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186     stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196         @for f in $(FILES); do \
197              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
199              fi ; \
200         done
201         @$(TOUCH) $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
208 # be displayed.
209 # Restriction: at the moment when using a non-empty target dir %(from) may
210 # not have 
211 %define rule_join to=/A from=/A text=
213 %(to) : %(from)
214 ifneq (%(text),)
215         @$(ECHO) %(text)
216 endif
217         @$(CAT) $^ >$@
218 %end
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean 
227 %define include_deps deps=$(DEPS)/M  depstargets=
228 ifneq (%(deps),)
229   ifneq (%(depstargets),)
230     ifneq ($(findstring $(TARGET),%(depstargets)),)
231       -include %(deps)
232     endif
233   else
234     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
235       -include %(deps)
236     endif
237   endif
238 endif
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default. 
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
252 %end
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
261 # options
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 #   the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 #   it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
270 ifeq (%(targetdir),)
271   TMP_TARGETBASE := %(basename)
272 else
273   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
274 endif
276 ifeq ($(findstring %(compiler),host kernel target),)
277   $(error unknown compiler %(compiler))
278 endif
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 endif
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 endif
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 endif
304 ifeq (%(nix),yes)
305   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
306 else
307   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
308 endif
309 $(TMP_TARGETBASE).o : %(basename).c
310         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
312 ifeq (%(dflags),)
313   ifeq (%(nix),yes)
314     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
315   else
316     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317   endif
318 else
319   ifeq (%(nix),yes)
320     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
321   else
322     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
323   endif
324 endif
325 $(TMP_TARGETBASE).d : %(basename).c
326         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
327 %end
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile a C++ source file to an object file and generate
333 # the dependency file. Basename may contain a directory part, then the source
334 # file has to be in that directory. The generated file will be put in the
335 # object directory without the directory.
336 # options
337 # - basename: the basename of the file to compile. Use % for a wildcard rule
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 #   the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 #   it is put in the same directory as the .c file
343 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
345 ifeq (%(targetdir),)
346   TMP_TARGETBASE := %(basename)
347 else
348   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
349 endif
351 # Adjust compiler flags to suit C++
352 TMP_CXXFLAGS := %(cflags)
353 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
354 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
356 ifeq ($(findstring %(compiler),host kernel target),)
357   $(error unknown compiler %(compiler))
358 endif
359 ifeq (%(compiler),target)
360 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
361 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
362 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
363 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
364 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
365 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
366 endif
367 ifeq (%(compiler),host)
368 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
369 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
370 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
371 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
372 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
373 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
374 endif
375 ifeq (%(compiler),kernel)
376 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
377 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
378 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
379 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
380 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
381 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
382 endif
384 ifeq (%(nix),yes)
385   $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_CXXFLAGS)
386 else
387   $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
388 endif
389 $(TMP_TARGETBASE).o : %(basename).cpp
390         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
392 ifeq (%(dflags),)
393   ifeq (%(nix),yes)
394     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
395   else
396     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
397   endif
398 else
399   ifeq (%(nix),yes)
400     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
401   else
402     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
403   endif
404 endif
405 $(TMP_TARGETBASE).d : %(basename).cpp
406         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
407 %end
408 #------------------------------------------------------------------------------
411 #------------------------------------------------------------------------------
412 # Generate a rule to compile multiple C source files to an object file and
413 # generate the corresponding dependency files. The generated file will be put
414 # in the object directory without the directory part of the source file.
415 # options
416 # - basenames: the basenames of the files to compile. The names may include
417 #   relative or absolute path names. No wildcard is allowed
418 # - cflags (default $(CFLAGS)): the C flags to use for compilation
419 # - dflags: the flags used during creation of dependency file. If not specified
420 #   the same value as cflags will be used
421 # - targetdir: the directory to put the .o file and the .d file. By default
422 #   it is put in the same directory as the .c file. When targetdir is not
423 #   empty, path names will be stripped from the file names so that all files
424 #   are in that dir and not in subdirectories.
425 # - compiler (default target): compiler to use, target, kernel or host
426 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
427     compiler=target
429 ifeq (%(targetdir),)
430 TMP_TARGETS := $(addsuffix .o,%(basenames))
431 TMP_DTARGETS := $(addsuffix .d,%(basenames))
432 TMP_WILDCARD := %
433 else
434 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
435 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
436 TMP_WILDCARD := %(targetdir)/%
438 # Be sure that all .c files are generated
439 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
441 # Be sure that all .c files are found
442 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
443 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
444 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
445 ifneq ($(TMP_DIRS),)
446     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
447     vpath %.c $(TMP_DIRS)
448 endif
450 endif
452 ifeq ($(findstring %(compiler),host kernel target),)
453   $(error unknown compiler %(compiler))
454 endif
455 ifeq (%(compiler),target)
456 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
457 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
458 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
459 endif
460 ifeq (%(compiler),host)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
462 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
463 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
464 endif
465 ifeq (%(compiler),kernel)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
467 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
469 endif
471 $(TMP_TARGETS) : CFLAGS := %(cflags)
472 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
473         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
475 ifeq (%(dflags),)
476 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
477 else
478 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
479 endif
480 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
481         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
482 %end
483 #------------------------------------------------------------------------------
486 #------------------------------------------------------------------------------
487 # Generate a rule to compile multiple C++ source files to an object file and
488 # generate the corresponding dependency files. The generated file will be put
489 # in the object directory without the directory part of the source file.
490 # options
491 # - basenames: the basenames of the files to compile. The names may include
492 #   relative or absolute path names. No wildcard is allowed
493 # - cflags (default $(CFLAGS)): the C flags to use for compilation
494 # - dflags: the flags used during creation of dependency file. If not specified
495 #   the same value as cflags will be used
496 # - targetdir: the directory to put the .o file and the .d file. By default
497 #   it is put in the same directory as the .c file. When targetdir is not
498 #   empty, path names will be stripped from the file names so that all files
499 #   are in that dir and not in subdirectories.
500 # - compiler (default target): compiler to use, target, kernel or host
501 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
502     targetdir= compiler=target
504 # Adjust compiler flags to suit C++
505 TMP_CXXFLAGS := %(cflags)
506 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
507 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
509 ifeq (%(targetdir),)
510 TMP_TARGETS := $(addsuffix .o,%(basenames))
511 TMP_DTARGETS := $(addsuffix .d,%(basenames))
512 TMP_WILDCARD := %
513 else
514 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
515 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
516 TMP_WILDCARD := %(targetdir)/%
518 # Be sure that all .cpp files are generated
519 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .cpp,%(basenames))
521 # Be sure that all .cpp files are found
522 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
523 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
524 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
525 ifneq ($(TMP_DIRS),)
526     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
527     vpath %.cpp $(TMP_DIRS)
528 endif
530 endif
532 ifeq ($(findstring %(compiler),host kernel target),)
533   $(error unknown compiler %(compiler))
534 endif
535 ifeq (%(compiler),target)
536 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CXX) $(TARGET_CFLAGS)
537 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
538 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
539 endif
540 ifeq (%(compiler),host)
541 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
542 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
543 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
544 endif
545 ifeq (%(compiler),kernel)
546 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
547 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
548 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
549 endif
551 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
552 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
553         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
555 ifeq (%(dflags),)
556 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
557 else
558 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
559 endif
560 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
561         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
562 %end
563 #------------------------------------------------------------------------------
566 #------------------------------------------------------------------------------
567 # Make an alias from one arch specific build to another arch.
568 # arguments:
569 # - mainmmake: the mmake of the module in the main tree
570 # - arch: the current arch
571 # - alias: the alias to which this should point
572 %define rule_archalias mainmmake=\A arch=\A alias=\A
574 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
575 %end
576 #------------------------------------------------------------------------------
579 #------------------------------------------------------------------------------
580 # Generate a rule to compile a C source file to a shared object file with a
581 # .so suffix. Basename may contain a directory part, then the source
582 # file has to be in that directory. The generated file will be put in the
583 # object directory without the directory.
584 # options
585 # - basename: the basename of the file to compile. Use % for a wildcard rule
586 # - cflags (default $(CFLAGS)): the C flags to use for compilation
587 # - targetdir: the directory to put the .o file and the .d file. By default
588 #   it is put in the same directory as the .c file
589 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
591 ifeq (%(targetdir),)
592   TMP_TARGETBASE := %(basename)
593 else
594   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
595 endif
597 ifeq ($(findstring %(compiler),host kernel target),)
598   $(error unknown compiler %(compiler))
599 endif
600 ifeq (%(compiler),target)
601 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
602 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
603 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
604 endif
605 ifeq (%(compiler),host)
606 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
607 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
608 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
609 endif
610 ifeq (%(compiler),kernel)
611 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
612 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
613 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
614 endif
616 $(TMP_TARGETBASE).so : %(basename).c
617         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
618 %end
619 #------------------------------------------------------------------------------
622 #------------------------------------------------------------------------------
623 # Generate a rule to assemble a source file to an object file. Basename may
624 # contain a directory part, then the source file has to be in that directory.
625 # The generated file will be put in the object directory without the directory.
626 # options
627 # - basename: the basename of the file to compile. Use % for a wildcard rule
628 # - flags (default $(AFLAGS)): the asm flags to use for assembling
629 # - targetdir: the directory to put the .o file in. By default it is put in the
630 #   same directory as the .s file
631 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
633 ifeq (%(targetdir),)
634 %(basename).o : AFLAGS := %(aflags)
635 %(basename).o : %(basename).s
636         %assemble_q
637 %(basename).o : %(basename).S
638         %assemble_q
640 else
641 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
642 %(targetdir)/$(notdir %(basename)).o : %(basename).s
643         %assemble_q
644 %(targetdir)/$(notdir %(basename)).o : %(basename).S
645         %assemble_q
647 endif
648 %end
649 #------------------------------------------------------------------------------
652 #------------------------------------------------------------------------------
653 # Generate a rule to assemble multiple source files to an object file. The
654 # generated file will be put in the object directory with the directory part
655 # of the source file stripped off.
656 # options
657 # - basenames: the basenames of the files to compile. The names may include
658 #   relative or absolute path names. No wildcard is allowed
659 # - aflags (default $(AFLAGS)): the flags to use for assembly
660 # - targetdir: the directory to put the .o file and the .d file. By default
661 #   it is put in the same directory as the .c file. When targetdir is not
662 #   empty, path names will be stripped from the file names so that all files
663 #   are in that dir and not in subdirectories.
664 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
666 ifeq (%(targetdir),)
667 TMP_TARGETS := $(addsuffix .o,%(basenames))
668 TMP_WILDCARD := %
669 else
670 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
671 TMP_WILDCARD := %(targetdir)/%
673 # Be sure that all .s files are generated
674 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
676 # Be sure that all .c files are found
677 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
678 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
679 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
680 ifneq ($(TMP_DIRS),)
681     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
682     vpath %%(suffix) $(TMP_DIRS)
683 endif
685 endif
687 ifeq ($(findstring %(compiler),host kernel target),)
688   $(error unknown compiler %(compiler))
689 endif
690 ifeq (%(compiler),target)
691 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
692 endif
693 ifeq (%(compiler),host)
694 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
695 endif
696 ifeq (%(compiler),kernel)
697 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
698 endif
700 $(TMP_TARGETS) : AFLAGS := %(aflags)
701 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
702         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
703 %end
704 #------------------------------------------------------------------------------
707 #------------------------------------------------------------------------------
708 # Link %(objs) to %(prog) using the libraries in %(uselibs)
709 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
710     usehostlibs= usestartup=yes detach=no nix=no linker=target
712 TMP_EXTRA_LDFLAGS := 
713 ifeq (%(nix),yes)
714     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
715 endif
716 ifeq (%(usestartup),no)
717     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
718 endif
719 ifeq (%(detach),yes)
720     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
721 endif
723 # Make a list of the lib files this program depends on.
724 # In LDFLAGS remove white space between -L and directory
725 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
726 # Filter out only the libdirs and remove -L
727 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
728 # Add trailing /
729 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
730 # Add normal linklib path
731 TMP_DIRS += $(LIBDIR)/
732 # add lib and .a to static linklib names
733 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
734 # search for the linklibs in the given path, ignore ones not found
735 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
736     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
739 ifeq (%(linker),target)
740 %(prog) : CMD:=$(TARGET_CC)
741 %(prog) : STRIPCMD:=$(TARGET_STRIP)
742 endif
743 ifeq (%(linker),host)
744 %(prog) : CMD:=$(HOST_CC)
745 %(prog) : STRIPCMD:=$(HOST_STRIP)
746 endif
747 ifeq (%(linker),kernel)
748 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
749 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
750 endif
752 %(prog) : OBJS := %(objs)
753 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
754 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
755 %(prog) : %(objs) $(TMP_DEPLIBS)
756         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
757 %end
758 #------------------------------------------------------------------------------
761 #------------------------------------------------------------------------------
762 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
763 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
764 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
765     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
766     usestartup=yes detach=no
768 TMP_EXTRA_LDFLAGS := 
769 ifeq (%(nix),yes)
770     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
771 endif
772 ifeq (%(usestartup),no)
773     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
774 endif
775 ifeq (%(detach),yes)
776     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
777 endif
779 # Make a list of the lib files the programs depend on.
780 # In LDFLAGS remove white space between -L and directory
781 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
782 # Filter out only the libdirs and remove -L
783 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
784 # Add trailing /
785 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
786 # Add normal linklib path
787 TMP_DIRS += $(LIBDIR)/
788 # add lib and .a to static linklib names
789 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
790 # search for the linklibs in the given path, ignore ones not found
791 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
792     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
795 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
796 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
797 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
798         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
799 %end
800 #------------------------------------------------------------------------------
803 #------------------------------------------------------------------------------
804 # Link the %(objs) to the library %(libdir)/lib%(libname).a
805 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
807 ifeq (%(linker),target)
808 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
809 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
810 endif
811 ifeq (%(linker),host)
812 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
813 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
814 endif
815 ifeq (%(linker),kernel)
816 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
817 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
818 endif
820 %(libdir)/lib%(libname).a : %(objs)
821         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
822 %end
823 #------------------------------------------------------------------------------
826 #------------------------------------------------------------------------------
827 # Link the %(objs) to the library %(libdir)/lib%(libname).so
828 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
830 %(libdir)/lib%(libname).so : %(objs)
831         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
832 %end
833 #------------------------------------------------------------------------------
836 #------------------------------------------------------------------------------
837 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
838 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
839 # The -noarosc flag is added so that modules are not linked with arosc.library
840 # (see /config/specs.in file)
841 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
842     ldflags=$(LDFLAGS) uselibs= usehostlibs=
844 TMP_LDFLAGS  := %(ldflags)
845 # Make a list of the lib files the programs depend on.
846 # In LDFLAGS remove white space between -L and directory
847 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
848 # Filter out only the libdirs and remove -L
849 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
850 # Add trailing /
851 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
852 # Add normal linklib path
853 TMP_DIRS += $(LIBDIR)/
854 # add lib and .a to static linklib names
855 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
856 # search for the linklibs in the given path, ignore ones not found
857 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
858     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
861 %(module) : LIB_NAMES := %(uselibs)
862 %(module) : OBJS := %(objs)
863 %(module) : ENDTAG := %(endobj)
864 %(module) : ERR := %(err)
865 %(module) : OBJDIR := %(objdir)
866 %(module) : LDFLAGS := $(TMP_LDFLAGS)
867 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
868                     -L/usr/lib $(addprefix -l,%(usehostlibs))
869 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
870         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
872 %end
873 #------------------------------------------------------------------------------
876 #------------------------------------------------------------------------------
877 # Generate the libdefs.h include file for a module.
878 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
880 TMP_TARGET := %(modname)_libdefs.h
881 TMP_DEPS := $(GENMODULE)
882 TMP_OPTS := 
883 ifneq (%(conffile),)
884     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
885     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
886 else
887     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
888     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
889 endif
890 ifneq (%(modsuffix),)
891     TMP_OPTS += -s %(modsuffix)
892 endif
893 ifneq (%(targetdir),)
894     TMP_OPTS += -d %(targetdir)
895     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
896 endif
897 ifneq (%(version),)
898     TMP_OPTS += -v %(version)
899 endif
901 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
902 $(TMP_TARGET) : MODNAME := %(modname)
903 $(TMP_TARGET) : MODTYPE := %(modtype)
904 $(TMP_TARGET) : $(TMP_DEPS)
905         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
906         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
907 %end
908 #------------------------------------------------------------------------------
910 #------------------------------------------------------------------------------
911 # Generate the _lib.fd file for a module.
912 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
914 TMP_TARGET := %(modname)_lib.fd
915 TMP_DEPS := $(GENMODULE)
916 TMP_OPTS := 
917 ifneq (%(conffile),)
918     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
919     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
920 else
921     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
922     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
923 endif
924 ifneq (%(modsuffix),)
925     TMP_OPTS += -s %(modsuffix)
926 endif
927 ifneq (%(targetdir),)
928     TMP_OPTS += -d %(targetdir)
929     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
930 endif
932 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
933 $(TMP_TARGET) : MODNAME := %(modname)
934 $(TMP_TARGET) : MODTYPE := %(modtype)
935 $(TMP_TARGET) : $(TMP_DEPS)
936         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
937         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
938 %end
939 #------------------------------------------------------------------------------
941 #------------------------------------------------------------------------------
942 # Generate a Makefile.%(modname) with the genmodule program and include this
943 # generated file in this Makefile
944 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
945     targetdir=
947 TMP_TARGET := Makefile.%(modname)
948 TMP_DEPS := $(GENMODULE)
949 TMP_OPTS := 
950 ifneq (%(conffile),)
951     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
952     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
953 else
954     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
955     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
956 endif
957 ifneq (%(modsuffix),)
958     TMP_OPTS += -s %(modsuffix)
959 endif
960 ifneq (%(targetdir),)
961     TMP_OPTS += -d %(targetdir)
962     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
963 endif
965 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
966 $(TMP_TARGET) : MODNAME := %(modname)
967 $(TMP_TARGET) : MODTYPE := %(modtype)
968 $(TMP_TARGET) : $(TMP_DEPS)
969         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
970 %end
971 #------------------------------------------------------------------------------
974 #------------------------------------------------------------------------------
975 # Generate the support files for compiling a module. This includes include
976 # files and source files. This rule has to be preceeded by
977 # %rule_genmodule_makefile
978 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
979     conffile=
981 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
982                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
983 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
984                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
986 TMP_DEPS := $(GENMODULE)
987 TMP_OPTS :=
989 ifneq (%(conffile),)
990     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
991     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
992 else
993     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
994     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
995 endif
996 ifneq (%(modsuffix),)
997     TMP_OPTS += -s %(modsuffix)
998 endif
999 ifneq (%(targetdir),)
1000     TMP_OPTS += -d %(targetdir)
1001     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1002     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1003 endif
1005 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1006 $(TMP_TARGETS) : MODNAME := %(modname)
1007 $(TMP_TARGETS) : MODTYPE := %(modtype)
1008 $(TMP_TARGETS) : $(TMP_DEPS)
1009         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1010 ifneq (%(conffile),lib.conf)
1011         @$(IF) $(TEST) -f lib.conf; then \
1012           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1013         fi
1014 endif
1015         @$(IF) $(TEST) -f libdefs.h; then \
1016           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1017         fi
1018         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1019 %end
1020 #------------------------------------------------------------------------------
1023 #------------------------------------------------------------------------------
1024 # Generate the support files for compiling a module. This includes include
1025 # files and source files.
1026 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1027     targetdir= conffile=
1029 ifneq ($(%(modname)_INCLUDES),)
1030 TMP_TARGETS := $(%(modname)_INCLUDES)
1032 TMP_DEPS := $(GENMODULE)
1033 TMP_OPTS :=
1035 ifneq (%(conffile),)
1036     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1037     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1038 else
1039     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1040     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1041 endif
1042 ifneq (%(modsuffix),)
1043     TMP_OPTS += -s %(modsuffix)
1044 endif
1045 ifneq (%(targetdir),)
1046     TMP_OPTS += -d %(targetdir)
1047     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1048 endif
1050 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1051 $(TMP_TARGETS) : MODNAME := %(modname)
1052 $(TMP_TARGETS) : MODTYPE := %(modtype)
1053 $(TMP_TARGETS) : $(TMP_DEPS)
1054         @$(ECHO) "Generating include files"
1055         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1056 endif
1057 %end
1058 #------------------------------------------------------------------------------
1061 #------------------------------------------------------------------------------
1062 # Common rules for all makefiles
1063 %define common
1064 # Delete generated makefiles
1066 clean ::
1067         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1069 include $(SRCDIR)/config/make.tail
1071 BDID := $(BDTARGETID)
1072 %end
1073 #------------------------------------------------------------------------------
1074       
1076 #############################################################################
1077 #############################################################################
1078 ##                                                                         ##
1079 ## Here are the mmakefile build macros. These are macros that takes care   ##
1080 ## of everything to go from the sources to the generated target. Also all  ##
1081 ## intermediate files and directories that are needed are created by these ##
1082 ## rules.                                                                  ##
1083 ##                                                                         ##
1084 #############################################################################
1085 #############################################################################
1087 #------------------------------------------------------------------------------
1088 # Build a program
1089 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1090     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1091     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1092     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1093     compiler=target linker= srcdir=
1095 .PHONY : %(mmake)
1097 BD_PROGNAME  := %(progname)
1098 BD_OBJDIR    := %(objdir)
1099 BD_TARGETDIR := %(targetdir)
1100 BD_LINKER    := %(linker)
1102 # If not supplied, linker is equal to compiler
1103 ifeq ($(BD_LINKER),)
1104     BD_LINKER := %(compiler)
1105 endif
1107 BD_FILES     := %(files)
1108 BD_CXXFILES  := %(cxxfiles)
1109 BD_ASMFILES  := %(asmfiles)
1111 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1112 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1113 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1115 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))
1116 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES)))
1118 BD_CFLAGS    := %(cflags)
1119 BD_AFLAGS    := %(aflags)
1120 BD_DFLAGS    := %(dflags)
1121 BD_LDFLAGS   := %(ldflags)
1124 %(mmake)-quick : %(mmake)
1126 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1127 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1129 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1130 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1131     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1132 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1133     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1134 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1135     aflags=$(BD_AFLAGS) compiler=%(compiler)
1137 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1138     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1139     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1140     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1141     linker=$(BD_LINKER)
1143 endif
1145 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1147 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1148 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1149 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1151 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1153 %(mmake)-clean ::
1154         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1155         @$(RM) $(FILES)
1157 %end
1158 #------------------------------------------------------------------------------
1161 #------------------------------------------------------------------------------
1162 # Build programs, for every C file an executable will be built with the same
1163 # name as the C file
1164 %define build_progs mmake=/A files=/A nix=no \
1165     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1166     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1167     uselibs= usehostlibs= usestartup=yes detach=no
1169 .PHONY : %(mmake)
1171 BD_OBJDIR    := %(objdir)
1172 BD_TARGETDIR := %(targetdir)
1174 BD_FILES     := %(files)
1175 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1176 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1177 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1179 BD_CFLAGS    := %(cflags)
1180 BD_DFLAGS    := %(dflags)
1181 BD_LDFLAGS   := %(ldflags)
1184 %(mmake)-quick : %(mmake)
1186 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1187 %(mmake) : $(BD_EXES)
1189 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1190 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1191     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1193 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1194     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1195     ldflags=$(BD_LDFLAGS) \
1196     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1197     usestartup="%(usestartup)" detach="%(detach)"
1199 endif
1201 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1203 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1204 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1205 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1207 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1209 %(mmake)-clean ::
1210         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1211         @$(RM) $(FILES)
1213 %end
1214 #------------------------------------------------------------------------------
1217 #------------------------------------------------------------------------------
1218 # Build a module.
1219 # This is a bare version: It just compiles and links the given files. It is
1220 # assumed that all needed boiler plate code is in the files. This should only
1221 # be used for compiling external code. For AROS code use %build_module
1222 %define build_module_simple mmake=/A modname=/A modtype=/A \
1223     files="$(basename $(call WILDCARD, *.c))" \
1224     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1225     objdir=$(OBJDIR) moduledir= \
1226     uselibs= usehostlibs= compiler=target
1228 # Define metamake targets and their dependencies
1229 #MM %(mmake) : core-linklibs includes-generate-deps
1230 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1231 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1232 #MM %(mmake)-kobj-quick
1233 #MM %(mmake)-pkg-quick
1234 #MM %(mmake)-quick
1235 #MM %(mmake)-clean
1237 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1239 .PHONY : $(BD_ALLTARGETS)
1241 ifeq (%(modname),)
1242 $(error using %build_module_simple: modname may not be empty)
1243 endif
1244 ifeq (%(modtype),)
1245 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1246 endif
1248 # Default values for variables and arguments
1249 BD_DEFLINKLIBNAME := %(modname)
1250 BD_DEFDFLAGS := %(cflags)
1251 OBJDIR ?= $(GENDIR)/$(CURDIR)
1252 BD_MODDIR := %(moduledir)
1253 ifeq ($(BD_MODDIR),)
1254   ifeq (%(modtype),library)
1255     BD_MODDIR  := $(AROS_LIBS)
1256   endif
1257   ifeq (%(modtype),gadget)
1258     BD_MODDIR  := $(AROS_GADGETS)
1259   endif
1260   ifeq (%(modtype),datatype)
1261     BD_MODDIR  := $(AROS_DATATYPES)
1262   endif
1263   ifeq (%(modtype),handler)
1264     BD_MODDIR  := $(AROS_FS)
1265   endif
1266   ifeq (%(modtype),device)
1267     BD_MODDIR  := $(AROS_DEVS)
1268   endif
1269   ifeq (%(modtype),resource)
1270     BD_MODDIR  := $(AROS_RESOURCES)
1271   endif
1272   ifeq (%(modtype),hook)
1273     BD_MODDIR  := $(AROS_RESOURCES)
1274   endif
1275   ifeq (%(modtype),mui)
1276     BD_MODDIR  := $(AROS_CLASSES)/Zune
1277   endif
1278   ifeq (%(modtype),mcc)
1279     BD_MODDIR  := $(AROS_CLASSES)/Zune
1280   endif
1281   ifeq (%(modtype),mcp)
1282     BD_MODDIR  := $(AROS_CLASSES)/Zune
1283   endif
1284   ifeq (%(modtype),usbclass)
1285     BD_MODDIR  := $(AROS_CLASSES)/USB
1286   endif
1287   ifeq (%(modtype),hidd)
1288     BD_MODDIR  := $(AROS_DRIVERS)
1289   endif
1290   ifeq (%(modtype),printer)
1291     BD_MODDIR  := $(AROS_PRINTERS)
1292   endif
1293 endif
1294 ifeq ($(BD_MODDIR),)
1295   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1296 endif
1298 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1299 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1300 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1302 %rule_compile_multi \
1303     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1304     cflags="%(cflags)" dflags="%(dflags)" \
1305     compiler=%(compiler)
1307 # Handlers use dash instead of dot in their names
1308 ifeq (%(modtype),handler)
1309 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1310 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1311 else
1312 ifeq (%(modtype),printer)
1313 BD_MODULE := $(BD_MODDIR)/%(modname)
1314 BD_PKGMOD := $(PKGDIR)/%(modname)
1315 else
1316 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1317 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1318 endif
1319 endif
1320 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1322 %(mmake)-quick : %(mmake)
1323 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1324 %(mmake)-kobj-quick : $(BD_KOBJ)
1325 %(mmake)       : $(BD_MODULE)
1326 %(mmake)-pkg   : $(BD_PKGMOD)
1327 %(mmake)-kobj  : $(BD_KOBJ)
1329 # The module is linked from all the compiled .o files
1330 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1332 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1333 # This breaks con-handler build. Here we work around this
1334 ifeq (%(modname),con)
1335     BD_ERR := $(notdir $(BD_MODULE)).err
1336 else
1337     BD_ERR := %(modname).err
1338 endif
1340 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1341                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1342                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1344 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1345                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1346                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1348 # Link kernel object file
1349 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1351 # Make these symbols local
1352 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1353             UtilityBase ExpansionBase KeymapBase KernelBase
1355 BD_SYMBOLS := $(BD_KBASE)
1357 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1358 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1359 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1360 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1361 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1362 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1363         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1364         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1365         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1368 ## Dependency fine-tuning
1370 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1371 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1373 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1374 $(BD_MODULE) : | $(BD_MODDIR)
1375 $(BD_KOBJ) : | $(KOBJSDIR)
1376 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1378 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1379 %(mmake)-clean ::
1380         @$(ECHO) "Cleaning up for module %(modname)"
1381         @$(RM) $(FILES)
1382 %end
1383 #------------------------------------------------------------------------------
1386 #------------------------------------------------------------------------------
1387 # Build a module
1388 # Explanation of this macro is done in the developer's manual
1389 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1390   conffile= files="$(basename $(call WILDCARD, *.c))" \
1391   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1392   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1393   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1394   compiler=target nostartup=yes
1396 # Define metamake targets and their dependencies
1397 #MM- includes-all : %(mmake)-includes
1398 #MM- linklibs-%(modname): %(mmake)-linklib
1399 #MM- includes-%(modname): %(mmake)-includes
1400 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1401 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1402 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1403 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1404 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1405 #MM %(mmake)-linklib : %(mmake)-includes
1406 #MM %(mmake)-quick : %(mmake)-includes-quick
1407 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1408 #MM     includes-generate-deps %(mmake)-fd
1409 #MM %(mmake)-includes-quick
1410 #MM %(mmake)-includes-dirs
1411 #MM %(mmake)-fd
1412 #MM %(mmake)-makefile
1413 #MM %(mmake)-clean
1415 # All MetaMake targets defined by this macro
1416 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1417     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1418     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1419     %(mmake)-linklib %(mmake)-fd
1421 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1423 ifeq (%(modname),)
1424 $(error using %build_module: modname may not be empty)
1425 endif
1426 ifeq (%(modtype),)
1427 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1428 endif
1430 # Default values for variables and arguments
1431 BD_DEFLINKLIBNAME := %(modname)
1432 BD_DEFDFLAGS := %(cflags)
1433 OBJDIR ?= $(GENDIR)/$(CURDIR)
1435 ## Create genmodule include Makefile for the module
1437 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1439 %rule_genmodule_makefile \
1440     modname=%(modname) modtype=%(modtype) \
1441     modsuffix=%(modsuffix) targetdir=%(objdir) \
1442     conffile=%(conffile)
1444 %(objdir)/Makefile.%(modname) : | %(objdir)
1446 GLOB_MKDIRS += %(objdir)
1448 # Do not parse these statements if metatarget is not appropriate
1449 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1451 include %(objdir)/Makefile.%(modname)
1453 BD_DEFMODDIR := $(%(modname)_MODDIR)
1456 ## include files generation
1458 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1459 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1460 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1462 %(mmake)-includes-quick : %(mmake)-includes
1463 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1464     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1465     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1467 ifneq ($(%(modname)_INCLUDES),)
1468 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1469                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1470                          conffile=%(conffile)
1472 %rule_copy_diff_multi \
1473     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1474     stampfile=%(objdir)/%(modname)_geninc
1476 %rule_copy_diff_multi \
1477     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1478     stampfile=%(objdir)/%(modname)_incs
1480 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1482 TMP%(modname)_INCDIRS := \
1483     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1484     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1485     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1486 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1488 endif
1490 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1491                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1492                            conffile=%(conffile) version=%(version)
1494 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1495 $(BD_DEFLIBDEFSINC) :
1496         @$(ECHO) "generating $@"
1497         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1499 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1500 GLOB_MKDIRS += %(objdir)/include
1502 ## Extra genmodule src files generation
1503 ## 
1504 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1505                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1506                       conffile=%(conffile)
1509 ## Create FD file
1510 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1511 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1513 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1514                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1516 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1518 GLOB_MKDIRS += $(BD_FDDIR)
1521 ## Compilation
1523 BD_FILES      := %(files)
1524 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1525 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1526 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1528 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1529 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1530 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1532 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1533 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1535 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1536 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1537 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1538     BD_LINKLIB :=
1539 else
1540     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1541 endif
1542 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1544 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1545 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1546 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1547     BD_RELLINKLIB :=
1548 else
1549     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel.a
1550 endif
1551 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1553 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1554 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1555     $(BD_RELLINKLIBCFILES)
1557 %rule_compile_multi \
1558     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1559     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1560     compiler=%(compiler)
1561 %rule_compile_multi \
1562     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1563     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1564     compiler=%(compiler)
1566 ifneq ($(BD_LINKLIBAFILES),)
1567 %rule_assemble_multi \
1568     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1569 endif
1571 ## Linking
1573 ifeq (%(modsuffix),)
1574 BD_SUFFIX := %(modtype)
1575 else
1576 BD_SUFFIX := %(modsuffix)
1577 endif
1579 # Handlers use dash instead of dot in their names
1580 ifeq ($(BD_SUFFIX),handler)
1581 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1582 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1583 else
1584 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1585 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1586 endif
1587 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1589 %(mmake)-quick      : %(mmake)
1590 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1591 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1592 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1593 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1594 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1595 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1597 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1598                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1600 ifeq (%(nostartup),yes)
1601 # Handlers always have entry point
1602 ifneq (%(modtype),handler)
1603 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1604 endif
1605 endif
1607 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1608 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1609                  %(linklibobjs)
1610 BD_RELLINKLIBOBJS \
1611               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1612                  %(linklibobjs)
1614 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1615 # This breaks con-handler build. Here we work around this
1616 ifeq (%(modname),con)
1617     BD_ERR := $(notdir $(BD_MODULE)).err
1618 else
1619     BD_ERR := %(modname).err
1620 endif
1622 # The module is linked from all the compiled .o files
1623 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1624                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1625                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1627 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1628                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1629                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1631 # Link static lib
1632 ifneq ($(BD_LINKLIB),)
1633 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1635 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1636 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1637 endif
1639 ifneq ($(BD_RELLINKLIB),)
1640 %rule_link_linklib libname=%(linklibname)_rel objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1642 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1643 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1644 endif
1646 # Link kernel object file
1647 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1649 # Make these symbols local
1650 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1651             UtilityBase ExpansionBase KeymapBase KernelBase
1653 BD_SYMBOLS := $(BD_KBASE)
1655 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1656 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1657 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1658 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1659 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1660 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1661         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1662         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1663         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1665 ## Dependency fine-tuning
1667 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1668 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1670 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1671 $(BD_MODULE) : | %(prefix)/%(moduledir)
1672 $(BD_PKGMOD) : | $(PKGDIR)
1673 $(BD_KOBJ)   : | $(KOBJSDIR)
1674 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1676 # Some include files need to be generated before the .c can be parsed.
1677 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1679 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1680     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1681 $(BD_DEPS) : $(BD_DFILE_DEPS)
1682 endif
1684 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1685     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1686     %(objdir)/Makefile.%(modname) \
1687     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1688     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1689     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1690     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1691     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1692     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1693     $(BD_ENDOBJS)
1694 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1695 %(mmake)-clean ::
1696         @$(ECHO) "Cleaning up for module %(modname)"
1697         @$(RM) $(FILES)
1699 endif # $(TARGET) in $(BD_ALLTARGETS)
1700 %end
1701 #------------------------------------------------------------------------------
1704 #------------------------------------------------------------------------------
1705 # Build a module skeleton
1706 # This is a stripped-down version of build_module, it only creates include files,
1707 # but no actual object. This is used when for plugins or classes with the same
1708 # API, but no actual implementation here.
1709 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1710   conffile= \
1711   objdir=$(OBJDIR) prefix=$(AROSDIR)
1713 # Define metamake targets and their dependencies
1714 #MM- includes-all : %(mmake)-includes
1715 #MM %(mmake) : %(mmake)-includes core-linklibs
1716 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1717 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1718 #MM %(mmake)-linklib : %(mmake)-includes
1719 #MM %(mmake)-quick : %(mmake)-includes-quick
1720 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1721 #MM     includes-generate-deps
1722 #MM %(mmake)-includes-quick
1723 #MM %(mmake)-includes-dirs
1724 #MM %(mmake)-makefile
1725 #MM %(mmake)-clean
1727 # All MetaMake targets defined by this macro
1728 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1729     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1730     %(mmake)-kobj %(mmake)-pkg
1732 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1734 ifeq (%(modname),)
1735 $(error using %build_module_skeleton: modname may not be empty)
1736 endif
1737 ifeq (%(modtype),)
1738 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1739 endif
1741 # Default values for variables and arguments
1742 BD_DEFLINKLIBNAME := %(modname)
1743 BD_DEFDFLAGS := %(cflags)
1744 OBJDIR ?= $(GENDIR)/$(CURDIR)
1746 ## Create genmodule include Makefile for the module
1748 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1750 %rule_genmodule_makefile \
1751     modname=%(modname) modtype=%(modtype) \
1752     modsuffix=%(modsuffix) targetdir=%(objdir) \
1753     conffile=%(conffile)
1755 %(objdir)/Makefile.%(modname) : | %(objdir)
1757 GLOB_MKDIRS += %(objdir)
1759 # Do not parse these statements if metatarget is not appropriate
1760 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1762 include %(objdir)/Makefile.%(modname)
1764 BD_DEFMODDIR := $(%(modname)_MODDIR)
1767 ## include files generation
1769 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1770 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1771 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1773 %(mmake)-includes-quick : %(mmake)-includes
1774 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1775     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1776     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1778 ifneq ($(%(modname)_INCLUDES),)
1779 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1780                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1781                          conffile=%(conffile)
1783 %rule_copy_diff_multi \
1784     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1785     stampfile=%(objdir)/%(modname)_geninc
1787 %rule_copy_diff_multi \
1788     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1789     stampfile=%(objdir)/%(modname)_incs
1791 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1793 TMP%(modname)_INCDIRS := \
1794     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1795     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1796     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1797 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1799 endif
1801 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1802                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1803                            conffile=%(conffile)
1805 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1806 $(BD_DEFLIBDEFSINC) :
1807         @$(ECHO) "generating $@"
1808         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1810 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1811 GLOB_MKDIRS += %(objdir)/include
1813 ## Extra genmodule src files generation
1814 ## 
1815 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1816                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1817                       conffile=%(conffile)
1819 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1820     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1821     %(objdir)/Makefile.%(modname) \
1822     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1823     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1824     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1825     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1826     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1827     $(BD_DEFLIBDEFSINC)
1828 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1829 %(mmake)-clean ::
1830         @$(ECHO) "Cleaning up for module %(modname)"
1831         @$(RM) $(FILES)
1833 endif # $(TARGET) in $(BD_ALLTARGETS)
1834 %end
1835 #------------------------------------------------------------------------------
1838 #------------------------------------------------------------------------------
1839 # Build a linklib.
1840 # - mmake is the mmaketarget
1841 # - libname is the baselibname e.g. lib%(libname).a will be created
1842 # - files are the C source files to include in the lib. The list of files
1843 #   has to be given without the .c suffix
1844 # - asmfiles are the asm files to include in the lib. The list of files has to
1845 #   be given without the .s suffix
1846 # - objs additional object to link into the linklib. The objects have to be
1847 #   given with full absolute path and the .o suffix.
1848 # - cflags are the flags to compile the source (default $(CFLAGS))
1849 # - dflags are the flags use during makedepend (default equal to cflags)
1850 # - aflags are the flags use during assembling (default $(AFLAGS))
1851 # - objdir is where the .o are generated
1852 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1853 %define build_linklib mmake=/A libname=/A \
1854   files="$(basename $(call WILDCARD, *.c))" \
1855   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1856   asmfiles= objs= compiler=target \
1857   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1859 # assign and generate the local variables used in this macro
1860 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1862 BD_FILES      := %(files)
1863 BD_CXXFILES   := %(cxxfiles)
1864 BD_ASMFILES   := %(asmfiles)
1866 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1867 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1868 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1870 BD_OBJS       := $(BD_ARCHOBJS) \
1871                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
1872                  %(objs)
1873 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1875 BD_CFLAGS     := %(cflags)
1876 ifeq (%(dflags),)
1877 BD_DFLAGS     := $(BD_CFLAGS)
1878 else
1879 BD_DFLAGS     := %(dflags)
1880 endif
1881 BD_AFLAGS     := %(aflags)
1883 BD_LINKLIB    := %(libdir)/lib%(libname).a
1885 .PHONY : %(mmake) %(mmake)-clean
1887 #MM %(mmake) : includes-generate-deps
1888 %(mmake) : $(BD_LINKLIB)
1891 %(mmake)-clean ::
1892         @$(RM) $(BD_OBJS) $(BD_DEPS)
1894 ifeq ($(TARGET),%(mmake))
1895 ifneq ($(dir $(BD_FILES)),./)
1896 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1897 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1898 endif
1900 %rule_compile_multi basenames=$(BD_FILES) targetdir=%(objdir) \
1901     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1902 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1903     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1904 %rule_assemble basename=% targetdir=%(objdir) \
1905     aflags=$(BD_AFLAGS)
1907 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1908 endif
1910 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1912 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1913 $(BD_LINKLIB) : | %(libdir)
1914 GLOB_MKDIRS += %(objdir) %(libdir)
1916 %end
1917 #------------------------------------------------------------------------------
1920 #------------------------------------------------------------------------------
1921 # Build catalogs.
1922 # - mmake is the mmaketarget
1923 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1924 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1925 # - subdir is the destination subdirectory of the catalogs
1926 # - name is the name of the destination catalog, without the .catalog suffix
1927 # - source is the path to the generated source code file
1928 # - dir is the base destination directory (default $(AROS_CATALOGS))
1929 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1930 # - srcdir is the directory in which the *.cd and *.ct files are searched
1932 %define build_catalogs mmake=/A name=/A subdir=/A \
1933  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1934  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1936 ifeq (%(description),)
1937 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1938 else
1939 BD_DESC := %(description)
1940 endif
1942 ifeq (%(catalogs),)
1943 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1944 else
1945 BD_LNGS := %(catalogs)
1946 endif
1948 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1949 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1952 %(mmake) : $(BD_OBJS) %(source)
1954 $(BD_OBJS) : | $(BD_DIRS)
1955 GLOB_MKDIRS += $(BD_DIRS)
1957 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1958         @$(ECHO) "Creating   %(name) catalog for language $*."
1959         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1961 ifneq (%(source),)
1962 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1963 %(source) : $(BD_DESC).cd | $(dir %(source))
1964         @$(ECHO) "Creating   %(name) catalog source file %(source)"
1965         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1966 endif
1969 %(mmake)-clean ::
1970         $(RM) $(BD_OBJS) %(source)
1972 .PHONY: %(mmake) %(mmake)-clean
1974 %end
1975 #-----------------------------------------------------------------------------
1978 #-----------------------------------------------------------------------------
1979 # Build icons.
1980 # - mmake is the mmaketarget
1981 # - icons is a list of icon base names (ie. without the .info suffix)
1982 # - dir is the destination directory
1983 # - srcdir is where *.png and *.info.src are searched
1984 #-----------------------------------------------------------------------------
1986 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1988 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1991 %(mmake) : $(BD_OBJS)
1993 ifeq (%(image),)
1995 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1996         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1997         @$(ILBMTOICON) $+ $@
1999 else
2001 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2002         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2003         @$(ILBMTOICON) $+ $@
2005 endif
2007 $(BD_OBJS) : | %(dir)
2008 GLOB_MKDIRS += %(dir)
2010 %(mmake)-clean : FILES := $(BD_OBJS)
2012 %(mmake)-clean ::
2013         @$(RM) $(FILES)
2015 .PHONY: %(mmake) %(mmake)-clean
2017 %end
2018 #-----------------------------------------------------------------------------
2021 #------------------------------------------------------------------------------
2022 # Compile files for an arch-specific replacement of code for a module
2023 # - files: the basenames of the C files to compile.
2024 # - asmfiles: the basenames of the asm files to assemble.
2025 # - mainmmake: the mmake of the module in the main directory to compile these
2026 #   arch specific files for.
2027 # - maindir: the object directory for the main module
2028 # - arch: the arch for which to compile these files. It can have the form
2029 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2030 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2031 # - dflags: the flags used during creation of dependency file. If not specified
2032 #   the same value as cflags will be used
2033 # - aflags: the flags used during assembling
2034 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2035 #   the target compiler is used
2036 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2037 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2039 ifeq (%(files) %(asmfiles),)
2040   $(error no files or asmfiles given)
2041 endif
2043 %buildid targets="%(mainmmake)-%(arch)"
2045 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2046 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2047 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2048 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2049 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2050 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2051 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2052 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2053 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2054 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2055 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2056 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2057 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2058 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2059 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2060 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2061 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2062 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2063 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2064 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2065 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2067 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2069 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2070 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2071 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2072 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2073 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2075 ifneq (%(modulename),)
2076 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2077 endif
2079 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2080     BD_TARGET := %(mainmmake)-%(arch)-quick
2081 else
2082     BD_TARGET := %(mainmmake)-%(arch)
2083 endif
2086 ifeq ($(TARGET),$(BD_TARGET))
2087 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2088 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2089 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2090 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2091 endif
2093 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2094 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2097 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2100 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2102 ifeq ($(findstring %(compiler),host kernel target),)
2103   $(error unknown compiler %(compiler))
2104 endif
2105 ifeq (%(compiler),target)
2106 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2107 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2108 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2109 endif
2110 ifeq (%(compiler),host)
2111 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2112 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2113 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2114 endif
2115 ifeq (%(compiler),kernel)
2116 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2117 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2118 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2119 endif
2120 ifneq (%(modulename),)
2121 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2122 else
2123 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2124 endif
2125 ifeq ($(TARGET),$(BD_TARGET))
2126 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2127         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2128 endif
2130 ifeq (%(dflags),)
2131 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2132 else
2133 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2134 endif
2135 ifeq ($(TARGET),$(BD_TARGET))
2136 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2137         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2138 endif
2140 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2142 ifeq ($(TARGET),$(BD_TARGET))
2143 $(BD_OBJDIR$(BDID))/%.o : %.s
2144         %assemble_q opt=$(AFLAGS)
2145 $(BD_OBJDIR$(BDID))/%.o : %.S
2146         %assemble_q opt=$(AFLAGS)
2147 endif
2149 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2150 %end
2151 #------------------------------------------------------------------------------
2154 #------------------------------------------------------------------------------
2155 # generate asm files from c files (for debugging purposes)
2156 %define ctoasm_q
2157 %.s : %.c
2158         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2159         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2160 %end
2161 #------------------------------------------------------------------------------
2164 #------------------------------------------------------------------------------
2165 # Copy files from one directory to another.
2167 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2169 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2171 GLOB_MKDIRS += %(dst)
2173 .PHONY : %(mmake)
2176 %(mmake) : | %(dst) 
2177         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2179 %end
2180 #------------------------------------------------------------------------------
2183 #------------------------------------------------------------------------------
2184 # Copy a directory recursively to another place, preserving the original 
2185 # hierarchical structure
2187 # src: the source directory whose content will be copied
2188 # dst: the directory where to copy src's content. If not existing, it will be made.
2190 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2192 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2193 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
2194 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2196 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2197 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2199 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2201 .PHONY : %(mmake)
2204 %(mmake): | $(GENDIR)/$(CURDIR)
2205         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2206         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2207         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2208         for d in $(%(mmake)_DIRS); do                      \
2209             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2210         done
2211         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2212         for f in $(%(mmake)_FILES); do                                            \
2213             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2214         done;  \
2215         for dst in %(dst); do \
2216             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2217         done
2219 %end
2220 #------------------------------------------------------------------------------
2223 #------------------------------------------------------------------------------
2224 #   Copy include files into the includes directories. There are currently
2225 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2226 #   for building tools that need to run on the host system $(GENINCDIR). The
2227 #   $(GENINCDIR) path must not contain any references to the C runtime
2228 #   library header files.
2230 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2231     dir= compiler=target
2233 ifeq ($(findstring %(compiler),host kernel target),)
2234 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2235 endif
2237 ifneq (%(dir),)
2238 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2239 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2240 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2241 else
2242 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2243 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2244 endif
2246 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2247         @$(CP) $< $@
2250 ifeq (%(compiler),target)
2252 ifneq (%(dir),)
2253 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2254 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2255 else
2256 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2257 endif
2259 BD_INCL_FILES += $(BD_INCL_FILES2)
2261 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2262         @$(CP) $< $@
2263 endif
2266 %(mmake) : $(BD_INCL_FILES)
2268 .PHONY: %(mmake)
2270 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2271 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2272 %end
2273 #------------------------------------------------------------------------------
2276 #------------------------------------------------------------------------------
2277 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2278 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2279 STUBS_MEM := $(addsuffix .o,$(STUBS))
2280 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2281 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2282 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2284 #MM- linklibs : hidd-%(hidd)-stubs
2285 #MM- %(parenttarget): hidd-%(hidd)-stubs
2286 #MM hidd-%(hidd)-stubs : includes includes-copy
2287 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2289 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2290         %mklib_q from=$^
2292 $(STUBS_OBJ) : $(STUBS_SRC) 
2293         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2295 $(STUBS_DEP) : $(STUBS_SRC)
2296         %mkdepend_q flags=%(dflags)
2298 setup ::
2299         %mkdirs_q $(OBJDIR) $(LIBDIR)
2302 clean ::
2303         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2305 DEPS := $(DEPS) $(STUBS_DEP)
2307 %end
2308 #------------------------------------------------------------------------------
2311 #------------------------------------------------------------------------------
2312 # Build an imported source tree which uses the configure script from the
2313 # autoconf package.  This rule will try to "integrate" the produced files as
2314 # much as possible in the AROS build, for example by putting libraries in the
2315 # standard library directory, includes in the standard include directory, and
2316 # so on. You can however override this behaviour.
2318 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2319 # be %(bindir) (or its deduced value) when running "make install", and
2320 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2321 # configure script some more parameters whose value depends upon the PROGDIR
2322 # env var, so that the program gets all its stuff installed in the proper place
2323 # when building it, but when running it from inside AROS it can also find that
2324 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2325 # the configuration parameters set when running ./configure
2327 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2328 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2329 # to the name which has to follow it.
2332 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2333     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2334     install_target=install preconfigure= postconfigure= postinstall= \
2335     install_env= use_build_env=no
2337 ifneq (%(prefix),)
2338     %(mmake)-prefix := %(prefix)
2339 else
2340     %(mmake)-prefix := $(AROS_CONTRIB)
2341 endif
2343 ifneq (%(aros_prefix),)
2344     %(mmake)-aros_prefix := %(aros_prefix)
2345 else
2346     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2347 endif
2349 ifeq (%(nix),yes)
2350     %(mmake)-nix    := -nix
2351     %(mmake)-volpfx := /
2352     %(mmake)-volsfx := /
2353     
2354     ifeq (%(nix_dir_layout),)
2355         %(mmake)-nix_dir_layout := yes
2356     endif
2357 else
2358     %(mmake)-volsfx := :
2359     
2360     ifeq (%(nix_dir_layout),)
2361         %(mmake)-nix_dir_layout := no
2362     endif
2363 endif
2365 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2367 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2368         exec_prefix=$(%(mmake)-prefix) %(install_env)
2370 # Check if chosen compiler is valid
2371 ifeq ($(findstring %(compiler),host target kernel),)
2372   $(error unknown compiler %(compiler))
2373 endif
2375 # Set legacy 'host' variable based on chosen compiler
2376 ifeq (%(compiler),host)
2377     host := yes
2378         ifeq (%(package),)
2379                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2380         else
2381                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2382         endif
2383 else
2384     host := no
2385         ifeq (%(package),)
2386                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2387         else
2388                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2389         endif
2390 endif
2392 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2393 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2395 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2396     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2397     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2398 else
2399     ifeq (%(nix),yes)
2400         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2401         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2402     else
2403         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2404     endif
2406     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2407     
2408     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2409         sbindir=$(%(mmake)-prefix) \
2410         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2411         oldincludedir=$(AROS_INCLUDES) %(install_env)
2412 endif
2414 ifneq ($(DEBUG),yes)
2415     %(mmake)-s_flag = -s
2416 endif
2418 # Set up build environment, and options for configure script
2419 ifeq (%(compiler),host)
2420     CONFIG_ENV := \
2421         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2422         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2423         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2424         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2425     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2426 endif
2427 ifeq (%(compiler),target)
2428     CONFIG_ENV := \
2429         CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2430         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2431         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2432         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2433         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2434     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2435         --host=$(AROS_TARGET_CPU)-aros\
2436         --target=$(AROS_TARGET_CPU)-aros\
2437         --disable-nls\
2438         --without-x --without-pic --disable-shared
2439 endif
2440 ifeq (%(compiler),kernel)
2441     CONFIG_ENV := \
2442         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2443         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2444         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2445     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2446         --host=$(AROS_TARGET_CPU)-aros\
2447         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2448         --without-x --without-pic --disable-shared
2449 endif
2451 ifeq (%(use_build_env),yes)
2452     BUILD_ENV := $(CONFIG_ENV)
2453 endif
2456 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2458 #MM- %(mmake) : setup includes core-linklibs %(mmake)-quick
2460 # Using -j1 in install_command may result in a warning but finally
2461 # it does its job. make install for gcc does not work reliably for -jN
2462 # where N > 1.
2463 ifneq (%(install_target),)
2464     %(mmake)-install_command = \
2465         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2466         -C $(%(mmake)-pkgdir) %(install_target) -j1
2468     %(mmake)-uninstall_command = \
2469     $(RM) $(%(mmake)-installflag) && \
2470     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2471     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2472 else
2473     %(mmake)-install_command   := true
2474     %(mmake)-uninstall_command := true
2475 endif
2477 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2480 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2482 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2483         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2484             $(RM)  $(%(mmake)-installflag) && \
2485             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2486              -C $(%(mmake)-pkgdir) && \
2487             $(%(mmake)-install_command) && \
2488             $(TOUCH) $@ -r $^; \
2489         fi
2491 $(%(mmake)-pkgdir)/.files-touched:
2492         %mkdirs_q $(%(mmake)-pkgdir)
2493         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2494         $(TOUCH) $@
2497 %(mmake)-uninstall :
2498         $(%(mmake)-uninstall_command)
2501 %(mmake)-configure : $(%(mmake)-configflag)
2503 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2504 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2505         $(RM) $@
2506         %mkdirs_q $(%(mmake)-pkgdir)
2507         cd $(%(mmake)-pkgdir) && \
2508         find . -name config.cache -exec $(RM) '{}' \; && \
2509         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2510             %(extraoptions) && \
2511         $(TOUCH) $@
2514 %(mmake)-clean : %(mmake)-uninstall
2515         @$(RM) $(%(mmake)-pkgdir)
2516 %end
2517 #------------------------------------------------------------------------------
2520 #------------------------------------------------------------------------------
2521 # Given an archive name, patches names and locations where to find them, fetch
2522 # the archive and the patches from any of those locations, unpack the archive
2523 # and then apply the patches.
2525 # Locations currently supported are http and ftp sites, plus local filesystem
2526 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2527 # the fetch.sh script needs to be modified, since this macro relies on that script.
2529 # Arguments:
2531 #     - mmake           = mmaketarget
2532 #     - archive_origins = list of locations where to find the archive. They are tried
2533 #                         in sequence, until the archive is found and fetching it 
2534 #                         succeeded. If not specified, the current directory is assumed.
2535 #     - archive         = the archive name. Mandatory.
2536 #     - suffixes        = a list of suffixes to append to the the package name plus the
2537 #                         version. Each one of them is tried until a matching archive is
2538 #                         found. They are appended to patches and these are tried the
2539 #                         same way as packages are.
2540 #     - location        = the local directory where to put the fetched archive and patches.
2541 #                         If not specified, the directory specified by destination is used.
2542 #     - destination     = the directory to unpack the archive to.
2543 #                         If not specified, the current directory is assumed.
2544 #     - patches_origins = list of locations where to find the patches. They are tried
2545 #                         in sequence, until a patch is found and fetching it 
2546 #                         succeeded. If not specified, the current directory is assumed.
2547 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2548 #                         patch_name[:[patch_subdir][:patch_opt]].
2550 #                             - patch_name   = the name of the patch file
2551 #                             - patch_subdir = the directory within \destination\ where to
2552 #                                              apply the patch.
2553 #                             - patch_opt    = any options to pass to the `patch' command
2554 #                                              when applying the patch.
2555 #                         
2556 #                         The patch_subdir and patch_opt fields are optional.
2558 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2559     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2561 .PHONY: %(mmake)
2563 ifneq (%(location),)
2564     %(mmake)-location := %(location)
2565 else
2566     %(mmake)-location := %(destination)
2567 endif
2570 %(mmake) :
2571         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2572         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2573 %end
2574 #------------------------------------------------------------------------------
2577 #------------------------------------------------------------------------------
2578 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2579 # unpatched source tree and runs diff against this and a previously fetched and possibly
2580 # patched tree. Depending on what happens after patching during a normal build it might
2581 # give best results if the new patch is created directly after fetch.
2583 # Arguments:
2585 #     - mmake       = mmaketarget
2586 #     - archive     = archive base name
2587 #     - srcdir      = directory the package is unpacked to, useful if archive unpacks to
2588 #                     a directory other than its name suggests.
2589 #     - suffixes    = a list of suffixes to append to the the package name plus the
2590 #                     version. Each one of them is tried until a matching archive is
2591 #                     found.
2592 #     - destination = the directory to unpack the archive to.
2593 #     - excludes    = diff patterns to exclude files or directories from the patch
2595 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2597 .PHONY: %(mmake)
2599 ifneq (%(excludes),)
2600     %(mmake)-exclude := -X ./exclude.patterns
2601 endif
2603 ifneq (%srcdir),)
2604     %(mmake)-srcdir := %(srcdir)
2605 else
2606     %(mmake)-srcdir := %(archive)
2607 endif
2610 %(mmake):
2611         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2612         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2613         cd %(destination)/tmp ; \
2614         $(FOR) f in %(excludes) ; do \
2615             $(ECHO) $$f >> ./exclude.patterns ; \
2616         done ; \
2617         diff -ruN $(%(mmake)-exclude) \
2618             $(%(mmake)-srcdir) \
2619             $(%(mmake)-srcdir).aros \
2620             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2621         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2622         $(RM) %(destination)/tmp
2623 %end
2624 #------------------------------------------------------------------------------
2627 #------------------------------------------------------------------------------
2628 # Joins the features of %fetch and %build_with_configure, taking advantage of
2629 # the naming scheme of GNU packages. GNU packages names are in the form
2631 #     <package name>-<version number>.<archive format suffix>
2633 # If a patch is provided, it *must* be named the following way:
2635 #    <package name>-<version number>-aros.diff
2637 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2638 # CD'ing into the archive's extracted directory.
2640 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2641 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2642 # to make that patch fully comprehensive.
2644 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2646 # Arguments:
2648 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2649 #                     macro.
2650 #    - package      = the GNU package name, sans version and archive format suffixes.
2651 #    - version      = the package's version number, or otherwise any other version string.
2652 #                     It gets appended to the package name to form the basename of the archive.
2653 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2654 #                     version. Each one of them is tried until a matching archive is found.
2655 #                     Defaults to "tar.bz2 tar.gz".
2656 #    - destination  = same meaning as the one for the %fetch macro
2657 #    - location     = same meaning as the one for the %fetch macro
2658 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2659 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2660 #                     fetched or not
2661 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2662 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2663 #                     $(GNUDIR).
2664 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2665 #                     /GNU.
2666 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2667 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2668 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2669 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2671 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2672     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2673     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2675 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2676 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2677 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2678 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2680 %(mmake)-archbase  := %(package)-%(version)
2682 ifeq (%(compiler),host)
2683     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2684 else
2685     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2686 endif
2688 ifeq (%(prefix),)
2689     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2690 else
2691     %(mmake)-prefix := %(prefix)
2692 endif
2694 ifneq (%(subpackage),)
2695     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2696 else
2697     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2698 endif
2700 ifneq (%(srcdir),)
2701     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2702 else
2703     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2704 endif
2706 ifeq (%(patch),yes)
2707     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2708 else
2709     %(mmake)-%(subpackage)-patches_specs := ::
2710 endif
2712 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2713     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2714     archive_origins=". %(package_repo)" \
2715     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2717 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2718     archive=$(%(mmake)-%(subpackage)-archbase) \
2719     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2720     suffixes="%(suffixes)" \
2721     destination=$(%(mmake)-portdir)
2723 #MM- %(mmake) : %(mmake)-%(subpackage)
2725 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2727 %(mmake)-%(subpackage)-package-basename := \
2728     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2730 ifneq (%(create_pkg),no)
2731     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2732 endif
2734 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2735      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2736      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2737      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2738      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2740 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2741 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2744 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2746 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2747 #that $^ and $@ have exactly the same mtime, and in that case make tries
2748 #to rebuild $@ again, which would fail because the directory where
2749 #the package got installed would not exist anymore. 
2750 #We work this around by using an if statement to manually check the mtimes.
2751 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2752         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2753         $(RM) $@ ; \
2754         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2755         mkdir -p "$(DISTDIR)/Packages" ; \
2756         mkdir -p "$(%(mmake)-prefix)" ; \
2757         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2758         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2759         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2760     fi
2761 %end
2762 #------------------------------------------------------------------------------
2765 #------------------------------------------------------------------------------
2766 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2767     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2768     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2770 GNU_REPOSITORY := gnu://
2772 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2773     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2774     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2775     patch="%(patch)" patch_repo="%(patch_repo)" \
2776     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2777     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2779 %end
2780 #------------------------------------------------------------------------------
2783 #------------------------------------------------------------------------------
2784 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2785 # that the package is a "Development" package, and as such it needs to be placed
2786 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2788 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2789 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2790 # "mmake" argument, because the metatarget is implicitely defined as
2792 #     #MM- development-%(package)
2794 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2795     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2796     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2798 #MM- development : development-%(package)
2801 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2802    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2803    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2804    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2805    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2808 postinstall-%(package)-delete-la-files:
2809         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2811 %end
2812 #------------------------------------------------------------------------------
2814 # Builds a kickstart package in PKG format
2815 # mmake   - target name
2816 # file    - Destination file name with path
2817 # startup - The file which will be put first
2818 # Other arguments are self-explanatory
2820 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2822 PKG_CLASSES   := $(addsuffix .class, %(classes))
2823 PKG_DEVICES   := $(addsuffix .device, %(devs))
2824 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2825 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2826 PKG_LIBS      := $(addsuffix .library, %(libs))
2827 PKG_RESOURCES := $(addsuffix .resource, %(res))
2829 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2830 PKG_DIR   := $(dir %(file))
2831 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2834 %(mmake) : %(file)
2837 %(mmake)-quick : %(file)
2839 %(file): PKG_FILES := $(PKG_FILES)
2840 %(file): $(PKG_DEPS) | $(PKG_DIR)
2841         @$(ECHO) Packaging $@...
2842         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2844 %compress_file mmake=%(mmake) file=%(file)
2846 GLOB_MKDIRS += $(PKG_DIR)
2848 %end
2850 #------------------------------------------------------------------------------
2851 # Compresses %(file) with a gzip.
2852 # Good in conjunction with for example %build_prog
2854 %define compress_file mmake=/A file=/A
2856 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2859 %(mmake)-gz-quick : %(file).gz
2861 %(file).gz: %(file)
2862         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2863         @gzip -9 -f $^
2865 %end
2867 #------------------------------------------------------------------------------
2868 # Links a kickstart module in ELF format
2869 # Arguments are similar to make_package
2871 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2872     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2874 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2875 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2876 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2877 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2878 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2879 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2881 ifeq (%(startup),)
2882     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2883 else
2884     KOBJ_STARTUP := %(startup)
2885 endif
2887 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2889 TMP_LDFLAGS := %(ldflags)
2891 # Make a list of the lib files this program depends on.
2892 # In LDFLAGS remove white space between -L and directory
2893 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2894 # Filter out only the libdirs and remove -L
2895 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2896 # Add trailing /
2897 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2898 # Add normal linklib path
2899 TMP_DIRS += $(LIBDIR)/
2900 # add lib and .a to static linklib names
2901 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2902 # search for the linklibs in the given path, ignore ones not found
2903 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2904     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2907 TMP_DIRS += $(dir %(file))
2908 ifneq (%(map),)
2909     TMP_LDFLAGS += $(GENMAP) %(map)
2910     TMP_DIRS    += $(dir %(map))
2911 endif
2913 #MM %(mmake) : %(deps)
2916 %(mmake) : %(file)
2919 %(mmake)-quick : %(file)
2921 %(file): KOBJS := $(KOBJS)
2922 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2923 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2924 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2925         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2926         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS) -noarosc
2927         @$(STRIP) $@
2929 %compress_file mmake=%(mmake) file=%(file)
2931 GLOB_MKDIRS += $(TMP_DIRS)
2933 %end
2935 #------------------------------------------------------------------------------
2936 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2937 # 'start' is an optional starting address
2938 # 'ldflags' is optional additional flags for the linker
2939 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2941 BD_OUTDIR := $(dir %(file))
2942 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2943 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2944 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2946 %(file) : %(objs) $(BD_OUTDIR)
2947         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2948         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2949         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2951 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2952     GLOB_MKDIRS += $(BD_OUTDIR)
2953 endif
2955 %end