remember the best mode seen so far, otherwise the last in the list is always taken
[cake.git] / config / make.tmpl
blob138e8fa5e2bc79d7dd0d7f86f19a34be3f6bd30e
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 : %(basename).c
296         %compile_q opt="%(cflags)" cmd=$(TMP_CMD)
298 ifeq (%(dflags),)
299 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
300 else
301 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
302 endif
303 $(TMP_TARGETBASE).d : %(basename).c
304         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
305 %end
306 #------------------------------------------------------------------------------
309 #------------------------------------------------------------------------------
310 # Generate a rule to compile multiple C source files to an object file and
311 # generate the corresponding dependency files. The generated file will be put
312 # in the object directory without the directory part of the source file.
313 # options
314 # - basenames: the basenames of the files to compile. The names may include
315 #   relative or absolute path names. No wildcard is allowed
316 # - cflags (default $(CFLAGS)): the C flags to use for compilation
317 # - dflags: the flags used during creation of dependency file. If not specified
318 #   the same value as cflags will be used
319 # - targetdir: the directory to put the .o file and the .d file. By default
320 #   it is put in the same directory as the .c file. When targetdir is not
321 #   empty, path names will be stripped from the file names so that all files
322 #   are in that dir and not in subdirectories.
323 # - compiler (default target): compiler to use, either target or host
324 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
325     compiler=target
327 ifeq (%(targetdir),)
328 TMP_TARGETS := $(addsuffix .o,%(basenames))
329 TMP_DTARGETS := $(addsuffix .d,%(basenames))
330 TMP_WILDCARD := %
331 else
332 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
333 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
334 TMP_WILDCARD := %(targetdir)/%
336 # Be sure that all .c files are generated
337 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
339 # Be sure that all .c files are found
340 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
341 ifneq ($(TMP_DIRS),)
342     vpath %.c $(TMP_DIRS)
343 endif
345 endif
347 ifeq ($(findstring %(compiler),host target),)
348   $(error unknown compiler %(compiler))
349 endif
350 ifeq (%(compiler),target)
351 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
352 endif
353 ifeq (%(compiler),host)
354 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
355 endif
357 $(TMP_TARGETS) : CFLAGS := %(cflags)
358 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
359         %compile_q cmd=$(CMD)
361 ifeq (%(dflags),)
362 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
363 else
364 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
365 endif
366 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
367         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
368 %end
369 #------------------------------------------------------------------------------
372 #------------------------------------------------------------------------------
373 # Make an alias from one arch specific build to another arch.
374 # arguments:
375 # - mainmmake: the mmake of the module in the main tree
376 # - arch: the current arch
377 # - alias: the alias to which this should point
378 %define rule_archalias mainmmake=\A arch=\A alias=\A
380 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
381 %end
382 #------------------------------------------------------------------------------
385 #------------------------------------------------------------------------------
386 # Generate a rule to compile a C source file to a shared object file with a
387 # .so suffix. Basename may contain a directory part, then the source
388 # file has to be in that directory. The generated file will be put in the
389 # object directory without the directory.
390 # options
391 # - basename: the basename of the file to compile. Use % for a wildcard rule
392 # - cflags (default $(CFLAGS)): the C flags to use for compilation
393 # - targetdir: the directory to put the .o file and the .d file. By default
394 #   it is put in the same directory as the .c file
395 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
397 ifeq (%(targetdir),)
398   TMP_TARGETBASE := %(basename)
399 else
400   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
401 endif
403 ifeq ($(findstring %(compiler),host target),)
404   $(error unknown compiler %(compiler))
405 endif
406 ifeq (%(compiler),target)
407 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
408 endif
409 ifeq (%(compiler),host)
410 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
411 endif
413 $(TMP_TARGETBASE).so : %(basename).c
414         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD)
415 %end
416 #------------------------------------------------------------------------------
419 #------------------------------------------------------------------------------
420 # Generate a rule to assemble a source file to an object file. Basename may
421 # contain a directory part, then the source file has to be in that directory.
422 # The generated file will be put in the object directory without the directory.
423 # options
424 # - basename: the basename of the file to compile. Use % for a wildcard rule
425 # - flags (default $(AFLAGS)): the asm flags to use for assembling
426 # - targetdir: the directory to put the .o file in. By default it is put in the
427 #   same directory as the .s file
428 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
430 ifeq (%(targetdir),)
431 %(basename).o : %(basename).s
432         %assemble_q opt=%(aflags)
434 else
435 %(targetdir)/$(notdir %(basename)).o : %(basename).s
436         %assemble_q opt=%(aflags)
438 endif
439 %end
440 #------------------------------------------------------------------------------
443 #------------------------------------------------------------------------------
444 # Generate a rule to assemble multiple source files to an object file. The
445 # generated file will be put in the object directory with the directory part
446 # of the source file stripped off.
447 # options
448 # - basenames: the basenames of the files to compile. The names may include
449 #   relative or absolute path names. No wildcard is allowed
450 # - aflags (default $(AFLAGS)): the flags to use for assembly
451 # - targetdir: the directory to put the .o file and the .d file. By default
452 #   it is put in the same directory as the .c file. When targetdir is not
453 #   empty, path names will be stripped from the file names so that all files
454 #   are in that dir and not in subdirectories.
455 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
457 ifeq (%(targetdir),)
458 TMP_TARGETS := $(addsuffix .o,%(basenames))
459 TMP_WILDCARD := %
460 else
461 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
462 TMP_WILDCARD := %(targetdir)/%
464 # Be sure that all .s files are generated
465 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
467 # Be sure that all .c files are found
468 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
469 ifneq ($(TMP_DIRS),)
470     vpath %%(suffix) $(TMP_DIRS)
471 endif
473 endif
475 $(TMP_TARGETS) : AFLAGS := %(aflags)
476 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
477         %assemble_q opt=$(AFLAGS)
478 %end
479 #------------------------------------------------------------------------------
482 #------------------------------------------------------------------------------
483 # Link %(objs) to %(prog) using the libraries in %(uselibs)
484 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
485     usehostlibs= usestartup=yes detach=no nix=no
487 TMP_EXTRA_LDFLAGS := 
488 ifeq (%(nix),yes)
489     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
490 endif
491 ifeq (%(usestartup),no)
492     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
493 endif
494 ifeq (%(detach),yes)
495     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
496 endif
497 %(prog) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
499 %(prog) : %(objs) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
500         %link_q from="%(objs)" opt="%(ldflags) $(EXTRA_LDFLAGS)" \
501             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
502 %end
503 #------------------------------------------------------------------------------
506 #------------------------------------------------------------------------------
507 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
508 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
509 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) \
510     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
511     usestartup=yes detach=no
513 TMP_EXTRA_LDFLAGS := 
514 ifeq (%(nix),yes)
515     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
516 endif
517 ifeq (%(usestartup),no)
518     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
519 endif
520 ifeq (%(detach),yes)
521     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
522 endif
523 $(addprefix %(targetdir)/,%(progs)) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
525 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o \
526     $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
527         %link_q from=$< opt="%(ldflags) $(EXTRA_LDFLAGS)" \
528             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
529 %end
530 #------------------------------------------------------------------------------
533 #------------------------------------------------------------------------------
534 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
535 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
537 %(libdir)/lib%(libname).a : %(objs)
538         %mklib_q from=$^
539 %end
540 #------------------------------------------------------------------------------
543 #------------------------------------------------------------------------------
544 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
545 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
547 %(libdir)/lib%(libname).so : %(objs)
548         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
549 %end
550 #------------------------------------------------------------------------------
553 #------------------------------------------------------------------------------
554 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
555 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
556 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A uselibs= usehostlibs=
558 %(module) : OBJS := %(objs)
559 %(module) : ENDTAG := %(endobj)
560 %(module) : ERR := %(err)
561 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
562 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
563         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS)
565 %end
566 #------------------------------------------------------------------------------
569 #------------------------------------------------------------------------------
570 # Generate a rule to generate a function reference file from a C source file.
571 # Basename may contain a directory part, then the source file has to be in that
572 # directory. The generated file will be put in the object directory without the
573 # directory.
574 # options
575 # - basename: the basename of the file to compile. Use % for a wildcard rule
576 # - cflags (default $(CFLAGS)): the C flags to use for compilation
577 # - targetdir: the directory to put the generated .ref file. By default the
578 #   .ref file will be put in the same directory as the .c file.
579 # - includefile: This file will be included at the head of the source file
580 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
582 ifeq (%(targetdir),)
583 GENFILE_TMP := %(basename).ref
584 else
585 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
586 endif
588 ifeq ($(filter %(compiler),target host),)
589 $(error use of %rule_ref: compiler has to be 'host' or 'target')
590 endif
592 ifeq (%(compiler),target)
593 $(GENFILE_TMP) : CC:=$(TARGET_CC)
594 else
595 $(GENFILE_TMP) : CC:=$(HOST_CC)
596 endif
598 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
599 ifeq (%(includefile),)
600         %mkref_q cc=$(CC) cflags="%(cflags)"
601 else
602         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
603 endif
605 %end
606 #------------------------------------------------------------------------------
609 #------------------------------------------------------------------------------
610 # Generate a rule to generate a function reference file from a C source file.
611 # Basename may contain a directory part, then the source file has to be in that
612 # directory. The generated file will be put in the object directory without the
613 # directory.
614 # options
615 # - basenames: the basenames of the files to compile. No wildcard is allowed
616 # - cflags (default $(CFLAGS)): the C flags to use for compilation
617 # - targetdir: the directory to put the generated .ref file. By default the
618 #   .ref file will be put in the same directory as the .c file. When targetdir
619 #   is not empty all files will be put there and path parts in the basenames
620 #   will be stripped off.
621 # - includefile: This file will be included at the head of the source file
622 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
623     compiler=target
625 ifeq (%(targetdir),)
626 TMP_TARGETS := $(addsuffix .ref,%(basenames))
627 TMP_WILDCARD := %.ref
628 else
629 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
630 TMP_WILDCARD := %(targetdir)/%.ref
632 # Be sure that all .c files are generated
633 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
635 # Be sure that all .c files are found
636 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames))))
637 ifneq ($(TMP_DIRS),)
638     vpath %.c $(TMP_DIRS)
639 endif
641 endif
643 ifeq ($(filter %(compiler),target host),)
644 $(error use of %rule_ref: compiler has to be 'host' or 'target')
645 endif
647 ifeq (%(compiler),target)
648 $(TMP_TARGETS) : CC:=$(TARGET_CC)
649 else
650 $(TMP_TARGETS) : CC:=$(HOST_CC)
651 endif
652 ifeq (%(includefile),)
653 $(TMP_TARGETS) : CFLAGS:=%(cflags)
654 else
655 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
656 $(TMP_TARGETS) : %(includefile)
657 endif
658 $(TMP_TARGETS) : $(CXREF)
659 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
660         %mkref_q cc=$(CC)
661 %end
662 #------------------------------------------------------------------------------
665 #------------------------------------------------------------------------------
666 # Generate the libdefs.h include file for a module.
667 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
669 TMP_TARGET := %(modname)_libdefs.h
670 TMP_DEPS := $(GENMODULE)
671 TMP_OPTS := 
672 ifneq (%(conffile),)
673     TMP_OPTS += -c %(conffile)
674     TMP_DEPS += %(conffile)
675 else
676     TMP_DEPS += %(modname).conf
677 endif
678 ifneq (%(modsuffix),)
679     TMP_OPTS += -s %(modsuffix)
680 endif
681 ifneq (%(targetdir),)
682     TMP_OPTS += -d %(targetdir)
683     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
684 endif
686 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
687 $(TMP_TARGET) : MODNAME := %(modname)
688 $(TMP_TARGET) : MODTYPE := %(modtype)
689 $(TMP_TARGET) : $(TMP_DEPS)
690         @$(ECHO) "Generating $(notdir $@)"
691         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
692 %end
693 #------------------------------------------------------------------------------
696 #------------------------------------------------------------------------------
697 # Generate the libdefs.h include file for a module.
698 %define rule_genmodule_funclist \
699     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
701 TMP_TARGET := %(modname).funclist
702 TMP_DEPS := $(GENMODULE)
703 TMP_OPTS := 
704 ifeq (%(reffile),)
705     $(error reffile needed in rule_genmodule_funclist but none specified)
706 endif
707 TMP_OPTS := -r %(reffile)
708 TMP_DEPS += %(reffile)
709 ifneq (%(conffile),)
710     TMP_OPTS += -c %(conffile)
711     TMP_DEPS += %(conffile)
712 else
713     TMP_DEPS += %(modname).conf
714 endif
715 ifneq (%(modsuffix),)
716     TMP_OPTS += -s %(modsuffix)
717 endif
718 ifneq (%(targetdir),)
719     TMP_OPTS += -d %(targetdir)
720     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
721 endif
723 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
724 $(TMP_TARGET) : MODNAME := %(modname)
725 $(TMP_TARGET) : MODTYPE := %(modtype)
726 $(TMP_TARGET) : $(TMP_DEPS)
727         @$(ECHO) "Generating $(notdir $@)"
728         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
729 %end
730 #------------------------------------------------------------------------------
733 #------------------------------------------------------------------------------
734 # Generate a Makefile.%(modname) with the genmodule program and include this
735 # generated file in this Makefile
736 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
737     targetdir=
739 TMP_TARGET := Makefile.%(modname)
740 TMP_DEPS := $(GENMODULE)
741 TMP_OPTS := 
742 ifneq (%(conffile),)
743     TMP_OPTS += -c %(conffile)
744     TMP_DEPS += %(conffile)
745 else
746     TMP_DEPS += %(modname).conf
747 endif
748 ifneq (%(modsuffix),)
749     TMP_OPTS += -s %(modsuffix)
750 endif
751 ifneq (%(targetdir),)
752     TMP_OPTS += -d %(targetdir)
753     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
754 endif
756 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
757 $(TMP_TARGET) : MODNAME := %(modname)
758 $(TMP_TARGET) : MODTYPE := %(modtype)
759 $(TMP_TARGET) : $(TMP_DEPS)
760         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
761 %end
762 #------------------------------------------------------------------------------
764 #------------------------------------------------------------------------------
765 # Generate dummy support files so cxref when used on the a module source file
766 # will find something to include. This rule has to be preceeded by
767 # %rule_genmodule_makefile
768 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
770 ifneq ($(%(modname)_INCLUDES),)
771 TMP_TARGETS := $(%(modname)_INCLUDES)
773 TMP_DEPS := $(GENMODULE)
774 TMP_OPTS := 
775 ifneq (%(conffile),)
776     TMP_OPTS += -c %(conffile)
777     TMP_DEPS += %(conffile)
778 else
779     TMP_DEPS += %(modname).conf
780 endif
781 ifneq (%(modsuffix),)
782     TMP_OPTS += -s %(modsuffix)
783 endif
784 ifneq (%(targetdir),)
785     TMP_OPTS += -d %(targetdir)
786     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
787 endif
789 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
790 $(TMP_TARGETS) : MODNAME := %(modname)
791 $(TMP_TARGETS) : MODTYPE := %(modtype)
792 $(TMP_TARGETS) : $(TMP_DEPS)
793         @$(ECHO) "Generating dummy include files"
794         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
795 endif
796 %end
797 #------------------------------------------------------------------------------
800 #------------------------------------------------------------------------------
801 # Generate the support files for compiling a module. This includes include
802 # files and source files. This rule has to be preceeded by
803 # %rule_genmodule_makefile
804 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
805     conffile= reffile=
807 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
808                $(%(modname)_LINKLIBFILES)
809 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
811 TMP_DEPS := $(GENMODULE)
812 ifeq ($(%(modname)_NEEDREF), yes)
813     ifeq (%(reffile),)
814         $(error reffile needed in rule_genmodule_files but none specified)
815     endif
816     TMP_OPTS := -r %(reffile)
817     TMP_DEPS += %(reffile)
818 else
819     TMP_OPTS :=
820 endif
821 ifneq (%(conffile),)
822     TMP_OPTS += -c %(conffile)
823     TMP_DEPS += %(conffile)
824 else
825     TMP_DEPS += %(modname).conf
826 endif
827 ifneq (%(modsuffix),)
828     TMP_OPTS += -s %(modsuffix)
829 endif
830 ifneq (%(targetdir),)
831     TMP_OPTS += -d %(targetdir)
832     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
833 endif
835 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
836 $(TMP_TARGETS) : MODNAME := %(modname)
837 $(TMP_TARGETS) : MODTYPE := %(modtype)
838 $(TMP_TARGETS) : $(TMP_DEPS)
839         @$(ECHO) "Generating functable and support files for module $(BD_MODNAME$(BDID))"
840 ifneq (%(conffile),lib.conf)
841         @$(IF) $(TEST) -f lib.conf; then \
842           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
843         fi
844 endif
845         @$(IF) $(TEST) -f libdefs.h; then \
846           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
847         fi
848         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
849 %end
850 #------------------------------------------------------------------------------
852 #------------------------------------------------------------------------------
853 # Generate the support files for compiling a module. This includes include
854 # files and source files.
855 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
856     targetdir= conffile= reffile=
859 ifneq ($(%(modname)_INCLUDES),)
860 TMP_TARGETS := $(%(modname)_INCLUDES)
862 TMP_DEPS := $(GENMODULE)
863 ifeq ($(%(modname)_NEEDREF), yes)
864     ifeq (%(reffile),)
865         $(error reffile needed in rule_genmodule_files but none specified)
866     endif
867     TMP_OPTS := -r %(reffile)
868     TMP_DEPS += %(reffile)
869 else
870     TMP_OPTS :=
871 endif
872 ifneq (%(conffile),)
873     TMP_OPTS += -c %(conffile)
874     TMP_DEPS += %(conffile)
875 else
876     TMP_DEPS += %(modname).conf
877 endif
878 ifneq (%(modsuffix),)
879     TMP_OPTS += -s %(modsuffix)
880 endif
881 ifneq (%(targetdir),)
882     TMP_OPTS += -d %(targetdir)
883     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
884 endif
886 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
887 $(TMP_TARGETS) : MODNAME := %(modname)
888 $(TMP_TARGETS) : MODTYPE := %(modtype)
889 $(TMP_TARGETS) : $(TMP_DEPS)
890         @$(ECHO) "Generating include files"
891         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
892 endif
893 %end
894 #------------------------------------------------------------------------------
896 #------------------------------------------------------------------------------
897 # Common rules for all makefiles
898 %define common
899 # Delete generated makefiles
901 clean ::
902         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
904 include $(TOP)/config/make.tail
906 BDID := $(BDTARGETID)
907 %end
908 #------------------------------------------------------------------------------
909       
911 #############################################################################
912 #############################################################################
913 ##                                                                         ##
914 ## Here are the mmakefile build macro's. These are macro's that takes care ##
915 ## of everything to go from the sources to the generated target. Also all  ##
916 ## intermediate files and directories that are needed are created by these ##
917 ## rules.                                                                  ##
918 ##                                                                         ##
919 #############################################################################
920 #############################################################################
922 #------------------------------------------------------------------------------
923 # Build a program
924 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME$(BDID)) asmfiles= \
925     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
926     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
927     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no
929 .PHONY : %(mmake)
931 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
933 BD_PROGNAME$(BDID)  := %(progname)
934 BD_OBJDIR$(BDID)    := %(objdir)
935 BD_TARGETDIR$(BDID) := %(targetdir)
937 BD_FILES$(BDID)     := %(files)
938 BD_ASMFILES$(BDID)  := %(asmfiles)
939 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID))))
940 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
942 BD_CFLAGS$(BDID)    := %(cflags)
943 BD_AFLAGS$(BDID)    := %(aflags)
944 BD_DFLAGS$(BDID)    := %(dflags)
945 BD_LDFLAGS$(BDID)   := %(ldflags)
948 %(mmake)-quick : %(mmake)
950 #MM %(mmake) : includes-generate-deps
951 %(mmake) : $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID))
953 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
954 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
955     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
956 %rule_assemble_multi basenames=$(BD_ASMFILES$(BDID)) targetdir=$(BD_OBJDIR$(BDID)) \
957     aflags=$(BD_AFLAGS$(BDID))
959 %rule_link_prog prog=$(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) \
960     objs=$(BD_OBJS$(BDID)) ldflags=$(BD_LDFLAGS$(BDID)) \
961     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
962     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
964 endif
966 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
968 $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) : | $(BD_OBJDIR$(BDID))
969 $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) : | $(BD_TARGETDIR$(BDID))
970 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_TARGETDIR$(BDID))
972 %end
973 #------------------------------------------------------------------------------
976 #------------------------------------------------------------------------------
977 # Build programs, for every C file an executable will be built with the same
979 %define build_progs mmake=/A files=/A \
980     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
981     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
982     uselibs= usehostlibs= usestartup=yes detach=no
984 .PHONY : %(mmake)
986 %buildid targets="%(mmake) %(mmake)-clean %(mmake)-quick"
988 BD_OBJDIR$(BDID)    := %(objdir)
989 BD_TARGETDIR$(BDID) := %(targetdir)
991 BD_FILES$(BDID)     := %(files)
992 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
993 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
994 BD_EXES$(BDID)      := $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID)))
996 BD_CFLAGS$(BDID)    := %(cflags)
997 ifneq ($(strip $(filter arosc_shared,%(uselibs))),)
998 BD_CFLAGS$(BDID)    += -D_CLIB_LIBRARY_ -I$(TOP)/rom/exec
999 endif
1000 BD_DFLAGS$(BDID)    := %(dflags)
1001 BD_LDFLAGS$(BDID)   := %(ldflags)
1004 %(mmake)-quick : %(mmake)
1006 #MM %(mmake) : includes-generate-deps
1007 %(mmake) : $(BD_EXES$(BDID))
1009 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1010 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1011     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1013 %rule_link_progs progs=$(BD_FILES$(BDID)) \
1014     targetdir=$(BD_TARGETDIR$(BDID)) objdir=$(BD_OBJDIR$(BDID)) \
1015     ldflags=$(BD_LDFLAGS$(BDID)) \
1016     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1017     usestartup="%(usestartup)" detach="%(detach)"
1019 endif
1021 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
1023 $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID))) : | $(BD_TARGETDIR$(BDID))
1024 $(BD_DEPS$(BDID)) $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1025 GLOB_MKDIRS += $(BD_TARGETDIR$(BDID)) $(BD_OBJDIR$(BDID))
1027 %end
1028 #------------------------------------------------------------------------------
1031 #------------------------------------------------------------------------------
1032 # Build a module.
1033 # This is a bare version: It just compiles and links the given files. It is
1034 # assumed that all needed boiler plate code is in the files. This should only
1035 # be used for compiling external code. For AROS code use %build_module
1036 %define build_module_simple mmake=/A modname=/A modtype=/A \
1037     files="$(basename $(wildcard *.c))" \
1038     cflags=$(CFLAGS) dflags=$(BD_DEFDFLASGS) \
1039     objdir=$(OBJDIR) moduledir= \
1040     uselibs= usehostlibs= compiler=target
1042 # Define metamake targets and their dependencies
1043 #MM %(mmake) : core-linklibs includes-generate-deps
1044 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1045 #MM %(mmake)-quick
1046 #MM %(mmake)-clean
1048 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1050 .PHONY : $(BD_ALLTARGETS)
1052 ifeq (%(modname),)
1053 $(error using %build_module_simple: modname may not be empty)
1054 endif
1055 ifeq (%(modtype),)
1056 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1057 endif
1059 # Default values for variables and arguments
1060 BD_DEFLINKLIBNAME := %(modname)
1061 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1062 BD_DEFDFLAGS := %(cflags)
1063 OBJDIR ?= $(GENDIR)/$(CURDIR)
1064 BD_MODDIR := %(moduledir)
1065 ifeq ($(BD_MODDIR),)
1066   ifeq (%(modtype),library)
1067     BD_MODDIR  := $(AROS_LIBS)
1068   endif
1069   ifeq (%(modtype),gadget)
1070     BD_MODDIR  := $(AROS_GADGETS)
1071   endif
1072   ifeq (%(modtype),datatype)
1073     BD_MODDIR  := $(AROS_DATATYPES)
1074   endif
1075   ifeq (%(modtype),handler)
1076     BD_MODDIR  := $(AROS_FS)
1077   endif
1078   ifeq (%(modtype),device)
1079     BD_MODDIR  := $(AROS_DEVS)
1080   endif
1081   ifeq (%(modtype),resource)
1082     BD_MODDIR  := $(AROS_RESOURCES)
1083   endif
1084   ifeq (%(modtype),mui)
1085     BD_MODDIR  := $(AROS_CLASSES)/Zune
1086   endif
1087   ifeq (%(modtype),mcc)
1088     BD_MODDIR  := $(AROS_CLASSES)/Zune
1089   endif
1090   ifeq (%(modtype),mcp)
1091     BD_MODDIR  := $(AROS_CLASSES)/Zune
1092   endif
1093   ifeq (%(modtype),hidd)
1094     BD_MODDIR  := $(AROS_DRIVERS)
1095   endif
1096 endif
1097 ifeq ($(BD_MODDIR),)
1098   $(error Don't where to put the file for modtype %(modtype). Specify moduledir=)
1099 endif
1101 %rule_compile_multi \
1102     basenames="%(files)" targetdir="%(objdir)" \
1103     cflags="%(cflags)" dflags="%(dflags)" \
1104     compiler=%(compiler)
1106 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1107 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1109 %(mmake)-quick : %(mmake)
1110 %(mmake) : $(BD_MODULE)
1111 %(mmake)-kobj : $(BD_KOBJ)
1113 # The module is linked from all the compiled .o files
1114 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1115 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1116                  endobj= err=%(modname).err \
1117                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1119 # Link kernel object file
1120 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1121     expansion keymap
1122 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1123     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1124 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1125 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1126 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1127 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1128 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1129         @$(ECHO) "Linking $@"
1130         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1131         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1134 ## Dependency fine-tuning
1136 BD_DEPS       := $(addprefix %(objdir), $(addsuffix .o,%(files)))
1137 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1139 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1140 $(BD_MODULE) : | $(BD_MODDIR)
1141 $(BD_KOBJ) : | $(KOBJSDIR)
1142 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1144 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1145 %(mmake)-clean ::
1146         @$(ECHO) "Cleaning up for module %(modname)"
1147         @$(RM) $(BD_OBJS) $(BD_KOBJ)
1148 %end
1151 #------------------------------------------------------------------------------
1152 # Build a module
1153 # Explanation of this macro is done in the developer's manual
1154 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1155   conffile= files="$(basename $(wildcard *.c))" \
1156   linklibfiles= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1157   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1158   reffile=$(BD_DEFREFFILE) noref= \
1159   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1160   compiler=target genincludes=
1162 # Define metamake targets and their dependencies
1163 #MM- includes-all : %(mmake)-includes
1164 #MM %(mmake) : %(mmake)-includes core-linklibs
1165 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1166 #MM %(mmake)-linklib : %(mmake)-includes
1167 #MM %(mmake)-quick : %(mmake)-includes-quick
1168 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1169 #MM     includes-generate-deps
1170 #MM %(mmake)-includes-quick
1171 #MM %(mmake)-includes-dirs
1172 #MM %(mmake)-makefile
1173 #MM %(mmake)-funclist
1174 #MM %(mmake)-clean
1176 # All MetaMake targets defined by this macro
1177 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1178     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1179     %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1181 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1183 ifeq (%(modname),)
1184 $(error using %build_module: modname may not be empty)
1185 endif
1186 ifeq (%(modtype),)
1187 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1188 endif
1190 # Default values for variables and arguments
1191 BD_DEFLINKLIBNAME := %(modname)
1192 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1193 BD_DEFDFLAGS := %(cflags)
1194 OBJDIR ?= $(GENDIR)/$(CURDIR)
1196 ## Create genmodule include Makefile for the module
1198 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1200 %rule_genmodule_makefile \
1201     modname=%(modname) modtype=%(modtype) \
1202     modsuffix=%(modsuffix) targetdir=%(objdir) \
1203     conffile=%(conffile)
1205 %(objdir)/Makefile.%(modname) : | %(objdir)
1207 GLOB_MKDIRS += %(objdir)
1209 # Do not parse these statements if metatarget is not appropriate
1210 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1212 include %(objdir)/Makefile.%(modname)
1214 BD_DEFMODDIR := $(%(modname)_MODDIR)
1217 ## include files generation
1219 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1220 ifeq (%(genincludes),yes)
1221     %(modname)_INCLUDES := proto/%(modname).h clib/%(modname)_protos.h defines/%(modname).h 
1222 endif
1223 ifeq (%(genincludes),no)
1224     %(modname)_INCLUDES :=
1225 endif
1226 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1227 BD_DEFLIBDEFSINC := %(objdir)/%(modname)_deflibdefs.h
1229 %(mmake)-includes-quick : %(mmake)-includes
1230 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1231     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1232     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1234 ifneq ($(%(modname)_INCLUDES),)
1235 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1236                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1237                          conffile=%(conffile) reffile=%(reffile)
1239 %rule_copy_diff_multi \
1240     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1241     stampfile=%(objdir)/%(modname)_geninc
1243 %rule_copy_diff_multi \
1244     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1245     stampfile=%(objdir)/%(modname)_incs
1247 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1248                       modsuffix=%(modsuffix) \
1249                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1251 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1253 TMP%(modname)_INCDIRS := \
1254     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1255     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1256     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1257 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1259 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1260 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1262 endif
1264 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1265                            modsuffix=%(modsuffix) targetdir=%(objdir) \
1266                            conffile=%(conffile)
1268 BD_LIBDEFSINC := %(objdir)/%(modname)_libdefs.h
1270 %(objdir)/%(modname)_deflibdefs.h : FILENAME := $(BD_LIBDEFSINC)
1271 %(objdir)/%(modname)_deflibdefs.h :
1272         @$(ECHO) "generating $@"
1273         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1276 ## Generation of the funclist file
1278 %(mmake)-funclist : %(modname).funclist
1280 %rule_genmodule_funclist \
1281     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1282     conffile=%(conffile) reffile=%(reffile)
1285 ## Extra genmodule src files generation
1286 ## 
1287 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1288                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1289                       conffile=%(conffile) reffile=%(reffile)
1291 ## Compilation
1293 BD_FILES      := %(files)
1294 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1295 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1297 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1298 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1299 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1301 BD_CFLAGS     := %(cflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1302 BD_DFLAGS     := %(dflags) -I%(objdir) -idirafter $(TOP)/$(CURDIR) -include %(objdir)/%(modname)_deflibdefs.h
1304 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1305 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1306 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1307     BD_LINKLIB :=
1308 else
1309     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1310 endif
1311 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1313 BD_CCFILES := $(BD_NARCHFILES) $(BD_STARTFILES) \
1314     $(BD_ENDFILES) $(BD_LINKLIBCFILES) %(linklibfiles)
1316 %rule_compile_multi \
1317     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1318     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1319     compiler=%(compiler)
1321 ifneq ($(BD_LINKLIBAFILES),)
1322 %rule_assemble_multi \
1323     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1324 endif
1326 ## function reference files generation
1328 %rule_ref_multi \
1329     basenames=$(BD_FILES) targetdir=%(objdir) \
1330     cflags="-I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip $(BD_CFLAGS))" \
1331     compiler=%(compiler)
1333 ifeq (%(noref),)
1334 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1335 else
1336 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1337 endif
1339 %rule_join from=$(BD_REFS) to=%(reffile) \
1340            text="Collecting function references for module %(modname)"
1343 ## Linking
1345 ifeq (%(modsuffix),)
1346 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1347 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1348 else
1349 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1350 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1351 endif
1353 %(mmake)-quick : %(mmake)
1354 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1355 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1356 %(mmake)-linklib : $(BD_LINKLIB)
1358 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1359                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1360 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1361 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES))
1363 # The module is linked from all the compiled .o files
1364 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1365                  endobj=$(BD_ENDOBJS) err=$(BD_MODNAME).err \
1366                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1368 # Link static lib
1369 ifneq ($(BD_LINKLIB),)
1370 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1372 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1373 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1374 endif
1376 # Link kernel object file
1377 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1378     expansion keymap
1379 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1380     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1381 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1382 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1383 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1384 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1385 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1386         @$(ECHO) "Linking $@"
1387         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1388         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1390 ## Dependency fine-tuning
1392 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES))))
1393 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1395 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1396 $(BD_MODULE) : | %(prefix)/%(moduledir)
1397 $(BD_KOBJ) : | $(KOBJSDIR)
1398 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1400 # Some include files need to be generated before the .c can be parsed.
1401 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1402 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1403     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1404 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1406 BD_DFILE_DEPS := $(BD_LIBDEFSINC) %(objdir)/%(modname)_deflibdefs.h \
1407     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1408 $(BD_DEPS) : $(BD_DFILE_DEPS)
1409 endif
1411 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1412     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1413     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1414     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1415     $(addprefix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1416     %(objdir)/%(modname)_deflibdefs.h \
1417     $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1418     $(BD_ENDOBJS)
1419 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1420 %(mmake)-clean ::
1421         @$(ECHO) "Cleaning up for module %(modname)"
1422         @$(RM) $(FILES)
1424 endif # $(TARGET) in $(BD_ALLTARGETS)
1425 %end
1426 #------------------------------------------------------------------------------
1429 #------------------------------------------------------------------------------
1430 # Build a linklib.
1431 # - mmake is the mmaketarget
1432 # - libname is the baselibname e.g. lib%(libname).a will be created
1433 # - files are the C source files to include in the lib. The list of files
1434 #   has to be given without the .c suffix
1435 # - asmfiles are the asm files to include in the lib. The list of files has to
1436 #   be given with the .s suffix
1437 # - cflags are the flags to compile the source (default $(CFLAGS))
1438 # - dflags are the flags use during makedepend (default equal to cflags)
1439 # - aflags are the flags use during assembling (default $(AFLAGS))
1440 # - objdir is where the .o are generated
1441 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1442 %define build_linklib mmake=/A libname=/A files="$(basename $(wildcard *.c))" \
1443   asmfiles= cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1445 %buildid targets="%(mmake) %(mmake)-clean"
1447 # assign and generate the local variables used in this macro
1448 BD_LIBNAME$(BDID)    := %(libname)
1449 OBJDIR               ?= $(GENDIR)/$(CURDIR)
1450 BD_OBJDIR$(BDID)     := %(objdir)
1451 BD_LIBDIR$(BDID)     := %(libdir)
1453 BD_FILES$(BDID)      := %(files)
1454 BD_ASMFILES$(BDID)   := %(asmfiles)
1455 BD_SRCS$(BDID)       := $(addsuffix .c,$(BD_FILES$(BDID)))
1456 BD_OBJS$(BDID)       := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir $(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID)))))
1457 BD_DEPS$(BDID)       := $(patsubst %.o,%.d,$(BD_OBJS$(BDID)))
1459 BD_CFLAGS$(BDID)     := %(cflags)
1460 ifeq (%(dflags),)
1461 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
1462 else
1463 BD_DFLAGS$(BDID)     := %(dflags)
1464 endif
1465 BD_AFLAGS$(BDID)     := %(aflags)
1467 BD_LINKLIB$(BDID)    := $(BD_LIBDIR$(BDID))/lib$(BD_LIBNAME$(BDID)).a
1469 .PHONY : %(mmake) %(mmake)-clean
1471 #MM %(mmake) : includes-generate-deps
1472 %(mmake) : $(BD_LINKLIB$(BDID))
1475 %(mmake)-clean ::
1476         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID))
1478 ifeq ($(TARGET),%(mmake))
1479 ifneq ($(dir $(BD_FILES$(BDID))),./)
1480 vpath %.c $(filter-out ./,$(dir $(BD_FILES$(BDID))))
1481 endif
1483 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1484               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1485 %rule_assemble basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1486               aflags=$(BD_AFLAGS$(BDID))
1487 endif
1489 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS$(BDID)) libdir=$(BD_LIBDIR$(BDID))
1491 %include_deps depstargets=%(mmake) deps=$(BD_DEPS$(BDID))
1493 $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) : | $(BD_OBJDIR$(BDID))
1494 $(BD_LINKLIB$(BDID)) : | $(BD_LIBDIR$(BDID))
1495 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBDIR$(BDID))
1497 %end
1498 #------------------------------------------------------------------------------
1501 #------------------------------------------------------------------------------
1502 # Build catalogs.
1503 # - mmake is the mmaketarget
1504 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1505 # - description is the catalog description file (.cd) (default *.cd)
1506 # - subdir is the destination subdir of the catalogs
1507 # - name is the name of the destination catalog, without the .catalog suffix
1508 # - source is the path to the generated source code file
1509 # - dir is the base destination directory (default $(AROS_CATALOGS))
1510 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1512 %define build_catalogs mmake=/A name=/A subdir=/A \
1513  catalogs="$(basename $(wildcard *.ct))" source="../strings.h" \
1514  description="$(basename $(wildcard *.cd))" dir=$(AROS_CATALOGS) \
1515  sourcedescription="$(TOOLDIR)/C_h_orig"
1517 %buildid targets="%(mmake) %(mmake)-clean"
1519 BD_SRCS$(BDID) := $(addsuffix .ct, %(catalogs))
1520 BD_OBJS$(BDID) := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1521 BD_DIRS$(BDID) := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1524 %(mmake) : $(BD_OBJS$(BDID)) %(source)
1526 $(BD_OBJS$(BDID)) : | $(BD_DIRS$(BDID))
1527 GLOB_MKDIRS += $(BD_DIRS$(BDID))
1529 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1530         @$(ECHO) "Creating %(name) catalog for language $*."
1531         @$(FLEXCAT) %(description).cd $*.ct CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1533 ifneq (%(source),)
1534 %(source) : %(description).cd
1535         @$(ECHO) "Creating %(name) catalog source file %(source)"
1536         @$(FLEXCAT) %(description).cd %(source)=%(sourcedescription).sd
1537 endif
1540 %(mmake)-clean ::
1541         $(RM) $(BD_OBJS$(BDID)) %(source)
1543 .PHONY: %(mmake) %(mmake-clean)
1545 %end
1547 #-----------------------------------------------------------------------------
1549 #-----------------------------------------------------------------------------
1550 # Build icons.
1551 # - mmake is the mmaketarget
1552 # - icons is a list of icon base names (ie. without the .info suffix)
1553 # - dir is the destination directory
1554 #-----------------------------------------------------------------------------
1556 %define build_icons mmake=/A icons=/A dir=/A
1558 %buildid targets="%(mmake) %(mmake)-clean"
1560 BD_OBJS$(BDID) := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1563 %(mmake) : $(BD_OBJS$(BDID))
1565 %(dir)/%.info : %.info.src %.png
1566         @$(ECHO) Creating $(notdir $@)...
1567         @$(ILBMTOICON) $+ $@
1569 $(BD_OBJS$(BDID)) : | %(dir)
1570 GLOB_MKDIRS += %(dir)
1573 %(mmake)-clean ::
1574         @$(RM) $(BD_OBJS$(BDID))
1576 .PHONY: %(mmake)
1578 %end
1580 #-----------------------------------------------------------------------------
1582 #------------------------------------------------------------------------------
1583 # Compile files for an arch-specific replacement of code for a module
1584 # - files: the basenames of the C files to compile.
1585 # - asmfiles: the basenames of the asm files to assemble.
1586 # - mainmmake: the mmake of the module in the main directory to compile these
1587 #   arch specific files for.
1588 # - maindir: the object directory for the main module
1589 # - arch: the arch for which to compile these files. It can have the form
1590 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1591 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1592 # - dflags: the flags used during creation of dependency file. If not specified
1593 #   the same value as cflags will be used
1594 # - aflags: the flags used during assembling
1595 # - compiler: (host or target) specifies which compiler to use. By default
1596 #   the target compiler is used
1597 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1598 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1600 ifeq (%(files) %(asmfiles),)
1601   $(error no files or asmfiles given)
1602 endif
1604 %buildid targets="%(mainmmake)-%(arch)"
1606 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1607 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1608 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1610 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1612 ifeq (%(arch),)
1613   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1614 endif
1616 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1617 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1618 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1619 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1620 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1622 ifeq ($(TARGET),%(mainmmake)-%(arch))
1623 vpath %.c $(filter-out ./,$(dir %(files)))
1624 vpath %.s $(filter-out ./,$(dir %(asmfiles)))
1625 vpath %.S $(filter-out ./,$(dir %(asmfiles)))
1626 endif
1628 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1629 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1632 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1634 ifeq ($(findstring %(compiler),host target),)
1635   $(error unknown compiler %(compiler))
1636 endif
1637 ifeq (%(compiler),target)
1638 $(BD_COBJS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1639 endif
1640 ifeq (%(compiler),host)
1641 $(BD_COBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
1642 endif
1643 ifneq (%(modulename),)
1644 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1645                      --include $(GENDIR)/%(maindir)/%(modulename)_deflibdefs.h
1646 else
1647 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1648 endif
1649 ifeq ($(TARGET),%(mainmmake)-%(arch))
1650 $(BD_OBJDIR$(BDID))/%.o : %.c
1651         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD)
1652 endif
1654 ifeq (%(dflags),)
1655 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1656 else
1657 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1658 endif
1659 ifeq ($(TARGET),%(mainmmake)-%(arch))
1660 $(BD_OBJDIR$(BDID))/%.d : %.c
1661         %mkdepend_q flags=$(TMP_DFLAGS)
1662 endif
1664 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1666 ifeq ($(TARGET),%(mainmmake)-%(arch))
1667 $(BD_OBJDIR$(BDID))/%.o : %.s
1668         %assemble_q opt=$(AFLAGS)
1669 $(BD_OBJDIR$(BDID))/%.o : %.S
1670         %assemble_q opt=$(AFLAGS)
1671 endif
1673 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1674 %end
1675 #------------------------------------------------------------------------------
1683 # ======================
1684 # Old stuff, will probably be removed in the future
1689 # GNU Make automatic variables
1690 # $@ current target
1691 # $< First dependency
1692 # $? All newer dependencies
1693 # $^ All dependencies
1694 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1695 #    a.%.b, then the stem is dir/foo)
1697 #------------------------------------------------------------------------------
1698 # rule to generate libdefs.h with archtool (options may go away!)
1699 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1700 %(dest) : %(conffile) %(genlibdefstool)
1701         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1702         @%(genlibdefstool) -c -o $@ %(conffile)
1703 %end
1706 #------------------------------------------------------------------------------
1707 # generate asm files from c files (for debugging purposes)
1708 %define ctoasm_q
1709 %.s : %.c
1710         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1711         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1712 %end
1714 #------------------------------------------------------------------------------
1715 # Convert two png images to an Amiga icon file based on the description
1716 # file %(from), with outputfile going to %(to).
1717 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1718         @$(ECHO) "Creating icon %(to)..."
1719         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1720         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1721         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1722 %end
1724 #------------------------------------------------------------------------------
1725 # NOTE: The following are all part of Iain's build changes, please don't use
1726 # or change anything below this line until you know what you are doing. This
1727 # is so that I don't conflict with the semantics of any of the above macros.
1728 #------------------------------------------------------------------------------
1730 #------------------------------------------------------------------------------
1731 # Copy files from one directory to another.
1733 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1735 SRC_FILES := $(addprefix %(src)/, %(files))
1736 DST_FILES := $(addprefix %(dst)/, %(files))
1738 %(maketarget) : setup $(DST_FILES)
1740 $(DST_FILES) : %(dst)/% : %(src)/%
1741         @$(CP) $< $@
1742         
1743 setup ::
1744         %mkdirs_q %(dst)
1746 %end
1748 #----------------------------------------------------------------------------------
1749 # Copy a diretory recursively to another place, preserving the original 
1750 # hierarchical structure
1752 # src: the source directory whose content will be copied
1753 # dst: the directory where to copy src's content. If not existing, it will be made.
1755 %define copy_dir_recursive mmake=/A src=$(TOP)/$(CURDIR) dst=/A
1757 %(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)
1758 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1760 define %(mmake)_mkdir
1761 $(1):
1762         $(MKDIR) $$@
1763 endef
1765 define %(mmake)_copy
1766 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1767         $(CP) $$< $$@
1768 endef
1770 .PHONY : %(mmake)
1773 %(mmake): | $(GENDIR)/$(CURDIR)
1774         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1775         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1776         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1777         for d in $(%(mmake)_DIRS); do                      \
1778             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1779         done
1780         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1781         for f in $(%(mmake)_FILES); do                                            \
1782             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1783         done;  \
1784         for dst in %(dst); do \
1785             $(MAKE) -f $$m DST=$$dst SRC=%(src) all; \
1786         done
1788 $(GENDIR)/$(CURDIR):
1789         $(MKDIR) $@
1791 %end
1793 #------------------------------------------------------------------------------
1794 #   Copy include files into the includes directories. There are currently
1795 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1796 #   for building tools that need to run on the host system $(GENINCDIR). The
1797 #   $(GENINCDIR) path must not contain any references to the C runtime
1798 #   library header files.
1800 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1801     dir= compiler=target
1803 ifeq ($(findstring %(compiler),host target),)
1804 $(error %copy_includes: compiler argument (%(compiler)) has to be host or target)
1805 endif
1807 ifneq (%(dir),)
1808 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1809 BD_INC_PATH := %(dir)/
1810 else
1811 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1812 BD_INC_PATH :=
1813 endif
1815 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1816         @$(CP) $< $@
1819 ifeq (%(compiler),target)
1821 ifneq (%(dir),)
1822 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1823 else
1824 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1825 endif
1827 BD_INCL_FILES += $(BD_INCL_FILES2)
1829 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1830         @$(CP) $< $@
1831 endif
1834 %(mmake) : $(BD_INCL_FILES)
1836 .PHONY: %(mmake)
1838 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1839 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1840 %end
1843 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1844 STUBS_SRC := $(addsuffix .c,$(STUBS))
1845 STUBS_MEM := $(addsuffix .o,$(STUBS))
1846 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1847 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1848 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1850 #MM- linklibs : hidd-%(hidd)-stubs
1851 #MM- %(parenttarget): hidd-%(hidd)-stubs
1852 #MM hidd-%(hidd)-stubs : includes includes-copy
1853 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1855 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1856         %mklib_q from=$^
1858 $(STUBS_OBJ) : $(STUBS_SRC) 
1859         %compile_q cmd=$(TARGET_CC) opt=%(cflags)
1861 $(STUBS_DEP) : $(STUBS_SRC)
1862         %mkdepend_q flags=%(dflags)
1864 setup ::
1865         %mkdirs_q $(OBJDIR) $(LIBDIR)
1868 clean ::
1869         -@$(RM) $(HIDD_LIB) $(OBJDIR)
1871 DEPS := $(DEPS) $(STUBS_DEP)
1873 %end
1874       
1875 #------------------------------------------------------------------------------
1876 # Build an imported source tree which uses the configure script from the
1877 # autoconf package.  This rule will try to "integrate" the produced files as
1878 # much as possible in the AROS build, for example by putting libraries in the
1879 # standard library directory, includes in the standard include directory, and
1880 # so on. You can however override this behaviour.
1882 # As a special "bonus" for you, the PROGDIR environment variable is defined to
1883 # be %(bindir) (or its deduced value) when running "make install", and
1884 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
1885 # configure script some more parameters whose value depends upon the PROGDIR
1886 # env var, so that the program gets all its stuff installed in the proper place
1887 # when building it, but when running it from inside AROS it can also find that
1888 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
1889 # the configuration parameters set when running ./configure
1891 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
1892 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
1893 # to the name which has to follow it.
1896 %define build_with_configure mmake=/A srcdir=$(TOP)/$(CURDIR) prefix= \
1897     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
1898     install_target=install postconfigure= postinstall=
1900 ifneq (%(prefix),)
1901     %(mmake)-prefix := %(prefix)
1902 else
1903     %(mmake)-prefix := $(AROS_CONTRIB)
1904 endif
1906 ifneq (%(aros_prefix),)
1907     %(mmake)-aros_prefix := %(aros_prefix)
1908 else
1909     %(mmake)-aros_prefix := $(%(mmake)-prefix)
1910 endif
1912 ifeq (%(nix),yes)
1913     %(mmake)-nix    := -nix
1914     %(mmake)-volpfx := /
1915     %(mmake)-volsfx := /
1916     
1917     ifeq (%(nix_dir_layout),)
1918         %(mmake)-nix_dir_layout := yes
1919     endif
1920 else
1921     %(mmake)-volsfx := :
1922     
1923     ifeq (%(nix_dir_layout),)
1924         %(mmake)-nix_dir_layout := no
1925     endif
1926 endif
1928 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
1930 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) exec_prefix=$(%(mmake)-prefix)
1932 # Check if chosen compiler is valid
1933 ifeq ($(findstring %(compiler),host target kernel),)
1934   $(error unknown compiler %(compiler))
1935 endif
1937 # Set legacy 'host' variable based on chosen compiler
1938 ifeq (%(compiler),host)
1939     host := yes
1940 else
1941     host := no
1942 endif
1944 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) %(host)),yes)
1945     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
1946     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1947 else
1948     ifeq (%(nix),yes)
1949         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
1950         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
1951     else
1952         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1953     endif
1955     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
1956     
1957     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) sbindir=$(%(mmake)-prefix) \
1958     libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) oldincludedir=$(AROS_INCLUDES)
1959 endif
1962 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
1964 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
1966 ifneq (%(install_target),)
1967     %(mmake)-install_command = \
1968         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1969         -C $(GENDIR)/$(CURDIR) %(install_target) && \
1970         $(TOUCH) $(GENDIR)/$(CURDIR)/.installed
1972     %(mmake)-uninstall_command = \
1973     $(RM) $(GENDIR)/$(CURDIR)/.installed && \
1974     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1975     -C $(GENDIR)/$(CURDIR) uninstall
1976 else
1977     %(mmake)-install_command   := true
1978     %(mmake)-uninstall_command := true
1979 endif
1981 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
1984 %(mmake)-build_and_install-quick :  $(GENDIR)/$(CURDIR)/.configured
1985         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(GENDIR)/$(CURDIR); then \
1986             $(RM)  $(GENDIR)/$(CURDIR)/.installed && \
1987             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(GENDIR)/$(CURDIR) && \
1988             $(%(mmake)-install_command); \
1989         fi
1991 %(srcdir)/.files-touched:
1992         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
1993         $(TOUCH) $@
1996 %(mmake)-uninstall :
1997         $(%(mmake)-uninstall_command)
1999 ifneq ($(DEBUG),yes)
2000     %(mmake)-s_flag = -s
2001 endif
2004 %(mmake)-configure : $(GENDIR)/$(CURDIR)/.configured
2006 ifeq (%(compiler),host)
2007 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2008         $(RM) $@ 
2009         %mkdirs_q $(GENDIR)/$(CURDIR)
2010         cd $(GENDIR)/$(CURDIR) && \
2011         find . -name config.cache -exec $(RM) '{}' \; && \
2012         CC="$(HOST_CC)" \
2013             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2014             $(TOUCH) $@
2015 endif
2016 ifeq (%(compiler),target)
2017 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2018         $(RM) $@
2019         %mkdirs_q $(GENDIR)/$(CURDIR)
2020         cd $(GENDIR)/$(CURDIR) && \
2021         find . -name config.cache -exec $(RM) '{}' \; && \
2022         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2023             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" \
2024             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2025             --host=$(AROS_TARGET_CPU)-aros \
2026             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls \
2027             --without-x --without-pic --disable-shared && \
2028             $(TOUCH) $@
2029 endif
2030 ifeq (%(compiler),kernel)
2031 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2032         $(RM) $@
2033         %mkdirs_q $(GENDIR)/$(CURDIR)
2034         cd $(GENDIR)/$(CURDIR) && \
2035         find . -name config.cache -exec $(RM) '{}' \; && \
2036         CC="$(KERNEL_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2037             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" \
2038             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2039             --host=$(AROS_TARGET_CPU)-aros \
2040             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls \
2041             --without-x --without-pic --disable-shared && \
2042             $(TOUCH) $@
2043 endif
2044         
2046 %(mmake)-clean : %(mmake)-uninstall
2047         @$(RM) $(GENDIR)/$(CURDIR)
2048 %end
2050 #############################################################################
2051 #############################################################################
2052 ##                                                                         ##
2053 ## Miscellaneous macros. Everything that doesn't fit above should be put   ##
2054 ## here.                                                                   ##
2055 ##                                                                         ##
2056 #############################################################################
2057 #############################################################################
2059 #----------------------------------------------------------------------------------
2060 # Given an archive name, patches names and locations where to find them, fetch
2061 # the archive and the patches from any of those locations, unpack the archive
2062 # and then apply the patches.
2064 # Locations currently supported are http and ftp sites, plus local filesystem
2065 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2066 # the fetch.sh script needs to be modified, since this macro relies on that script.
2068 # Arguments:
2070 #     - archive_origins = list of locations where to find the archive. They are tried
2071 #                         in sequence, until the archive is found and fetching it 
2072 #                         succeeded. If not specified, the current directory is assumed.
2073 #     - archive         = the archive name. Mandatory.
2074 #     - destination     = the local directory where to put the archive and patches.
2075 #                         If not specified, the current directory is assumed.
2076 #     - patches_origins = list of locations where to find the patches. They are tried
2077 #                         in sequence, until a patch is found and fetching it 
2078 #                         succeeded. If not specified, the current directory is assumed.
2079 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2080 #                         patch_name[:[patch_subdir][:patch_opt]].
2081 #                         
2082 #                             - patch_name   = the name of the patch file
2083 #                             - patch_subdir = the directory within \destination\ where to
2084 #                                              apply the patch.
2085 #                             - patch_opt    = any options to pass to the `patch' command
2086 #                                              when applying the patch.
2087 #                         
2088 #                         The patch_subdir and patch_opt fields are optional.
2090 %define fetch archive_origins=. archive=/A suffixes= destination=. patches_origins=. patches_specs=::
2091         $(FETCH) -ao "%(archive_origins)" -a %(archive) -as "%(suffixes)" -d %(destination) \
2092         -po "%(patches_origins)" -p %(patches_specs)
2093 %end
2095 #-----------------------------------------------------------------------------------------
2096 # Joins the features of %fetch and %build_with_configure, taking advantage of
2097 # the naming scheme of GNU packages. GNU packages names are in the form
2099 #     <package name>-<version number>.<archive format suffix>
2101 # If a patch is provided, it *must* be named the following way:
2103 #    <package name>-<version number>-aros.diff
2105 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2106 # CD'ing into the archive's extracted directory.
2108 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2109 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2110 # to make that patch fully comprehensive.
2112 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2114 # Arguments:
2116 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2117 #                     macro.
2118 #    - package      = the GNU package name, sans version and archive format suffixes.
2119 #    - version      = the package's version number, or otherwise any other version string.
2120 #                     It gets appended to the package name to form the basename of the archive.
2121 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2122 #                     version. Each one of them is tried until a matching archive is found.
2123 #                     Defaults to "tat.bz2 tar.gz".
2124 #    - destination  = same meaning as the one for the %fetch macro
2125 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2126 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2127 #                     fetched or not
2128 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2129 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2130 #                     $(GNUDIR).
2131 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2132 #                     /GNU.
2133 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2134 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2136 %define fetch_and_build mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2137     srcdir= package_repo= patch=no patch_repo= prefix= \
2138     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2140 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2141 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2143 %(mmake)-archbase  := %(package)-%(version)
2145 ifeq (%(prefix),)
2146     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2147 else
2148     %(mmake)-prefix := %(prefix)
2149 endif
2151 ifneq (%(subpackage),)
2152     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2153 else
2154     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2155 endif
2157 ifneq (%(srcdir),)
2158     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2159 else
2160     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2161 endif
2163 ifeq (%(patch),yes)
2164     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2165 else
2166     %(mmake)-%(subpackage)-patches_specs := ::
2167 endif
2169 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2171 .PHONY : %(mmake)-%(subpackage)-fetch
2173 %(mmake)-%(subpackage)-fetch :
2174         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2175             destination=$(PORTSDIR)/%(package) \
2176             archive_origins=". %(package_repo)" \
2177             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins=". %(patch_repo)"
2179 #MM- %(mmake) : %(mmake)-%(subpackage)
2181 PACKAGES_DIR := $(AROSDIR)/../Packages
2183 %(mmake)-%(subpackage)-package-dir := $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)
2185 %(mmake)-%(subpackage)-package-basename := \
2186     $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2188 %build_with_configure mmake=%(mmake)-%(subpackage) \
2189      srcdir=$(PORTSDIR)/%(package)/$(%(mmake)-%(subpackage)-srcdir) \
2190      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-%(subpackage)-package-dir)" \
2191      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2192      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2194 .PHONY : %(mmake)-%(subpackage)-make-package
2195 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2198 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2200 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2201 #that $^ and $@ have exactly the same mtime, and in that case make tries
2202 #to rebuild $@ again, which would fail because the directory where
2203 #the package got installed would not exist anymore. 
2204 #We work this around by using an if statement to manually check the mtimes.
2205 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2206         @if test $(GENDIR)/$(CURDIR)/.installed -nt $@ || ! test -f $@; then \
2207             $(RM) $@ && \
2208             $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" && \
2209             cd $(%(mmake)-%(subpackage)-package-dir) && \
2210             tar --remove-files -cvf $(%(mmake)-%(subpackage)-package-basename).tar * && \
2211             mkdir -p "$(%(mmake)-prefix)" && \
2212             tar -xf $(%(mmake)-%(subpackage)-package-basename).tar -C "%(prefix)"/ && \
2213             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar && \
2214             cd .. && $(RM) $(%(mmake)-%(subpackage)-archbase); \
2215         fi
2216 %end
2218 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2219     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2220     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2222 GNU_REPOSITORY := http://ftp.gnu.org/pub/gnu
2224 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2225     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2226     package_repo="%(package_repo) $(GNU_REPOSITORY)/%(package)" \
2227     patch="%(patch)" patch_repo="%(patch_repo)" \
2228     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2229     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2231 %end
2233 #-----------------------------------------------------------------------------------------
2234 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2235 # that the package is a "Development" package, and as such it needs to be placed
2236 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2238 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2239 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2240 # "mmake" argument, because the metatarget is implicitely defined as
2242 #     #MM- development-%(package)
2244 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2245     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2246     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2248 #MM- development : development-%(package)
2251 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2252    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2253    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2254    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2255    extraoptions="%(extraoptions)"
2256     
2257 %end