- renamed 'Cesko' flag file to 'Czech_Republic' to complement the change of the
[AROS.git] / config / make.tmpl
blobd1b438b254b7ecab3b3b0c38c8bfd73e02853e3c
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt).
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=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS)
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 # Generate a rule to compile a C source file to an object file and generate
265 # the dependency file. Basename may contain a directory part, then the source
266 # file has to be in that directory. The generated file will be put in the
267 # object directory without the directory.
268 # options
269 # - basename: the basename of the file to compile. Use % for a wildcard rule
270 # - cflags (default $(CFLAGS)): the C flags to use for compilation
271 # - dflags: the flags used during creation of dependency file. If not specified
272 #   the same value as cflags will be used
273 # - targetdir: the directory to put the .o file and the .d file. By default
274 #   it is put in the same directory as the .c file
275 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
277 ifeq (%(targetdir),)
278   TMP_TARGETBASE := %(basename)
279 else
280   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
281 endif
283 ifeq ($(findstring %(compiler),host target),)
284   $(error unknown compiler %(compiler))
285 endif
286 ifeq (%(compiler),target)
287 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC)
288 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC)
289 endif
290 ifeq (%(compiler),host)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
293 endif
295 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
296 $(TMP_TARGETBASE).o : %(basename).c
297         %compile_q cmd=$(TMP_CMD)
299 ifeq (%(dflags),)
300 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
301 else
302 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
303 endif
304 $(TMP_TARGETBASE).d : %(basename).c
305         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
306 %end
307 #------------------------------------------------------------------------------
310 #------------------------------------------------------------------------------
311 # Generate a rule to compile multiple C source files to an object file and
312 # generate the corresponding dependency files. The generated file will be put
313 # in the object directory without the directory part of the source file.
314 # options
315 # - basenames: the basenames of the files to compile. The names may include
316 #   relative or absolute path names. No wildcard is allowed
317 # - cflags (default $(CFLAGS)): the C flags to use for compilation
318 # - dflags: the flags used during creation of dependency file. If not specified
319 #   the same value as cflags will be used
320 # - targetdir: the directory to put the .o file and the .d file. By default
321 #   it is put in the same directory as the .c file. When targetdir is not
322 #   empty, path names will be stripped from the file names so that all files
323 #   are in that dir and not in subdirectories.
324 # - compiler (default target): compiler to use, either target or host
325 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
326     compiler=target
328 ifeq (%(targetdir),)
329 TMP_TARGETS := $(addsuffix .o,%(basenames))
330 TMP_DTARGETS := $(addsuffix .d,%(basenames))
331 TMP_WILDCARD := %
332 else
333 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
334 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
335 TMP_WILDCARD := %(targetdir)/%
337 # Be sure that all .c files are generated
338 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
340 # Be sure that all .c files are found
341 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
342 ifneq ($(TMP_DIRS),)
343     vpath %.c $(TMP_DIRS)
344 endif
346 endif
348 ifeq ($(findstring %(compiler),host target),)
349   $(error unknown compiler %(compiler))
350 endif
351 ifeq (%(compiler),target)
352 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
353 endif
354 ifeq (%(compiler),host)
355 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
356 endif
358 $(TMP_TARGETS) : CFLAGS := %(cflags)
359 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
360         %compile_q cmd=$(CMD)
362 ifeq (%(dflags),)
363 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
364 else
365 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
366 endif
367 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
368         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
369 %end
370 #------------------------------------------------------------------------------
373 #------------------------------------------------------------------------------
374 # Make an alias from one arch specific build to another arch.
375 # arguments:
376 # - mainmmake: the mmake of the module in the main tree
377 # - arch: the current arch
378 # - alias: the alias to which this should point
379 %define rule_archalias mainmmake=\A arch=\A alias=\A
381 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
382 %end
383 #------------------------------------------------------------------------------
386 #------------------------------------------------------------------------------
387 # Generate a rule to compile a C source file to a shared object file with a
388 # .so suffix. Basename may contain a directory part, then the source
389 # file has to be in that directory. The generated file will be put in the
390 # object directory without the directory.
391 # options
392 # - basename: the basename of the file to compile. Use % for a wildcard rule
393 # - cflags (default $(CFLAGS)): the C flags to use for compilation
394 # - targetdir: the directory to put the .o file and the .d file. By default
395 #   it is put in the same directory as the .c file
396 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
398 ifeq (%(targetdir),)
399   TMP_TARGETBASE := %(basename)
400 else
401   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
402 endif
404 ifeq ($(findstring %(compiler),host target),)
405   $(error unknown compiler %(compiler))
406 endif
407 ifeq (%(compiler),target)
408 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
409 endif
410 ifeq (%(compiler),host)
411 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
412 endif
414 $(TMP_TARGETBASE).so : %(basename).c
415         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD)
416 %end
417 #------------------------------------------------------------------------------
420 #------------------------------------------------------------------------------
421 # Generate a rule to assemble a source file to an object file. Basename may
422 # contain a directory part, then the source file has to be in that directory.
423 # The generated file will be put in the object directory without the directory.
424 # options
425 # - basename: the basename of the file to compile. Use % for a wildcard rule
426 # - flags (default $(AFLAGS)): the asm flags to use for assembling
427 # - targetdir: the directory to put the .o file in. By default it is put in the
428 #   same directory as the .s file
429 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
431 ifeq (%(targetdir),)
432 %(basename).o : AFLAGS := %(aflags)
433 %(basename).o : %(basename).s
434         %assemble_q
436 else
437 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
438 %(targetdir)/$(notdir %(basename)).o : %(basename).s
439         %assemble_q
441 endif
442 %end
443 #------------------------------------------------------------------------------
446 #------------------------------------------------------------------------------
447 # Generate a rule to assemble multiple source files to an object file. The
448 # generated file will be put in the object directory with the directory part
449 # of the source file stripped off.
450 # options
451 # - basenames: the basenames of the files to compile. The names may include
452 #   relative or absolute path names. No wildcard is allowed
453 # - aflags (default $(AFLAGS)): the flags to use for assembly
454 # - targetdir: the directory to put the .o file and the .d file. By default
455 #   it is put in the same directory as the .c file. When targetdir is not
456 #   empty, path names will be stripped from the file names so that all files
457 #   are in that dir and not in subdirectories.
458 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
460 ifeq (%(targetdir),)
461 TMP_TARGETS := $(addsuffix .o,%(basenames))
462 TMP_WILDCARD := %
463 else
464 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
465 TMP_WILDCARD := %(targetdir)/%
467 # Be sure that all .s files are generated
468 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
470 # Be sure that all .c files are found
471 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
472 ifneq ($(TMP_DIRS),)
473     vpath %%(suffix) $(TMP_DIRS)
474 endif
476 endif
478 $(TMP_TARGETS) : AFLAGS := %(aflags)
479 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
480         %assemble_q opt=$(AFLAGS)
481 %end
482 #------------------------------------------------------------------------------
485 #------------------------------------------------------------------------------
486 # Link %(objs) to %(prog) using the libraries in %(uselibs)
487 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
488     usehostlibs= usestartup=yes detach=no nix=no
490 TMP_EXTRA_LDFLAGS := 
491 ifeq (%(nix),yes)
492     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
493 endif
494 ifeq (%(usestartup),no)
495     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
496 endif
497 ifeq (%(detach),yes)
498     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
499 endif
500 %(prog) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
502 %(prog) : %(objs) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
503         %link_q from="%(objs)" opt="%(ldflags) $(EXTRA_LDFLAGS)" \
504             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
505 %end
506 #------------------------------------------------------------------------------
509 #------------------------------------------------------------------------------
510 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
511 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
512 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) \
513     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
514     usestartup=yes detach=no
516 TMP_EXTRA_LDFLAGS := 
517 ifeq (%(nix),yes)
518     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
519 endif
520 ifeq (%(usestartup),no)
521     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
522 endif
523 ifeq (%(detach),yes)
524     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
525 endif
526 $(addprefix %(targetdir)/,%(progs)) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
528 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o \
529     $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
530         %link_q from=$< opt="%(ldflags) $(EXTRA_LDFLAGS)" \
531             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
532 %end
533 #------------------------------------------------------------------------------
536 #------------------------------------------------------------------------------
537 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
538 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
540 %(libdir)/lib%(libname).a : %(objs)
541         %mklib_q from=$^
542 %end
543 #------------------------------------------------------------------------------
546 #------------------------------------------------------------------------------
547 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
548 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
550 %(libdir)/lib%(libname).so : %(objs)
551         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
552 %end
553 #------------------------------------------------------------------------------
556 #------------------------------------------------------------------------------
557 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
558 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
559 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
560     uselibs= usehostlibs=
562 %(module) : OBJS := %(objs)
563 %(module) : ENDTAG := %(endobj)
564 %(module) : ERR := %(err)
565 %(module) : OBJDIR := %(objdir)
566 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
567 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
568         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR)
570 %end
571 #------------------------------------------------------------------------------
574 #------------------------------------------------------------------------------
575 # Generate a rule to generate a function reference file from a C source file.
576 # Basename may contain a directory part, then the source file has to be in that
577 # directory. The generated file will be put in the object directory without the
578 # directory.
579 # options
580 # - basename: the basename of the file to compile. Use % for a wildcard rule
581 # - cflags (default $(CFLAGS)): the C flags to use for compilation
582 # - targetdir: the directory to put the generated .ref file. By default the
583 #   .ref file will be put in the same directory as the .c file.
584 # - includefile: This file will be included at the head of the source file
585 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
587 ifeq (%(targetdir),)
588 GENFILE_TMP := %(basename).ref
589 else
590 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
591 endif
593 ifeq ($(filter %(compiler),target host),)
594 $(error use of %rule_ref: compiler has to be 'host' or 'target')
595 endif
597 ifeq (%(compiler),target)
598 $(GENFILE_TMP) : CC:=$(TARGET_CC)
599 else
600 $(GENFILE_TMP) : CC:=$(HOST_CC)
601 endif
603 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
604 ifeq (%(includefile),)
605         %mkref_q cc=$(CC) cflags="%(cflags)"
606 else
607         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
608 endif
610 %end
611 #------------------------------------------------------------------------------
614 #------------------------------------------------------------------------------
615 # Generate a rule to generate a function reference file from a C source file.
616 # Basename may contain a directory part, then the source file has to be in that
617 # directory. The generated file will be put in the object directory without the
618 # directory.
619 # options
620 # - basenames: the basenames of the files to compile. No wildcard is allowed
621 # - cflags (default $(CFLAGS)): the C flags to use for compilation
622 # - targetdir: the directory to put the generated .ref file. By default the
623 #   .ref file will be put in the same directory as the .c file. When targetdir
624 #   is not empty all files will be put there and path parts in the basenames
625 #   will be stripped off.
626 # - includefile: This file will be included at the head of the source file
627 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
628     compiler=target
630 ifeq (%(targetdir),)
631 TMP_TARGETS := $(addsuffix .ref,%(basenames))
632 TMP_WILDCARD := %.ref
633 else
634 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
635 TMP_WILDCARD := %(targetdir)/%.ref
637 # Be sure that all .c files are generated
638 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
640 # Be sure that all .c files are found
641 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
642 ifneq ($(TMP_DIRS),)
643     vpath %.c $(TMP_DIRS)
644 endif
646 endif
648 ifeq ($(filter %(compiler),target host),)
649 $(error use of %rule_ref: compiler has to be 'host' or 'target')
650 endif
652 ifeq (%(compiler),target)
653 $(TMP_TARGETS) : CC:=$(TARGET_CC)
654 else
655 $(TMP_TARGETS) : CC:=$(HOST_CC)
656 endif
657 ifeq (%(includefile),)
658 $(TMP_TARGETS) : CFLAGS:=%(cflags)
659 else
660 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
661 $(TMP_TARGETS) : %(includefile)
662 endif
663 $(TMP_TARGETS) : $(CXREF)
664 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
665         %mkref_q cc=$(CC)
666 %end
667 #------------------------------------------------------------------------------
670 #------------------------------------------------------------------------------
671 # Generate the libdefs.h include file for a module.
672 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
674 TMP_TARGET := %(modname)_libdefs.h
675 TMP_DEPS := $(GENMODULE)
676 TMP_OPTS := 
677 ifneq (%(conffile),)
678     TMP_OPTS += -c %(conffile)
679     TMP_DEPS += %(conffile)
680 else
681     TMP_DEPS += %(modname).conf
682 endif
683 ifneq (%(modsuffix),)
684     TMP_OPTS += -s %(modsuffix)
685 endif
686 ifneq (%(targetdir),)
687     TMP_OPTS += -d %(targetdir)
688     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
689 endif
691 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
692 $(TMP_TARGET) : MODNAME := %(modname)
693 $(TMP_TARGET) : MODTYPE := %(modtype)
694 $(TMP_TARGET) : $(TMP_DEPS)
695         @$(ECHO) "Generating $(notdir $@)"
696         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
697 %end
698 #------------------------------------------------------------------------------
701 #------------------------------------------------------------------------------
702 # Generate the libdefs.h include file for a module.
703 %define rule_genmodule_funclist \
704     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
706 TMP_TARGET := %(modname).funclist
707 TMP_DEPS := $(GENMODULE)
708 TMP_OPTS := 
709 ifeq (%(reffile),)
710     $(error reffile needed in rule_genmodule_funclist but none specified)
711 endif
712 TMP_OPTS := -r %(reffile)
713 TMP_DEPS += %(reffile)
714 ifneq (%(conffile),)
715     TMP_OPTS += -c %(conffile)
716     TMP_DEPS += %(conffile)
717 else
718     TMP_DEPS += %(modname).conf
719 endif
720 ifneq (%(modsuffix),)
721     TMP_OPTS += -s %(modsuffix)
722 endif
723 ifneq (%(targetdir),)
724     TMP_OPTS += -d %(targetdir)
725     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
726 endif
728 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
729 $(TMP_TARGET) : MODNAME := %(modname)
730 $(TMP_TARGET) : MODTYPE := %(modtype)
731 $(TMP_TARGET) : $(TMP_DEPS)
732         @$(ECHO) "Generating $(notdir $@)"
733         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
734 %end
735 #------------------------------------------------------------------------------
738 #------------------------------------------------------------------------------
739 # Generate a Makefile.%(modname) with the genmodule program and include this
740 # generated file in this Makefile
741 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
742     targetdir=
744 TMP_TARGET := Makefile.%(modname)
745 TMP_DEPS := $(GENMODULE)
746 TMP_OPTS := 
747 ifneq (%(conffile),)
748     TMP_OPTS += -c %(conffile)
749     TMP_DEPS += %(conffile)
750 else
751     TMP_DEPS += %(modname).conf
752 endif
753 ifneq (%(modsuffix),)
754     TMP_OPTS += -s %(modsuffix)
755 endif
756 ifneq (%(targetdir),)
757     TMP_OPTS += -d %(targetdir)
758     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
759 endif
761 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
762 $(TMP_TARGET) : MODNAME := %(modname)
763 $(TMP_TARGET) : MODTYPE := %(modtype)
764 $(TMP_TARGET) : $(TMP_DEPS)
765         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
766 %end
767 #------------------------------------------------------------------------------
769 #------------------------------------------------------------------------------
770 # Generate dummy support files so cxref when used on the a module source file
771 # will find something to include. This rule has to be preceeded by
772 # %rule_genmodule_makefile
773 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
775 ifneq ($(%(modname)_INCLUDES),)
776 TMP_TARGETS := $(%(modname)_INCLUDES)
778 TMP_DEPS := $(GENMODULE)
779 TMP_OPTS := 
780 ifneq (%(conffile),)
781     TMP_OPTS += -c %(conffile)
782     TMP_DEPS += %(conffile)
783 else
784     TMP_DEPS += %(modname).conf
785 endif
786 ifneq (%(modsuffix),)
787     TMP_OPTS += -s %(modsuffix)
788 endif
789 ifneq (%(targetdir),)
790     TMP_OPTS += -d %(targetdir)
791     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
792 endif
794 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
795 $(TMP_TARGETS) : MODNAME := %(modname)
796 $(TMP_TARGETS) : MODTYPE := %(modtype)
797 $(TMP_TARGETS) : $(TMP_DEPS)
798         @$(ECHO) "Generating dummy include files"
799         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
800 endif
801 %end
802 #------------------------------------------------------------------------------
805 #------------------------------------------------------------------------------
806 # Generate the support files for compiling a module. This includes include
807 # files and source files. This rule has to be preceeded by
808 # %rule_genmodule_makefile
809 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
810     conffile= reffile=
812 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
813                $(%(modname)_LINKLIBFILES)
814 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
816 TMP_DEPS := $(GENMODULE)
817 ifeq ($(%(modname)_NEEDREF), yes)
818     ifeq (%(reffile),)
819         $(error reffile needed in rule_genmodule_files but none specified)
820     endif
821     TMP_OPTS := -r %(reffile)
822     TMP_DEPS += %(reffile)
823 else
824     TMP_OPTS :=
825 endif
826 ifneq (%(conffile),)
827     TMP_OPTS += -c %(conffile)
828     TMP_DEPS += %(conffile)
829 else
830     TMP_DEPS += %(modname).conf
831 endif
832 ifneq (%(modsuffix),)
833     TMP_OPTS += -s %(modsuffix)
834 endif
835 ifneq (%(targetdir),)
836     TMP_OPTS += -d %(targetdir)
837     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
838 endif
840 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
841 $(TMP_TARGETS) : MODNAME := %(modname)
842 $(TMP_TARGETS) : MODTYPE := %(modtype)
843 $(TMP_TARGETS) : $(TMP_DEPS)
844         @$(ECHO) "Generating functable and support files for module $(BD_MODNAME$(BDID))"
845 ifneq (%(conffile),lib.conf)
846         @$(IF) $(TEST) -f lib.conf; then \
847           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
848         fi
849 endif
850         @$(IF) $(TEST) -f libdefs.h; then \
851           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
852         fi
853         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
854 %end
855 #------------------------------------------------------------------------------
857 #------------------------------------------------------------------------------
858 # Generate the support files for compiling a module. This includes include
859 # files and source files.
860 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
861     targetdir= conffile= reffile=
864 ifneq ($(%(modname)_INCLUDES),)
865 TMP_TARGETS := $(%(modname)_INCLUDES)
867 TMP_DEPS := $(GENMODULE)
868 ifeq ($(%(modname)_NEEDREF), yes)
869     ifeq (%(reffile),)
870         $(error reffile needed in rule_genmodule_files but none specified)
871     endif
872     TMP_OPTS := -r %(reffile)
873     TMP_DEPS += %(reffile)
874 else
875     TMP_OPTS :=
876 endif
877 ifneq (%(conffile),)
878     TMP_OPTS += -c %(conffile)
879     TMP_DEPS += %(conffile)
880 else
881     TMP_DEPS += %(modname).conf
882 endif
883 ifneq (%(modsuffix),)
884     TMP_OPTS += -s %(modsuffix)
885 endif
886 ifneq (%(targetdir),)
887     TMP_OPTS += -d %(targetdir)
888     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
889 endif
891 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
892 $(TMP_TARGETS) : MODNAME := %(modname)
893 $(TMP_TARGETS) : MODTYPE := %(modtype)
894 $(TMP_TARGETS) : $(TMP_DEPS)
895         @$(ECHO) "Generating include files"
896         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
897 endif
898 %end
899 #------------------------------------------------------------------------------
901 #------------------------------------------------------------------------------
902 # Common rules for all makefiles
903 %define common
904 # Delete generated makefiles
906 clean ::
907         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
909 include $(TOP)/config/make.tail
911 BDID := $(BDTARGETID)
912 %end
913 #------------------------------------------------------------------------------
914       
916 #############################################################################
917 #############################################################################
918 ##                                                                         ##
919 ## Here are the mmakefile build macro's. These are macro's that takes care ##
920 ## of everything to go from the sources to the generated target. Also all  ##
921 ## intermediate files and directories that are needed are created by these ##
922 ## rules.                                                                  ##
923 ##                                                                         ##
924 #############################################################################
925 #############################################################################
927 #------------------------------------------------------------------------------
928 # Build a program
929 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME$(BDID)) asmfiles= \
930     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
931     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
932     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no
934 .PHONY : %(mmake)
936 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
938 BD_PROGNAME$(BDID)  := %(progname)
939 BD_OBJDIR$(BDID)    := %(objdir)
940 BD_TARGETDIR$(BDID) := %(targetdir)
942 BD_FILES$(BDID)     := %(files)
943 BD_ASMFILES$(BDID)  := %(asmfiles)
944 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID))))
945 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
947 BD_CFLAGS$(BDID)    := %(cflags)
948 BD_AFLAGS$(BDID)    := %(aflags)
949 BD_DFLAGS$(BDID)    := %(dflags)
950 BD_LDFLAGS$(BDID)   := %(ldflags)
953 %(mmake)-quick : %(mmake)
955 #MM %(mmake) : includes-generate-deps
956 %(mmake) : $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID))
958 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
959 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
960     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
961 %rule_assemble_multi basenames=$(BD_ASMFILES$(BDID)) targetdir=$(BD_OBJDIR$(BDID)) \
962     aflags=$(BD_AFLAGS$(BDID))
964 %rule_link_prog prog=$(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) \
965     objs=$(BD_OBJS$(BDID)) ldflags=$(BD_LDFLAGS$(BDID)) \
966     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
967     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
969 endif
971 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
973 $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) : | $(BD_OBJDIR$(BDID))
974 $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) : | $(BD_TARGETDIR$(BDID))
975 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_TARGETDIR$(BDID))
977 %end
978 #------------------------------------------------------------------------------
981 #------------------------------------------------------------------------------
982 # Build programs, for every C file an executable will be built with the same
984 %define build_progs mmake=/A files=/A \
985     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
986     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
987     uselibs= usehostlibs= usestartup=yes detach=no
989 .PHONY : %(mmake)
991 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
993 BD_OBJDIR$(BDID)    := %(objdir)
994 BD_TARGETDIR$(BDID) := %(targetdir)
996 BD_FILES$(BDID)     := %(files)
997 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
998 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
999 BD_EXES$(BDID)      := $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID)))
1001 BD_CFLAGS$(BDID)    := %(cflags)
1002 ifneq ($(strip $(filter arosc_shared,%(uselibs))),)
1003 BD_CFLAGS$(BDID)    += -D_CLIB_LIBRARY_ -I$(TOP)/rom/exec
1004 endif
1005 BD_DFLAGS$(BDID)    := %(dflags)
1006 BD_LDFLAGS$(BDID)   := %(ldflags)
1009 %(mmake)-quick : %(mmake)
1011 #MM %(mmake) : includes-generate-deps
1012 %(mmake) : $(BD_EXES$(BDID))
1014 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1015 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1016     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1018 %rule_link_progs progs=$(BD_FILES$(BDID)) \
1019     targetdir=$(BD_TARGETDIR$(BDID)) objdir=$(BD_OBJDIR$(BDID)) \
1020     ldflags=$(BD_LDFLAGS$(BDID)) \
1021     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1022     usestartup="%(usestartup)" detach="%(detach)"
1024 endif
1026 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
1028 $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID))) : | $(BD_TARGETDIR$(BDID))
1029 $(BD_DEPS$(BDID)) $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1030 GLOB_MKDIRS += $(BD_TARGETDIR$(BDID)) $(BD_OBJDIR$(BDID))
1032 %end
1033 #------------------------------------------------------------------------------
1036 #------------------------------------------------------------------------------
1037 # Build a module.
1038 # This is a bare version: It just compiles and links the given files. It is
1039 # assumed that all needed boiler plate code is in the files. This should only
1040 # be used for compiling external code. For AROS code use %build_module
1041 %define build_module_simple mmake=/A modname=/A modtype=/A \
1042     files="$(basename $(wildcard *.c))" \
1043     cflags=$(CFLAGS) dflags=$(BD_DEFDFLASGS) \
1044     objdir=$(OBJDIR) moduledir= \
1045     uselibs= usehostlibs= compiler=target
1047 # Define metamake targets and their dependencies
1048 #MM %(mmake) : core-linklibs includes-generate-deps
1049 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1050 #MM %(mmake)-quick
1051 #MM %(mmake)-clean
1053 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1055 .PHONY : $(BD_ALLTARGETS)
1057 ifeq (%(modname),)
1058 $(error using %build_module_simple: modname may not be empty)
1059 endif
1060 ifeq (%(modtype),)
1061 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1062 endif
1064 # Default values for variables and arguments
1065 BD_DEFLINKLIBNAME := %(modname)
1066 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1067 BD_DEFDFLAGS := %(cflags)
1068 OBJDIR ?= $(GENDIR)/$(CURDIR)
1069 BD_MODDIR := %(moduledir)
1070 ifeq ($(BD_MODDIR),)
1071   ifeq (%(modtype),library)
1072     BD_MODDIR  := $(AROS_LIBS)
1073   endif
1074   ifeq (%(modtype),gadget)
1075     BD_MODDIR  := $(AROS_GADGETS)
1076   endif
1077   ifeq (%(modtype),datatype)
1078     BD_MODDIR  := $(AROS_DATATYPES)
1079   endif
1080   ifeq (%(modtype),handler)
1081     BD_MODDIR  := $(AROS_FS)
1082   endif
1083   ifeq (%(modtype),device)
1084     BD_MODDIR  := $(AROS_DEVS)
1085   endif
1086   ifeq (%(modtype),resource)
1087     BD_MODDIR  := $(AROS_RESOURCES)
1088   endif
1089   ifeq (%(modtype),mui)
1090     BD_MODDIR  := $(AROS_CLASSES)/Zune
1091   endif
1092   ifeq (%(modtype),mcc)
1093     BD_MODDIR  := $(AROS_CLASSES)/Zune
1094   endif
1095   ifeq (%(modtype),mcp)
1096     BD_MODDIR  := $(AROS_CLASSES)/Zune
1097   endif
1098   ifeq (%(modtype),hidd)
1099     BD_MODDIR  := $(AROS_DRIVERS)
1100   endif
1101 endif
1102 ifeq ($(BD_MODDIR),)
1103   $(error Don't where to put the file for modtype %(modtype). Specify moduledir=)
1104 endif
1106 %rule_compile_multi \
1107     basenames="%(files)" targetdir="%(objdir)" \
1108     cflags="%(cflags)" dflags="%(dflags)" \
1109     compiler=%(compiler)
1111 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1112 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1114 %(mmake)-quick : %(mmake)
1115 %(mmake) : $(BD_MODULE)
1116 %(mmake)-kobj : $(BD_KOBJ)
1118 # The module is linked from all the compiled .o files
1119 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1120 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1121                  endobj= err=%(modname).err objdir=%(objdir) \
1122                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1124 # Link kernel object file
1125 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1126     expansion keymap
1127 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1128     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1129 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1130 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1131 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1132 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1133 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1134         @$(ECHO) "Linking $@"
1135         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1136         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1139 ## Dependency fine-tuning
1141 BD_DEPS       := $(addprefix %(objdir), $(addsuffix .o,%(files)))
1142 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1144 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1145 $(BD_MODULE) : | $(BD_MODDIR)
1146 $(BD_KOBJ) : | $(KOBJSDIR)
1147 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1149 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1150 %(mmake)-clean ::
1151         @$(ECHO) "Cleaning up for module %(modname)"
1152         @$(RM) $(BD_OBJS) $(BD_KOBJ)
1153 %end
1156 #------------------------------------------------------------------------------
1157 # Build a module
1158 # Explanation of this macro is done in the developer's manual
1159 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1160   conffile= files="$(basename $(wildcard *.c))" \
1161   linklibfiles= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1162   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1163   reffile=$(BD_DEFREFFILE) noref= \
1164   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1165   compiler=target genincludes=
1167 # Define metamake targets and their dependencies
1168 #MM- includes-all : %(mmake)-includes
1169 #MM %(mmake) : %(mmake)-includes core-linklibs
1170 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1171 #MM %(mmake)-linklib : %(mmake)-includes
1172 #MM %(mmake)-quick : %(mmake)-includes-quick
1173 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1174 #MM     includes-generate-deps
1175 #MM %(mmake)-includes-quick
1176 #MM %(mmake)-includes-dirs
1177 #MM %(mmake)-makefile
1178 #MM %(mmake)-funclist
1179 #MM %(mmake)-clean
1181 # All MetaMake targets defined by this macro
1182 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1183     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1184     %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1186 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1188 ifeq (%(modname),)
1189 $(error using %build_module: modname may not be empty)
1190 endif
1191 ifeq (%(modtype),)
1192 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1193 endif
1195 # Default values for variables and arguments
1196 BD_DEFLINKLIBNAME := %(modname)
1197 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1198 BD_DEFDFLAGS := %(cflags)
1199 OBJDIR ?= $(GENDIR)/$(CURDIR)
1201 ## Create genmodule include Makefile for the module
1203 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1205 %rule_genmodule_makefile \
1206     modname=%(modname) modtype=%(modtype) \
1207     modsuffix=%(modsuffix) targetdir=%(objdir) \
1208     conffile=%(conffile)
1210 %(objdir)/Makefile.%(modname) : | %(objdir)
1212 GLOB_MKDIRS += %(objdir)
1214 # Do not parse these statements if metatarget is not appropriate
1215 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1217 include %(objdir)/Makefile.%(modname)
1219 BD_DEFMODDIR := $(%(modname)_MODDIR)
1222 ## include files generation
1224 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1225 ifeq (%(genincludes),yes)
1226     %(modname)_INCLUDES := proto/%(modname).h clib/%(modname)_protos.h defines/%(modname).h 
1227 endif
1228 ifeq (%(genincludes),no)
1229     %(modname)_INCLUDES :=
1230 endif
1231 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1232 BD_DEFLIBDEFSINC := %(objdir)/%(modname)_deflibdefs.h
1234 %(mmake)-includes-quick : %(mmake)-includes
1235 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1236     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1237     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1239 ifneq ($(%(modname)_INCLUDES),)
1240 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1241                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1242                          conffile=%(conffile) reffile=%(reffile)
1244 %rule_copy_diff_multi \
1245     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1246     stampfile=%(objdir)/%(modname)_geninc
1248 %rule_copy_diff_multi \
1249     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1250     stampfile=%(objdir)/%(modname)_incs
1252 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1253                       modsuffix=%(modsuffix) \
1254                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1256 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1258 TMP%(modname)_INCDIRS := \
1259     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1260     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1261     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1262 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1264 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1265 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1267 endif
1269 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1270                            modsuffix=%(modsuffix) targetdir=%(objdir) \
1271                            conffile=%(conffile)
1273 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1275 %(objdir)/%(modname)_deflibdefs.h : FILENAME := $(BD_LIBDEFSINC)
1276 %(objdir)/%(modname)_deflibdefs.h :
1277         @$(ECHO) "generating $@"
1278         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1281 ## Generation of the funclist file
1283 %(mmake)-funclist : %(modname).funclist
1285 %rule_genmodule_funclist \
1286     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1287     conffile=%(conffile) reffile=%(reffile)
1290 ## Extra genmodule src files generation
1291 ## 
1292 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1293                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1294                       conffile=%(conffile) reffile=%(reffile)
1296 ## Compilation
1298 BD_FILES      := %(files)
1299 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1300 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1302 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1303 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1304 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1306 BD_CFLAGS     := %(cflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1307 BD_DFLAGS     := %(dflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1309 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1310 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1311 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1312     BD_LINKLIB :=
1313 else
1314     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1315 endif
1316 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1318 BD_CCFILES := $(BD_NARCHFILES) $(BD_STARTFILES) \
1319     $(BD_ENDFILES) $(BD_LINKLIBCFILES) %(linklibfiles)
1321 %rule_compile_multi \
1322     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1323     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1324     compiler=%(compiler)
1326 ifneq ($(BD_LINKLIBAFILES),)
1327 %rule_assemble_multi \
1328     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1329 endif
1331 ## function reference files generation
1333 %rule_ref_multi \
1334     basenames=$(BD_FILES) targetdir=%(objdir) \
1335     cflags="-I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip $(BD_CFLAGS))" \
1336     compiler=%(compiler)
1338 ifeq (%(noref),)
1339 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1340 else
1341 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1342 endif
1344 %rule_join from=$(BD_REFS) to=%(reffile) \
1345            text="Collecting function references for module %(modname)"
1348 ## Linking
1350 ifeq (%(modsuffix),)
1351 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1352 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1353 else
1354 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1355 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1356 endif
1358 %(mmake)-quick : %(mmake)
1359 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1360 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1361 %(mmake)-linklib : $(BD_LINKLIB)
1363 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1364                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1365 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1366 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES))
1368 # The module is linked from all the compiled .o files
1369 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1370                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1371                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1373 # Link static lib
1374 ifneq ($(BD_LINKLIB),)
1375 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1377 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1378 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1379 endif
1381 # Link kernel object file
1382 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1383     expansion keymap
1384 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1385     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1386 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1387 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1388 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1389 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1390 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1391         @$(ECHO) "Linking $@"
1392         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1393         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1395 ## Dependency fine-tuning
1397 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES))))
1398 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1400 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1401 $(BD_MODULE) : | %(prefix)/%(moduledir)
1402 $(BD_KOBJ) : | $(KOBJSDIR)
1403 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1405 # Some include files need to be generated before the .c can be parsed.
1406 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1407 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1408     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1409 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1411 BD_DFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1412     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1413 $(BD_DEPS) : $(BD_DFILE_DEPS)
1414 endif
1416 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1417     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1418     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1419     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1420     $(addprefix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1421     %(objdir)/%(modname)_deflibdefs.h \
1422     $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1423     $(BD_ENDOBJS)
1424 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1425 %(mmake)-clean ::
1426         @$(ECHO) "Cleaning up for module %(modname)"
1427         @$(RM) $(FILES)
1429 endif # $(TARGET) in $(BD_ALLTARGETS)
1430 %end
1431 #------------------------------------------------------------------------------
1434 #------------------------------------------------------------------------------
1435 # Build a linklib.
1436 # - mmake is the mmaketarget
1437 # - libname is the baselibname e.g. lib%(libname).a will be created
1438 # - files are the C source files to include in the lib. The list of files
1439 #   has to be given without the .c suffix
1440 # - asmfiles are the asm files to include in the lib. The list of files has to
1441 #   be given with the .s suffix
1442 # - cflags are the flags to compile the source (default $(CFLAGS))
1443 # - dflags are the flags use during makedepend (default equal to cflags)
1444 # - aflags are the flags use during assembling (default $(AFLAGS))
1445 # - objdir is where the .o are generated
1446 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1447 %define build_linklib mmake=/A libname=/A files="$(basename $(wildcard *.c))" \
1448   asmfiles= cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1450 # assign and generate the local variables used in this macro
1451 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1453 BD_FILES      := %(files)
1454 BD_ASMFILES   := %(asmfiles)
1456 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1457 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1458 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1460 BD_OBJS       := $(BD_ARCHOBJS) $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES))))
1461 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1463 BD_CFLAGS     := %(cflags)
1464 ifeq (%(dflags),)
1465 BD_DFLAGS     := $(BD_CFLAGS)
1466 else
1467 BD_DFLAGS     := %(dflags)
1468 endif
1469 BD_AFLAGS     := %(aflags)
1471 BD_LINKLIB    := %(libdir)/lib%(libname).a
1473 .PHONY : %(mmake) %(mmake)-clean
1475 #MM %(mmake) : includes-generate-deps
1476 %(mmake) : $(BD_LINKLIB)
1479 %(mmake)-clean ::
1480         @$(RM) $(BD_OBJS) $(BD_DEPS)
1482 ifeq ($(TARGET),%(mmake))
1483 ifneq ($(dir $(BD_FILES)),./)
1484 vpath %.c $(filter-out ./,$(dir $(BD_FILES)))
1485 endif
1487 %rule_compile basename=% targetdir=%(objdir) \
1488               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1489 %rule_assemble basename=% targetdir=%(objdir) \
1490               aflags=$(BD_AFLAGS)
1491 endif
1493 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1495 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1497 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1498 $(BD_LINKLIB) : | %(libdir)
1499 GLOB_MKDIRS += %(objdir) %(libdir)
1501 %end
1502 #------------------------------------------------------------------------------
1505 #------------------------------------------------------------------------------
1506 # Build catalogs.
1507 # - mmake is the mmaketarget
1508 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1509 # - description is the catalog description file (.cd) (default *.cd)
1510 # - subdir is the destination subdir of the catalogs
1511 # - name is the name of the destination catalog, without the .catalog suffix
1512 # - source is the path to the generated source code file
1513 # - dir is the base destination directory (default $(AROS_CATALOGS))
1514 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1516 %define build_catalogs mmake=/A name=/A subdir=/A \
1517  catalogs="$(basename $(wildcard *.ct))" source="../strings.h" \
1518  description="$(basename $(wildcard *.cd))" dir=$(AROS_CATALOGS) \
1519  sourcedescription="$(TOOLDIR)/C_h_orig"
1521 %buildid targets="%(mmake) %(mmake)-clean"
1523 BD_SRCS$(BDID) := $(addsuffix .ct, %(catalogs))
1524 BD_OBJS$(BDID) := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1525 BD_DIRS$(BDID) := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1528 %(mmake) : $(BD_OBJS$(BDID)) %(source)
1530 $(BD_OBJS$(BDID)) : | $(BD_DIRS$(BDID))
1531 GLOB_MKDIRS += $(BD_DIRS$(BDID))
1533 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1534         @$(ECHO) "Creating %(name) catalog for language $*."
1535         @$(FLEXCAT) %(description).cd $*.ct CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1537 ifneq (%(source),)
1538 %(source) : %(description).cd
1539         @$(ECHO) "Creating %(name) catalog source file %(source)"
1540         @$(FLEXCAT) %(description).cd %(source)=%(sourcedescription).sd
1541 endif
1544 %(mmake)-clean ::
1545         $(RM) $(BD_OBJS$(BDID)) %(source)
1547 .PHONY: %(mmake) %(mmake-clean)
1549 %end
1551 #-----------------------------------------------------------------------------
1553 #-----------------------------------------------------------------------------
1554 # Build icons.
1555 # - mmake is the mmaketarget
1556 # - icons is a list of icon base names (ie. without the .info suffix)
1557 # - dir is the destination directory
1558 #-----------------------------------------------------------------------------
1560 %define build_icons mmake=/A icons=/A dir=/A
1562 %buildid targets="%(mmake) %(mmake)-clean"
1564 BD_OBJS$(BDID) := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1567 %(mmake) : $(BD_OBJS$(BDID))
1569 %(dir)/%.info : %.info.src %.png
1570         @$(ECHO) Creating $(notdir $@)...
1571         @$(ILBMTOICON) $+ $@
1573 $(BD_OBJS$(BDID)) : | %(dir)
1574 GLOB_MKDIRS += %(dir)
1577 %(mmake)-clean ::
1578         @$(RM) $(BD_OBJS$(BDID))
1580 .PHONY: %(mmake)
1582 %end
1584 #-----------------------------------------------------------------------------
1586 #------------------------------------------------------------------------------
1587 # Compile files for an arch-specific replacement of code for a module
1588 # - files: the basenames of the C files to compile.
1589 # - asmfiles: the basenames of the asm files to assemble.
1590 # - mainmmake: the mmake of the module in the main directory to compile these
1591 #   arch specific files for.
1592 # - maindir: the object directory for the main module
1593 # - arch: the arch for which to compile these files. It can have the form
1594 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1595 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1596 # - dflags: the flags used during creation of dependency file. If not specified
1597 #   the same value as cflags will be used
1598 # - aflags: the flags used during assembling
1599 # - compiler: (host or target) specifies which compiler to use. By default
1600 #   the target compiler is used
1601 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1602 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1604 ifeq (%(files) %(asmfiles),)
1605   $(error no files or asmfiles given)
1606 endif
1608 %buildid targets="%(mainmmake)-%(arch)"
1610 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1611 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1612 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1614 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1616 ifeq (%(arch),)
1617   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1618 endif
1620 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1621 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1622 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1623 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1624 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1626 ifeq ($(TARGET),%(mainmmake)-%(arch))
1627 vpath %.c $(filter-out ./,$(dir %(files)))
1628 vpath %.s $(filter-out ./,$(dir %(asmfiles)))
1629 vpath %.S $(filter-out ./,$(dir %(asmfiles)))
1630 endif
1632 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1633 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1636 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1638 ifeq ($(findstring %(compiler),host target),)
1639   $(error unknown compiler %(compiler))
1640 endif
1641 ifeq (%(compiler),target)
1642 $(BD_COBJS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1643 endif
1644 ifeq (%(compiler),host)
1645 $(BD_COBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
1646 endif
1647 ifneq (%(modulename),)
1648 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1649                      --include $(GENDIR)/%(maindir)/%(modulename)_deflibdefs.h
1650 else
1651 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1652 endif
1653 ifeq ($(TARGET),%(mainmmake)-%(arch))
1654 $(BD_OBJDIR$(BDID))/%.o : %.c
1655         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD)
1656 endif
1658 ifeq (%(dflags),)
1659 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1660 else
1661 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1662 endif
1663 ifeq ($(TARGET),%(mainmmake)-%(arch))
1664 $(BD_OBJDIR$(BDID))/%.d : %.c
1665         %mkdepend_q flags=$(TMP_DFLAGS)
1666 endif
1668 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1670 ifeq ($(TARGET),%(mainmmake)-%(arch))
1671 $(BD_OBJDIR$(BDID))/%.o : %.s
1672         %assemble_q opt=$(AFLAGS)
1673 $(BD_OBJDIR$(BDID))/%.o : %.S
1674         %assemble_q opt=$(AFLAGS)
1675 endif
1677 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1678 %end
1679 #------------------------------------------------------------------------------
1687 # ======================
1688 # Old stuff, will probably be removed in the future
1693 # GNU Make automatic variables
1694 # $@ current target
1695 # $< First dependency
1696 # $? All newer dependencies
1697 # $^ All dependencies
1698 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1699 #    a.%.b, then the stem is dir/foo)
1701 #------------------------------------------------------------------------------
1702 # rule to generate libdefs.h with archtool (options may go away!)
1703 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1704 %(dest) : %(conffile) %(genlibdefstool)
1705         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1706         @%(genlibdefstool) -c -o $@ %(conffile)
1707 %end
1710 #------------------------------------------------------------------------------
1711 # generate asm files from c files (for debugging purposes)
1712 %define ctoasm_q
1713 %.s : %.c
1714         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1715         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1716 %end
1718 #------------------------------------------------------------------------------
1719 # Convert two png images to an Amiga icon file based on the description
1720 # file %(from), with outputfile going to %(to).
1721 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1722         @$(ECHO) "Creating icon %(to)..."
1723         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1724         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1725         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1726 %end
1728 #------------------------------------------------------------------------------
1729 # NOTE: The following are all part of Iain's build changes, please don't use
1730 # or change anything below this line until you know what you are doing. This
1731 # is so that I don't conflict with the semantics of any of the above macros.
1732 #------------------------------------------------------------------------------
1734 #------------------------------------------------------------------------------
1735 # Copy files from one directory to another.
1737 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1739 SRC_FILES := $(addprefix %(src)/, %(files))
1740 DST_FILES := $(addprefix %(dst)/, %(files))
1742 %(maketarget) : setup $(DST_FILES)
1744 $(DST_FILES) : %(dst)/% : %(src)/%
1745         @$(CP) $< $@
1746         
1747 setup ::
1748         %mkdirs_q %(dst)
1750 %end
1752 #----------------------------------------------------------------------------------
1753 # Copy a diretory recursively to another place, preserving the original 
1754 # hierarchical structure
1756 # src: the source directory whose content will be copied
1757 # dst: the directory where to copy src's content. If not existing, it will be made.
1759 %define copy_dir_recursive mmake=/A src=$(TOP)/$(CURDIR) dst=/A
1761 %(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)
1762 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1764 define %(mmake)_mkdir
1765 $(1):
1766         $(MKDIR) $$@
1767 endef
1769 define %(mmake)_copy
1770 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1771         $(CP) $$< $$@
1772 endef
1774 .PHONY : %(mmake)
1777 %(mmake): | $(GENDIR)/$(CURDIR)
1778         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1779         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1780         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1781         for d in $(%(mmake)_DIRS); do                      \
1782             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1783         done
1784         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1785         for f in $(%(mmake)_FILES); do                                            \
1786             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1787         done;  \
1788         for dst in %(dst); do \
1789             $(MAKE) -f $$m DST=$$dst SRC=%(src) all; \
1790         done
1792 $(GENDIR)/$(CURDIR):
1793         $(MKDIR) $@
1795 %end
1797 #------------------------------------------------------------------------------
1798 #   Copy include files into the includes directories. There are currently
1799 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1800 #   for building tools that need to run on the host system $(GENINCDIR). The
1801 #   $(GENINCDIR) path must not contain any references to the C runtime
1802 #   library header files.
1804 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1805     dir= compiler=target
1807 ifeq ($(findstring %(compiler),host target),)
1808 $(error %copy_includes: compiler argument (%(compiler)) has to be host or target)
1809 endif
1811 ifneq (%(dir),)
1812 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1813 BD_INC_PATH := %(dir)/
1814 else
1815 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1816 BD_INC_PATH :=
1817 endif
1819 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1820         @$(CP) $< $@
1823 ifeq (%(compiler),target)
1825 ifneq (%(dir),)
1826 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1827 else
1828 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1829 endif
1831 BD_INCL_FILES += $(BD_INCL_FILES2)
1833 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1834         @$(CP) $< $@
1835 endif
1838 %(mmake) : $(BD_INCL_FILES)
1840 .PHONY: %(mmake)
1842 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1843 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1844 %end
1847 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1848 STUBS_SRC := $(addsuffix .c,$(STUBS))
1849 STUBS_MEM := $(addsuffix .o,$(STUBS))
1850 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1851 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1852 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1854 #MM- linklibs : hidd-%(hidd)-stubs
1855 #MM- %(parenttarget): hidd-%(hidd)-stubs
1856 #MM hidd-%(hidd)-stubs : includes includes-copy
1857 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1859 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1860         %mklib_q from=$^
1862 $(STUBS_OBJ) : $(STUBS_SRC) 
1863         %compile_q cmd=$(TARGET_CC) opt=%(cflags)
1865 $(STUBS_DEP) : $(STUBS_SRC)
1866         %mkdepend_q flags=%(dflags)
1868 setup ::
1869         %mkdirs_q $(OBJDIR) $(LIBDIR)
1872 clean ::
1873         -@$(RM) $(HIDD_LIB) $(OBJDIR)
1875 DEPS := $(DEPS) $(STUBS_DEP)
1877 %end
1878       
1879 #------------------------------------------------------------------------------
1880 # Build an imported source tree which uses the configure script from the
1881 # autoconf package.  This rule will try to "integrate" the produced files as
1882 # much as possible in the AROS build, for example by putting libraries in the
1883 # standard library directory, includes in the standard include directory, and
1884 # so on. You can however override this behaviour.
1886 # As a special "bonus" for you, the PROGDIR environment variable is defined to
1887 # be %(bindir) (or its deduced value) when running "make install", and
1888 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
1889 # configure script some more parameters whose value depends upon the PROGDIR
1890 # env var, so that the program gets all its stuff installed in the proper place
1891 # when building it, but when running it from inside AROS it can also find that
1892 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
1893 # the configuration parameters set when running ./configure
1895 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
1896 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
1897 # to the name which has to follow it.
1900 %define build_with_configure mmake=/A srcdir=$(TOP)/$(CURDIR) prefix= \
1901     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
1902     install_target=install postconfigure= postinstall=
1904 ifneq (%(prefix),)
1905     %(mmake)-prefix := %(prefix)
1906 else
1907     %(mmake)-prefix := $(AROS_CONTRIB)
1908 endif
1910 ifneq (%(aros_prefix),)
1911     %(mmake)-aros_prefix := %(aros_prefix)
1912 else
1913     %(mmake)-aros_prefix := $(%(mmake)-prefix)
1914 endif
1916 ifeq (%(nix),yes)
1917     %(mmake)-nix    := -nix
1918     %(mmake)-volpfx := /
1919     %(mmake)-volsfx := /
1920     
1921     ifeq (%(nix_dir_layout),)
1922         %(mmake)-nix_dir_layout := yes
1923     endif
1924 else
1925     %(mmake)-volsfx := :
1926     
1927     ifeq (%(nix_dir_layout),)
1928         %(mmake)-nix_dir_layout := no
1929     endif
1930 endif
1932 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
1934 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) exec_prefix=$(%(mmake)-prefix)
1936 # Check if chosen compiler is valid
1937 ifeq ($(findstring %(compiler),host target kernel),)
1938   $(error unknown compiler %(compiler))
1939 endif
1941 # Set legacy 'host' variable based on chosen compiler
1942 ifeq (%(compiler),host)
1943     host := yes
1944 else
1945     host := no
1946 endif
1948 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) %(host)),yes)
1949     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
1950     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1951 else
1952     ifeq (%(nix),yes)
1953         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
1954         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
1955     else
1956         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1957     endif
1959     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
1960     
1961     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) sbindir=$(%(mmake)-prefix) \
1962     libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) oldincludedir=$(AROS_INCLUDES)
1963 endif
1966 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
1968 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
1970 ifneq (%(install_target),)
1971     %(mmake)-install_command = \
1972         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1973         -C $(GENDIR)/$(CURDIR) %(install_target) && \
1974         $(TOUCH) $(GENDIR)/$(CURDIR)/.installed
1976     %(mmake)-uninstall_command = \
1977     $(RM) $(GENDIR)/$(CURDIR)/.installed && \
1978     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1979     -C $(GENDIR)/$(CURDIR) uninstall
1980 else
1981     %(mmake)-install_command   := true
1982     %(mmake)-uninstall_command := true
1983 endif
1985 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
1988 %(mmake)-build_and_install-quick :  $(GENDIR)/$(CURDIR)/.configured
1989         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(GENDIR)/$(CURDIR); then \
1990             $(RM)  $(GENDIR)/$(CURDIR)/.installed && \
1991             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(GENDIR)/$(CURDIR) && \
1992             $(%(mmake)-install_command); \
1993         fi
1995 %(srcdir)/.files-touched:
1996         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
1997         $(TOUCH) $@
2000 %(mmake)-uninstall :
2001         $(%(mmake)-uninstall_command)
2003 ifneq ($(DEBUG),yes)
2004     %(mmake)-s_flag = -s
2005 endif
2008 %(mmake)-configure : $(GENDIR)/$(CURDIR)/.configured
2010 ifeq (%(compiler),host)
2011 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2012         $(RM) $@ 
2013         %mkdirs_q $(GENDIR)/$(CURDIR)
2014         cd $(GENDIR)/$(CURDIR) && \
2015         find . -name config.cache -exec $(RM) '{}' \; && \
2016         CC="$(HOST_CC)" \
2017             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2018             $(TOUCH) $@
2019 endif
2020 ifeq (%(compiler),target)
2021 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2022         $(RM) $@
2023         %mkdirs_q $(GENDIR)/$(CURDIR)
2024         cd $(GENDIR)/$(CURDIR) && \
2025         find . -name config.cache -exec $(RM) '{}' \; && \
2026         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2027             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" \
2028             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2029             --host=$(AROS_TARGET_CPU)-aros \
2030             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls \
2031             --without-x --without-pic --disable-shared && \
2032             $(TOUCH) $@
2033 endif
2034 ifeq (%(compiler),kernel)
2035 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2036         $(RM) $@
2037         %mkdirs_q $(GENDIR)/$(CURDIR)
2038         cd $(GENDIR)/$(CURDIR) && \
2039         find . -name config.cache -exec $(RM) '{}' \; && \
2040         CC="$(KERNEL_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2041             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" \
2042             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2043             --host=$(AROS_TARGET_CPU)-aros \
2044             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls \
2045             --without-x --without-pic --disable-shared && \
2046             $(TOUCH) $@
2047 endif
2048         
2050 %(mmake)-clean : %(mmake)-uninstall
2051         @$(RM) $(GENDIR)/$(CURDIR)
2052 %end
2054 #############################################################################
2055 #############################################################################
2056 ##                                                                         ##
2057 ## Miscellaneous macros. Everything that doesn't fit above should be put   ##
2058 ## here.                                                                   ##
2059 ##                                                                         ##
2060 #############################################################################
2061 #############################################################################
2063 #----------------------------------------------------------------------------------
2064 # Given an archive name, patches names and locations where to find them, fetch
2065 # the archive and the patches from any of those locations, unpack the archive
2066 # and then apply the patches.
2068 # Locations currently supported are http and ftp sites, plus local filesystem
2069 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2070 # the fetch.sh script needs to be modified, since this macro relies on that script.
2072 # Arguments:
2074 #     - archive_origins = list of locations where to find the archive. They are tried
2075 #                         in sequence, until the archive is found and fetching it 
2076 #                         succeeded. If not specified, the current directory is assumed.
2077 #     - archive         = the archive name. Mandatory.
2078 #     - destination     = the local directory where to put the archive and patches.
2079 #                         If not specified, the current directory is assumed.
2080 #     - patches_origins = list of locations where to find the patches. They are tried
2081 #                         in sequence, until a patch is found and fetching it 
2082 #                         succeeded. If not specified, the current directory is assumed.
2083 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2084 #                         patch_name[:[patch_subdir][:patch_opt]].
2085 #                         
2086 #                             - patch_name   = the name of the patch file
2087 #                             - patch_subdir = the directory within \destination\ where to
2088 #                                              apply the patch.
2089 #                             - patch_opt    = any options to pass to the `patch' command
2090 #                                              when applying the patch.
2091 #                         
2092 #                         The patch_subdir and patch_opt fields are optional.
2094 %define fetch archive_origins=. archive=/A suffixes= destination=. patches_origins=. patches_specs=::
2095         $(FETCH) -ao "%(archive_origins)" -a %(archive) -as "%(suffixes)" -d %(destination) \
2096         -po "%(patches_origins)" -p %(patches_specs)
2097 %end
2099 #-----------------------------------------------------------------------------------------
2100 # Joins the features of %fetch and %build_with_configure, taking advantage of
2101 # the naming scheme of GNU packages. GNU packages names are in the form
2103 #     <package name>-<version number>.<archive format suffix>
2105 # If a patch is provided, it *must* be named the following way:
2107 #    <package name>-<version number>-aros.diff
2109 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2110 # CD'ing into the archive's extracted directory.
2112 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2113 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2114 # to make that patch fully comprehensive.
2116 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2118 # Arguments:
2120 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2121 #                     macro.
2122 #    - package      = the GNU package name, sans version and archive format suffixes.
2123 #    - version      = the package's version number, or otherwise any other version string.
2124 #                     It gets appended to the package name to form the basename of the archive.
2125 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2126 #                     version. Each one of them is tried until a matching archive is found.
2127 #                     Defaults to "tat.bz2 tar.gz".
2128 #    - destination  = same meaning as the one for the %fetch macro
2129 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2130 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2131 #                     fetched or not
2132 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2133 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2134 #                     $(GNUDIR).
2135 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2136 #                     /GNU.
2137 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2138 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2140 %define fetch_and_build mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2141     srcdir= package_repo= patch=no patch_repo= prefix= \
2142     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2144 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2145 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2147 %(mmake)-archbase  := %(package)-%(version)
2149 ifeq (%(prefix),)
2150     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2151 else
2152     %(mmake)-prefix := %(prefix)
2153 endif
2155 ifneq (%(subpackage),)
2156     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2157 else
2158     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2159 endif
2161 ifneq (%(srcdir),)
2162     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2163 else
2164     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2165 endif
2167 ifeq (%(patch),yes)
2168     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2169 else
2170     %(mmake)-%(subpackage)-patches_specs := ::
2171 endif
2173 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2175 .PHONY : %(mmake)-%(subpackage)-fetch
2177 %(mmake)-%(subpackage)-fetch :
2178         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2179             destination=$(PORTSDIR)/%(package) \
2180             archive_origins=". %(package_repo)" \
2181             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins=". %(patch_repo)"
2183 #MM- %(mmake) : %(mmake)-%(subpackage)
2185 PACKAGES_DIR := $(AROSDIR)/../Packages
2187 %(mmake)-%(subpackage)-package-dir := $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)
2189 %(mmake)-%(subpackage)-package-basename := \
2190     $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2192 %build_with_configure mmake=%(mmake)-%(subpackage) \
2193      srcdir=$(PORTSDIR)/%(package)/$(%(mmake)-%(subpackage)-srcdir) \
2194      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-%(subpackage)-package-dir)" \
2195      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2196      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2198 .PHONY : %(mmake)-%(subpackage)-make-package
2199 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2202 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2204 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2205 #that $^ and $@ have exactly the same mtime, and in that case make tries
2206 #to rebuild $@ again, which would fail because the directory where
2207 #the package got installed would not exist anymore. 
2208 #We work this around by using an if statement to manually check the mtimes.
2209 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2210         @if test $(GENDIR)/$(CURDIR)/.installed -nt $@ || ! test -f $@; then \
2211             $(RM) $@ && \
2212             $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" && \
2213             cd $(%(mmake)-%(subpackage)-package-dir) && \
2214             tar --remove-files -cvf $(%(mmake)-%(subpackage)-package-basename).tar * && \
2215             mkdir -p "$(%(mmake)-prefix)" && \
2216             tar -xf $(%(mmake)-%(subpackage)-package-basename).tar -C "%(prefix)"/ && \
2217             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar && \
2218             cd .. && $(RM) $(%(mmake)-%(subpackage)-archbase); \
2219         fi
2220 %end
2222 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2223     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2224     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2226 GNU_REPOSITORY := http://ftp.gnu.org/pub/gnu
2228 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2229     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2230     package_repo="%(package_repo) $(GNU_REPOSITORY)/%(package)" \
2231     patch="%(patch)" patch_repo="%(patch_repo)" \
2232     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2233     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2235 %end
2237 #-----------------------------------------------------------------------------------------
2238 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2239 # that the package is a "Development" package, and as such it needs to be placed
2240 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2242 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2243 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2244 # "mmake" argument, because the metatarget is implicitely defined as
2246 #     #MM- development-%(package)
2248 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2249     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2250     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2252 #MM- development : development-%(package)
2255 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2256    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2257    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2258    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2259    extraoptions="%(extraoptions)"
2260     
2261 %end