Don't use -iquote directly.
[cake.git] / config / make.tmpl
blob9023d25ee4af69904c507eb858be69da8e7655c6
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 %(from)"
17         @$(IF) %(cmd) $(CFLAGS_IQUOTE) $(SRCDIR)/$(CURDIR) $(CFLAGS_IQUOTE) . $(CFLAGS_IQUOTE_END) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) $(CFLAGS_IQUOTE) $(SRCDIR)/$(CURDIR) $(CFLAGS_IQUOTE) . $(CFLAGS_IQUOTE_END) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) $(CFLAGS_IQUOTE) $(SRCDIR)/$(CURDIR) $(CFLAGS_IQUOTE) . $(CFLAGS_IQUOTE_END) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS)
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) -I$(SRCDIR)/$(CURDIR) %(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) : COPYSRCDIR := %(srcdir)
201 %(stampfile) : TGTDIR := %(targetdir)
202 %(stampfile) : FILES := %(files)
203 %(stampfile) : $(addprefix %(srcdir)/,%(files))
204         @for f in $(FILES); do \
205              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
206                  $(CP) $(COPYSRCDIR)/$$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 nix=no
277 ifeq (%(targetdir),)
278   TMP_TARGETBASE := %(basename)
279 else
280   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
281 endif
283 ifeq ($(findstring %(compiler),host kernel 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
294 ifeq (%(compiler),kernel)
295 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
296 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 endif
299 ifeq (%(nix),yes)
300   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
301 else
302   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
303 endif
304 $(TMP_TARGETBASE).o : %(basename).c
305         %compile_q cmd=$(TMP_CMD)
307 ifeq (%(dflags),)
308   ifeq (%(nix),yes)
309     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
310   else
311     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
312   endif
313 else
314   ifeq (%(nix),yes)
315     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
316   else
317     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
318   endif
319 endif
320 $(TMP_TARGETBASE).d : %(basename).c
321         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
322 %end
323 #------------------------------------------------------------------------------
326 #------------------------------------------------------------------------------
327 # Generate a rule to compile multiple C source files to an object file and
328 # generate the corresponding dependency files. The generated file will be put
329 # in the object directory without the directory part of the source file.
330 # options
331 # - basenames: the basenames of the files to compile. The names may include
332 #   relative or absolute path names. No wildcard is allowed
333 # - cflags (default $(CFLAGS)): the C flags to use for compilation
334 # - dflags: the flags used during creation of dependency file. If not specified
335 #   the same value as cflags will be used
336 # - targetdir: the directory to put the .o file and the .d file. By default
337 #   it is put in the same directory as the .c file. When targetdir is not
338 #   empty, path names will be stripped from the file names so that all files
339 #   are in that dir and not in subdirectories.
340 # - compiler (default target): compiler to use, target, kernel or host
341 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
342     compiler=target
344 ifeq (%(targetdir),)
345 TMP_TARGETS := $(addsuffix .o,%(basenames))
346 TMP_DTARGETS := $(addsuffix .d,%(basenames))
347 TMP_WILDCARD := %
348 else
349 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
350 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
351 TMP_WILDCARD := %(targetdir)/%
353 # Be sure that all .c files are generated
354 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
356 # Be sure that all .c files are found
357 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
358 ifneq ($(TMP_DIRS),)
359     vpath %.c $(TMP_DIRS)
360 endif
362 endif
364 ifeq ($(findstring %(compiler),host kernel target),)
365   $(error unknown compiler %(compiler))
366 endif
367 ifeq (%(compiler),target)
368 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
369 endif
370 ifeq (%(compiler),host)
371 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
372 endif
373 ifeq (%(compiler),kernel)
374 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
375 endif
377 $(TMP_TARGETS) : CFLAGS := %(cflags)
378 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
379         %compile_q cmd=$(CMD)
381 ifeq (%(dflags),)
382 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
383 else
384 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
385 endif
386 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
387         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
388 %end
389 #------------------------------------------------------------------------------
392 #------------------------------------------------------------------------------
393 # Make an alias from one arch specific build to another arch.
394 # arguments:
395 # - mainmmake: the mmake of the module in the main tree
396 # - arch: the current arch
397 # - alias: the alias to which this should point
398 %define rule_archalias mainmmake=\A arch=\A alias=\A
400 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
401 %end
402 #------------------------------------------------------------------------------
405 #------------------------------------------------------------------------------
406 # Generate a rule to compile a C source file to a shared object file with a
407 # .so suffix. Basename may contain a directory part, then the source
408 # file has to be in that directory. The generated file will be put in the
409 # object directory without the directory.
410 # options
411 # - basename: the basename of the file to compile. Use % for a wildcard rule
412 # - cflags (default $(CFLAGS)): the C flags to use for compilation
413 # - targetdir: the directory to put the .o file and the .d file. By default
414 #   it is put in the same directory as the .c file
415 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
417 ifeq (%(targetdir),)
418   TMP_TARGETBASE := %(basename)
419 else
420   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
421 endif
423 ifeq ($(findstring %(compiler),host kernel target),)
424   $(error unknown compiler %(compiler))
425 endif
426 ifeq (%(compiler),target)
427 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
428 endif
429 ifeq (%(compiler),host)
430 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
431 endif
432 ifeq (%(compiler),kernel)
433 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
434 endif
436 $(TMP_TARGETBASE).so : %(basename).c
437         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD)
438 %end
439 #------------------------------------------------------------------------------
442 #------------------------------------------------------------------------------
443 # Generate a rule to assemble a source file to an object file. Basename may
444 # contain a directory part, then the source file has to be in that directory.
445 # The generated file will be put in the object directory without the directory.
446 # options
447 # - basename: the basename of the file to compile. Use % for a wildcard rule
448 # - flags (default $(AFLAGS)): the asm flags to use for assembling
449 # - targetdir: the directory to put the .o file in. By default it is put in the
450 #   same directory as the .s file
451 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
453 ifeq (%(targetdir),)
454 %(basename).o : AFLAGS := %(aflags)
455 %(basename).o : %(basename).s
456         %assemble_q
458 else
459 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
460 %(targetdir)/$(notdir %(basename)).o : %(basename).s
461         %assemble_q
463 endif
464 %end
465 #------------------------------------------------------------------------------
468 #------------------------------------------------------------------------------
469 # Generate a rule to assemble multiple source files to an object file. The
470 # generated file will be put in the object directory with the directory part
471 # of the source file stripped off.
472 # options
473 # - basenames: the basenames of the files to compile. The names may include
474 #   relative or absolute path names. No wildcard is allowed
475 # - aflags (default $(AFLAGS)): the flags to use for assembly
476 # - targetdir: the directory to put the .o file and the .d file. By default
477 #   it is put in the same directory as the .c file. When targetdir is not
478 #   empty, path names will be stripped from the file names so that all files
479 #   are in that dir and not in subdirectories.
480 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
482 ifeq (%(targetdir),)
483 TMP_TARGETS := $(addsuffix .o,%(basenames))
484 TMP_WILDCARD := %
485 else
486 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
487 TMP_WILDCARD := %(targetdir)/%
489 # Be sure that all .s files are generated
490 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
492 # Be sure that all .c files are found
493 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
494 ifneq ($(TMP_DIRS),)
495     vpath %%(suffix) $(TMP_DIRS)
496 endif
498 endif
500 $(TMP_TARGETS) : AFLAGS := %(aflags)
501 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
502         %assemble_q opt=$(AFLAGS)
503 %end
504 #------------------------------------------------------------------------------
507 #------------------------------------------------------------------------------
508 # Link %(objs) to %(prog) using the libraries in %(uselibs)
509 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
510     usehostlibs= usestartup=yes detach=no nix=no
512 TMP_EXTRA_LDFLAGS := 
513 ifeq (%(nix),yes)
514     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
515 endif
516 ifeq (%(usestartup),no)
517     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
518 endif
519 ifeq (%(detach),yes)
520     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
521 endif
523 # Make a list of the lib files this program depends on.
524 ifneq (%(uselibs),)
525 # In LDFLAGS remove white space between -L and directory
526 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
527 # Filter out only the libdirs and remove -L
528 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
529 # Add trailing /
530 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
531 # Add normal linklib path
532 TMP_DIRS += $(LIBDIR)/
533 # add lib and .a to static linklib names
534 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
535 # search for the linklibs in the given path, ignore ones not found
536 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
537     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
539 else
540 TMP_DEPLIBS :=
541 endif
543 %(prog) : OBJS := %(objs)
544 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
545 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
546 %(prog) : %(objs) $(TMP_DEPLIBS)
547         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
548 %end
549 #------------------------------------------------------------------------------
552 #------------------------------------------------------------------------------
553 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
554 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
555 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
556     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
557     usestartup=yes detach=no
559 TMP_EXTRA_LDFLAGS := 
560 ifeq (%(nix),yes)
561     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
562 endif
563 ifeq (%(usestartup),no)
564     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
565 endif
566 ifeq (%(detach),yes)
567     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
568 endif
570 # Make a list of the lib files the programs depend on.
571 ifneq (%(uselibs),)
572 # In LDFLAGS remove white space between -L and directory
573 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
574 # Filter out only the libdirs and remove -L
575 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
576 # Add trailing /
577 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
578 # Add normal linklib path
579 TMP_DIRS += $(LIBDIR)/lib/
580 # add lib and .a to static linklib names
581 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
582 # search for the linklibs in the given path, ignore ones not found
583 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
584     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
586 else
587 TMP_DEPLIBS :=
588 endif
590 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
591 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
592 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
593         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
594 %end
595 #------------------------------------------------------------------------------
598 #------------------------------------------------------------------------------
599 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
600 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
602 %(libdir)/lib%(libname).a : %(objs)
603         %mklib_q from=$^
604 %end
605 #------------------------------------------------------------------------------
608 #------------------------------------------------------------------------------
609 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
610 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
612 %(libdir)/lib%(libname).so : %(objs)
613         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
614 %end
615 #------------------------------------------------------------------------------
618 #------------------------------------------------------------------------------
619 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
620 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
621 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
622     uselibs= usehostlibs=
624 %(module) : OBJS := %(objs)
625 %(module) : ENDTAG := %(endobj)
626 %(module) : ERR := %(err)
627 %(module) : OBJDIR := %(objdir)
628 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
629 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
630         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR)
632 %end
633 #------------------------------------------------------------------------------
636 #------------------------------------------------------------------------------
637 # Generate a rule to generate a function reference file from a C source file.
638 # Basename may contain a directory part, then the source file has to be in that
639 # directory. The generated file will be put in the object directory without the
640 # directory.
641 # options
642 # - basename: the basename of the file to compile. Use % for a wildcard rule
643 # - cflags (default $(CFLAGS)): the C flags to use for compilation
644 # - targetdir: the directory to put the generated .ref file. By default the
645 #   .ref file will be put in the same directory as the .c file.
646 # - includefile: This file will be included at the head of the source file
647 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
649 ifeq (%(targetdir),)
650 GENFILE_TMP := %(basename).ref
651 else
652 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
653 endif
655 ifeq ($(filter %(compiler),target kernel host),)
656 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
657 endif
659 ifeq (%(compiler),target)
660 $(GENFILE_TMP) : CC:=$(TARGET_CC)
661 endif
662 ifeq (%(compiler),host)
663 $(GENFILE_TMP) : CC:=$(HOST_CC)
664 endif
665 ifeq(%(compiler),kernel)
666 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
667 endif
669 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
670 ifeq (%(includefile),)
671         %mkref_q cc=$(CC) cflags="%(cflags)"
672 else
673         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
674 endif
676 %end
677 #------------------------------------------------------------------------------
680 #------------------------------------------------------------------------------
681 # Generate a rule to generate a function reference file from a C source file.
682 # Basename may contain a directory part, then the source file has to be in that
683 # directory. The generated file will be put in the object directory without the
684 # directory.
685 # options
686 # - basenames: the basenames of the files to compile. No wildcard is allowed
687 # - cflags (default $(CFLAGS)): the C flags to use for compilation
688 # - targetdir: the directory to put the generated .ref file. By default the
689 #   .ref file will be put in the same directory as the .c file. When targetdir
690 #   is not empty all files will be put there and path parts in the basenames
691 #   will be stripped off.
692 # - includefile: This file will be included at the head of the source file
693 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
694     compiler=target
696 ifeq (%(targetdir),)
697 TMP_TARGETS := $(addsuffix .ref,%(basenames))
698 TMP_WILDCARD := %.ref
699 else
700 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
701 TMP_WILDCARD := %(targetdir)/%.ref
703 # Be sure that all .c files are generated
704 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
706 # Be sure that all .c files are found
707 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
708 ifneq ($(TMP_DIRS),)
709     vpath %.c $(TMP_DIRS)
710 endif
712 endif
714 ifeq ($(filter %(compiler),target kernel host),)
715 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
716 endif
718 ifeq (%(compiler),target)
719 $(TMP_TARGETS) : CC:=$(TARGET_CC)
720 endif
721 ifeq (%(compiler),host)
722 $(TMP_TARGETS) : CC:=$(HOST_CC)
723 endif
724 ifeq (%(compiler),kernel)
725 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
726 endif
727 ifeq (%(includefile),)
728 $(TMP_TARGETS) : CFLAGS:=%(cflags)
729 else
730 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
731 $(TMP_TARGETS) : %(includefile)
732 endif
733 $(TMP_TARGETS) : $(CXREF)
734 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
735         %mkref_q cc=$(CC)
736 %end
737 #------------------------------------------------------------------------------
740 #------------------------------------------------------------------------------
741 # Generate the libdefs.h include file for a module.
742 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
744 TMP_TARGET := %(modname)_libdefs.h
745 TMP_DEPS := $(GENMODULE)
746 TMP_OPTS := 
747 ifneq (%(conffile),)
748     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
749     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
750 else
751     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
752     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
753 endif
754 ifneq (%(modsuffix),)
755     TMP_OPTS += -s %(modsuffix)
756 endif
757 ifneq (%(targetdir),)
758     TMP_OPTS += -d %(targetdir)
759     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
760 endif
762 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
763 $(TMP_TARGET) : MODNAME := %(modname)
764 $(TMP_TARGET) : MODTYPE := %(modtype)
765 $(TMP_TARGET) : $(TMP_DEPS)
766         @$(ECHO) "Generating $(notdir $@)"
767         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
768 %end
769 #------------------------------------------------------------------------------
772 #------------------------------------------------------------------------------
773 # Generate the libdefs.h include file for a module.
774 %define rule_genmodule_funclist \
775     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
777 TMP_TARGET := %(modname).funclist
778 TMP_DEPS := $(GENMODULE)
779 TMP_OPTS := 
780 ifeq (%(reffile),)
781     $(error reffile needed in rule_genmodule_funclist but none specified)
782 endif
783 TMP_OPTS := -r %(reffile)
784 TMP_DEPS += %(reffile)
785 ifneq (%(conffile),)
786     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
787     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
788 else
789     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
790     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
791 endif
792 ifneq (%(modsuffix),)
793     TMP_OPTS += -s %(modsuffix)
794 endif
795 ifneq (%(targetdir),)
796     TMP_OPTS += -d %(targetdir)
797     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
798 endif
800 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
801 $(TMP_TARGET) : MODNAME := %(modname)
802 $(TMP_TARGET) : MODTYPE := %(modtype)
803 $(TMP_TARGET) : $(TMP_DEPS)
804         @$(ECHO) "Generating $(notdir $@)"
805         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
806 %end
807 #------------------------------------------------------------------------------
810 #------------------------------------------------------------------------------
811 # Generate a Makefile.%(modname) with the genmodule program and include this
812 # generated file in this Makefile
813 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
814     targetdir=
816 TMP_TARGET := Makefile.%(modname)
817 TMP_DEPS := $(GENMODULE)
818 TMP_OPTS := 
819 ifneq (%(conffile),)
820     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
821     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
822 else
823     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
824     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
825 endif
826 ifneq (%(modsuffix),)
827     TMP_OPTS += -s %(modsuffix)
828 endif
829 ifneq (%(targetdir),)
830     TMP_OPTS += -d %(targetdir)
831     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
832 endif
834 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
835 $(TMP_TARGET) : MODNAME := %(modname)
836 $(TMP_TARGET) : MODTYPE := %(modtype)
837 $(TMP_TARGET) : $(TMP_DEPS)
838         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
839 %end
840 #------------------------------------------------------------------------------
842 #------------------------------------------------------------------------------
843 # Generate dummy support files so cxref when used on the a module source file
844 # will find something to include. This rule has to be preceeded by
845 # %rule_genmodule_makefile
846 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
848 ifneq ($(%(modname)_INCLUDES),)
849 TMP_TARGETS := $(%(modname)_INCLUDES)
851 TMP_DEPS := $(GENMODULE)
852 TMP_OPTS := 
853 ifneq (%(conffile),)
854     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
855     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
856 else
857     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
858     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
859 endif
860 ifneq (%(modsuffix),)
861     TMP_OPTS += -s %(modsuffix)
862 endif
863 ifneq (%(targetdir),)
864     TMP_OPTS += -d %(targetdir)
865     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
866 endif
868 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
869 $(TMP_TARGETS) : MODNAME := %(modname)
870 $(TMP_TARGETS) : MODTYPE := %(modtype)
871 $(TMP_TARGETS) : $(TMP_DEPS)
872         @$(ECHO) "Generating dummy include files"
873         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
874 endif
875 %end
876 #------------------------------------------------------------------------------
879 #------------------------------------------------------------------------------
880 # Generate the support files for compiling a module. This includes include
881 # files and source files. This rule has to be preceeded by
882 # %rule_genmodule_makefile
883 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
884     conffile= reffile=
886 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
887                $(%(modname)_LINKLIBFILES)
888 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
890 TMP_DEPS := $(GENMODULE)
891 ifeq ($(%(modname)_NEEDREF), yes)
892     ifeq (%(reffile),)
893         $(error reffile needed in rule_genmodule_files but none specified)
894     endif
895     TMP_OPTS := -r %(reffile)
896     TMP_DEPS += %(reffile)
897 else
898     TMP_OPTS :=
899 endif
900 ifneq (%(conffile),)
901     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
902     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
903 else
904     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
905     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
906 endif
907 ifneq (%(modsuffix),)
908     TMP_OPTS += -s %(modsuffix)
909 endif
910 ifneq (%(targetdir),)
911     TMP_OPTS += -d %(targetdir)
912     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
913 endif
915 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
916 $(TMP_TARGETS) : MODNAME := %(modname)
917 $(TMP_TARGETS) : MODTYPE := %(modtype)
918 $(TMP_TARGETS) : $(TMP_DEPS)
919         @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
920 ifneq (%(conffile),lib.conf)
921         @$(IF) $(TEST) -f lib.conf; then \
922           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
923         fi
924 endif
925         @$(IF) $(TEST) -f libdefs.h; then \
926           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
927         fi
928         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
929 %end
930 #------------------------------------------------------------------------------
932 #------------------------------------------------------------------------------
933 # Generate the support files for compiling a module. This includes include
934 # files and source files.
935 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
936     targetdir= conffile= reffile=
939 ifneq ($(%(modname)_INCLUDES),)
940 TMP_TARGETS := $(%(modname)_INCLUDES)
942 TMP_DEPS := $(GENMODULE)
943 ifeq ($(%(modname)_NEEDREF), yes)
944     ifeq (%(reffile),)
945         $(error reffile needed in rule_genmodule_files but none specified)
946     endif
947     TMP_OPTS := -r %(reffile)
948     TMP_DEPS += %(reffile)
949 else
950     TMP_OPTS :=
951 endif
952 ifneq (%(conffile),)
953     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
954     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
955 else
956     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
957     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
958 endif
959 ifneq (%(modsuffix),)
960     TMP_OPTS += -s %(modsuffix)
961 endif
962 ifneq (%(targetdir),)
963     TMP_OPTS += -d %(targetdir)
964     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
965 endif
967 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
968 $(TMP_TARGETS) : MODNAME := %(modname)
969 $(TMP_TARGETS) : MODTYPE := %(modtype)
970 $(TMP_TARGETS) : $(TMP_DEPS)
971         @$(ECHO) "Generating include files"
972         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
973 endif
974 %end
975 #------------------------------------------------------------------------------
977 #------------------------------------------------------------------------------
978 # Common rules for all makefiles
979 %define common
980 # Delete generated makefiles
982 clean ::
983         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
985 include $(SRCDIR)/config/make.tail
987 BDID := $(BDTARGETID)
988 %end
989 #------------------------------------------------------------------------------
990       
992 #############################################################################
993 #############################################################################
994 ##                                                                         ##
995 ## Here are the mmakefile build macro's. These are macro's that takes care ##
996 ## of everything to go from the sources to the generated target. Also all  ##
997 ## intermediate files and directories that are needed are created by these ##
998 ## rules.                                                                  ##
999 ##                                                                         ##
1000 #############################################################################
1001 #############################################################################
1003 #------------------------------------------------------------------------------
1004 # Build a program
1005 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1006     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1007     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1008     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1009     srcdir=
1011 .PHONY : %(mmake)
1013 BD_PROGNAME  := %(progname)
1014 BD_OBJDIR    := %(objdir)
1015 BD_TARGETDIR := %(targetdir)
1017 BD_FILES     := %(files)
1018 BD_ASMFILES  := %(asmfiles)
1019 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES) $(BD_ASMFILES)))
1020 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1022 BD_CFLAGS    := %(cflags)
1023 BD_AFLAGS    := %(aflags)
1024 BD_DFLAGS    := %(dflags)
1025 BD_LDFLAGS   := %(ldflags)
1028 %(mmake)-quick : %(mmake)
1030 #MM %(mmake) : includes-generate-deps
1031 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1033 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1034 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1035     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1036 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1037     aflags=$(BD_AFLAGS)
1039 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1040     objs=$(BD_OBJS) ldflags=$(BD_LDFLAGS) \
1041     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1042     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
1044 endif
1046 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1048 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1049 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1050 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1052 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1054 %(mmake)-clean ::
1055         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1056         @$(RM) $(FILES)
1058 %end
1059 #------------------------------------------------------------------------------
1062 #------------------------------------------------------------------------------
1063 # Build programs, for every C file an executable will be built with the same
1065 %define build_progs mmake=/A files=/A nix=no \
1066     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1067     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1068     uselibs= usehostlibs= usestartup=yes detach=no
1070 .PHONY : %(mmake)
1072 BD_OBJDIR    := %(objdir)
1073 BD_TARGETDIR := %(targetdir)
1075 BD_FILES     := %(files)
1076 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1077 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1078 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1080 BD_CFLAGS    := %(cflags)
1081 BD_DFLAGS    := %(dflags)
1082 BD_LDFLAGS   := %(ldflags)
1085 %(mmake)-quick : %(mmake)
1087 #MM %(mmake) : includes-generate-deps
1088 %(mmake) : $(BD_EXES)
1090 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1091 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1092     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1094 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1095     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1096     ldflags=$(BD_LDFLAGS) \
1097     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1098     usestartup="%(usestartup)" detach="%(detach)"
1100 endif
1102 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1104 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1105 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1106 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1108 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1110 %(mmake)-clean ::
1111         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1112         @$(RM) $(FILES)
1114 %end
1115 #------------------------------------------------------------------------------
1118 #------------------------------------------------------------------------------
1119 # Build a module.
1120 # This is a bare version: It just compiles and links the given files. It is
1121 # assumed that all needed boiler plate code is in the files. This should only
1122 # be used for compiling external code. For AROS code use %build_module
1123 %define build_module_simple mmake=/A modname=/A modtype=/A \
1124     files="$(basename $(call WILDCARD, *.c))" \
1125     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1126     objdir=$(OBJDIR) moduledir= \
1127     uselibs= usehostlibs= compiler=target
1129 # Define metamake targets and their dependencies
1130 #MM %(mmake) : core-linklibs includes-generate-deps
1131 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1132 #MM %(mmake)-quick
1133 #MM %(mmake)-clean
1135 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1137 .PHONY : $(BD_ALLTARGETS)
1139 ifeq (%(modname),)
1140 $(error using %build_module_simple: modname may not be empty)
1141 endif
1142 ifeq (%(modtype),)
1143 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1144 endif
1146 # Default values for variables and arguments
1147 BD_DEFLINKLIBNAME := %(modname)
1148 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1149 BD_DEFDFLAGS := %(cflags)
1150 OBJDIR ?= $(GENDIR)/$(CURDIR)
1151 BD_MODDIR := %(moduledir)
1152 ifeq ($(BD_MODDIR),)
1153   ifeq (%(modtype),library)
1154     BD_MODDIR  := $(AROS_LIBS)
1155   endif
1156   ifeq (%(modtype),gadget)
1157     BD_MODDIR  := $(AROS_GADGETS)
1158   endif
1159   ifeq (%(modtype),datatype)
1160     BD_MODDIR  := $(AROS_DATATYPES)
1161   endif
1162   ifeq (%(modtype),handler)
1163     BD_MODDIR  := $(AROS_FS)
1164   endif
1165   ifeq (%(modtype),device)
1166     BD_MODDIR  := $(AROS_DEVS)
1167   endif
1168   ifeq (%(modtype),resource)
1169     BD_MODDIR  := $(AROS_RESOURCES)
1170   endif
1171   ifeq (%(modtype),mui)
1172     BD_MODDIR  := $(AROS_CLASSES)/Zune
1173   endif
1174   ifeq (%(modtype),mcc)
1175     BD_MODDIR  := $(AROS_CLASSES)/Zune
1176   endif
1177   ifeq (%(modtype),mcp)
1178     BD_MODDIR  := $(AROS_CLASSES)/Zune
1179   endif
1180   ifeq (%(modtype),hidd)
1181     BD_MODDIR  := $(AROS_DRIVERS)
1182   endif
1183 endif
1184 ifeq ($(BD_MODDIR),)
1185   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1186 endif
1188 %rule_compile_multi \
1189     basenames="%(files)" targetdir="%(objdir)" \
1190     cflags="%(cflags)" dflags="%(dflags)" \
1191     compiler=%(compiler)
1193 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1194 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1196 %(mmake)-quick : %(mmake)
1197 %(mmake) : $(BD_MODULE)
1198 %(mmake)-kobj : $(BD_KOBJ)
1200 # The module is linked from all the compiled .o files
1201 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1202 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1203                  endobj= err=%(modname).err objdir=%(objdir) \
1204                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1206 # Link kernel object file
1207 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1208     expansion keymap
1209 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1210     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1211 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1212 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1213 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1214 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1215 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1216         @$(ECHO) "Linking $@"
1217         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1218         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1221 ## Dependency fine-tuning
1223 BD_DEPS       := $(addprefix %(objdir), $(addsuffix .o,%(files)))
1224 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1226 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1227 $(BD_MODULE) : | $(BD_MODDIR)
1228 $(BD_KOBJ) : | $(KOBJSDIR)
1229 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1231 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1232 %(mmake)-clean ::
1233         @$(ECHO) "Cleaning up for module %(modname)"
1234         @$(RM) $(FILES)
1235 %end
1238 #------------------------------------------------------------------------------
1239 # Build a module
1240 # Explanation of this macro is done in the developer's manual
1241 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1242   conffile= files="$(basename $(call WILDCARD, *.c))" \
1243   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1244   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1245   reffile=$(BD_DEFREFFILE) noref= \
1246   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1247   compiler=target
1249 # Define metamake targets and their dependencies
1250 #MM- includes-all : %(mmake)-includes
1251 #MM %(mmake) : %(mmake)-includes core-linklibs
1252 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1253 #MM %(mmake)-linklib : %(mmake)-includes
1254 #MM %(mmake)-quick : %(mmake)-includes-quick
1255 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1256 #MM     includes-generate-deps
1257 #MM %(mmake)-includes-quick
1258 #MM %(mmake)-includes-dirs
1259 #MM %(mmake)-makefile
1260 #MM %(mmake)-funclist
1261 #MM %(mmake)-clean
1263 # All MetaMake targets defined by this macro
1264 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1265     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1266     %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1268 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1270 ifeq (%(modname),)
1271 $(error using %build_module: modname may not be empty)
1272 endif
1273 ifeq (%(modtype),)
1274 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1275 endif
1277 # Default values for variables and arguments
1278 BD_DEFLINKLIBNAME := %(modname)
1279 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1280 BD_DEFDFLAGS := %(cflags)
1281 OBJDIR ?= $(GENDIR)/$(CURDIR)
1283 ## Create genmodule include Makefile for the module
1285 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1287 %rule_genmodule_makefile \
1288     modname=%(modname) modtype=%(modtype) \
1289     modsuffix=%(modsuffix) targetdir=%(objdir) \
1290     conffile=%(conffile)
1292 %(objdir)/Makefile.%(modname) : | %(objdir)
1294 GLOB_MKDIRS += %(objdir)
1296 # Do not parse these statements if metatarget is not appropriate
1297 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1299 include %(objdir)/Makefile.%(modname)
1301 BD_DEFMODDIR := $(%(modname)_MODDIR)
1304 ## include files generation
1306 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1307 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1308 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1310 %(mmake)-includes-quick : %(mmake)-includes
1311 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1312     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1313     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1315 ifneq ($(%(modname)_INCLUDES),)
1316 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1317                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1318                          conffile=%(conffile) reffile=%(reffile)
1320 %rule_copy_diff_multi \
1321     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1322     stampfile=%(objdir)/%(modname)_geninc
1324 %rule_copy_diff_multi \
1325     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1326     stampfile=%(objdir)/%(modname)_incs
1328 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1329                       modsuffix=%(modsuffix) \
1330                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1332 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1334 TMP%(modname)_INCDIRS := \
1335     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1336     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1337     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1338 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1340 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1341 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1343 endif
1345 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1346                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1347                            conffile=%(conffile)
1349 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1350 $(BD_DEFLIBDEFSINC) :
1351         @$(ECHO) "generating $@"
1352         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1354 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1355 GLOB_MKDIRS += %(objdir)/include
1357 ## Generation of the funclist file
1359 %(mmake)-funclist : %(modname).funclist
1361 %rule_genmodule_funclist \
1362     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1363     conffile=%(conffile) reffile=%(reffile)
1366 ## Extra genmodule src files generation
1367 ## 
1368 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1369                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1370                       conffile=%(conffile) reffile=%(reffile)
1372 ## Compilation
1374 BD_FILES      := %(files)
1375 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1376 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1377 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1379 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1380 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1381 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1383 TMP_QUOTE     := $(CFLAGS_IQUOTE) $(TOP)/$(CURDIR) \
1384     $(addprefix $(CFLAGS_IQUOTE),$(BD_FDIRS)) \
1385     $(CFLAGS_IQUOTE_END)
1386 BD_CFLAGS     := $(TMP_QUOTE) %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1387 BD_DFLAGS     := $(TMP_QUOTE) %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1389 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1390 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1391 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1392     BD_LINKLIB :=
1393 else
1394     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1395 endif
1396 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1398 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1399 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1401 %rule_compile_multi \
1402     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1403     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1404     compiler=%(compiler)
1405 %rule_compile_multi \
1406     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1407     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1408     compiler=%(compiler)
1410 ifneq ($(BD_LINKLIBAFILES),)
1411 %rule_assemble_multi \
1412     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1413 endif
1415 ## function reference files generation
1417 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1418 %rule_ref_multi \
1419     basenames=$(BD_FILES) targetdir=%(objdir) \
1420     cflags=$(BD_CFLAGS_REF) \
1421     compiler=%(compiler)
1423 ifeq (%(noref),)
1424 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1425 else
1426 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1427 endif
1429 %rule_join from=$(BD_REFS) to=%(reffile) \
1430            text="Collecting function references for module %(modname)"
1433 ## Linking
1435 ifeq (%(modsuffix),)
1436 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1437 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1438 else
1439 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1440 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1441 endif
1443 %(mmake)-quick : %(mmake)
1444 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1445 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1446 %(mmake)-linklib : $(BD_LINKLIB)
1448 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1449                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1450 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1451 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1452                  %(linklibobjs)
1454 # The module is linked from all the compiled .o files
1455 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1456                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1457                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1459 # Link static lib
1460 ifneq ($(BD_LINKLIB),)
1461 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1463 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1464 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1465 endif
1467 # Link kernel object file
1468 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1469     expansion keymap
1470 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1471     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1472 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1473 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1474 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1475 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1476 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1477         @$(ECHO) "Linking $@"
1478         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1479         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1481 ## Dependency fine-tuning
1483 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1484 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1486 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1487 $(BD_MODULE) : | %(prefix)/%(moduledir)
1488 $(BD_KOBJ) : | $(KOBJSDIR)
1489 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1491 # Some include files need to be generated before the .c can be parsed.
1492 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1493 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1494     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1495 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1497 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1498     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1499 $(BD_DEPS) : $(BD_DFILE_DEPS)
1500 endif
1502 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1503     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1504     %(objdir)/Makefile.%(modname) \
1505     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1506     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1507     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1508     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1509     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1510     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1511     $(BD_ENDOBJS)
1512 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1513 %(mmake)-clean ::
1514         @$(ECHO) "Cleaning up for module %(modname)"
1515         @$(RM) $(FILES)
1517 endif # $(TARGET) in $(BD_ALLTARGETS)
1518 %end
1519 #------------------------------------------------------------------------------
1522 #------------------------------------------------------------------------------
1523 # Build a linklib.
1524 # - mmake is the mmaketarget
1525 # - libname is the baselibname e.g. lib%(libname).a will be created
1526 # - files are the C source files to include in the lib. The list of files
1527 #   has to be given without the .c suffix
1528 # - asmfiles are the asm files to include in the lib. The list of files has to
1529 #   be given without the .s suffix
1530 # - objs additional object to link into the linklib. The objects have to be
1531 #   given with full absolute path and the .o suffix.
1532 # - cflags are the flags to compile the source (default $(CFLAGS))
1533 # - dflags are the flags use during makedepend (default equal to cflags)
1534 # - aflags are the flags use during assembling (default $(AFLAGS))
1535 # - objdir is where the .o are generated
1536 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1537 %define build_linklib mmake=/A libname=/A \
1538   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1539   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1541 # assign and generate the local variables used in this macro
1542 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1544 BD_FILES      := %(files)
1545 BD_ASMFILES   := %(asmfiles)
1547 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1548 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1549 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1551 BD_OBJS       := $(BD_ARCHOBJS) \
1552                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1553                  %(objs)
1554 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1556 BD_CFLAGS     := %(cflags)
1557 ifeq (%(dflags),)
1558 BD_DFLAGS     := $(BD_CFLAGS)
1559 else
1560 BD_DFLAGS     := %(dflags)
1561 endif
1562 BD_AFLAGS     := %(aflags)
1564 BD_LINKLIB    := %(libdir)/lib%(libname).a
1566 .PHONY : %(mmake) %(mmake)-clean
1568 #MM %(mmake) : includes-generate-deps
1569 %(mmake) : $(BD_LINKLIB)
1572 %(mmake)-clean ::
1573         @$(RM) $(BD_OBJS) $(BD_DEPS)
1575 ifeq ($(TARGET),%(mmake))
1576 ifneq ($(dir $(BD_FILES)),./)
1577 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1578 endif
1580 %rule_compile basename=% targetdir=%(objdir) \
1581               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1582 %rule_assemble basename=% targetdir=%(objdir) \
1583               aflags=$(BD_AFLAGS)
1584 endif
1586 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1588 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1590 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1591 $(BD_LINKLIB) : | %(libdir)
1592 GLOB_MKDIRS += %(objdir) %(libdir)
1594 %end
1595 #------------------------------------------------------------------------------
1598 #------------------------------------------------------------------------------
1599 # Build catalogs.
1600 # - mmake is the mmaketarget
1601 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1602 # - description is the catalog description file (.cd) (default *.cd)
1603 # - subdir is the destination subdir of the catalogs
1604 # - name is the name of the destination catalog, without the .catalog suffix
1605 # - source is the path to the generated source code file
1606 # - dir is the base destination directory (default $(AROS_CATALOGS))
1607 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1609 %define build_catalogs mmake=/A name=/A subdir=/A \
1610  catalogs="$(basename $(call WILDCARD, *.ct))" source="../strings.h" \
1611  description="$(basename $(call WILDCARD, *.cd))" dir=$(AROS_CATALOGS) \
1612  sourcedescription="$(TOOLDIR)/C_h_orig"
1614 BD_SRCS := $(addsuffix .ct, %(catalogs))
1615 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1616 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1619 %(mmake) : $(BD_OBJS) %(source)
1621 $(BD_OBJS) : | $(BD_DIRS)
1622 GLOB_MKDIRS += $(BD_DIRS)
1624 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1625         @$(ECHO) "Creating %(name) catalog for language $*."
1626         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1628 ifneq (%(source),)
1629 %(source) : %(description).cd
1630         @$(ECHO) "Creating %(name) catalog source file %(source)"
1631         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd %(source)=%(sourcedescription).sd
1632 endif
1634 %(mmake)-clean : FILES := $(BD_OJS) %(source)
1636 %(mmake)-clean ::
1637         $(RM) $(FILES)
1639 .PHONY: %(mmake) %(mmake)-clean
1641 %end
1643 #-----------------------------------------------------------------------------
1645 #-----------------------------------------------------------------------------
1646 # Build icons.
1647 # - mmake is the mmaketarget
1648 # - icons is a list of icon base names (ie. without the .info suffix)
1649 # - dir is the destination directory
1650 #-----------------------------------------------------------------------------
1652 %define build_icons mmake=/A icons=/A dir=/A
1654 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1657 %(mmake) : $(BD_OBJS)
1659 %(dir)/%.info : %.info.src %.png
1660         @$(ECHO) Creating $(notdir $@)...
1661         @$(ILBMTOICON) $+ $@
1663 $(BD_OBJS) : | %(dir)
1664 GLOB_MKDIRS += %(dir)
1666 %(mmake)-clean : FILES := $(BD_OBJS)
1668 %(mmake)-clean ::
1669         @$(RM) $(FILES)
1671 .PHONY: %(mmake) %(mmake)-clean
1673 %end
1675 #-----------------------------------------------------------------------------
1677 #------------------------------------------------------------------------------
1678 # Compile files for an arch-specific replacement of code for a module
1679 # - files: the basenames of the C files to compile.
1680 # - asmfiles: the basenames of the asm files to assemble.
1681 # - mainmmake: the mmake of the module in the main directory to compile these
1682 #   arch specific files for.
1683 # - maindir: the object directory for the main module
1684 # - arch: the arch for which to compile these files. It can have the form
1685 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1686 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1687 # - dflags: the flags used during creation of dependency file. If not specified
1688 #   the same value as cflags will be used
1689 # - aflags: the flags used during assembling
1690 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1691 #   the target compiler is used
1692 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1693 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1695 ifeq (%(files) %(asmfiles),)
1696   $(error no files or asmfiles given)
1697 endif
1699 %buildid targets="%(mainmmake)-%(arch)"
1701 ifeq ($(AROS_TARGET_VARIANT),)
1702 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1703 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1704 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1705 else
1706 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1707 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1708 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1709 endif
1711 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1713 ifeq (%(arch),)
1714   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1715 endif
1717 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1718 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1719 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1720 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1721 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1723 ifeq ($(TARGET),%(mainmmake)-%(arch))
1724 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(files)))
1725 vpath %.s $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1726 vpath %.S $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1727 endif
1729 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1730 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1733 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1735 ifeq ($(findstring %(compiler),host kernel target),)
1736   $(error unknown compiler %(compiler))
1737 endif
1738 ifeq (%(compiler),target)
1739 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1740 endif
1741 ifeq (%(compiler),host)
1742 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1743 endif
1744 ifeq (%(compiler),kernel)
1745 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1746 endif
1747 ifneq (%(modulename),)
1748 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1749                      -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1750 else
1751 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1752 endif
1753 ifeq ($(TARGET),%(mainmmake)-%(arch))
1754 $(BD_OBJDIR$(BDID))/%.o : %.c
1755         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD)
1756 endif
1758 ifeq (%(dflags),)
1759 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1760 else
1761 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1762 endif
1763 ifeq ($(TARGET),%(mainmmake)-%(arch))
1764 $(BD_OBJDIR$(BDID))/%.d : %.c
1765         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1766 endif
1768 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1770 ifeq ($(TARGET),%(mainmmake)-%(arch))
1771 $(BD_OBJDIR$(BDID))/%.o : %.s
1772         %assemble_q opt=$(AFLAGS)
1773 $(BD_OBJDIR$(BDID))/%.o : %.S
1774         %assemble_q opt=$(AFLAGS)
1775 endif
1777 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1778 %end
1779 #------------------------------------------------------------------------------
1787 # ======================
1788 # Old stuff, will probably be removed in the future
1793 # GNU Make automatic variables
1794 # $@ current target
1795 # $< First dependency
1796 # $? All newer dependencies
1797 # $^ All dependencies
1798 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1799 #    a.%.b, then the stem is dir/foo)
1801 #------------------------------------------------------------------------------
1802 # rule to generate libdefs.h with archtool (options may go away!)
1803 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1804 %(dest) : %(conffile) %(genlibdefstool)
1805         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1806         @%(genlibdefstool) -c -o $@ %(conffile)
1807 %end
1810 #------------------------------------------------------------------------------
1811 # generate asm files from c files (for debugging purposes)
1812 %define ctoasm_q
1813 %.s : %.c
1814         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1815         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1816 %end
1818 #------------------------------------------------------------------------------
1819 # Convert two png images to an Amiga icon file based on the description
1820 # file %(from), with outputfile going to %(to).
1821 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1822         @$(ECHO) "Creating icon %(to)..."
1823         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1824         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1825         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1826 %end
1828 #------------------------------------------------------------------------------
1829 # NOTE: The following are all part of Iain's build changes, please don't use
1830 # or change anything below this line until you know what you are doing. This
1831 # is so that I don't conflict with the semantics of any of the above macros.
1832 #------------------------------------------------------------------------------
1834 #------------------------------------------------------------------------------
1835 # Copy files from one directory to another.
1837 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1839 %(maketarget) : setup 
1840         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src))/, $(file)) $(addprefix %(dst)/, $(file))))
1842 setup ::
1843         %mkdirs_q %(dst)
1845 %end
1847 #----------------------------------------------------------------------------------
1848 # Copy a diretory recursively to another place, preserving the original 
1849 # hierarchical structure
1851 # src: the source directory whose content will be copied
1852 # dst: the directory where to copy src's content. If not existing, it will be made.
1854 %define copy_dir_recursive mmake=/A src=. dst=/A
1856 %(mmake)_FILES := $(shell cd $(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(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)
1857 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1859 define %(mmake)_mkdir
1860 $(1):
1861         $(MKDIR) $$@
1862 endef
1864 define %(mmake)_copy
1865 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1866         $(CP) $$< $$@
1867 endef
1869 .PHONY : %(mmake)
1872 %(mmake): | $(GENDIR)/$(CURDIR)
1873         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1874         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1875         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1876         for d in $(%(mmake)_DIRS); do                      \
1877             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1878         done
1879         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1880         for f in $(%(mmake)_FILES); do                                            \
1881             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1882         done;  \
1883         for dst in %(dst); do \
1884             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src)) all; \
1885         done
1887 $(GENDIR)/$(CURDIR):
1888         $(MKDIR) $@
1890 %end
1892 #------------------------------------------------------------------------------
1893 #   Copy include files into the includes directories. There are currently
1894 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1895 #   for building tools that need to run on the host system $(GENINCDIR). The
1896 #   $(GENINCDIR) path must not contain any references to the C runtime
1897 #   library header files.
1899 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1900     dir= compiler=target
1902 ifeq ($(findstring %(compiler),host kernel target),)
1903 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1904 endif
1906 ifneq (%(dir),)
1907 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1908 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1909 else
1910 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1911 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1912 endif
1914 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1915         @$(CP) $< $@
1918 ifeq (%(compiler),target)
1920 ifneq (%(dir),)
1921 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1922 else
1923 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1924 endif
1926 BD_INCL_FILES += $(BD_INCL_FILES2)
1928 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1929         @$(CP) $< $@
1930 endif
1933 %(mmake) : $(BD_INCL_FILES)
1935 .PHONY: %(mmake)
1937 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1938 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1939 %end
1942 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1943 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1944 STUBS_MEM := $(addsuffix .o,$(STUBS))
1945 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1946 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1947 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1949 #MM- linklibs : hidd-%(hidd)-stubs
1950 #MM- %(parenttarget): hidd-%(hidd)-stubs
1951 #MM hidd-%(hidd)-stubs : includes includes-copy
1952 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1954 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1955         %mklib_q from=$^
1957 $(STUBS_OBJ) : $(STUBS_SRC) 
1958         %compile_q cmd=$(TARGET_CC) opt=%(cflags)
1960 $(STUBS_DEP) : $(STUBS_SRC)
1961         %mkdepend_q flags=%(dflags)
1963 setup ::
1964         %mkdirs_q $(OBJDIR) $(LIBDIR)
1967 clean ::
1968         -@$(RM) $(HIDD_LIB) $(OBJDIR)
1970 DEPS := $(DEPS) $(STUBS_DEP)
1972 %end
1973       
1974 #------------------------------------------------------------------------------
1975 # Build an imported source tree which uses the configure script from the
1976 # autoconf package.  This rule will try to "integrate" the produced files as
1977 # much as possible in the AROS build, for example by putting libraries in the
1978 # standard library directory, includes in the standard include directory, and
1979 # so on. You can however override this behaviour.
1981 # As a special "bonus" for you, the PROGDIR environment variable is defined to
1982 # be %(bindir) (or its deduced value) when running "make install", and
1983 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
1984 # configure script some more parameters whose value depends upon the PROGDIR
1985 # env var, so that the program gets all its stuff installed in the proper place
1986 # when building it, but when running it from inside AROS it can also find that
1987 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
1988 # the configuration parameters set when running ./configure
1990 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
1991 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
1992 # to the name which has to follow it.
1995 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
1996     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
1997     install_target=install postconfigure= postinstall= \
1998     install_env=
2000 ifneq (%(prefix),)
2001     %(mmake)-prefix := %(prefix)
2002 else
2003     %(mmake)-prefix := $(AROS_CONTRIB)
2004 endif
2006 ifneq (%(aros_prefix),)
2007     %(mmake)-aros_prefix := %(aros_prefix)
2008 else
2009     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2010 endif
2012 ifeq (%(nix),yes)
2013     %(mmake)-nix    := -nix
2014     %(mmake)-volpfx := /
2015     %(mmake)-volsfx := /
2016     
2017     ifeq (%(nix_dir_layout),)
2018         %(mmake)-nix_dir_layout := yes
2019     endif
2020 else
2021     %(mmake)-volsfx := :
2022     
2023     ifeq (%(nix_dir_layout),)
2024         %(mmake)-nix_dir_layout := no
2025     endif
2026 endif
2028 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2030 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2031         exec_prefix=$(%(mmake)-prefix) %(install_env)
2033 # Check if chosen compiler is valid
2034 ifeq ($(findstring %(compiler),host target kernel),)
2035   $(error unknown compiler %(compiler))
2036 endif
2038 # Set legacy 'host' variable based on chosen compiler
2039 ifeq (%(compiler),host)
2040     host := yes
2041         ifeq (%(package),)
2042                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2043         else
2044                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2045         endif
2046 else
2047     host := no
2048         ifeq (%(package),)
2049                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2050         else
2051                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2052         endif
2053 endif
2055 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2056 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2058 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2059     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2060     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2061 else
2062     ifeq (%(nix),yes)
2063         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2064         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2065     else
2066         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2067     endif
2069     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2070     
2071     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2072         sbindir=$(%(mmake)-prefix) \
2073         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2074         oldincludedir=$(AROS_INCLUDES) %(install_env)
2075 endif
2078 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2080 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2082 # Using -j1 in install_command may result in a warning but finally
2083 # it does its job. make install for gcc does not work reliable for -jN
2084 # where N > 1.
2085 ifneq (%(install_target),)
2086     %(mmake)-install_command = \
2087         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2088         -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2089         $(TOUCH) $(%(mmake)-installflag)
2091     %(mmake)-uninstall_command = \
2092     $(RM) $(%(mmake)-installflag) && \
2093     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2094     -C $(%(mmake)-pkgdir) uninstall
2095 else
2096     %(mmake)-install_command   := true
2097     %(mmake)-uninstall_command := true
2098 endif
2100 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2103 %(mmake)-build_and_install-quick :  $(%(mmake)-configflag)
2104         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2105             $(RM)  $(%(mmake)-installflag) && \
2106             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2107             $(%(mmake)-install_command); \
2108         fi
2110 %(srcdir)/.files-touched:
2111         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
2112         $(TOUCH) $@
2115 %(mmake)-uninstall :
2116         $(%(mmake)-uninstall_command)
2118 ifneq ($(DEBUG),yes)
2119     %(mmake)-s_flag = -s
2120 endif
2123 %(mmake)-configure : $(%(mmake)-configflag)
2125 ifeq (%(compiler),host)
2126 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2127         $(RM) $@ 
2128         %mkdirs_q $(%(mmake)-pkgdir)
2129         cd $(%(mmake)-pkgdir) && \
2130         find . -name config.cache -exec $(RM) '{}' \; && \
2131         CC="$(HOST_CC)" \
2132             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2133             $(TOUCH) $@
2134 endif
2135 ifeq (%(compiler),target)
2136 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2137         $(RM) $@
2138         %mkdirs_q $(%(mmake)-pkgdir)
2139         cd $(%(mmake)-pkgdir) && \
2140         find . -name config.cache -exec $(RM) '{}' \; && \
2141         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2142             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2143             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2144             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2145             --host=$(AROS_TARGET_CPU)-aros \
2146             --target=$(AROS_TARGET_CPU)-aros \
2147             --disable-nls \
2148             --without-x --without-pic --disable-shared && \
2149             $(TOUCH) $@
2150 endif
2151 ifeq (%(compiler),kernel)
2152 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2153         $(RM) $@
2154         %mkdirs_q $(%(mmake)-pkgdir)
2155         cd $(%(mmake)-pkgdir) && \
2156         find . -name config.cache -exec $(RM) '{}' \; && \
2157         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2158             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2159             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2160             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2161             --host=$(AROS_TARGET_CPU)-aros \
2162             --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2163             --without-x --without-pic --disable-shared && \
2164             $(TOUCH) $@
2165 endif
2166         
2168 %(mmake)-clean : %(mmake)-uninstall
2169         @$(RM) $(%(mmake)-pkgdir)
2170 %end
2172 #############################################################################
2173 #############################################################################
2174 ##                                                                         ##
2175 ## Miscellaneous macros. Everything that doesn't fit above should be put   ##
2176 ## here.                                                                   ##
2177 ##                                                                         ##
2178 #############################################################################
2179 #############################################################################
2181 #----------------------------------------------------------------------------------
2182 # Given an archive name, patches names and locations where to find them, fetch
2183 # the archive and the patches from any of those locations, unpack the archive
2184 # and then apply the patches.
2186 # Locations currently supported are http and ftp sites, plus local filesystem
2187 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2188 # the fetch.sh script needs to be modified, since this macro relies on that script.
2190 # Arguments:
2192 #     - archive_origins = list of locations where to find the archive. They are tried
2193 #                         in sequence, until the archive is found and fetching it 
2194 #                         succeeded. If not specified, the current directory is assumed.
2195 #     - archive         = the archive name. Mandatory.
2196 #     - suffixes        = a list of suffixes to append to the the package name plus the
2197 #                         version. Each one of them is tried until a matching archive is
2198 #                         found. They are appended to patches and these are tried the
2199 #                         same way as packages are.
2200 #     - destination     = the local directory where to put the archive and patches.
2201 #                         If not specified, the current directory is assumed.
2202 #     - patches_origins = list of locations where to find the patches. They are tried
2203 #                         in sequence, until a patch is found and fetching it 
2204 #                         succeeded. If not specified, the current directory is assumed.
2205 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2206 #                         patch_name[:[patch_subdir][:patch_opt]].
2207 #                         
2208 #                             - patch_name   = the name of the patch file
2209 #                             - patch_subdir = the directory within \destination\ where to
2210 #                                              apply the patch.
2211 #                             - patch_opt    = any options to pass to the `patch' command
2212 #                                              when applying the patch.
2213 #                         
2214 #                         The patch_subdir and patch_opt fields are optional.
2216 %define fetch archive_origins=. archive=/A suffixes= location=%destination destination=. patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2217         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l %(location) -d %(destination) \
2218         -po "%(patches_origins)" -p %(patches_specs)
2219 %end
2221 #-----------------------------------------------------------------------------------------
2222 # Joins the features of %fetch and %build_with_configure, taking advantage of
2223 # the naming scheme of GNU packages. GNU packages names are in the form
2225 #     <package name>-<version number>.<archive format suffix>
2227 # If a patch is provided, it *must* be named the following way:
2229 #    <package name>-<version number>-aros.diff
2231 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2232 # CD'ing into the archive's extracted directory.
2234 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2235 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2236 # to make that patch fully comprehensive.
2238 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2240 # Arguments:
2242 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2243 #                     macro.
2244 #    - package      = the GNU package name, sans version and archive format suffixes.
2245 #    - version      = the package's version number, or otherwise any other version string.
2246 #                     It gets appended to the package name to form the basename of the archive.
2247 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2248 #                     version. Each one of them is tried until a matching archive is found.
2249 #                     Defaults to "tar.bz2 tar.gz".
2250 #    - destination  = same meaning as the one for the %fetch macro
2251 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2252 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2253 #                     fetched or not
2254 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2255 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2256 #                     $(GNUDIR).
2257 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2258 #                     /GNU.
2259 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2260 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2262 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2263     srcdir= package_repo= patch=no patch_repo= prefix= \
2264     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2266 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2267 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2268 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2270 %(mmake)-archbase  := %(package)-%(version)
2272 ifeq (%(compiler),host)
2273     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2274 else
2275     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2276 endif
2278 ifeq (%(prefix),)
2279     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2280 else
2281     %(mmake)-prefix := %(prefix)
2282 endif
2284 ifneq (%(subpackage),)
2285     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2286 else
2287     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2288 endif
2290 ifneq (%(srcdir),)
2291     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2292 else
2293     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2294 endif
2296 ifeq (%(patch),yes)
2297     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2298 else
2299     %(mmake)-%(subpackage)-patches_specs := ::
2300 endif
2302 .PHONY : %(mmake)-%(subpackage)-fetch
2304 %(mmake)-%(subpackage)-fetch :
2305         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2306             location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2307             archive_origins=". %(package_repo)" \
2308             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2310 #MM- %(mmake) : %(mmake)-%(subpackage)
2312 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2314 %(mmake)-%(subpackage)-package-basename := \
2315     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2317 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2318      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2319      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2320      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2321      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2323 .PHONY : %(mmake)-%(subpackage)-make-package
2324 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2327 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2329 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2330 #that $^ and $@ have exactly the same mtime, and in that case make tries
2331 #to rebuild $@ again, which would fail because the directory where
2332 #the package got installed would not exist anymore. 
2333 #We work this around by using an if statement to manually check the mtimes.
2334 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2335         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2336         $(RM) $@ ; \
2337         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2338         mkdir -p "$(DISTDIR)/Packages" ; \
2339         mkdir -p "$(%(mmake)-prefix)" ; \
2340         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2341         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2342         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2343     fi
2344 %end
2346 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2347     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2348     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2350 GNU_REPOSITORY := gnu://
2352 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2353     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2354     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2355     patch="%(patch)" patch_repo="%(patch_repo)" \
2356     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2357     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2359 %end
2361 #-----------------------------------------------------------------------------------------
2362 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2363 # that the package is a "Development" package, and as such it needs to be placed
2364 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2366 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2367 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2368 # "mmake" argument, because the metatarget is implicitely defined as
2370 #     #MM- development-%(package)
2372 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2373     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2374     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2376 #MM- development : development-%(package)
2379 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2380    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2381    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2382    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2383    extraoptions="%(extraoptions)"
2384     
2385 %end