In %build_module forgot to include %(mmake)-includes-quick in the .PHONY targets...
[AROS.git] / config / make.tmpl
blobcc36e8f5a03ac49814ee48bccdbaecea6b5e5f65
1 ############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macro's that are used as commands in the body    ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefile 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).
15 %define compile_q cmd=$(TARGET_CC) opt=$(CFLAGS) from=$< to=$@
16         @$(ECHO) "Compiling $(notdir %(from))"
17         @$(IF) %(cmd) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(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) %(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=$(AS) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) -c %(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) -c %(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)
56         @$(ECHO) "Linking %(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
72 #-------------------------------------------------------------------------
73 # Link a module based upon a number of arguments and the standard $(LIBS)
74 # and $(DEPLIBS) make variables.
76 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
77         @$(ECHO) "Building $(notdir $@) ..."
78         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
79             $(GENMAP) %(objdir)/%(module).map \
80             %(objs) %(libs) %(endtag) \
81             -o $@ 2>&1 > %(objdir)/%(err); \
82         then \
83             cat %(objdir)/%(err); \
84         else \
85             cat %(objdir)/%(err); \
86             exit 1; \
87         fi
89         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
90         @$(STRIP) $@
91 %end
92 #------------------------------------------------------------------------------
94 #------------------------------------------------------------------------------
95 # Create the library
96 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
97         @$(ECHO) "Creating library %(to)..."
98         @%(ar) %(to) %(from)
99         @%(ranlib) %(to)
100 %end
102 #------------------------------------------------------------------------------
103 # Create the dependency file %(to) for %(from)
104 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
105         %mkdir_q dir="$(dir %(to))"
106         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
107         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) %(from) -o %(to)
108 %end
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the function reference file %(to) to %(from)
113 %define mkref_q cc=$(AROS_CC) cppflags="-E -C -dD -D__CXREF__" cflags=$(CFLAGS) from=$< to=$@
114         @$(ECHO) "Generating ref for $(notdir %(from))..."
115         @$(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to) 2>$(GENDIR)/cerrors
116         @$(IF) $(TEST) -s %(to) ; \
117         then \
118             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
119                 $(ECHO) "%(from): $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" >> $(GENDIR)/errors ; \
120                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
121             fi ; \
122         else \
123             $(ECHO) "Reference generation failed: $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" 1>&2 ; \
124             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
125             $(RM) %(to) ; \
126             exit 1 ; \
127         fi
128 %end
130 #------------------------------------------------------------------------------
131 # Create one directory without any output
132 %define mkdir_q dir=.
133         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
134 %end
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
144 #############################################################################
145 #############################################################################
146 ##                                                                         ##
147 ## Here are the mmakefile macro's that are used to do certain tasks in a   ##
148 ## mmakefile. They consist of one or more full makefile rules.             ##
149 ## In general the files generated in these macro's are also defined as     ##
150 ## make targets so that they can be used as a dependency in other rules    ##
151 ##                                                                         ##
152 #############################################################################
153 #############################################################################
155 #------------------------------------------------------------------------------
156 # Generate a unique id for each of the %build... rules
157 %define buildid targets=/A
158 BDID := $(BDID)_
159 ifneq ($(filter $(TARGET),%(targets)),)
160 BDTARGETID := $(BDID)
161 endif
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy file %(from) to %(to) in a makefile rule
168 %define rule_copy from=/A to=/A
169 %(to) : %(from)
170         @$(CP) $< $@
171 %end
172 #------------------------------------------------------------------------------
175 #------------------------------------------------------------------------------
176 # Copy the files %(files) to %(targetdir). For each file in %(files),
177 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
178 # appropriate subdirs are not generated by this rule so they have to be
179 # present.
180 %define rule_copy_multi files=/A targetdir=/A srcdir=.
182 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
183         @$(CP) $< $@
184 %end
185 #------------------------------------------------------------------------------
187 #------------------------------------------------------------------------------
188 # Copy the files %(files) to %(targetdir). For each file in %(files),
189 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
190 # %(stampfile) is used to keep track of when the last time the comparison has
191 # been done. The targetdir and the appropriate subdirs are not generated by 
192 # this rule so they have to be present.
193 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
194     stampfile=$(TMP_SRCDIR)/.copy_stamp
196 TMP_SRCDIR := %(srcdir)
198 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
200 %(stampfile) : SRCDIR := %(srcdir)
201 %(stampfile) : TGTDIR := %(targetdir)
202 %(stampfile) : FILES := %(files)
203 %(stampfile) : $(addprefix %(srcdir)/,%(files))
204         @for f in $(FILES); do \
205              $(IF) ! $(CMP) -s $(SRCDIR)/$$f $(TGTDIR)/$$f ; then \
206                  $(CP) $(SRCDIR)/$$f $(TGTDIR)/$$f ; \
207              fi ; \
208         done
209         @$(TOUCH) $@
210 %end
211 #------------------------------------------------------------------------------
213 #------------------------------------------------------------------------------
214 # Will join all the files in %(from) to %(to). When text is specified it will
215 # be displayed.
216 # Restriction: at the moment when using a non-empty target dir %(from) may
217 # not have 
218 %define rule_join to=/A from=/A text=
220 %(to) : %(from)
221 ifneq (%(text),)
222         @$(ECHO) %(text)
223 endif
224         @$(CAT) $^ >$@
225 %end
226 #------------------------------------------------------------------------------
229 #------------------------------------------------------------------------------
230 # Include the dependency files and add some internal rules
231 # When depstargets is provided the depencies will only be included when one of
232 # these targets is the $(TARGET). Otherwise the dependencies will only be
233 # include when the $(TARGET) is not for setup or clean 
234 %define include_deps deps=$(DEPS)/M  depstargets=
235 ifneq (%(deps),)
236   ifneq (%(depstargets),)
237     ifneq ($(findstring $(TARGET),%(depstargets)),)
238       -include %(deps)
239     endif
240   else
241     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
242       -include %(deps)
243     endif
244   endif
245 endif
246 %end
247 #------------------------------------------------------------------------------
250 #------------------------------------------------------------------------------
251 # Create the directories %(dirs). The creation will be done by adding rules to
252 # the %(setuptarget) make target with setup as the default. 
253 %define rule_makedirs dirs=/A setuptarget=setup
255 %(setuptarget) :: %(dirs)
257 GLOB_MKDIRS += %(dirs)
259 %end
260 #------------------------------------------------------------------------------
263 #------------------------------------------------------------------------------
264 # Rule to generate a functable
266 %define rule_genfunctable name=functable files=/A dir=. libdefs=libdefs.h
268 %(dir)/%(name).c : $(addsuffix .c,%(files)) $(SCRIPTDIR)/genfunctable.awk %(libdefs)
269         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
270 ifneq (%(files),)
271         $(AWK) -v file=%(libdefs) -f $(SCRIPTDIR)/genfunctable.awk $(addsuffix .c,%(files)) > $@
272 else
273         $(ARCHTOOL) -t
274         $(MV) functable.c $@
275 endif
276 %end
277 #------------------------------------------------------------------------------
280 #------------------------------------------------------------------------------
281 # Generate a rule to compile a C source file to an object file and generate
282 # the dependency file. Basename may contain a directory part, then the source
283 # file has to be in that directory. The generated file will be put in the
284 # object directory without the directory.
285 # options
286 # - basename: the basename of the file to compile. Use % for a wildcard rule
287 # - cflags (default $(CFLAGS)): the C flags to use for compilation
288 # - dflags: the flags used during creation of dependency file. If not specified
289 #   the same value as cflags will be used
290 # - targetdir: the directory to put the .o file and the .d file. By default
291 #   it is put in the same directory as the .c file
292 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
294 ifeq (%(targetdir),)
295   TMP_TARGETBASE := %(basename)
296 else
297   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
298 endif
300 ifeq ($(findstring %(compiler),host target),)
301   $(error unknown compiler %(compiler))
302 endif
303 ifeq (%(compiler),target)
304 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC)
305 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC)
306 endif
307 ifeq (%(compiler),host)
308 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
309 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
310 endif
312 $(TMP_TARGETBASE).o : %(basename).c
313         %compile_q opt="%(cflags)" cmd=$(TMP_CMD)
315 ifeq (%(dflags),)
316 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317 else
318 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
319 endif
320 $(TMP_TARGETBASE).d : %(basename).c
321         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
322 %end
323 #------------------------------------------------------------------------------
326 #------------------------------------------------------------------------------
327 # Generate a rule to compile multiple C source files to an object file and
328 # generate the corresponding dependency files. The generated file will be put
329 # in the object directory without the directory part of the source file.
330 # options
331 # - basenames: the basenames of the files to compile. The names may include
332 #   relative or absolute path names. No wildcard is allowed
333 # - cflags (default $(CFLAGS)): the C flags to use for compilation
334 # - dflags: the flags used during creation of dependency file. If not specified
335 #   the same value as cflags will be used
336 # - targetdir: the directory to put the .o file and the .d file. By default
337 #   it is put in the same directory as the .c file. When targetdir is not
338 #   empty, path names will stripped from the file names so that all files are in
339 #   that dir and not in subdirectories.
340 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
341     compiler=target
343 ifeq (%(targetdir),)
344 TMP_TARGETS := $(addsuffix .o,%(basenames))
345 TMP_DTARGETS := $(addsuffix .d,%(basenames))
346 TMP_WILDCARD := %
347 else
348 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
349 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
350 TMP_WILDCARD := %(targetdir)/%
352 # Be sure that all .c files are generated
353 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
355 # Be sure that all .c files are found
356 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
357 ifneq ($(TMP_DIRS),)
358     vpath %.c $(TMP_DIRS)
359 endif
361 endif
363 ifeq ($(findstring %(compiler),host target),)
364   $(error unknown compiler %(compiler))
365 endif
366 ifeq (%(compiler),target)
367 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
368 endif
369 ifeq (%(compiler),host)
370 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
371 endif
373 $(TMP_TARGETS) : CFLAGS := %(cflags)
374 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
375         %compile_q cmd=$(CMD)
377 ifeq (%(dflags),)
378 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
379 else
380 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
381 endif
382 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
383         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
384 %end
385 #------------------------------------------------------------------------------
388 #------------------------------------------------------------------------------
389 # Make an alias from one arch specific build to another arch.
390 # arguments:
391 # - mainmmake: the mmake of the module in the main tree
392 # - arch: the current arch
393 # - alias: the alias to which this should point
394 %define rule_archalias mainmmake=\A arch=\A alias=\A
396 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
397 %end
398 #------------------------------------------------------------------------------
401 #------------------------------------------------------------------------------
402 # Generate a rule to compile a C source file to an shared object file with a
403 # .so suffix. Basename may contain a directory part, then the source
404 # file has to be in that directory. The generated file will be put in the
405 # object directory without the directory.
406 # options
407 # - basename: the basename of the file to compile. Use % for a wildcard rule
408 # - cflags (default $(CFLAGS)): the C flags to use for compilation
409 # - targetdir: the directory to put the .o file and the .d file. By default
410 #   it is put in the same directory as the .c file
411 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
413 ifeq (%(targetdir),)
414   TMP_TARGETBASE := %(basename)
415 else
416   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
417 endif
419 ifeq ($(findstring %(compiler),host target),)
420   $(error unknown compiler %(compiler))
421 endif
422 ifeq (%(compiler),target)
423 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
424 endif
425 ifeq (%(compiler),host)
426 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
427 endif
429 $(TMP_TARGETBASE).so : %(basename).c
430         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD)
431 %end
432 #------------------------------------------------------------------------------
435 #------------------------------------------------------------------------------
436 # Generate a rule to assemble a source file to an object file. Basename may
437 # contain a directory part, then the source file has to be in that directory.
438 # The generated file will be put in the object directory without the directory.
439 # options
440 # - basename: the basename of the file to compile. Use % for a wildcard rule
441 # - flags (default $(AFLAGS)): the asm flags to use for assembling
442 # - targetdir: the directory to put the .o file. By default it is put in the
443 #   same directory as the .s file
444 %define rule_assemble basename=/A flags=$(AFLAGS) targetdir=
446 ifeq (%(targetdir),)
447 %(basename).o : %(basename).s
448         %assemble_q opt=%(flags)
450 else
451 %(targetdir)/$(notdir %(basename)).o : %(basename).s
452         %assemble_q opt=%(flags)
454 endif
455 %end
456 #------------------------------------------------------------------------------
459 #------------------------------------------------------------------------------
460 # Generate a rule to assemble multiple source files to an object file. The
461 # generated file will be put in the object directory with the directory part
462 # of the source file stripped of.
463 # options
464 # - basenames: the basenames of the files to compile. The names may include
465 #   relative or absolute path names. No wildcard is allowed
466 # - aflags (default $(AFLAGS)): the C flags to use for compilation
467 # - targetdir: the directory to put the .o file and the .d file. By default
468 #   it is put in the same directory as the .c file. When targetdir is not
469 #   empty, path names will stripped from the file names so that all files are in
470 #   that dir and not in subdirectories.
471 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
473 ifeq (%(targetdir),)
474 TMP_TARGETS := $(addsuffix .o,%(basenames))
475 TMP_WILDCARD := %
476 else
477 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
478 TMP_WILDCARD := %(targetdir)/%
480 # Be sure that all .s files are generated
481 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
483 # Be sure that all .c files are found
484 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
485 ifneq ($(TMP_DIRS),)
486     vpath %%(suffix) $(TMP_DIRS)
487 endif
489 endif
491 $(TMP_TARGETS) : AFLAGS := %(aflags)
492 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
493         %assemble_q opt=$(AFLAGS)
494 %end
495 #------------------------------------------------------------------------------
498 #------------------------------------------------------------------------------
499 # Link %(objs) to %(prog) using the libraries in %(uselibs)
500 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
501     usehostlibs= usestartup=yes detach=no nix=no
503 TMP_EXTRA_LDFLAGS := 
504 ifeq (%(nix),yes)
505     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
506 endif
507 ifeq (%(usestartup),no)
508     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
509 endif
510 ifeq (%(detach),yes)
511     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
512 endif
513 %(prog) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
515 %(prog) : %(objs) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
516         %link_q from="%(objs)" opt="%(ldflags) $(EXTRA_LDFLAGS)" \
517             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
518 %end
519 #------------------------------------------------------------------------------
522 #------------------------------------------------------------------------------
523 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
524 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
525 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) \
526     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
527     usestartup=yes detach=no
529 TMP_EXTRA_LDFLAGS := 
530 ifeq (%(nix),yes)
531     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
532 endif
533 ifeq (%(usestartup),no)
534     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
535 endif
536 ifeq (%(detach),yes)
537     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
538 endif
539 $(addprefix %(targetdir)/,%(progs)) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
541 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o \
542     $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
543         %link_q from=$< opt="%(ldflags) $(EXTRA_LDFLAGS)" \
544             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
545 %end
546 #------------------------------------------------------------------------------
549 #------------------------------------------------------------------------------
550 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
551 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
553 %(libdir)/lib%(libname).a : %(objs)
554         %mklib_q from=$^
555 %end
556 #------------------------------------------------------------------------------
559 #------------------------------------------------------------------------------
560 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
561 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
563 %(libdir)/lib%(libname).so : %(objs)
564         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
565 %end
566 #------------------------------------------------------------------------------
569 #------------------------------------------------------------------------------
570 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
571 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
572 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A uselibs= usehostlibs=
574 %(module) : OBJS := %(objs)
575 %(module) : ENDTAG := %(endobj)
576 %(module) : ERR := %(err)
577 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
578 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
579         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS)
581 %end
582 #------------------------------------------------------------------------------
585 #------------------------------------------------------------------------------
586 # Generate a rule to generate a function reference file from a C source file.
587 # Basename may contain a directory part, then the source file has to be in that
588 # directory. The generated file will be put in the object directory without the
589 # directory.
590 # options
591 # - basename: the basename of the file to compile. Use % for a wildcard rule
592 # - cflags (default $(CFLAGS)): the C flags to use for compilation
593 # - targetdir: the directory to put the generated .ref file. By default the
594 #   .ref file will be put in the same directory as the .c file.
595 # - includefile: This file will be included at the head of the source file
596 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
598 ifeq (%(targetdir),)
599 GENFILE_TMP := %(basename).ref
600 else
601 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
602 endif
604 ifeq ($(filter %(compiler),target host),)
605 $(error use of %rule_ref: compiler has to be 'host' or 'target')
606 endif
608 ifeq (%(compiler),target)
609 $(GENFILE_TMP) : CC:=$(TARGET_CC)
610 else
611 $(GENFILE_TMP) : CC:=$(HOST_CC)
612 endif
614 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
615 ifeq (%(includefile),)
616         %mkref_q cc=$(CC) cflags="%(cflags)"
617 else
618         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
619 endif
621 %end
622 #------------------------------------------------------------------------------
625 #------------------------------------------------------------------------------
626 # Generate a rule to generate a function reference file from a C source file.
627 # Basename may contain a directory part, then the source file has to be in that
628 # directory. The generated file will be put in the object directory without the
629 # directory.
630 # options
631 # - basenames: the basenames of the files to compile. No wildcard is allowed
632 # - cflags (default $(CFLAGS)): the C flags to use for compilation
633 # - targetdir: the directory to put the generated .ref file. By default the
634 #   .ref file will be put in the same directory as the .c file. When targetdir
635 #   is not empty all files will be put there and path parts in the basenames
636 #   will be stripped off.
637 # - includefile: This file will be included at the head of the source file
638 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
639     compiler=target
641 ifeq (%(targetdir),)
642 TMP_TARGETS := $(addsuffix .ref,%(basenames))
643 TMP_WILDCARD := %.ref
644 else
645 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
646 TMP_WILDCARD := %(targetdir)/%.ref
648 # Be sure that all .c files are generated
649 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
651 # Be sure that all .c files are found
652 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
653 ifneq ($(TMP_DIRS),)
654     vpath %.c $(TMP_DIRS)
655 endif
657 endif
659 ifeq ($(filter %(compiler),target host),)
660 $(error use of %rule_ref: compiler has to be 'host' or 'target')
661 endif
663 ifeq (%(compiler),target)
664 $(TMP_TARGETS) : CC:=$(TARGET_CC)
665 else
666 $(TMP_TARGETS) : CC:=$(HOST_CC)
667 endif
668 ifeq (%(includefile),)
669 $(TMP_TARGETS) : CFLAGS:=%(cflags)
670 else
671 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
672 $(TMP_TARGETS) : %(includefile)
673 endif
674 $(TMP_TARGETS) : $(CXREF)
675 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
676         %mkref_q cc=$(CC)
677 %end
678 #------------------------------------------------------------------------------
681 #------------------------------------------------------------------------------
682 # Generate the libdefs.h include file for a module.
683 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
685 TMP_TARGET := %(modname)_libdefs.h
686 TMP_DEPS := $(GENMODULE)
687 TMP_OPTS := 
688 ifneq (%(conffile),)
689     TMP_OPTS += -c %(conffile)
690     TMP_DEPS += %(conffile)
691 else
692     TMP_DEPS += %(modname).conf
693 endif
694 ifneq (%(modsuffix),)
695     TMP_OPTS += -s %(modsuffix)
696 endif
697 ifneq (%(targetdir),)
698     TMP_OPTS += -d %(targetdir)
699     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
700 endif
702 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
703 $(TMP_TARGET) : MODNAME := %(modname)
704 $(TMP_TARGET) : MODTYPE := %(modtype)
705 $(TMP_TARGET) : $(TMP_DEPS)
706         @$(ECHO) "Generating $(notdir $@)"
707         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
708 %end
709 #------------------------------------------------------------------------------
712 #------------------------------------------------------------------------------
713 # Generate the libdefs.h include file for a module.
714 %define rule_genmodule_funclist \
715     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
717 TMP_TARGET := %(modname).funclist
718 TMP_DEPS := $(GENMODULE)
719 TMP_OPTS := 
720 ifeq (%(reffile),)
721     $(error reffile needed in rule_genmodule_funclist but none specified)
722 endif
723 TMP_OPTS := -r %(reffile)
724 TMP_DEPS += %(reffile)
725 ifneq (%(conffile),)
726     TMP_OPTS += -c %(conffile)
727     TMP_DEPS += %(conffile)
728 else
729     TMP_DEPS += %(modname).conf
730 endif
731 ifneq (%(modsuffix),)
732     TMP_OPTS += -s %(modsuffix)
733 endif
734 ifneq (%(targetdir),)
735     TMP_OPTS += -d %(targetdir)
736     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
737 endif
739 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
740 $(TMP_TARGET) : MODNAME := %(modname)
741 $(TMP_TARGET) : MODTYPE := %(modtype)
742 $(TMP_TARGET) : $(TMP_DEPS)
743         @$(ECHO) "Generating $(notdir $@)"
744         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
745 %end
746 #------------------------------------------------------------------------------
749 #------------------------------------------------------------------------------
750 # Generate a Makefile.%(modname) with the genmodule program and include this
751 # generated file in this Makefile
752 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
753     targetdir=
755 TMP_TARGET := Makefile.%(modname)
756 TMP_DEPS := $(GENMODULE)
757 TMP_OPTS := 
758 ifneq (%(conffile),)
759     TMP_OPTS += -c %(conffile)
760     TMP_DEPS += %(conffile)
761 else
762     TMP_DEPS += %(modname).conf
763 endif
764 ifneq (%(modsuffix),)
765     TMP_OPTS += -s %(modsuffix)
766 endif
767 ifneq (%(targetdir),)
768     TMP_OPTS += -d %(targetdir)
769     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
770 endif
772 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
773 $(TMP_TARGET) : MODNAME := %(modname)
774 $(TMP_TARGET) : MODTYPE := %(modtype)
775 $(TMP_TARGET) : $(TMP_DEPS)
776         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
777 %end
778 #------------------------------------------------------------------------------
780 #------------------------------------------------------------------------------
781 # Generate dummy support files so cxref when used on the a module source file
782 # will find something to include. This rule has to be preceeded by
783 # %rule_genmodule_makefile
784 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
786 ifneq ($(%(modname)_INCLUDES),)
787 TMP_TARGETS := $(%(modname)_INCLUDES)
789 TMP_DEPS := $(GENMODULE)
790 TMP_OPTS := 
791 ifneq (%(conffile),)
792     TMP_OPTS += -c %(conffile)
793     TMP_DEPS += %(conffile)
794 else
795     TMP_DEPS += %(modname).conf
796 endif
797 ifneq (%(modsuffix),)
798     TMP_OPTS += -s %(modsuffix)
799 endif
800 ifneq (%(targetdir),)
801     TMP_OPTS += -d %(targetdir)
802     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
803 endif
805 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
806 $(TMP_TARGETS) : MODNAME := %(modname)
807 $(TMP_TARGETS) : MODTYPE := %(modtype)
808 $(TMP_TARGETS) : $(TMP_DEPS)
809         @$(ECHO) "Generating dummy include files"
810         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
811 endif
812 %end
813 #------------------------------------------------------------------------------
816 #------------------------------------------------------------------------------
817 # Generate the support files for compiling a module. This includes include
818 # files and source files. This rule has to be preceeded by
819 # %rule_genmodule_makefile
820 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
821     conffile= reffile=
823 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
824                $(%(modname)_LINKLIBFILES)
825 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
827 TMP_DEPS := $(GENMODULE)
828 ifeq ($(%(modname)_NEEDREF), yes)
829     ifeq (%(reffile),)
830         $(error reffile needed in rule_genmodule_files but none specified)
831     endif
832     TMP_OPTS := -r %(reffile)
833     TMP_DEPS += %(reffile)
834 else
835     TMP_OPTS :=
836 endif
837 ifneq (%(conffile),)
838     TMP_OPTS += -c %(conffile)
839     TMP_DEPS += %(conffile)
840 else
841     TMP_DEPS += %(modname).conf
842 endif
843 ifneq (%(modsuffix),)
844     TMP_OPTS += -s %(modsuffix)
845 endif
846 ifneq (%(targetdir),)
847     TMP_OPTS += -d %(targetdir)
848     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
849 endif
851 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
852 $(TMP_TARGETS) : MODNAME := %(modname)
853 $(TMP_TARGETS) : MODTYPE := %(modtype)
854 $(TMP_TARGETS) : $(TMP_DEPS)
855         @$(ECHO) "Generating functable and support files for module $(BD_MODNAME$(BDID))"
856 ifneq (%(conffile),lib.conf)
857         @$(IF) $(TEST) -f lib.conf; then \
858           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
859         fi
860 endif
861         @$(IF) $(TEST) -f libdefs.h; then \
862           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
863         fi
864         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
865 %end
866 #------------------------------------------------------------------------------
868 #------------------------------------------------------------------------------
869 # Generate the support files for compiling a module. This includes include
870 # files and source files.
871 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
872     targetdir= conffile= reffile=
875 ifneq ($(%(modname)_INCLUDES),)
876 TMP_TARGETS := $(%(modname)_INCLUDES)
878 TMP_DEPS := $(GENMODULE)
879 ifeq ($(%(modname)_NEEDREF), yes)
880     ifeq (%(reffile),)
881         $(error reffile needed in rule_genmodule_files but none specified)
882     endif
883     TMP_OPTS := -r %(reffile)
884     TMP_DEPS += %(reffile)
885 else
886     TMP_OPTS :=
887 endif
888 ifneq (%(conffile),)
889     TMP_OPTS += -c %(conffile)
890     TMP_DEPS += %(conffile)
891 else
892     TMP_DEPS += %(modname).conf
893 endif
894 ifneq (%(modsuffix),)
895     TMP_OPTS += -s %(modsuffix)
896 endif
897 ifneq (%(targetdir),)
898     TMP_OPTS += -d %(targetdir)
899     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
900 endif
902 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
903 $(TMP_TARGETS) : MODNAME := %(modname)
904 $(TMP_TARGETS) : MODTYPE := %(modtype)
905 $(TMP_TARGETS) : $(TMP_DEPS)
906         @$(ECHO) "Generating include files"
907         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
908 endif
909 %end
910 #------------------------------------------------------------------------------
912 #------------------------------------------------------------------------------
913 # Common rules for all makefiles
914 %define common
915 # Delete generated makefiles
917 clean ::
918         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
920 include $(TOP)/config/make.tail
922 BDID := $(BDTARGETID)
923 %end
924 #------------------------------------------------------------------------------
925       
927 #############################################################################
928 #############################################################################
929 ##                                                                         ##
930 ## Here are the mmakefile build macro's. These are macro's that takes care ##
931 ## of everything to go from the sources to the generated target. Also all  ##
932 ## intermediate files and directories that are needed are created by these ##
933 ## rules.                                                                  ##
934 ##                                                                         ##
935 #############################################################################
936 #############################################################################
938 #------------------------------------------------------------------------------
939 # Build a program
940 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME$(BDID)) asmfiles= \
941     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
942     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
943     aflags=$(AFLAFS) uselibs= usehostlibs= usestartup=yes detach=no nix=no
945 .PHONY : %(mmake)
947 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
949 BD_PROGNAME$(BDID)  := %(progname)
950 BD_OBJDIR$(BDID)    := %(objdir)
951 BD_TARGETDIR$(BDID) := %(targetdir)
953 BD_FILES$(BDID)     := %(files)
954 BD_ASMFILES$(BDID)  := %(asmfiles)
955 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID))))
956 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
958 BD_CFLAGS$(BDID)    := %(cflags)
959 BD_AFLAGS$(BDID)    := %(aflags)
960 BD_DFLAGS$(BDID)    := %(dflags)
961 BD_LDFLAGS$(BDID)   := %(ldflags)
964 %(mmake)-quick : %(mmake)
967 %(mmake) : $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID))
969 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
970 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
971     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
972 %rule_assemble basename=% targetdir=$(BD_OBJDIR$(BDID)) \
973                flags=$(BD_AFLAGS$(BDID))
975 %rule_link_prog prog=$(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) \
976     objs=$(BD_OBJS$(BDID)) ldflags=$(BD_LDFLAGS$(BDID)) \
977     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
978     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
980 endif
982 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
984 $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) : | $(BD_OBJDIR$(BDID))
985 $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) : | $(BD_TARGETDIR$(BDID))
986 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_TARGETDIR$(BDID))
988 %end
989 #------------------------------------------------------------------------------
992 #------------------------------------------------------------------------------
993 # Build programs, for every C file an executable will be built with the same
995 %define build_progs mmake=/A files=/A \
996     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
997     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
998     uselibs= usehostlibs= usestartup=yes detach=no
1000 .PHONY : %(mmake)
1002 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
1004 BD_OBJDIR$(BDID)    := %(objdir)
1005 BD_TARGETDIR$(BDID) := %(targetdir)
1007 BD_FILES$(BDID)     := %(files)
1008 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
1009 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
1010 BD_EXES$(BDID)      := $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID)))
1012 BD_CFLAGS$(BDID)    := %(cflags)
1013 ifneq ($(strip $(filter arosc_shared,%(uselibs))),)
1014 BD_CFLAGS$(BDID)    += -D_CLIB_LIBRARY_ -I$(TOP)/rom/exec
1015 endif
1016 BD_DFLAGS$(BDID)    := %(dflags)
1017 BD_LDFLAGS$(BDID)   := %(ldflags)
1020 %(mmake)-quick : %(mmake)
1023 %(mmake) : $(BD_EXES$(BDID))
1025 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1026 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1027     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1029 %rule_link_progs progs=$(BD_FILES$(BDID)) \
1030     targetdir=$(BD_TARGETDIR$(BDID)) objdir=$(BD_OBJDIR$(BDID)) \
1031     ldflags=$(BD_LDFLAGS$(BDID)) \
1032     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1033     usestartup="%(usestartup)" detach="%(detach)"
1035 endif
1037 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
1039 $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID))) : | $(BD_TARGETDIR$(BDID))
1040 $(BD_DEPS$(BDID)) $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1041 GLOB_MKDIRS += $(BD_TARGETDIR$(BDID)) $(BD_OBJDIR$(BDID))
1043 %end
1044 #------------------------------------------------------------------------------
1047 #------------------------------------------------------------------------------
1048 # Build a module.
1049 # This is a bare version: It just compiles and links the given files. It is
1050 # assumed that all needed boiler plate code is in the files. This should only
1051 # be used for compiling external code. For AROS code use %build_module
1052 %define build_module_simple mmake=/A modname=/A modtype=/A \
1053     files="$(basename $(wildcard *.c))" \
1054     cflags=$(CFLAGS) dflags=$(BD_DEFDFLASGS) \
1055     objdir=$(OBJDIR) moduledir= \
1056     uselibs= usehostlibs= compiler=target
1058 # Define metamake targets and their dependencies
1059 #MM %(mmake) : core-linklibs includes-generate-deps
1060 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1061 #MM %(mmake)-quick
1062 #MM %(mmake)-clean
1064 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1066 .PHONY : $(BD_ALLTARGETS)
1068 ifeq (%(modname),)
1069 $(error using %build_module_simple: modname may not be empty)
1070 endif
1071 ifeq (%(modtype),)
1072 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1073 endif
1075 # Default values for variables and arguments
1076 BD_DEFLINKLIBNAME := %(modname)
1077 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1078 BD_DEFDFLAGS := %(cflags)
1079 OBJDIR ?= $(GENDIR)/$(CURDIR)
1080 BD_MODDIR := %(moduledir)
1081 ifeq ($(BD_MODDIR),)
1082   ifeq (%(modtype),library)
1083     BD_MODDIR  := $(AROS_LIBS)
1084   endif
1085   ifeq (%(modtype),gadget)
1086     BD_MODDIR  := $(AROS_GADGETS)
1087   endif
1088   ifeq (%(modtype),datatype)
1089     BD_MODDIR  := $(AROS_DATATYPES)
1090   endif
1091   ifeq (%(modtype),handler)
1092     BD_MODDIR  := $(AROS_FS)
1093   endif
1094   ifeq (%(modtype),device)
1095     BD_MODDIR  := $(AROS_DEVS)
1096   endif
1097   ifeq (%(modtype),resource)
1098     BD_MODDIR  := $(AROS_RESOURCES)
1099   endif
1100   ifeq (%(modtype),mui)
1101     BD_MODDIR  := $(AROS_CLASSES)/Zune
1102   endif
1103   ifeq (%(modtype),mcc)
1104     BD_MODDIR  := $(AROS_CLASSES)/Zune
1105   endif
1106   ifeq (%(modtype),mcp)
1107     BD_MODDIR  := $(AROS_CLASSES)/Zune
1108   endif
1109   ifeq (%(modtype),hidd)
1110     BD_MODDIR  := $(AROS_DRIVERS)
1111   endif
1112 endif
1113 ifeq ($(BD_MODDIR),)
1114   $(error Don't where to put the file for modtype %(modtype). Specify moduledir=)
1115 endif
1117 %rule_compile_multi \
1118     basenames="%(files)" targetdir="%(objdir)" \
1119     cflags="%(cflags)" dflags="%(dflags)" \
1120     compiler=%(compiler)
1122 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1123 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1125 %(mmake)-quick : %(mmake)
1126 %(mmake) : $(BD_MODULE)
1127 %(mmake)-kobj : $(BD_KOBJ)
1129 # The module is linked from all the compiled .o files
1130 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1131 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1132                  endobj= err=%(modname).err \
1133                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1135 # Link kernel object file
1136 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1137     expansion keymap
1138 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1139     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1140 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1141 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1142 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1143 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1144 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1145         @$(ECHO) "Linking $@"
1146         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1147         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1150 ## Dependency fine-tuning
1152 BD_DEPS       := $(addprefix %(objdir), $(addsuffix .o,%(files)))
1153 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1155 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1156 $(BD_MODULE) : | $(BD_MODDIR)
1157 $(BD_KOBJ) : | $(KOBJSDIR)
1158 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1160 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1161 %(mmake)-clean ::
1162         @$(ECHO) "Cleaning up for module %(modname)"
1163         @$(RM) $(BD_OBJS) $(BD_KOBJ)
1164 %end
1167 #------------------------------------------------------------------------------
1168 # Build a module
1169 # Explanation of this macro is done in the developer's manual
1170 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1171   conffile= files="$(basename $(wildcard *.c))" \
1172   linklibfiles= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1173   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1174   reffile=$(BD_DEFREFFILE) noref= \
1175   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1176   compiler=target genincludes=
1178 # Define metamake targets and their dependencies
1179 #MM- includes-all : %(mmake)-includes
1180 #MM %(mmake) : %(mmake)-includes core-linklibs
1181 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1182 #MM %(mmake)-linklib : %(mmake)-includes
1183 #MM %(mmake)-quick : %(mmake)-includes-quick
1184 #MM %(mmake)-includes : %(mmake)-makefile includes-generate-deps
1185 #MM %(mmake)-includes-quick
1186 #MM %(mmake)-makefile
1187 #MM %(mmake)-funclist
1188 #MM %(mmake)-clean
1190 # All MetaMake targets defined by this macro
1191 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1192     %(mmake)-includes-quick %(mmake)-clean %(mmake)-kobj \
1193     %(mmake)-funclist %(mmake)-linklib
1195 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1197 ifeq (%(modname),)
1198 $(error using %build_module: modname may not be empty)
1199 endif
1200 ifeq (%(modtype),)
1201 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1202 endif
1204 # Default values for variables and arguments
1205 BD_DEFLINKLIBNAME := %(modname)
1206 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1207 BD_DEFDFLAGS := %(cflags)
1208 OBJDIR ?= $(GENDIR)/$(CURDIR)
1210 ## Create genmodule include Makefile for the module
1212 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1214 %rule_genmodule_makefile \
1215     modname=%(modname) modtype=%(modtype) \
1216     modsuffix=%(modsuffix) targetdir=%(objdir) \
1217     conffile=%(conffile)
1219 %(objdir)/Makefile.%(modname) : | %(objdir)
1221 GLOB_MKDIRS += %(objdir)
1223 # Do not parse these statements if metatarget is not appropriate
1224 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1226 include %(objdir)/Makefile.%(modname)
1228 BD_DEFMODDIR := $(%(modname)_MODDIR)
1231 ## include files generation
1233 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1234 ifeq (%(genincludes),yes)
1235     %(modname)_INCLUDES := proto/%(modname).h clib/%(modname)_protos.h defines/%(modname).h 
1236 endif
1237 ifeq (%(genincludes),no)
1238     %(modname)_INCLUDES :=
1239 endif
1240 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1241 BD_DEFLIBDEFSINC := %(objdir)/%(modname)_deflibdefs.h
1243 %(mmake)-includes-quick : %(mmake)-includes
1244 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1245     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1246     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1248 ifneq ($(%(modname)_INCLUDES),)
1249 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1250                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1251                          conffile=%(conffile) reffile=%(reffile)
1253 %rule_copy_diff_multi \
1254     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1255     stampfile=%(objdir)/%(modname)_geninc
1257 %rule_copy_diff_multi \
1258     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1259     stampfile=%(objdir)/%(modname)_incs
1261 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1262                       modsuffix=%(modsuffix) \
1263                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1265 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1266 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) : | %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS))
1267 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) : | $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS))
1268 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) : | $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1269 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1270 GLOB_MKDIRS += %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1271     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1272     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS)) \
1273     %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1275 endif
1277 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1278                            modsuffix=%(modsuffix) targetdir=%(objdir) \
1279                            conffile=%(conffile)
1281 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1283 %(objdir)/%(modname)_deflibdefs.h : FILENAME := $(BD_LIBDEFSINC)
1284 %(objdir)/%(modname)_deflibdefs.h :
1285         @$(ECHO) "generating $@"
1286         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1289 ## Generation of the funclist file
1291 %(mmake)-funclist : %(modname).funclist
1293 %rule_genmodule_funclist \
1294     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1295     conffile=%(conffile) reffile=%(reffile)
1298 ## Extra genmodule src files generation
1299 ## 
1300 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1301                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1302                       conffile=%(conffile) reffile=%(reffile)
1304 ## Compilation
1306 BD_FILES      := %(files)
1307 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1308 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1310 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1311 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1312 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1314 BD_CFLAGS     := %(cflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1315 BD_DFLAGS     := %(dflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1317 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1318 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1319 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1320     BD_LINKLIB :=
1321 else
1322     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1323 endif
1324 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1326 BD_CCFILES := $(BD_NARCHFILES) $(BD_STARTFILES) \
1327     $(BD_ENDFILES) $(BD_LINKLIBCFILES) %(linklibfiles)
1329 %rule_compile_multi \
1330     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1331     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1332     compiler=%(compiler)
1334 ifneq ($(BD_LINKLIBAFILES),)
1335 %rule_assemble_multi \
1336     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1337 endif
1339 ## function reference files generation
1341 %rule_ref_multi \
1342     basenames=$(BD_FILES) targetdir=%(objdir) \
1343     cflags="-I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip $(BD_CFLAGS))" \
1344     compiler=%(compiler)
1346 ifeq (%(noref),)
1347 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1348 else
1349 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1350 endif
1352 %rule_join from=$(BD_REFS) to=%(reffile) \
1353            text="Collecting function references for module %(modname)"
1356 ## Linking
1358 ifeq (%(modsuffix),)
1359 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1360 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1361 else
1362 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1363 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1364 endif
1366 %(mmake)-quick : %(mmake)
1367 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1368 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1369 %(mmake)-linklib : $(BD_LINKLIB)
1371 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1372                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1373 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1374 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES))
1376 # The module is linked from all the compiled .o files
1377 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1378                  endobj=$(BD_ENDOBJS) err=$(BD_MODNAME).err \
1379                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1381 # Link static lib
1382 ifneq ($(BD_LINKLIB),)
1383 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1385 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1386 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1387 endif
1389 # Link kernel object file
1390 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1391     expansion keymap
1392 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1393     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1394 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1395 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1396 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1397 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1398 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1399         @$(ECHO) "Linking $@"
1400         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1401         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1403 ## Dependency fine-tuning
1405 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES))))
1406 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1408 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1409 $(BD_MODULE) : | %(prefix)/%(moduledir)
1410 $(BD_KOBJ) : | $(KOBJSDIR)
1411 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1413 # Some include files need to be generated before the .c can be parsed.
1414 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1415 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1416     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1417 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1419 BD_DFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1420     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1421 $(BD_DEPS) : $(BD_DFILE_DEPS)
1422 endif
1424 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1425     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1426     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1427     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1428     $(addprefix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1429     %(objdir)/%(modname)_deflibdefs.h \
1430     $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1431     $(BD_ENDOBJS)
1432 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1433 %(mmake)-clean ::
1434         @$(ECHO) "Cleaning up for module %(modname)"
1435         @$(RM) $(FILES)
1437 endif # $(TARGET) in $(BD_ALLTARGETS)
1438 %end
1439 #------------------------------------------------------------------------------
1442 #------------------------------------------------------------------------------
1443 # Build a module using the deprecated macro's to define the functions in the
1444 # library. Explanation of this macro is done in the developer's manual
1445 %define build_module_macro mmake=/A modname=/A modtype=/A dir= \
1446   conffile=$(BD_MODNAME$(BDID)).conf initfile=$(BD_MODNAME$(BDID))_init \
1447   funcs= files= linklibfiles= cflags=$(CFLAGS) dflags= \
1448   objdir=$(OBJDIR) uselibs= usehostlibs= \
1449   genfunctable= genincludes= compiler=target
1451 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean %(mmake)-includes %(mmake)-linklib %(mmake)-quick %(mmake)-kobj"
1453 .PHONY : setup-module$(BDID)
1455 ifeq (%(modname),)
1456 $(error using %build_module: modname may not be empty)
1457 endif
1458 ifeq (%(modtype),)
1459 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1460 endif
1462 # assign and generate the local variables used in this macro
1463 BD_MODNAME$(BDID)    := %(modname)
1464 BD_MODTYPE$(BDID)    := %(modtype)
1465 BD_MODDIR$(BDID)     := %(dir)
1466 BD_CONFFILE$(BDID)   := %(conffile)
1467 OBJDIR               ?= $(GENDIR)/$(CURDIR)
1468 BD_OBJDIR$(BDID)     := %(objdir)
1470 BD_ARCHOBJS$(BDID)   := $(wildcard $(BD_OBJDIR$(BDID))/arch/*.o)
1471 BD_ARCHFILES$(BDID)  := $(basename $(notdir $(BD_ARCHOBJS$(BDID))))
1473 BD_INITFILE$(BDID)   := %(initfile)
1474 BD_FUNCS$(BDID)      := $(filter-out $(BD_ARCHFILES$(BDID)),%(funcs))
1475 BD_FILES$(BDID)      := $(filter-out $(BD_ARCHFILES$(BDID)),%(files))
1476 BD_LIBFILES$(BDID)   := %(linklibfiles)
1477 ifneq ($(wildcard $(BD_CONFFILE$(BDID))),)
1478 BD_ENDFILE$(BDID)    := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_end
1479 else
1480 BD_ENDFILE$(BDID)    := 
1481 endif
1483 BD_FUNCSRCS$(BDID)   := $(addsuffix .c,%(funcs))
1484 BD_SRCS$(BDID)       := $(addsuffix .c,$(BD_FILES$(BDID)))
1485 ifeq ($(filter $(BD_INITFILE$(BDID)), $(BD_ARCHFILES$(BDID))),)
1486   BD_INITOBJ$(BDID)  := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir $(BD_INITFILE$(BDID)))))
1487 else
1488   TMP_INITREPLACE    := $(filter $(notdir $(BD_INITFILE$(BDID))), $(BD_ARCHFILES$(BDID)))
1489   TMP_INITKEEP       := $(filter-out $(TMP_INITREPLACE),$(notdir $(BD_INITFILE$(BDID))))
1490   BD_INITOBJ$(BDID)  := $(addsuffix .o, \
1491                             $(addprefix $(BD_OBJDIR$(BDID))/arch/,$(TMP_INITREPLACE)) \
1492                             $(addprefix $(BD_OBJDIR$(BDID))/,$(TMP_INITKEEP)) \
1493                          )
1494   BD_ARCHOBJS$(BDID) := $(filter-out $(BD_INITOBJ$(BDID)),$(BD_ARCHOBJS$(BDID)))
1495 endif
1497 TMP_FILES            := $(notdir $(BD_FILES$(BDID)))
1498 ifeq (%(genfunctable),yes)
1499   TMP_FILES          := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1500 else
1501   ifneq ($(BD_FUNCS$(BDID)),)
1502     ifeq (%(genfunctable),)
1503       ifneq ($(BD_MODTYPE$(BDID)),resource)
1504         TMP_FILES    := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1505       endif
1506     else
1507       ifneq (%(genfunctable),no)
1508         TMP_FILES    := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1509       endif
1510     endif
1511     TMP_FILES        += $(BD_FUNCS$(BDID))
1512   endif
1513 endif
1514 BD_OBJS$(BDID)       := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(TMP_FILES))) $(BD_ARCHOBJS$(BDID))
1515 BD_ENDOBJ$(BDID)     := $(addsuffix .o,$(BD_ENDFILE$(BDID)))
1517 BD_DEPS$(BDID)       := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_INITFILE$(BDID)) $(TMP_FILES)))
1519 BD_GENINCS$(BDID)    :=
1520 ifneq (%(genincludes),)
1521   ifeq (%(genincludes),yes)
1522     BD_GENINCS$(BDID):= clib/$(BD_MODNAME$(BDID))_protos.h defines/$(BD_MODNAME$(BDID)).h proto/$(BD_MODNAME$(BDID)).h
1523   endif
1524 else
1525   ifneq ($(BD_FUNCS$(BDID)),)
1526     ifneq ($(findstring $(BD_MODTYPE$(BDID)),library gadget device),)
1527       BD_GENINCS$(BDID):= clib/$(BD_MODNAME$(BDID))_protos.h defines/$(BD_MODNAME$(BDID)).h proto/$(BD_MODNAME$(BDID)).h
1528     endif
1529   endif
1530 endif
1531 # Only generate libdefs.h if the config file exists
1532 ifneq ($(wildcard $(BD_CONFFILE$(BDID))),)
1533   BD_LIBDEFSINC$(BDID):= $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_libdefs.h
1534 else
1535   BD_LIBDEFSINC$(BDID):=
1536 endif
1538 BD_CFLAGS$(BDID)     := %(cflags) -I$(BD_OBJDIR$(BDID)) -I. -I$(TOP)/workbench/libs -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1539 ifeq (%(dflags),)
1540 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
1541 else
1542 BD_DFLAGS$(BDID)     := %(dflags) -I$(BD_OBJDIR$(BDID)) -I. -I$(TOP)/workbench/libs -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1543 endif
1545 # Add additional files depending the module type
1546 ifeq ($(findstring $(BD_MODTYPE$(BDID)),library gadget datatype handler device resource mui mcc mcp hidd),)
1547     $(error unhandled MODTYPE %(modtype))
1548 endif
1549 ifeq ($(BD_MODDIR$(BDID)),)
1550   ifeq ($(BD_MODTYPE$(BDID)),library)
1551     BD_MODDIR$(BDID)  := $(AROS_LIBS)
1552   endif
1553   ifeq ($(BD_MODTYPE$(BDID)),gadget)
1554     BD_MODDIR$(BDID)  := $(AROS_GADGETS)
1555   endif
1556   ifeq ($(BD_MODTYPE$(BDID)),datatype)
1557     BD_MODDIR$(BDID)  := $(AROS_DATATYPES)
1558   endif
1559   ifeq ($(BD_MODTYPE$(BDID)),handler)
1560     BD_MODDIR$(BDID)  := $(AROS_FS)
1561   endif
1562   ifeq ($(BD_MODTYPE$(BDID)),device)
1563     BD_MODDIR$(BDID)  := $(AROS_DEVS)
1564   endif
1565   ifeq ($(BD_MODTYPE$(BDID)),resource)
1566     BD_MODDIR$(BDID)  := $(AROS_RESOURCES)
1567   endif
1568   ifeq ($(BD_MODTYPE$(BDID)),mui)
1569     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1570   endif
1571   ifeq ($(BD_MODTYPE$(BDID)),mcc)
1572     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1573   endif
1574   ifeq ($(BD_MODTYPE$(BDID)),mcp)
1575     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1576   endif
1577   ifeq ($(BD_MODTYPE$(BDID)),hidd)
1578     BD_MODDIR$(BDID)  := $(AROS_DRIVERS)
1579   endif
1580 endif
1582 BD_MODULE$(BDID)    := $(BD_MODDIR$(BDID))/$(BD_MODNAME$(BDID)).$(BD_MODTYPE$(BDID))
1583 BD_GENFILES$(BDID)  := $(BD_MODULE$(BDID))
1584 BD_DEPS$(BDID)      += $(BD_LINKLIBDEPS$(BDID))
1586 #MM- includes-all : %(mmake)-includes
1587 #MM %(mmake) : %(mmake)-includes %(mmake)-setup
1588 #MM %(mmake)-includes : %(mmake)-setup
1591 %(mmake)-quick : %(mmake)
1593 %(mmake) : $(BD_GENFILES$(BDID))
1596 %(mmake)-clean ::
1597         @$(ECHO) "Cleaning up for module $(BD_MODNAME$(BDID))"
1598         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) \
1599             $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .c,$(BD_GENFILES$(BDID)))) \
1600             $(addprefix $(GENINCDIR)/,$(BD_GENINCS$(BDID))) \
1601             $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID))) \
1602             $(BD_LIBDEFSINC$(BDID)) \
1603             $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h \
1604             $(BD_ENDFILE$(BDID)).c $(BD_ENDOBJ$(BDID))
1607 %(mmake)-setup : setup-module$(BDID)
1609 #MM %(mmake)-includes : setup-clib
1611 TMP_DEPS := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1612 ifneq ($(BD_GENINCS$(BDID)),)
1613 TMP_DEPS += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp \
1614   $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID)))
1615 endif
1617 %(mmake)-includes : $(TMP_DEPS)
1618   
1619 $(TMP_DEPS) : $(BD_LIBDEFSINC$(BDID))
1621 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-linklib %(mmake)-quick %(mmake)-kobj),) # Avoid conflicts
1622 ifneq ($(dir $(BD_FILES$(BDID))),./)
1623 vpath %.c $(filter-out ./,$(dir $(BD_FUNCS$(BDID)) $(BD_FILES$(BDID))))
1624 endif
1626 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1627               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1628               compiler=%(compiler)
1629 %rule_compile basename=$(BD_ENDFILE$(BDID)) targetdir=$(BD_OBJDIR$(BDID)) \
1630               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1631               compiler=%(compiler)
1632 %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_functable targetdir=$(BD_OBJDIR$(BDID)) \
1633               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1634               compiler=%(compiler)
1635 endif
1637 BD_DFILE_DEPS$(BDID) := $(BD_LIBDEFSINC$(BDID)) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1639 # Some include files need to be generated before the .c can be parsed.
1640 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-linklib) %(mmake)-kobj,) # Only for this target these deps are wanted
1641 $(BD_DEPS$(BDID)) : $(BD_DFILE_DEPS$(BDID))
1642 endif
1644 # Generation of the autogenerated .c and .h files.
1645 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h :
1646         @$(ECHO) "generating $@"
1647         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(notdir $(BD_LIBDEFSINC$(BDID)))\"" >$@
1649 %libdefs_rule conffile=$(BD_CONFFILE$(BDID)) dest=$(BD_LIBDEFSINC$(BDID))
1651 ifneq ($(BD_ENDFILE$(BDID)),)
1652 $(BD_ENDFILE$(BDID)).c :
1653         @$(ECHO) "generating $@"
1654         @$(ECHO) "#include <libcore/libtail.c>" >$@
1655 endif
1657 %rule_genfunctable name=$(BD_MODNAME$(BDID))_functable files=$(BD_FUNCS$(BDID)) dir=$(BD_OBJDIR$(BDID)) \
1658   libdefs=$(BD_LIBDEFSINC$(BDID))
1660 # The module is linked from all the compiled .o files
1661 %rule_linkmodule module=$(BD_MODULE$(BDID)) objs="$(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID))" \
1662                  endobj=$(BD_ENDOBJ$(BDID)) err=$(BD_MODNAME).err uselibs="%(uselibs)" \
1663                  usehostlibs="%(usehostlibs)"
1665 BD_HEADER_DEPS$(BDID) := $(wildcard headers.tmpl) $(BD_LIBDEFSINC$(BDID)) \
1666             $(BD_FUNCSRCS$(BDID)) \
1667             $(SCRIPTDIR)/genshared \
1668             $(SCRIPTDIR)/genclib.awk $(SCRIPTDIR)/genpclib.awk \
1669             $(SCRIPTDIR)/gendefines.awk $(SCRIPTDIR)/genpdefines.awk
1671 # Regenerate the includes when some of the dependencies are changed
1672 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp : $(BD_HEADER_DEPS$(BDID))
1673         @$(SCRIPTDIR)/genshared -clib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1674         @$(SCRIPTDIR)/genshared -defines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1675         @$(SCRIPTDIR)/genshared -proto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1676         @$(SCRIPTDIR)/genshared -pclib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1677         @$(SCRIPTDIR)/genshared -pdefines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1678         @$(SCRIPTDIR)/genshared -pproto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1679         @$(TOUCH) $@
1681 # Generate includes the first time they are needed
1682 $(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_private_protos.h \
1683 $(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_protos.h \
1684 $(GENINCDIR)/defines/$(BD_MODNAME$(BDID)).h \
1685 $(GENINCDIR)/proto/$(BD_MODNAME$(BDID)).h :
1686         @$(SCRIPTDIR)/genshared -clib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1687         @$(SCRIPTDIR)/genshared -proto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1688         @$(SCRIPTDIR)/genshared -pclib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1689         @$(SCRIPTDIR)/genshared -pdefines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1690         @$(SCRIPTDIR)/genshared -pproto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1691         @$(TOUCH) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp
1693 # The include files generated in $(GENINCDIR) have to be mirrored in the AROS include directory
1694 %rule_copy from=$(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_protos.h to=$(AROS_INCLUDES)/clib/$(BD_MODNAME$(BDID))_protos.h
1695 %rule_copy from=$(GENINCDIR)/defines/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/defines/$(BD_MODNAME$(BDID)).h
1696 #%rule_copy from=$(GENINCDIR)/pragmas/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/pragmas/$(BD_MODNAME$(BDID)).h
1697 %rule_copy from=$(GENINCDIR)/proto/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/proto/$(BD_MODNAME$(BDID)).h
1699 MYDIRS$(BDID) := $(BD_OBJDIR$(BDID)) $(GENINCDIR) $(GENINCDIR)/clib \
1700   $(GENINCDIR)/proto $(GENINCDIR)/defines \
1701   $(GENINCDIR)/pragmas $(AROS_INCLUDES) $(AROS_INCLUDES)/clib $(AROS_INCLUDES)/proto \
1702   $(AROS_INCLUDES)/defines $(AROS_INCLUDES)/pragmas \
1703   $(BD_MODDIR$(BDID)) $(KOBJSDIR)
1705 %rule_makedirs dirs=$(MYDIRS$(BDID)) setuptarget=setup-module$(BDID)
1707 #MM %(mmake)-linklib : %(mmake)-setup setup-clib
1708 #MM %(mmake)-kobj : %(mmake)-setup setup-clib
1710 TMP_DEPS := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h \
1711   $(BD_LIBDEFSINC$(BDID))
1712 ifneq ($(BD_GENINCS$(BDID)),)
1713 TMP_DEPS += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp \
1714   $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID)))
1715 endif
1717 %(mmake)-linklib : $(TMP_DEPS)
1718 %(mmake)-kobj : $(TMP_DEPS)
1720 # Link only when target %(mmake)-linklib otherwise for example jpeg.datatype
1721 # that depend on the jpeg library can cause to get this rule executed unwanted
1722 ifneq ($(filter $(TARGET),%(mmake)-linklib %(mmake)-kobj),)
1723 %(mmake)-linklib : $(LIBDIR)/lib$(BD_MODNAME$(BDID)).a
1724 %(mmake)-kobj : $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODTYPE$(BDID)).o
1726 %rule_link_linklib libname=$(BD_MODNAME$(BDID)) libdir=$(LIBDIR) \
1727   objs="$(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID)) $(BD_ENDOBJ$(BDID))"
1729 $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODTYPE$(BDID)).o : \
1730 $(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID)) $(BD_ENDOBJ$(BDID))
1731         @$(ECHO) "Linking $@"
1732         $(AROS_LD) -Ur -o $@ $^
1733         $(OBJCOPY) $@ `$(NM_PLAIN) $@ | $(AWK) '$$3 ~ /^__.*_(LIST|END)__$$/ {print "-L " $$3;}'`
1734 endif
1736 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-linklib %(mmake)-kobj" deps=$(BD_DEPS$(BDID))
1737 %end
1738 #------------------------------------------------------------------------------
1741 #------------------------------------------------------------------------------
1742 # Build a linklib.
1743 # - mmake is the mmaketarget
1744 # - libname is the baselibname e.g. lib%(libname).a will be created
1745 # - files are the C source files to include in the lib. The list of files
1746 #   has to be given without the .c suffix
1747 # - asmfiles are the asm files to include in the lib. The list of files has to
1748 #   be given with the .s suffix
1749 # - cflags are the flags to compile the source (default $(CFLAGS))
1750 # - dflags are the flags use during makedepend (default equal to cflags)
1751 # - aflags are the flags use during assembling (default $(AFLAGS))
1752 # - objdir is where the .o are generated
1753 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1754 %define build_linklib mmake=/A libname=/A files="$(basename $(wildcard *.c))" \
1755   asmfiles= cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1757 %buildid targets="%(mmake) %(mmake)-clean"
1759 # assign and generate the local variables used in this macro
1760 BD_LIBNAME$(BDID)    := %(libname)
1761 OBJDIR               ?= $(GENDIR)/$(CURDIR)
1762 BD_OBJDIR$(BDID)     := %(objdir)
1763 BD_LIBDIR$(BDID)     := %(libdir)
1765 BD_FILES$(BDID)      := %(files)
1766 BD_ASMFILES$(BDID)   := %(asmfiles)
1767 BD_SRCS$(BDID)       := $(addsuffix .c,$(BD_FILES$(BDID)))
1768 BD_OBJS$(BDID)       := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir $(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID)))))
1769 BD_DEPS$(BDID)       := $(patsubst %.o,%.d,$(BD_OBJS$(BDID)))
1771 BD_CFLAGS$(BDID)     := %(cflags)
1772 ifeq (%(dflags),)
1773 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
1774 else
1775 BD_DFLAGS$(BDID)     := %(dflags)
1776 endif
1777 BD_AFLAGS$(BDID)     := %(aflags)
1779 BD_LINKLIB$(BDID)    := $(BD_LIBDIR$(BDID))/lib$(BD_LIBNAME$(BDID)).a
1781 .PHONY : %(mmake) %(mmake)-clean
1784 %(mmake) : $(BD_LINKLIB$(BDID))
1787 %(mmake)-clean ::
1788         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID))
1790 ifeq ($(TARGET),%(mmake))
1791 ifneq ($(dir $(BD_FILES$(BDID))),./)
1792 vpath %.c $(filter-out ./,$(dir $(BD_FILES$(BDID))))
1793 endif
1795 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1796               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1797 %rule_assemble basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1798                flags=$(BD_AFLAGS$(BDID))
1799 endif
1801 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS$(BDID)) libdir=$(BD_LIBDIR$(BDID))
1803 %include_deps depstargets=%(mmake) deps=$(BD_DEPS$(BDID))
1805 $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) : | $(BD_OBJDIR$(BDID))
1806 $(BD_LINKLIB$(BDID)) : | $(BD_LIBDIR$(BDID))
1807 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBDIR$(BDID))
1809 %end
1810 #------------------------------------------------------------------------------
1813 #------------------------------------------------------------------------------
1814 # Build catalogs.
1815 # - mmake is the mmaketarget
1816 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1817 # - description is the catalog description file (.cd) (default *.cd)
1818 # - subdir is the destination subdir of the catalogs
1819 # - name is the name of the destination catalog, without the .catalog suffix
1820 # - source is the path to the generated source code file
1821 # - dir is the base destination directory (default $(AROS_CATALOGS))
1822 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1824 %define build_catalogs mmake=/A name=/A subdir=/A \
1825  catalogs="$(basename $(wildcard *.ct))" source="../strings.h" \
1826  description="$(basename $(wildcard *.cd))" dir=$(AROS_CATALOGS) \
1827  sourcedescription="$(TOOLDIR)/C_h_orig"
1829 %buildid targets="%(mmake) %(mmake)-clean"
1831 BD_SRCS$(BDID) := $(foreach name, %(catalogs), $(name).ct)
1832 BD_OBJS$(BDID) := $(foreach name, %(catalogs), %(dir)/$(name)/%(subdir)/%(name).catalog)
1833 BD_DIRS$(BDID) := $(foreach name, %(catalogs), %(dir)/$(name)/%(subdir))
1836 %(mmake) : $(BD_OBJS$(BDID)) %(source)
1838 $(BD_OBJS$(BDID)) : | $(BD_DIRS$(BDID))
1839 GLOB_MKDIRS += $(BD_DIRS$(BDID))
1841 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1842         @$(ECHO) "Creating %(name) catalog for language $*."
1843         @$(FLEXCAT) %(description).cd $*.ct CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1845 ifneq (%(source),)
1846 %(source) : %(description).cd
1847         @$(ECHO) "Creating %(name) catalog source file %(source)"
1848         @$(FLEXCAT) %(description).cd %(source)=%(sourcedescription).sd
1849 endif
1852 %(mmake)-clean ::
1853         $(RM) $(BD_OBJS$(BDID)) %(source)
1855 .PHONY: %(mmake) %(mmake-clean)
1857 %end
1859 #-----------------------------------------------------------------------------
1861 #-----------------------------------------------------------------------------
1862 # Build icons.
1863 # - mmake is the mmaketarget
1864 # - icons is a list of icon base names (ie. without the .info suffix)
1865 # - dir is the destination directory
1866 #-----------------------------------------------------------------------------
1868 %define build_icons mmake=/A icons=/A dir=/A
1870 %buildid targets="%(mmake) %(mmake)-clean"
1872 BD_OBJS$(BDID) := $(foreach icon, %(icons), %(dir)/$(icon).info)
1875 %(mmake) : $(BD_OBJS$(BDID))
1877 %(dir)/%.info : %.info.src %.png
1878         @$(ECHO) Creating $(notdir $@)...
1879         @$(ILBMTOICON) $+ $@
1881 $(BD_OBJS$(BDID)) : | %(dir)
1882 GLOB_MKDIRS += %(dir)
1885 %(mmake)-clean ::
1886         @$(RM) $(BD_OBJS$(BDID))
1888 .PHONY: %(mmake)
1890 %end
1892 #-----------------------------------------------------------------------------
1894 #------------------------------------------------------------------------------
1895 # Compile files for a arch specific replacement of code for a module
1896 # - files: the basename of the C files to compile.
1897 # - asmfiles: the basename of the asm file to assemble.
1898 # - mainmmake: the mmake of the module in the main directory to compile these
1899 #   arch specific files for.
1900 # - maindir: the object directory for the main module
1901 # - arch: the arch for which to compile these files. It can has to have the form
1902 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1903 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1904 # - dflags: the flags used during creation of dependency file. If not specified
1905 #   the same value as cflags will be used
1906 # - aflags: the flags used during assembling
1907 # - compiler: (host or target) specifies which compiler to use. By default
1908 #   the target compiler is used
1909 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1910 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1912 ifeq (%(files) %(asmfiles),)
1913   $(error no files or asmfiles given)
1914 endif
1916 %buildid targets="%(mainmmake)-%(arch)"
1918 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1919 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1920 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1922 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1924 ifeq (%(arch),)
1925   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1926 endif
1928 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1929 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1930 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1931 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1932 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1934 ifeq ($(TARGET),%(mainmmake)-%(arch))
1935 vpath %.c $(filter-out ./,$(dir %(files)))
1936 vpath %.s $(filter-out ./,$(dir %(asmfiles)))
1937 vpath %.S $(filter-out ./,$(dir %(asmfiles)))
1938 endif
1940 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1941 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1944 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1946 ifeq ($(findstring %(compiler),host target),)
1947   $(error unknown compiler %(compiler))
1948 endif
1949 ifeq (%(compiler),target)
1950 $(BD_COBJS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1951 endif
1952 ifeq (%(compiler),host)
1953 $(BD_COBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
1954 endif
1955 ifneq (%(modulename),)
1956 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1957                      --include $(GENDIR)/%(maindir)/%(modulename)_deflibdefs.h
1958 else
1959 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1960 endif
1961 ifeq ($(TARGET),%(mainmmake)-%(arch))
1962 $(BD_OBJDIR$(BDID))/%.o : %.c
1963         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD)
1964 endif
1966 ifeq (%(dflags),)
1967 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1968 else
1969 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1970 endif
1971 ifeq ($(TARGET),%(mainmmake)-%(arch))
1972 $(BD_OBJDIR$(BDID))/%.d : %.c
1973         %mkdepend_q flags=$(TMP_DFLAGS)
1974 endif
1976 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1978 ifeq ($(TARGET),%(mainmmake)-%(arch))
1979 $(BD_OBJDIR$(BDID))/%.o : %.s
1980         %assemble_q opt=$(AFLAGS)
1981 $(BD_OBJDIR$(BDID))/%.o : %.S
1982         %assemble_q opt=$(AFLAGS)
1983 endif
1985 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1986 %end
1987 #------------------------------------------------------------------------------
1995 # ======================
1996 # Old stuff, will probably be removed in the future
2001 # GNU Make automatic variables
2002 # $@ current target
2003 # $< First dependency
2004 # $? All newer dependencies
2005 # $^ All dependencies
2006 # $* The stem (ie. target is dir/a.foo.b and the pattern is
2007 #    a.%.b, then the stem is dir/foo)
2009 #------------------------------------------------------------------------------
2010 # rule to generate libdefs.h with archtool (options may go away!)
2011 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
2012 %(dest) : %(conffile) %(genlibdefstool)
2013         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2014         @%(genlibdefstool) -c -o $@ %(conffile)
2015 %end
2018 #------------------------------------------------------------------------------
2019 # generate asm files from c files (for debugging purposes)
2020 %define ctoasm_q
2021 %.s : %.c
2022         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2023         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
2024 %end
2026 #------------------------------------------------------------------------------
2027 # Convert two png images to an Amiga icon file based on the description
2028 # file %(from), with outputfile going to %(to).
2029 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
2030         @$(ECHO) "Creating icon %(to)..."
2031         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
2032         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
2033         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
2034 %end
2036 #------------------------------------------------------------------------------
2037 # NOTE: The following are all part of Iain's build changes, please don't use
2038 # or change anything below this line until you know what you are doing. This
2039 # is so that I don't conflict with the semantics of any of the above macros.
2040 #------------------------------------------------------------------------------
2042 #------------------------------------------------------------------------------
2043 # Copy files from one directory to another.
2045 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
2047 SRC_FILES := $(foreach f, %(files), %(src)/$(f))
2048 DST_FILES := $(foreach f, %(files), %(dst)/$(f))
2050 %(maketarget) : setup $(DST_FILES)
2052 $(DST_FILES) : %(dst)/% : %(src)/%
2053         @$(CP) $< $@
2054         
2055 setup ::
2056         %mkdirs_q %(dst)
2058 %end
2060 #----------------------------------------------------------------------------------
2061 # Copy a diretory recursively to another place, preserving the original 
2062 # hierarchical structure
2064 # src: the source directory whose content will be copied
2065 # dst: the directory where to copy src's content. If not existing, it will be made.
2067 %define copy_dir_recursive mmake=/A src=$(TOP)/$(CURDIR) dst=/A
2069 %(mmake)_FILES := $(shell cd %(src); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune -o -type f -print)
2070 %(mmake)_DIRS  := $(sort $(foreach f,$(%(mmake)_FILES),$(dir $(f))))
2072 define %(mmake)_mkdir
2073 $(1):
2074         $(MKDIR) $$@
2075 endef
2077 define %(mmake)_copy
2078 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
2079         $(CP) $$< $$@
2080 endef
2082 .PHONY : %(mmake)
2085 %(mmake): | $(GENDIR)/$(CURDIR)
2086         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2087         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2088         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2089         for d in $(%(mmake)_DIRS); do                      \
2090             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2091         done
2092         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2093         for f in $(%(mmake)_FILES); do                                            \
2094             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2095         done;  \
2096         for dst in %(dst); do \
2097             $(MAKE) -f $$m DST=$$dst SRC=%(src) all; \
2098         done
2100 $(GENDIR)/$(CURDIR):
2101         $(MKDIR) $@
2103 %end
2105 #------------------------------------------------------------------------------
2106 #   Copy include files into the includes directories. There are currently
2107 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2108 #   for building tools that need to run on the host system $(GENINCDIR). The
2109 #   $(GENINCDIR) path must not contain any references to the C runtime
2110 #   library header files.
2112 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. dir=include
2114 ifneq (%(dir),)
2115 INCL_FILES_1 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
2116 INCL_FILES_2 := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
2117 _INC_PATH := %(dir)/
2118 else
2119 INCL_FILES_1 := $(foreach f,%(includes),$(AROS_INCLUDES)/%(path)/$(f))
2120 INCL_FILES_2 := $(foreach f,%(includes),$(GENINCDIR)/%(path)/$(f))
2121 _INC_PATH :=
2122 endif
2124 #MM %(mmake)
2126 ifneq (%(mmake),includes-copy)
2128 includes-copy : %(mmake)
2129 endif
2131 %(mmake) : $(INCL_FILES_1) $(INCL_FILES_2)
2133 .PHONY: %(mmake)
2135 $(AROS_INCLUDES)/%(path)/%.h : $(_INC_PATH)%.h
2136         @$(CP) $< $@
2138 $(GENINCDIR)/%(path)/%.h : $(_INC_PATH)%.h
2139         @$(CP) $< $@
2141 $(INCL_FILES_1) : | $(AROS_INCLUDES)/%(path)
2142 $(INCL_FILES_2) : | $(GENINCDIR)/%(path)
2143 GLOB_MKDIRS += $(AROS_INCLUDES)/%(path) $(GENINCDIR)/%(path)
2144 %end
2147 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2148 STUBS_SRC := $(foreach f,$(STUBS),$(f).c)
2149 STUBS_OBJ := $(foreach f,$(STUBS),$(OBJDIR)/$(f).o)
2150 STUBS_MEM := $(foreach f,$(STUBS),$(f).o)
2151 STUBS_DEP := $(foreach f,$(STUBS),$(OBJDIR)/$(f).d)
2152 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2154 #MM- linklibs : hidd-%(hidd)-stubs
2155 #MM- %(parenttarget): hidd-%(hidd)-stubs
2156 #MM hidd-%(hidd)-stubs : includes includes-copy
2157 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2159 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2160         %mklib_q from=$^
2162 $(STUBS_OBJ) : $(STUBS_SRC) 
2163         %compile_q cmd=$(TARGET_CC) opt=%(cflags)
2165 $(STUBS_DEP) : $(STUBS_SRC)
2166         %mkdepend_q flags=%(dflags)
2168 setup ::
2169         %mkdirs_q $(OBJDIR) $(LIBDIR)
2172 clean ::
2173         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2175 DEPS := $(DEPS) $(STUBS_DEP)
2177 %end
2178       
2179 #------------------------------------------------------------------------------
2180 # Build an imported source tree which uses the configure script from the
2181 # autoconf package.  This rule will try to "integrate" the produced files as
2182 # much as possible in the AROS build, for exampley by putting libraries in the
2183 # standard library directory, includes in the standard include directory, and
2184 # so on. You can however override this behaviour.
2186 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2187 # be %(bindir) (or its deduced value) when running "make install", and
2188 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2189 # configure script some more parameters whose value depends upon the PROGDIR
2190 # env var, so that the program gets all its stuff installed in the proper place
2191 # when building it, but when running it from inside AROS it can also find that
2192 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2193 # the configuration parameters set when running ./configure
2195 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2196 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2197 # to the name which has to follow it.
2200 %define build_with_configure mmake=/A srcdir=$(TOP)/$(CURDIR) prefix= aros_prefix= \
2201     extraoptions= nix_dir_layout= nix=no host=no \
2202     install_target=install postconfigure= postinstall=
2204 ifneq (%(prefix),)
2205     %(mmake)-prefix := %(prefix)
2206 else
2207     %(mmake)-prefix := $(AROS_CONTRIB)
2208 endif
2210 ifneq (%(aros_prefix),)
2211     %(mmake)-aros_prefix := %(aros_prefix)
2212 else
2213     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2214 endif
2216 ifeq (%(nix),yes)
2217     %(mmake)-nix    := -nix
2218     %(mmake)-volpfx := /
2219     %(mmake)-volsfx := /
2220     
2221     ifeq (%(nix_dir_layout),)
2222         %(mmake)-nix_dir_layout := yes
2223     endif
2224 else
2225     %(mmake)-volsfx := :
2226     
2227     ifeq (%(nix_dir_layout),)
2228         %(mmake)-nix_dir_layout := no
2229     endif
2230 endif
2232 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2234 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) exec_prefix=$(%(mmake)-prefix)
2236 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) %(host)),yes)
2237     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2238     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2239 else
2240     ifeq (%(nix),yes)
2241         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2242         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2243     else
2244         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2245     endif
2247     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2248     
2249     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) sbindir=$(%(mmake)-prefix) \
2250     libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) oldincludedir=$(AROS_INCLUDES)
2251 endif
2254 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2256 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2258 ifneq (%(install_target),)
2259     %(mmake)-install_command = \
2260         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2261         -C $(GENDIR)/$(CURDIR) %(install_target) && \
2262         $(TOUCH) $(GENDIR)/$(CURDIR)/.installed
2264     %(mmake)-uninstall_command = \
2265     $(RM) $(GENDIR)/$(CURDIR)/.installed && \
2266     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2267     -C $(GENDIR)/$(CURDIR) uninstall
2268 else
2269     %(mmake)-install_command   := true
2270     %(mmake)-uninstall_command := true
2271 endif
2273 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2276 %(mmake)-build_and_install-quick :  $(GENDIR)/$(CURDIR)/.configured
2277         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(GENDIR)/$(CURDIR); then \
2278             $(RM)  $(GENDIR)/$(CURDIR)/.installed && \
2279             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(GENDIR)/$(CURDIR) && \
2280             $(%(mmake)-install_command); \
2281         fi
2283 %(srcdir)/.files-touched:
2284         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
2285         $(TOUCH) $@
2288 %(mmake)-uninstall :
2289         $(%(mmake)-uninstall_command)
2291 ifneq ($(DEBUG),yes)
2292     %(mmake)-s_flag = -s
2293 endif
2296 %(mmake)-configure : $(GENDIR)/$(CURDIR)/.configured
2298 ifeq (%(host),yes)
2299 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2300         $(RM) $@ 
2301         %mkdirs_q $(GENDIR)/$(CURDIR)
2302         cd $(GENDIR)/$(CURDIR) && \
2303         find . -name config.cache -exec $(RM) '{}' \; && \
2304         CC="$(HOST_CC)" \
2305             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2306             $(TOUCH) $@
2307 else
2308 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2309         $(RM) $@
2310         %mkdirs_q $(GENDIR)/$(CURDIR)
2311         cd $(GENDIR)/$(CURDIR) && \
2312         find . -name config.cache -exec $(RM) '{}' \; && \
2313         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" CC_FOR_BUILD="$(HOST_CC)" \
2314             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) --host=$(AROS_TARGET_CPU)-aros \
2315             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls --without-x \
2316             --without-pic --disable-shared && \
2317             $(TOUCH) $@
2318 endif
2319         
2321 %(mmake)-clean : %(mmake)-uninstall
2322         @$(RM) $(GENDIR)/$(CURDIR)
2323 %end
2325 #############################################################################
2326 #############################################################################
2327 ##                                                                         ##
2328 ## Misciellanous macros. Everying that doesn't fin above should be put     ##
2329 ## here.                                                                   ##
2330 ##                                                                         ##
2331 #############################################################################
2332 #############################################################################
2334 #----------------------------------------------------------------------------------
2335 # Given an archive name, patches names and locations where to find them, fetch
2336 # the archive and the patches from any of those locations, unpack the archive
2337 # and then apply the patches.
2339 # Locations currently supported are http and ftp sites, plus local filesystem
2340 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2341 # the fetch.sh script needs to be modified, since this macro relies on that script.
2343 # Arguments:
2345 #     - archive_origins = list of locations where to find the archive. They are tried
2346 #                         in sequence, until the archive is found and fetching it 
2347 #                         succeeded. If not specified, the current directory is assumed.
2348 #     - archive         = the archive name. Mandatory.
2349 #     - destination     = the local directory where to put the archive and patches.
2350 #                         If not specified, the current directory is assumed.
2351 #     - patches_origins = list of locations where to find the patches. They are tried
2352 #                         in sequence, until a patch is found and fetching it 
2353 #                         succeeded. If not specified, the current directory is assumed.
2354 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2355 #                         patch_name[:[patch_subdir][:patch_opt]].
2356 #                         
2357 #                             - patch_name   = the name of the patch file
2358 #                             - patch_subdir = the directory within \destination\ where to
2359 #                                              apply the patch.
2360 #                             - patch_opt    = any options to pass to the `patch' command
2361 #                                              when applying the patch.
2362 #                         
2363 #                         The patch_subdir and patch_opt fields are optional.
2365 %define fetch archive_origins=. archive=/A suffixes= destination=. patches_origins=. patches_specs=::
2366         $(FETCH) -ao "%(archive_origins)" -a %(archive) -as "%(suffixes)" -d %(destination) \
2367         -po "%(patches_origins)" -p %(patches_specs)
2368 %end
2370 #-----------------------------------------------------------------------------------------
2371 # Joins the features of %fetch and %build_with_configure, taking advantage of
2372 # the naming scheme of GNU packages. GNU packages names are in the form
2374 #     <package name>-<version number>.<archive format suffix>
2376 # If a patch is provided, it *must* be named the following way:
2378 #    <package name>-<version number>-aros.diff
2380 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2381 # CD'ing into the archive's extracted directory.
2383 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2384 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2385 # to make that patch fully comprehensive.
2387 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2389 # Arguments:
2391 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2392 #                     macro.
2393 #    - package      = the GNU package name, sans version and archive format suffixes.
2394 #    - version      = the package's version number, or otherwise any other version string.
2395 #                     It gets appended to the package name to form the basename of the archive.
2396 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2397 #                     version. Each one of them is tried until a matching archive is found.
2398 #                     Defaults to "tat.bz2 tar.gz".
2399 #    - destination  = same meaning as the one for the %fetch macro
2400 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2401 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2402 #                     fetched or not
2403 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2404 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2405 #                     $(GNUDIR).
2406 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2407 #                     /GNU.
2408 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2409 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2411 %define fetch_and_build mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2412     srcdir= package_repo= patch=no patch_repo= prefix= \
2413     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2415 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2416 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2418 %(mmake)-archbase  := %(package)-%(version)
2420 ifeq (%(prefix),)
2421     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2422 else
2423     %(mmake)-prefix := %(prefix)
2424 endif
2426 ifneq (%(subpackage),)
2427     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2428 else
2429     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2430 endif
2432 ifneq (%(srcdir),)
2433     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2434 else
2435     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2436 endif
2438 ifeq (%(patch),yes)
2439     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2440 else
2441     %(mmake)-%(subpackage)-patches_specs := ::
2442 endif
2444 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2446 .PHONY : %(mmake)-%(subpackage)-fetch
2448 %(mmake)-%(subpackage)-fetch :
2449         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2450             destination=$(PORTSDIR)/%(package) \
2451             archive_origins=". %(package_repo)" \
2452             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins=". %(patch_repo)"
2454 #MM- %(mmake) : %(mmake)-%(subpackage)
2456 PACKAGES_DIR := $(AROSDIR)/../Packages
2458 %(mmake)-%(subpackage)-package-dir := $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)
2460 %(mmake)-%(subpackage)-package-basename := \
2461     $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2463 %build_with_configure mmake=%(mmake)-%(subpackage) \
2464      srcdir=$(PORTSDIR)/%(package)/$(%(mmake)-%(subpackage)-srcdir) \
2465      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-%(subpackage)-package-dir)" \
2466      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2467      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2469 .PHONY : %(mmake)-%(subpackage)-make-package
2470 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2473 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2475 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2476 #that $^ and $@ have exactly the same mtime, and in that case make tries
2477 #to rebuild $@ again, which would fail because the directory where
2478 #the package got installed would not exist anymore. 
2479 #We work this around by using an if statement to manually check the mtimes.
2480 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2481         @if test $(GENDIR)/$(CURDIR)/.installed -nt $@ || ! test -f $@; then \
2482             $(RM) $@ && \
2483             $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" && \
2484             cd $(%(mmake)-%(subpackage)-package-dir) && \
2485             tar --remove-files -cvf $(%(mmake)-%(subpackage)-package-basename).tar * && \
2486             mkdir -p "$(%(mmake)-prefix)" && \
2487             tar -xf $(%(mmake)-%(subpackage)-package-basename).tar -C "%(prefix)"/ && \
2488             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar && \
2489             cd .. && $(RM) $(%(mmake)-%(subpackage)-archbase); \
2490         fi
2491 %end
2493 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2494     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2495     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2497 GNU_REPOSITORY := http://ftp.gnu.org/pub/gnu
2499 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2500     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2501     package_repo="%(package_repo) $(GNU_REPOSITORY)/%(package)" \
2502     patch="%(patch)" patch_repo="%(patch_repo)" \
2503     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2504     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2506 %end
2508 #-----------------------------------------------------------------------------------------
2509 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2510 # that the package is a "Development" package, and as such it needs to be placed
2511 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2513 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2514 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2515 # "mmake" argument, because the metatarget is implicitely defined as
2517 #     #MM- development-%(package)
2519 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2520     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2521     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2523 #MM- development : development-%(package)
2526 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2527    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2528    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2529    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2530    extraoptions="%(extraoptions)"
2531     
2532 %end