Fixed typos.
[cake.git] / config / make.tmpl
blobb139eff7e7530385a4d027ab4076c1779f0a2caf
1 ############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd=$(TARGET_CC) opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling %(from)"
17         @$(IF) %(cmd) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS)
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 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
290 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
291 endif
292 ifeq (%(compiler),host)
293 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
294 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
297 endif
298 ifeq (%(compiler),kernel)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
303 endif
305 ifeq (%(nix),yes)
306   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
307 else
308   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
309 endif
310 $(TMP_TARGETBASE).o : %(basename).c
311         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
313 ifeq (%(dflags),)
314   ifeq (%(nix),yes)
315     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
316   else
317     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
318   endif
319 else
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
324   endif
325 endif
326 $(TMP_TARGETBASE).d : %(basename).c
327         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
328 %end
329 #------------------------------------------------------------------------------
332 #------------------------------------------------------------------------------
333 # Generate a rule to compile multiple C source files to an object file and
334 # generate the corresponding dependency files. The generated file will be put
335 # in the object directory without the directory part of the source file.
336 # options
337 # - basenames: the basenames of the files to compile. The names may include
338 #   relative or absolute path names. No wildcard is allowed
339 # - cflags (default $(CFLAGS)): the C flags to use for compilation
340 # - dflags: the flags used during creation of dependency file. If not specified
341 #   the same value as cflags will be used
342 # - targetdir: the directory to put the .o file and the .d file. By default
343 #   it is put in the same directory as the .c file. When targetdir is not
344 #   empty, path names will be stripped from the file names so that all files
345 #   are in that dir and not in subdirectories.
346 # - compiler (default target): compiler to use, target, kernel or host
347 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
348     compiler=target
350 ifeq (%(targetdir),)
351 TMP_TARGETS := $(addsuffix .o,%(basenames))
352 TMP_DTARGETS := $(addsuffix .d,%(basenames))
353 TMP_WILDCARD := %
354 else
355 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
356 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
357 TMP_WILDCARD := %(targetdir)/%
359 # Be sure that all .c files are generated
360 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
362 # Be sure that all .c files are found
363 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
364 ifneq ($(TMP_DIRS),)
365     vpath %.c $(TMP_DIRS)
366 endif
368 endif
370 ifeq ($(findstring %(compiler),host kernel target),)
371   $(error unknown compiler %(compiler))
372 endif
373 ifeq (%(compiler),target)
374 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
375 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
376 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
377 endif
378 ifeq (%(compiler),host)
379 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
380 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
382 endif
383 ifeq (%(compiler),kernel)
384 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
387 endif
389 $(TMP_TARGETS) : CFLAGS := %(cflags)
390 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
391         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
393 ifeq (%(dflags),)
394 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
395 else
396 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
397 endif
398 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
399         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
400 %end
401 #------------------------------------------------------------------------------
404 #------------------------------------------------------------------------------
405 # Make an alias from one arch specific build to another arch.
406 # arguments:
407 # - mainmmake: the mmake of the module in the main tree
408 # - arch: the current arch
409 # - alias: the alias to which this should point
410 %define rule_archalias mainmmake=\A arch=\A alias=\A
412 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
413 %end
414 #------------------------------------------------------------------------------
417 #------------------------------------------------------------------------------
418 # Generate a rule to compile a C source file to a shared object file with a
419 # .so suffix. Basename may contain a directory part, then the source
420 # file has to be in that directory. The generated file will be put in the
421 # object directory without the directory.
422 # options
423 # - basename: the basename of the file to compile. Use % for a wildcard rule
424 # - cflags (default $(CFLAGS)): the C flags to use for compilation
425 # - targetdir: the directory to put the .o file and the .d file. By default
426 #   it is put in the same directory as the .c file
427 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
429 ifeq (%(targetdir),)
430   TMP_TARGETBASE := %(basename)
431 else
432   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
433 endif
435 ifeq ($(findstring %(compiler),host kernel target),)
436   $(error unknown compiler %(compiler))
437 endif
438 ifeq (%(compiler),target)
439 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
440 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
441 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
442 endif
443 ifeq (%(compiler),host)
444 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
445 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
446 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
447 endif
448 ifeq (%(compiler),kernel)
449 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
450 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
451 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
452 endif
454 $(TMP_TARGETBASE).so : %(basename).c
455         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
456 %end
457 #------------------------------------------------------------------------------
460 #------------------------------------------------------------------------------
461 # Generate a rule to assemble a source file to an object file. Basename may
462 # contain a directory part, then the source file has to be in that directory.
463 # The generated file will be put in the object directory without the directory.
464 # options
465 # - basename: the basename of the file to compile. Use % for a wildcard rule
466 # - flags (default $(AFLAGS)): the asm flags to use for assembling
467 # - targetdir: the directory to put the .o file in. By default it is put in the
468 #   same directory as the .s file
469 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
471 ifeq (%(targetdir),)
472 %(basename).o : AFLAGS := %(aflags)
473 %(basename).o : %(basename).s
474         %assemble_q
476 else
477 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
478 %(targetdir)/$(notdir %(basename)).o : %(basename).s
479         %assemble_q
481 endif
482 %end
483 #------------------------------------------------------------------------------
486 #------------------------------------------------------------------------------
487 # Generate a rule to assemble multiple source files to an object file. The
488 # generated file will be put in the object directory with the directory part
489 # of the source file stripped off.
490 # options
491 # - basenames: the basenames of the files to compile. The names may include
492 #   relative or absolute path names. No wildcard is allowed
493 # - aflags (default $(AFLAGS)): the flags to use for assembly
494 # - targetdir: the directory to put the .o file and the .d file. By default
495 #   it is put in the same directory as the .c file. When targetdir is not
496 #   empty, path names will be stripped from the file names so that all files
497 #   are in that dir and not in subdirectories.
498 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
500 ifeq (%(targetdir),)
501 TMP_TARGETS := $(addsuffix .o,%(basenames))
502 TMP_WILDCARD := %
503 else
504 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
505 TMP_WILDCARD := %(targetdir)/%
507 # Be sure that all .s files are generated
508 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
510 # Be sure that all .c files are found
511 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
512 ifneq ($(TMP_DIRS),)
513     vpath %%(suffix) $(TMP_DIRS)
514 endif
516 endif
518 $(TMP_TARGETS) : AFLAGS := %(aflags)
519 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
520         %assemble_q opt=$(AFLAGS)
521 %end
522 #------------------------------------------------------------------------------
525 #------------------------------------------------------------------------------
526 # Link %(objs) to %(prog) using the libraries in %(uselibs)
527 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
528     usehostlibs= usestartup=yes detach=no nix=no
530 TMP_EXTRA_LDFLAGS := 
531 ifeq (%(nix),yes)
532     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
533 endif
534 ifeq (%(usestartup),no)
535     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
536 endif
537 ifeq (%(detach),yes)
538     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
539 endif
541 # Make a list of the lib files this program depends on.
542 ifneq (%(uselibs),)
543 # In LDFLAGS remove white space between -L and directory
544 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
545 # Filter out only the libdirs and remove -L
546 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
547 # Add trailing /
548 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
549 # Add normal linklib path
550 TMP_DIRS += $(LIBDIR)/
551 # add lib and .a to static linklib names
552 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
553 # search for the linklibs in the given path, ignore ones not found
554 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
555     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
557 else
558 TMP_DEPLIBS :=
559 endif
561 %(prog) : OBJS := %(objs)
562 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
563 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
564 %(prog) : %(objs) $(TMP_DEPLIBS)
565         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
566 %end
567 #------------------------------------------------------------------------------
570 #------------------------------------------------------------------------------
571 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
572 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
573 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
574     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
575     usestartup=yes detach=no
577 TMP_EXTRA_LDFLAGS := 
578 ifeq (%(nix),yes)
579     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
580 endif
581 ifeq (%(usestartup),no)
582     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
583 endif
584 ifeq (%(detach),yes)
585     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
586 endif
588 # Make a list of the lib files the programs depend on.
589 ifneq (%(uselibs),)
590 # In LDFLAGS remove white space between -L and directory
591 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
592 # Filter out only the libdirs and remove -L
593 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
594 # Add trailing /
595 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
596 # Add normal linklib path
597 TMP_DIRS += $(LIBDIR)/lib/
598 # add lib and .a to static linklib names
599 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
600 # search for the linklibs in the given path, ignore ones not found
601 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
602     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
604 else
605 TMP_DEPLIBS :=
606 endif
608 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
609 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
610 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
611         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
612 %end
613 #------------------------------------------------------------------------------
616 #------------------------------------------------------------------------------
617 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
618 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
620 %(libdir)/lib%(libname).a : %(objs)
621         %mklib_q from=$^
622 %end
623 #------------------------------------------------------------------------------
626 #------------------------------------------------------------------------------
627 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
628 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
630 %(libdir)/lib%(libname).so : %(objs)
631         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
632 %end
633 #------------------------------------------------------------------------------
636 #------------------------------------------------------------------------------
637 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
638 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
639 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
640     uselibs= usehostlibs=
642 %(module) : OBJS := %(objs)
643 %(module) : ENDTAG := %(endobj)
644 %(module) : ERR := %(err)
645 %(module) : OBJDIR := %(objdir)
646 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
647 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
648         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR)
650 %end
651 #------------------------------------------------------------------------------
654 #------------------------------------------------------------------------------
655 # Generate a rule to generate a function reference file from a C source file.
656 # Basename may contain a directory part, then the source file has to be in that
657 # directory. The generated file will be put in the object directory without the
658 # directory.
659 # options
660 # - basename: the basename of the file to compile. Use % for a wildcard rule
661 # - cflags (default $(CFLAGS)): the C flags to use for compilation
662 # - targetdir: the directory to put the generated .ref file. By default the
663 #   .ref file will be put in the same directory as the .c file.
664 # - includefile: This file will be included at the head of the source file
665 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
667 ifeq (%(targetdir),)
668 GENFILE_TMP := %(basename).ref
669 else
670 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
671 endif
673 ifeq ($(filter %(compiler),target kernel host),)
674 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
675 endif
677 ifeq (%(compiler),target)
678 $(GENFILE_TMP) : CC:=$(TARGET_CC)
679 endif
680 ifeq (%(compiler),host)
681 $(GENFILE_TMP) : CC:=$(HOST_CC)
682 endif
683 ifeq(%(compiler),kernel)
684 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
685 endif
687 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
688 ifeq (%(includefile),)
689         %mkref_q cc=$(CC) cflags="%(cflags)"
690 else
691         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
692 endif
694 %end
695 #------------------------------------------------------------------------------
698 #------------------------------------------------------------------------------
699 # Generate a rule to generate a function reference file from a C source file.
700 # Basename may contain a directory part, then the source file has to be in that
701 # directory. The generated file will be put in the object directory without the
702 # directory.
703 # options
704 # - basenames: the basenames of the files to compile. No wildcard is allowed
705 # - cflags (default $(CFLAGS)): the C flags to use for compilation
706 # - targetdir: the directory to put the generated .ref file. By default the
707 #   .ref file will be put in the same directory as the .c file. When targetdir
708 #   is not empty all files will be put there and path parts in the basenames
709 #   will be stripped off.
710 # - includefile: This file will be included at the head of the source file
711 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
712     compiler=target
714 ifeq (%(targetdir),)
715 TMP_TARGETS := $(addsuffix .ref,%(basenames))
716 TMP_WILDCARD := %.ref
717 else
718 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
719 TMP_WILDCARD := %(targetdir)/%.ref
721 # Be sure that all .c files are generated
722 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
724 # Be sure that all .c files are found
725 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
726 ifneq ($(TMP_DIRS),)
727     vpath %.c $(TMP_DIRS)
728 endif
730 endif
732 ifeq ($(filter %(compiler),target kernel host),)
733 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
734 endif
736 ifeq (%(compiler),target)
737 $(TMP_TARGETS) : CC:=$(TARGET_CC)
738 endif
739 ifeq (%(compiler),host)
740 $(TMP_TARGETS) : CC:=$(HOST_CC)
741 endif
742 ifeq (%(compiler),kernel)
743 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
744 endif
745 ifeq (%(includefile),)
746 $(TMP_TARGETS) : CFLAGS:=%(cflags)
747 else
748 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
749 $(TMP_TARGETS) : %(includefile)
750 endif
751 $(TMP_TARGETS) : $(CXREF)
752 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
753         %mkref_q cc=$(CC)
754 %end
755 #------------------------------------------------------------------------------
758 #------------------------------------------------------------------------------
759 # Generate the libdefs.h include file for a module.
760 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
762 TMP_TARGET := %(modname)_libdefs.h
763 TMP_DEPS := $(GENMODULE)
764 TMP_OPTS := 
765 ifneq (%(conffile),)
766     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
767     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
768 else
769     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
770     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
771 endif
772 ifneq (%(modsuffix),)
773     TMP_OPTS += -s %(modsuffix)
774 endif
775 ifneq (%(targetdir),)
776     TMP_OPTS += -d %(targetdir)
777     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
778 endif
780 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
781 $(TMP_TARGET) : MODNAME := %(modname)
782 $(TMP_TARGET) : MODTYPE := %(modtype)
783 $(TMP_TARGET) : $(TMP_DEPS)
784         @$(ECHO) "Generating $(notdir $@)"
785         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
786 %end
787 #------------------------------------------------------------------------------
790 #------------------------------------------------------------------------------
791 # Generate the libdefs.h include file for a module.
792 %define rule_genmodule_funclist \
793     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
795 TMP_TARGET := %(modname).funclist
796 TMP_DEPS := $(GENMODULE)
797 TMP_OPTS := 
798 ifeq (%(reffile),)
799     $(error reffile needed in rule_genmodule_funclist but none specified)
800 endif
801 TMP_OPTS := -r %(reffile)
802 TMP_DEPS += %(reffile)
803 ifneq (%(conffile),)
804     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
805     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
806 else
807     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
808     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
809 endif
810 ifneq (%(modsuffix),)
811     TMP_OPTS += -s %(modsuffix)
812 endif
813 ifneq (%(targetdir),)
814     TMP_OPTS += -d %(targetdir)
815     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
816 endif
818 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
819 $(TMP_TARGET) : MODNAME := %(modname)
820 $(TMP_TARGET) : MODTYPE := %(modtype)
821 $(TMP_TARGET) : $(TMP_DEPS)
822         @$(ECHO) "Generating $(notdir $@)"
823         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
824 %end
825 #------------------------------------------------------------------------------
828 #------------------------------------------------------------------------------
829 # Generate a Makefile.%(modname) with the genmodule program and include this
830 # generated file in this Makefile
831 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
832     targetdir=
834 TMP_TARGET := Makefile.%(modname)
835 TMP_DEPS := $(GENMODULE)
836 TMP_OPTS := 
837 ifneq (%(conffile),)
838     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
839     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
840 else
841     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
842     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
843 endif
844 ifneq (%(modsuffix),)
845     TMP_OPTS += -s %(modsuffix)
846 endif
847 ifneq (%(targetdir),)
848     TMP_OPTS += -d %(targetdir)
849     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
850 endif
852 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
853 $(TMP_TARGET) : MODNAME := %(modname)
854 $(TMP_TARGET) : MODTYPE := %(modtype)
855 $(TMP_TARGET) : $(TMP_DEPS)
856         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
857 %end
858 #------------------------------------------------------------------------------
860 #------------------------------------------------------------------------------
861 # Generate dummy support files so cxref when used on the a module source file
862 # will find something to include. This rule has to be preceeded by
863 # %rule_genmodule_makefile
864 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
866 ifneq ($(%(modname)_INCLUDES),)
867 TMP_TARGETS := $(%(modname)_INCLUDES)
869 TMP_DEPS := $(GENMODULE)
870 TMP_OPTS := 
871 ifneq (%(conffile),)
872     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
873     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
874 else
875     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
876     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
877 endif
878 ifneq (%(modsuffix),)
879     TMP_OPTS += -s %(modsuffix)
880 endif
881 ifneq (%(targetdir),)
882     TMP_OPTS += -d %(targetdir)
883     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
884 endif
886 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
887 $(TMP_TARGETS) : MODNAME := %(modname)
888 $(TMP_TARGETS) : MODTYPE := %(modtype)
889 $(TMP_TARGETS) : $(TMP_DEPS)
890         @$(ECHO) "Generating dummy include files"
891         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
892 endif
893 %end
894 #------------------------------------------------------------------------------
897 #------------------------------------------------------------------------------
898 # Generate the support files for compiling a module. This includes include
899 # files and source files. This rule has to be preceeded by
900 # %rule_genmodule_makefile
901 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
902     conffile= reffile=
904 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
905                $(%(modname)_LINKLIBFILES)
906 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
908 TMP_DEPS := $(GENMODULE)
909 ifeq ($(%(modname)_NEEDREF), yes)
910     ifeq (%(reffile),)
911         $(error reffile needed in rule_genmodule_files but none specified)
912     endif
913     TMP_OPTS := -r %(reffile)
914     TMP_DEPS += %(reffile)
915 else
916     TMP_OPTS :=
917 endif
918 ifneq (%(conffile),)
919     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
920     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
921 else
922     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
923     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
924 endif
925 ifneq (%(modsuffix),)
926     TMP_OPTS += -s %(modsuffix)
927 endif
928 ifneq (%(targetdir),)
929     TMP_OPTS += -d %(targetdir)
930     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
931 endif
933 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
934 $(TMP_TARGETS) : MODNAME := %(modname)
935 $(TMP_TARGETS) : MODTYPE := %(modtype)
936 $(TMP_TARGETS) : $(TMP_DEPS)
937         @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
938 ifneq (%(conffile),lib.conf)
939         @$(IF) $(TEST) -f lib.conf; then \
940           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
941         fi
942 endif
943         @$(IF) $(TEST) -f libdefs.h; then \
944           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
945         fi
946         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
947 %end
948 #------------------------------------------------------------------------------
950 #------------------------------------------------------------------------------
951 # Generate the support files for compiling a module. This includes include
952 # files and source files.
953 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
954     targetdir= conffile= reffile=
957 ifneq ($(%(modname)_INCLUDES),)
958 TMP_TARGETS := $(%(modname)_INCLUDES)
960 TMP_DEPS := $(GENMODULE)
961 ifeq ($(%(modname)_NEEDREF), yes)
962     ifeq (%(reffile),)
963         $(error reffile needed in rule_genmodule_files but none specified)
964     endif
965     TMP_OPTS := -r %(reffile)
966     TMP_DEPS += %(reffile)
967 else
968     TMP_OPTS :=
969 endif
970 ifneq (%(conffile),)
971     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
972     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
973 else
974     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
975     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
976 endif
977 ifneq (%(modsuffix),)
978     TMP_OPTS += -s %(modsuffix)
979 endif
980 ifneq (%(targetdir),)
981     TMP_OPTS += -d %(targetdir)
982     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
983 endif
985 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
986 $(TMP_TARGETS) : MODNAME := %(modname)
987 $(TMP_TARGETS) : MODTYPE := %(modtype)
988 $(TMP_TARGETS) : $(TMP_DEPS)
989         @$(ECHO) "Generating include files"
990         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
991 endif
992 %end
993 #------------------------------------------------------------------------------
995 #------------------------------------------------------------------------------
996 # Common rules for all makefiles
997 %define common
998 # Delete generated makefiles
1000 clean ::
1001         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1003 include $(SRCDIR)/config/make.tail
1005 BDID := $(BDTARGETID)
1006 %end
1007 #------------------------------------------------------------------------------
1008       
1010 #############################################################################
1011 #############################################################################
1012 ##                                                                         ##
1013 ## Here are the mmakefile build macro's. These are macro's that takes care ##
1014 ## of everything to go from the sources to the generated target. Also all  ##
1015 ## intermediate files and directories that are needed are created by these ##
1016 ## rules.                                                                  ##
1017 ##                                                                         ##
1018 #############################################################################
1019 #############################################################################
1021 #------------------------------------------------------------------------------
1022 # Build a program
1023 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1024     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1025     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1026     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1027     srcdir=
1029 .PHONY : %(mmake)
1031 BD_PROGNAME  := %(progname)
1032 BD_OBJDIR    := %(objdir)
1033 BD_TARGETDIR := %(targetdir)
1035 BD_FILES     := %(files)
1036 BD_ASMFILES  := %(asmfiles)
1037 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES) $(BD_ASMFILES)))
1038 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1040 BD_CFLAGS    := %(cflags)
1041 BD_AFLAGS    := %(aflags)
1042 BD_DFLAGS    := %(dflags)
1043 BD_LDFLAGS   := %(ldflags)
1046 %(mmake)-quick : %(mmake)
1048 #MM %(mmake) : includes-generate-deps
1049 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1051 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1052 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1053     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1054 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1055     aflags=$(BD_AFLAGS)
1057 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1058     objs=$(BD_OBJS) ldflags=$(BD_LDFLAGS) \
1059     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1060     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
1062 endif
1064 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1066 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1067 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1068 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1070 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1072 %(mmake)-clean ::
1073         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1074         @$(RM) $(FILES)
1076 %end
1077 #------------------------------------------------------------------------------
1080 #------------------------------------------------------------------------------
1081 # Build programs, for every C file an executable will be built with the same
1083 %define build_progs mmake=/A files=/A nix=no \
1084     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1085     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1086     uselibs= usehostlibs= usestartup=yes detach=no
1088 .PHONY : %(mmake)
1090 BD_OBJDIR    := %(objdir)
1091 BD_TARGETDIR := %(targetdir)
1093 BD_FILES     := %(files)
1094 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1095 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1096 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1098 BD_CFLAGS    := %(cflags)
1099 BD_DFLAGS    := %(dflags)
1100 BD_LDFLAGS   := %(ldflags)
1103 %(mmake)-quick : %(mmake)
1105 #MM %(mmake) : includes-generate-deps
1106 %(mmake) : $(BD_EXES)
1108 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1109 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1110     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1112 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1113     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1114     ldflags=$(BD_LDFLAGS) \
1115     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1116     usestartup="%(usestartup)" detach="%(detach)"
1118 endif
1120 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1122 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1123 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1124 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1126 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1128 %(mmake)-clean ::
1129         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1130         @$(RM) $(FILES)
1132 %end
1133 #------------------------------------------------------------------------------
1136 #------------------------------------------------------------------------------
1137 # Build a module.
1138 # This is a bare version: It just compiles and links the given files. It is
1139 # assumed that all needed boiler plate code is in the files. This should only
1140 # be used for compiling external code. For AROS code use %build_module
1141 %define build_module_simple mmake=/A modname=/A modtype=/A \
1142     files="$(basename $(call WILDCARD, *.c))" \
1143     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1144     objdir=$(OBJDIR) moduledir= \
1145     uselibs= usehostlibs= compiler=target
1147 # Define metamake targets and their dependencies
1148 #MM %(mmake) : core-linklibs includes-generate-deps
1149 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1150 #MM %(mmake)-quick
1151 #MM %(mmake)-clean
1153 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1155 .PHONY : $(BD_ALLTARGETS)
1157 ifeq (%(modname),)
1158 $(error using %build_module_simple: modname may not be empty)
1159 endif
1160 ifeq (%(modtype),)
1161 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1162 endif
1164 # Default values for variables and arguments
1165 BD_DEFLINKLIBNAME := %(modname)
1166 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1167 BD_DEFDFLAGS := %(cflags)
1168 OBJDIR ?= $(GENDIR)/$(CURDIR)
1169 BD_MODDIR := %(moduledir)
1170 ifeq ($(BD_MODDIR),)
1171   ifeq (%(modtype),library)
1172     BD_MODDIR  := $(AROS_LIBS)
1173   endif
1174   ifeq (%(modtype),gadget)
1175     BD_MODDIR  := $(AROS_GADGETS)
1176   endif
1177   ifeq (%(modtype),datatype)
1178     BD_MODDIR  := $(AROS_DATATYPES)
1179   endif
1180   ifeq (%(modtype),handler)
1181     BD_MODDIR  := $(AROS_FS)
1182   endif
1183   ifeq (%(modtype),device)
1184     BD_MODDIR  := $(AROS_DEVS)
1185   endif
1186   ifeq (%(modtype),resource)
1187     BD_MODDIR  := $(AROS_RESOURCES)
1188   endif
1189   ifeq (%(modtype),mui)
1190     BD_MODDIR  := $(AROS_CLASSES)/Zune
1191   endif
1192   ifeq (%(modtype),mcc)
1193     BD_MODDIR  := $(AROS_CLASSES)/Zune
1194   endif
1195   ifeq (%(modtype),mcp)
1196     BD_MODDIR  := $(AROS_CLASSES)/Zune
1197   endif
1198   ifeq (%(modtype),hidd)
1199     BD_MODDIR  := $(AROS_DRIVERS)
1200   endif
1201 endif
1202 ifeq ($(BD_MODDIR),)
1203   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1204 endif
1206 %rule_compile_multi \
1207     basenames="%(files)" targetdir="%(objdir)" \
1208     cflags="%(cflags)" dflags="%(dflags)" \
1209     compiler=%(compiler)
1211 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1212 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1214 %(mmake)-quick : %(mmake)
1215 %(mmake) : $(BD_MODULE)
1216 %(mmake)-kobj : $(BD_KOBJ)
1218 # The module is linked from all the compiled .o files
1219 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1220 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1221                  endobj= err=%(modname).err objdir=%(objdir) \
1222                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1224 # Link kernel object file
1225 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1226     expansion keymap
1227 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1228     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1229 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1230 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1231 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1232 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1233 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1234         @$(ECHO) "Linking $@"
1235         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1236         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1239 ## Dependency fine-tuning
1241 BD_DEPS       := $(addprefix %(objdir), $(addsuffix .o,%(files)))
1242 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1244 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1245 $(BD_MODULE) : | $(BD_MODDIR)
1246 $(BD_KOBJ) : | $(KOBJSDIR)
1247 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1249 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1250 %(mmake)-clean ::
1251         @$(ECHO) "Cleaning up for module %(modname)"
1252         @$(RM) $(FILES)
1253 %end
1256 #------------------------------------------------------------------------------
1257 # Build a module
1258 # Explanation of this macro is done in the developer's manual
1259 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1260   conffile= files="$(basename $(call WILDCARD, *.c))" \
1261   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1262   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1263   reffile=$(BD_DEFREFFILE) noref= \
1264   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1265   compiler=target
1267 # Define metamake targets and their dependencies
1268 #MM- includes-all : %(mmake)-includes
1269 #MM %(mmake) : %(mmake)-includes core-linklibs
1270 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1271 #MM %(mmake)-linklib : %(mmake)-includes
1272 #MM %(mmake)-quick : %(mmake)-includes-quick
1273 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1274 #MM     includes-generate-deps
1275 #MM %(mmake)-includes-quick
1276 #MM %(mmake)-includes-dirs
1277 #MM %(mmake)-makefile
1278 #MM %(mmake)-funclist
1279 #MM %(mmake)-clean
1281 # All MetaMake targets defined by this macro
1282 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1283     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1284     %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1286 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1288 ifeq (%(modname),)
1289 $(error using %build_module: modname may not be empty)
1290 endif
1291 ifeq (%(modtype),)
1292 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1293 endif
1295 # Default values for variables and arguments
1296 BD_DEFLINKLIBNAME := %(modname)
1297 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1298 BD_DEFDFLAGS := %(cflags)
1299 OBJDIR ?= $(GENDIR)/$(CURDIR)
1301 ## Create genmodule include Makefile for the module
1303 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1305 %rule_genmodule_makefile \
1306     modname=%(modname) modtype=%(modtype) \
1307     modsuffix=%(modsuffix) targetdir=%(objdir) \
1308     conffile=%(conffile)
1310 %(objdir)/Makefile.%(modname) : | %(objdir)
1312 GLOB_MKDIRS += %(objdir)
1314 # Do not parse these statements if metatarget is not appropriate
1315 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1317 include %(objdir)/Makefile.%(modname)
1319 BD_DEFMODDIR := $(%(modname)_MODDIR)
1322 ## include files generation
1324 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1325 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1326 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1328 %(mmake)-includes-quick : %(mmake)-includes
1329 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1330     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1331     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1333 ifneq ($(%(modname)_INCLUDES),)
1334 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1335                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1336                          conffile=%(conffile) reffile=%(reffile)
1338 %rule_copy_diff_multi \
1339     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1340     stampfile=%(objdir)/%(modname)_geninc
1342 %rule_copy_diff_multi \
1343     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1344     stampfile=%(objdir)/%(modname)_incs
1346 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1347                       modsuffix=%(modsuffix) \
1348                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1350 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1352 TMP%(modname)_INCDIRS := \
1353     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1354     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1355     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1356 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1358 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1359 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1361 endif
1363 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1364                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1365                            conffile=%(conffile)
1367 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1368 $(BD_DEFLIBDEFSINC) :
1369         @$(ECHO) "generating $@"
1370         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1372 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1373 GLOB_MKDIRS += %(objdir)/include
1375 ## Generation of the funclist file
1377 %(mmake)-funclist : %(modname).funclist
1379 %rule_genmodule_funclist \
1380     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1381     conffile=%(conffile) reffile=%(reffile)
1384 ## Extra genmodule src files generation
1385 ## 
1386 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1387                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1388                       conffile=%(conffile) reffile=%(reffile)
1390 ## Compilation
1392 BD_FILES      := %(files)
1393 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1394 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1395 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1397 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1398 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1399 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1401 TMP_IQUOTE := $(CFLAGS_IQUOTE)
1402 TMP_IQUOTE_END := $(CFLAGS_IQUOTE_END)
1403 ifeq (%(compiler),host)
1404 TMP_IQUOTE := $(HOST_IQUOTE)
1405 TMP_IQUOTE_END := $(HOST_IQUOTE_END)
1406 endif
1407 ifeq (%(compiler),kernel)
1408 TMP_IQUOTE := $(KERNEL_IQUOTE)
1409 TMP_IQUOTE_END := $(KERNEL_IQUOTE_END)
1410 endif
1412 TMP_QUOTE     := $(TMP_IQUOTE) $(TOP)/$(CURDIR) \
1413     $(addprefix $(TMP_IQUOTE),$(BD_FDIRS)) \
1414     $(TMP_IQUOTE_END)
1415 BD_CFLAGS     := $(TMP_QUOTE) %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1416 BD_DFLAGS     := $(TMP_QUOTE) %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1418 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1419 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1420 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1421     BD_LINKLIB :=
1422 else
1423     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1424 endif
1425 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1427 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1428 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1430 %rule_compile_multi \
1431     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1432     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1433     compiler=%(compiler)
1434 %rule_compile_multi \
1435     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1436     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1437     compiler=%(compiler)
1439 ifneq ($(BD_LINKLIBAFILES),)
1440 %rule_assemble_multi \
1441     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1442 endif
1444 ## function reference files generation
1446 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1447 %rule_ref_multi \
1448     basenames=$(BD_FILES) targetdir=%(objdir) \
1449     cflags=$(BD_CFLAGS_REF) \
1450     compiler=%(compiler)
1452 ifeq (%(noref),)
1453 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1454 else
1455 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1456 endif
1458 %rule_join from=$(BD_REFS) to=%(reffile) \
1459            text="Collecting function references for module %(modname)"
1462 ## Linking
1464 ifeq (%(modsuffix),)
1465 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1466 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1467 else
1468 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1469 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1470 endif
1472 %(mmake)-quick : %(mmake)
1473 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1474 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1475 %(mmake)-linklib : $(BD_LINKLIB)
1477 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1478                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1479 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1480 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1481                  %(linklibobjs)
1483 # The module is linked from all the compiled .o files
1484 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1485                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1486                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1488 # Link static lib
1489 ifneq ($(BD_LINKLIB),)
1490 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1492 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1493 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1494 endif
1496 # Link kernel object file
1497 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1498     expansion keymap
1499 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1500     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1501 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1502 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1503 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1504 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1505 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1506         @$(ECHO) "Linking $@"
1507         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1508         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1510 ## Dependency fine-tuning
1512 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1513 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1515 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1516 $(BD_MODULE) : | %(prefix)/%(moduledir)
1517 $(BD_KOBJ) : | $(KOBJSDIR)
1518 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1520 # Some include files need to be generated before the .c can be parsed.
1521 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1522 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1523     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1524 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1526 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1527     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1528 $(BD_DEPS) : $(BD_DFILE_DEPS)
1529 endif
1531 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1532     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1533     %(objdir)/Makefile.%(modname) \
1534     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1535     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1536     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1537     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1538     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1539     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1540     $(BD_ENDOBJS)
1541 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1542 %(mmake)-clean ::
1543         @$(ECHO) "Cleaning up for module %(modname)"
1544         @$(RM) $(FILES)
1546 endif # $(TARGET) in $(BD_ALLTARGETS)
1547 %end
1548 #------------------------------------------------------------------------------
1551 #------------------------------------------------------------------------------
1552 # Build a linklib.
1553 # - mmake is the mmaketarget
1554 # - libname is the baselibname e.g. lib%(libname).a will be created
1555 # - files are the C source files to include in the lib. The list of files
1556 #   has to be given without the .c suffix
1557 # - asmfiles are the asm files to include in the lib. The list of files has to
1558 #   be given without the .s suffix
1559 # - objs additional object to link into the linklib. The objects have to be
1560 #   given with full absolute path and the .o suffix.
1561 # - cflags are the flags to compile the source (default $(CFLAGS))
1562 # - dflags are the flags use during makedepend (default equal to cflags)
1563 # - aflags are the flags use during assembling (default $(AFLAGS))
1564 # - objdir is where the .o are generated
1565 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1566 %define build_linklib mmake=/A libname=/A \
1567   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1568   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1570 # assign and generate the local variables used in this macro
1571 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1573 BD_FILES      := %(files)
1574 BD_ASMFILES   := %(asmfiles)
1576 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1577 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1578 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1580 BD_OBJS       := $(BD_ARCHOBJS) \
1581                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1582                  %(objs)
1583 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1585 BD_CFLAGS     := %(cflags)
1586 ifeq (%(dflags),)
1587 BD_DFLAGS     := $(BD_CFLAGS)
1588 else
1589 BD_DFLAGS     := %(dflags)
1590 endif
1591 BD_AFLAGS     := %(aflags)
1593 BD_LINKLIB    := %(libdir)/lib%(libname).a
1595 .PHONY : %(mmake) %(mmake)-clean
1597 #MM %(mmake) : includes-generate-deps
1598 %(mmake) : $(BD_LINKLIB)
1601 %(mmake)-clean ::
1602         @$(RM) $(BD_OBJS) $(BD_DEPS)
1604 ifeq ($(TARGET),%(mmake))
1605 ifneq ($(dir $(BD_FILES)),./)
1606 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1607 endif
1609 %rule_compile basename=% targetdir=%(objdir) \
1610               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1611 %rule_assemble basename=% targetdir=%(objdir) \
1612               aflags=$(BD_AFLAGS)
1613 endif
1615 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1617 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1619 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1620 $(BD_LINKLIB) : | %(libdir)
1621 GLOB_MKDIRS += %(objdir) %(libdir)
1623 %end
1624 #------------------------------------------------------------------------------
1627 #------------------------------------------------------------------------------
1628 # Build catalogs.
1629 # - mmake is the mmaketarget
1630 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1631 # - description is the catalog description file (.cd) (default *.cd)
1632 # - subdir is the destination subdir of the catalogs
1633 # - name is the name of the destination catalog, without the .catalog suffix
1634 # - source is the path to the generated source code file
1635 # - dir is the base destination directory (default $(AROS_CATALOGS))
1636 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1638 %define build_catalogs mmake=/A name=/A subdir=/A \
1639  catalogs="$(basename $(call WILDCARD, *.ct))" source="../strings.h" \
1640  description="$(basename $(call WILDCARD, *.cd))" dir=$(AROS_CATALOGS) \
1641  sourcedescription="$(TOOLDIR)/C_h_orig"
1643 BD_SRCS := $(addsuffix .ct, %(catalogs))
1644 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1645 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1648 %(mmake) : $(BD_OBJS) %(source)
1650 $(BD_OBJS) : | $(BD_DIRS)
1651 GLOB_MKDIRS += $(BD_DIRS)
1653 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1654         @$(ECHO) "Creating %(name) catalog for language $*."
1655         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1657 ifneq (%(source),)
1658 %(source) : %(description).cd
1659         @$(ECHO) "Creating %(name) catalog source file %(source)"
1660         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd %(source)=%(sourcedescription).sd
1661 endif
1663 %(mmake)-clean : FILES := $(BD_OJS) %(source)
1665 %(mmake)-clean ::
1666         $(RM) $(FILES)
1668 .PHONY: %(mmake) %(mmake)-clean
1670 %end
1672 #-----------------------------------------------------------------------------
1674 #-----------------------------------------------------------------------------
1675 # Build icons.
1676 # - mmake is the mmaketarget
1677 # - icons is a list of icon base names (ie. without the .info suffix)
1678 # - dir is the destination directory
1679 #-----------------------------------------------------------------------------
1681 %define build_icons mmake=/A icons=/A dir=/A
1683 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1686 %(mmake) : $(BD_OBJS)
1688 %(dir)/%.info : %.info.src %.png
1689         @$(ECHO) Creating $(notdir $@)...
1690         @$(ILBMTOICON) $+ $@
1692 $(BD_OBJS) : | %(dir)
1693 GLOB_MKDIRS += %(dir)
1695 %(mmake)-clean : FILES := $(BD_OBJS)
1697 %(mmake)-clean ::
1698         @$(RM) $(FILES)
1700 .PHONY: %(mmake) %(mmake)-clean
1702 %end
1704 #-----------------------------------------------------------------------------
1706 #------------------------------------------------------------------------------
1707 # Compile files for an arch-specific replacement of code for a module
1708 # - files: the basenames of the C files to compile.
1709 # - asmfiles: the basenames of the asm files to assemble.
1710 # - mainmmake: the mmake of the module in the main directory to compile these
1711 #   arch specific files for.
1712 # - maindir: the object directory for the main module
1713 # - arch: the arch for which to compile these files. It can have the form
1714 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1715 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1716 # - dflags: the flags used during creation of dependency file. If not specified
1717 #   the same value as cflags will be used
1718 # - aflags: the flags used during assembling
1719 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1720 #   the target compiler is used
1721 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1722 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1724 ifeq (%(files) %(asmfiles),)
1725   $(error no files or asmfiles given)
1726 endif
1728 %buildid targets="%(mainmmake)-%(arch)"
1730 ifeq ($(AROS_TARGET_VARIANT),)
1731 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1732 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1733 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1734 else
1735 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1736 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1737 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1738 endif
1740 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1742 ifeq (%(arch),)
1743   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1744 endif
1746 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1747 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1748 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1749 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1750 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1752 ifeq ($(TARGET),%(mainmmake)-%(arch))
1753 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(files)))
1754 vpath %.s $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1755 vpath %.S $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1756 endif
1758 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1759 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1762 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1764 ifeq ($(findstring %(compiler),host kernel target),)
1765   $(error unknown compiler %(compiler))
1766 endif
1767 ifeq (%(compiler),target)
1768 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1769 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1770 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1771 endif
1772 ifeq (%(compiler),host)
1773 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1774 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1775 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1776 endif
1777 ifeq (%(compiler),kernel)
1778 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1779 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1780 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1781 endif
1782 ifneq (%(modulename),)
1783 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1784                      -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1785 else
1786 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1787 endif
1788 ifeq ($(TARGET),%(mainmmake)-%(arch))
1789 $(BD_OBJDIR$(BDID))/%.o : %.c
1790         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1791 endif
1793 ifeq (%(dflags),)
1794 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1795 else
1796 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1797 endif
1798 ifeq ($(TARGET),%(mainmmake)-%(arch))
1799 $(BD_OBJDIR$(BDID))/%.d : %.c
1800         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1801 endif
1803 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1805 ifeq ($(TARGET),%(mainmmake)-%(arch))
1806 $(BD_OBJDIR$(BDID))/%.o : %.s
1807         %assemble_q opt=$(AFLAGS)
1808 $(BD_OBJDIR$(BDID))/%.o : %.S
1809         %assemble_q opt=$(AFLAGS)
1810 endif
1812 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1813 %end
1814 #------------------------------------------------------------------------------
1822 # ======================
1823 # Old stuff, will probably be removed in the future
1828 # GNU Make automatic variables
1829 # $@ current target
1830 # $< First dependency
1831 # $? All newer dependencies
1832 # $^ All dependencies
1833 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1834 #    a.%.b, then the stem is dir/foo)
1836 #------------------------------------------------------------------------------
1837 # rule to generate libdefs.h with archtool (options may go away!)
1838 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1839 %(dest) : %(conffile) %(genlibdefstool)
1840         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1841         @%(genlibdefstool) -c -o $@ %(conffile)
1842 %end
1845 #------------------------------------------------------------------------------
1846 # generate asm files from c files (for debugging purposes)
1847 %define ctoasm_q
1848 %.s : %.c
1849         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1850         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1851 %end
1853 #------------------------------------------------------------------------------
1854 # Convert two png images to an Amiga icon file based on the description
1855 # file %(from), with outputfile going to %(to).
1856 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1857         @$(ECHO) "Creating icon %(to)..."
1858         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1859         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1860         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1861 %end
1863 #------------------------------------------------------------------------------
1864 # NOTE: The following are all part of Iain's build changes, please don't use
1865 # or change anything below this line until you know what you are doing. This
1866 # is so that I don't conflict with the semantics of any of the above macros.
1867 #------------------------------------------------------------------------------
1869 #------------------------------------------------------------------------------
1870 # Copy files from one directory to another.
1872 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1874 %(maketarget) : setup 
1875         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src))/, $(file)) $(addprefix %(dst)/, $(file))))
1877 setup ::
1878         %mkdirs_q %(dst)
1880 %end
1882 #----------------------------------------------------------------------------------
1883 # Copy a diretory recursively to another place, preserving the original 
1884 # hierarchical structure
1886 # src: the source directory whose content will be copied
1887 # dst: the directory where to copy src's content. If not existing, it will be made.
1889 %define copy_dir_recursive mmake=/A src=. dst=/A
1891 %(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)
1892 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1894 define %(mmake)_mkdir
1895 $(1):
1896         $(MKDIR) $$@
1897 endef
1899 define %(mmake)_copy
1900 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1901         $(CP) $$< $$@
1902 endef
1904 .PHONY : %(mmake)
1907 %(mmake): | $(GENDIR)/$(CURDIR)
1908         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1909         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1910         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1911         for d in $(%(mmake)_DIRS); do                      \
1912             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1913         done
1914         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1915         for f in $(%(mmake)_FILES); do                                            \
1916             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1917         done;  \
1918         for dst in %(dst); do \
1919             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src)) all; \
1920         done
1922 $(GENDIR)/$(CURDIR):
1923         $(MKDIR) $@
1925 %end
1927 #------------------------------------------------------------------------------
1928 #   Copy include files into the includes directories. There are currently
1929 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1930 #   for building tools that need to run on the host system $(GENINCDIR). The
1931 #   $(GENINCDIR) path must not contain any references to the C runtime
1932 #   library header files.
1934 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1935     dir= compiler=target
1937 ifeq ($(findstring %(compiler),host kernel target),)
1938 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1939 endif
1941 ifneq (%(dir),)
1942 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1943 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1944 else
1945 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1946 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1947 endif
1949 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1950         @$(CP) $< $@
1953 ifeq (%(compiler),target)
1955 ifneq (%(dir),)
1956 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1957 else
1958 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1959 endif
1961 BD_INCL_FILES += $(BD_INCL_FILES2)
1963 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1964         @$(CP) $< $@
1965 endif
1968 %(mmake) : $(BD_INCL_FILES)
1970 .PHONY: %(mmake)
1972 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1973 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1974 %end
1977 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1978 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1979 STUBS_MEM := $(addsuffix .o,$(STUBS))
1980 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1981 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1982 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1984 #MM- linklibs : hidd-%(hidd)-stubs
1985 #MM- %(parenttarget): hidd-%(hidd)-stubs
1986 #MM hidd-%(hidd)-stubs : includes includes-copy
1987 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1989 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1990         %mklib_q from=$^
1992 $(STUBS_OBJ) : $(STUBS_SRC) 
1993         %compile_q cmd=$(TARGET_CC) opt=%(cflags) iquote=$(CGLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
1995 $(STUBS_DEP) : $(STUBS_SRC)
1996         %mkdepend_q flags=%(dflags)
1998 setup ::
1999         %mkdirs_q $(OBJDIR) $(LIBDIR)
2002 clean ::
2003         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2005 DEPS := $(DEPS) $(STUBS_DEP)
2007 %end
2008       
2009 #------------------------------------------------------------------------------
2010 # Build an imported source tree which uses the configure script from the
2011 # autoconf package.  This rule will try to "integrate" the produced files as
2012 # much as possible in the AROS build, for example by putting libraries in the
2013 # standard library directory, includes in the standard include directory, and
2014 # so on. You can however override this behaviour.
2016 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2017 # be %(bindir) (or its deduced value) when running "make install", and
2018 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2019 # configure script some more parameters whose value depends upon the PROGDIR
2020 # env var, so that the program gets all its stuff installed in the proper place
2021 # when building it, but when running it from inside AROS it can also find that
2022 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2023 # the configuration parameters set when running ./configure
2025 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2026 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2027 # to the name which has to follow it.
2030 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2031     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
2032     install_target=install postconfigure= postinstall= \
2033     install_env=
2035 ifneq (%(prefix),)
2036     %(mmake)-prefix := %(prefix)
2037 else
2038     %(mmake)-prefix := $(AROS_CONTRIB)
2039 endif
2041 ifneq (%(aros_prefix),)
2042     %(mmake)-aros_prefix := %(aros_prefix)
2043 else
2044     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2045 endif
2047 ifeq (%(nix),yes)
2048     %(mmake)-nix    := -nix
2049     %(mmake)-volpfx := /
2050     %(mmake)-volsfx := /
2051     
2052     ifeq (%(nix_dir_layout),)
2053         %(mmake)-nix_dir_layout := yes
2054     endif
2055 else
2056     %(mmake)-volsfx := :
2057     
2058     ifeq (%(nix_dir_layout),)
2059         %(mmake)-nix_dir_layout := no
2060     endif
2061 endif
2063 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2065 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2066         exec_prefix=$(%(mmake)-prefix) %(install_env)
2068 # Check if chosen compiler is valid
2069 ifeq ($(findstring %(compiler),host target kernel),)
2070   $(error unknown compiler %(compiler))
2071 endif
2073 # Set legacy 'host' variable based on chosen compiler
2074 ifeq (%(compiler),host)
2075     host := yes
2076         ifeq (%(package),)
2077                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2078         else
2079                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2080         endif
2081 else
2082     host := no
2083         ifeq (%(package),)
2084                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2085         else
2086                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2087         endif
2088 endif
2090 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2091 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2093 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2094     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2095     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2096 else
2097     ifeq (%(nix),yes)
2098         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2099         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2100     else
2101         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2102     endif
2104     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2105     
2106     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2107         sbindir=$(%(mmake)-prefix) \
2108         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2109         oldincludedir=$(AROS_INCLUDES) %(install_env)
2110 endif
2113 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2115 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2117 # Using -j1 in install_command may result in a warning but finally
2118 # it does its job. make install for gcc does not work reliable for -jN
2119 # where N > 1.
2120 ifneq (%(install_target),)
2121     %(mmake)-install_command = \
2122         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2123         -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2124         $(TOUCH) $(%(mmake)-installflag)
2126     %(mmake)-uninstall_command = \
2127     $(RM) $(%(mmake)-installflag) && \
2128     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2129     -C $(%(mmake)-pkgdir) uninstall
2130 else
2131     %(mmake)-install_command   := true
2132     %(mmake)-uninstall_command := true
2133 endif
2135 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2138 %(mmake)-build_and_install-quick :  $(%(mmake)-configflag)
2139         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2140             $(RM)  $(%(mmake)-installflag) && \
2141             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2142             $(%(mmake)-install_command); \
2143         fi
2145 %(srcdir)/.files-touched:
2146         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
2147         $(TOUCH) $@
2150 %(mmake)-uninstall :
2151         $(%(mmake)-uninstall_command)
2153 ifneq ($(DEBUG),yes)
2154     %(mmake)-s_flag = -s
2155 endif
2158 %(mmake)-configure : $(%(mmake)-configflag)
2160 ifeq (%(compiler),host)
2161 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2162         $(RM) $@ 
2163         %mkdirs_q $(%(mmake)-pkgdir)
2164         cd $(%(mmake)-pkgdir) && \
2165         find . -name config.cache -exec $(RM) '{}' \; && \
2166         CC="$(HOST_CC)" \
2167             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2168             $(TOUCH) $@
2169 endif
2170 ifeq (%(compiler),target)
2171 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2172         $(RM) $@
2173         %mkdirs_q $(%(mmake)-pkgdir)
2174         cd $(%(mmake)-pkgdir) && \
2175         find . -name config.cache -exec $(RM) '{}' \; && \
2176         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2177             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2178             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2179             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2180             --host=$(AROS_TARGET_CPU)-aros \
2181             --target=$(AROS_TARGET_CPU)-aros \
2182             --disable-nls \
2183             --without-x --without-pic --disable-shared && \
2184             $(TOUCH) $@
2185 endif
2186 ifeq (%(compiler),kernel)
2187 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2188         $(RM) $@
2189         %mkdirs_q $(%(mmake)-pkgdir)
2190         cd $(%(mmake)-pkgdir) && \
2191         find . -name config.cache -exec $(RM) '{}' \; && \
2192         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2193             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2194             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2195             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2196             --host=$(AROS_TARGET_CPU)-aros \
2197             --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2198             --without-x --without-pic --disable-shared && \
2199             $(TOUCH) $@
2200 endif
2201         
2203 %(mmake)-clean : %(mmake)-uninstall
2204         @$(RM) $(%(mmake)-pkgdir)
2205 %end
2207 #############################################################################
2208 #############################################################################
2209 ##                                                                         ##
2210 ## Miscellaneous macros. Everything that doesn't fit above should be put   ##
2211 ## here.                                                                   ##
2212 ##                                                                         ##
2213 #############################################################################
2214 #############################################################################
2216 #----------------------------------------------------------------------------------
2217 # Given an archive name, patches names and locations where to find them, fetch
2218 # the archive and the patches from any of those locations, unpack the archive
2219 # and then apply the patches.
2221 # Locations currently supported are http and ftp sites, plus local filesystem
2222 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2223 # the fetch.sh script needs to be modified, since this macro relies on that script.
2225 # Arguments:
2227 #     - archive_origins = list of locations where to find the archive. They are tried
2228 #                         in sequence, until the archive is found and fetching it 
2229 #                         succeeded. If not specified, the current directory is assumed.
2230 #     - archive         = the archive name. Mandatory.
2231 #     - suffixes        = a list of suffixes to append to the the package name plus the
2232 #                         version. Each one of them is tried until a matching archive is
2233 #                         found. They are appended to patches and these are tried the
2234 #                         same way as packages are.
2235 #     - destination     = the local directory where to put the archive and patches.
2236 #                         If not specified, the current directory is assumed.
2237 #     - patches_origins = list of locations where to find the patches. They are tried
2238 #                         in sequence, until a patch is found and fetching it 
2239 #                         succeeded. If not specified, the current directory is assumed.
2240 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2241 #                         patch_name[:[patch_subdir][:patch_opt]].
2242 #                         
2243 #                             - patch_name   = the name of the patch file
2244 #                             - patch_subdir = the directory within \destination\ where to
2245 #                                              apply the patch.
2246 #                             - patch_opt    = any options to pass to the `patch' command
2247 #                                              when applying the patch.
2248 #                         
2249 #                         The patch_subdir and patch_opt fields are optional.
2251 %define fetch archive_origins=. archive=/A suffixes= location=%destination destination=. patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2252         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l %(location) -d %(destination) \
2253         -po "%(patches_origins)" -p %(patches_specs)
2254 %end
2256 #-----------------------------------------------------------------------------------------
2257 # Joins the features of %fetch and %build_with_configure, taking advantage of
2258 # the naming scheme of GNU packages. GNU packages names are in the form
2260 #     <package name>-<version number>.<archive format suffix>
2262 # If a patch is provided, it *must* be named the following way:
2264 #    <package name>-<version number>-aros.diff
2266 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2267 # CD'ing into the archive's extracted directory.
2269 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2270 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2271 # to make that patch fully comprehensive.
2273 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2275 # Arguments:
2277 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2278 #                     macro.
2279 #    - package      = the GNU package name, sans version and archive format suffixes.
2280 #    - version      = the package's version number, or otherwise any other version string.
2281 #                     It gets appended to the package name to form the basename of the archive.
2282 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2283 #                     version. Each one of them is tried until a matching archive is found.
2284 #                     Defaults to "tar.bz2 tar.gz".
2285 #    - destination  = same meaning as the one for the %fetch macro
2286 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2287 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2288 #                     fetched or not
2289 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2290 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2291 #                     $(GNUDIR).
2292 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2293 #                     /GNU.
2294 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2295 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2297 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2298     srcdir= package_repo= patch=no patch_repo= prefix= \
2299     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2301 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2302 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2303 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2305 %(mmake)-archbase  := %(package)-%(version)
2307 ifeq (%(compiler),host)
2308     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2309 else
2310     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2311 endif
2313 ifeq (%(prefix),)
2314     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2315 else
2316     %(mmake)-prefix := %(prefix)
2317 endif
2319 ifneq (%(subpackage),)
2320     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2321 else
2322     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2323 endif
2325 ifneq (%(srcdir),)
2326     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2327 else
2328     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2329 endif
2331 ifeq (%(patch),yes)
2332     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2333 else
2334     %(mmake)-%(subpackage)-patches_specs := ::
2335 endif
2337 .PHONY : %(mmake)-%(subpackage)-fetch
2339 %(mmake)-%(subpackage)-fetch :
2340         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2341             location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2342             archive_origins=". %(package_repo)" \
2343             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2345 #MM- %(mmake) : %(mmake)-%(subpackage)
2347 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2349 %(mmake)-%(subpackage)-package-basename := \
2350     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2352 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2353      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2354      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2355      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2356      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2358 .PHONY : %(mmake)-%(subpackage)-make-package
2359 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2362 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2364 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2365 #that $^ and $@ have exactly the same mtime, and in that case make tries
2366 #to rebuild $@ again, which would fail because the directory where
2367 #the package got installed would not exist anymore. 
2368 #We work this around by using an if statement to manually check the mtimes.
2369 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2370         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2371         $(RM) $@ ; \
2372         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2373         mkdir -p "$(DISTDIR)/Packages" ; \
2374         mkdir -p "$(%(mmake)-prefix)" ; \
2375         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2376         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2377         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2378     fi
2379 %end
2381 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2382     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2383     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2385 GNU_REPOSITORY := gnu://
2387 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2388     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2389     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2390     patch="%(patch)" patch_repo="%(patch_repo)" \
2391     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2392     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2394 %end
2396 #-----------------------------------------------------------------------------------------
2397 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2398 # that the package is a "Development" package, and as such it needs to be placed
2399 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2401 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2402 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2403 # "mmake" argument, because the metatarget is implicitely defined as
2405 #     #MM- development-%(package)
2407 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2408     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2409     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2411 #MM- development : development-%(package)
2414 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2415    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2416    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2417    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2418    extraoptions="%(extraoptions)"
2419     
2420 %end