#?.handler is at last #?-handler :), also for handlers created by build_module_simple.
[AROS.git] / config / make.tmpl
blob706f7b3521833282f1206581722a57b99c43e2f5
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) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling  $(CURDIR)/$(notdir %(from))"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(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) $(dir %(from)) %(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) $(dir %(from)) %(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) strip=$(STRIP)
56         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(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
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
121 %end
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128         @$(FOR) dir in %(dirs) ; do \
129             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
130         done
131 %end
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
137 ##                                                                         ##
138 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
139 ## mmakefile. They consist of one or more full makefile rules.             ##
140 ## In general the files generated in these macros are also defined as      ##
141 ## make targets so that they can be used as a dependency in other rules    ##
142 ##                                                                         ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
149 BDID := $(BDID)_
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
152 endif
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
160 %(to) : %(from)
161         @$(CP) $< $@
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
170 # present.
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
174         @$(CP) $< $@
175 %end
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by 
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186     stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196         @for f in $(FILES); do \
197              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
199              fi ; \
200         done
201         @$(TOUCH) $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
208 # be displayed.
209 # Restriction: at the moment when using a non-empty target dir %(from) may
210 # not have 
211 %define rule_join to=/A from=/A text=
213 %(to) : %(from)
214 ifneq (%(text),)
215         @$(ECHO) %(text)
216 endif
217         @$(CAT) $^ >$@
218 %end
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean 
227 %define include_deps deps=$(DEPS)/M  depstargets=
228 ifneq (%(deps),)
229   ifneq (%(depstargets),)
230     ifneq ($(findstring $(TARGET),%(depstargets)),)
231       -include %(deps)
232     endif
233   else
234     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
235       -include %(deps)
236     endif
237   endif
238 endif
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default. 
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
252 %end
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
261 # options
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 #   the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 #   it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
270 ifeq (%(targetdir),)
271   TMP_TARGETBASE := %(basename)
272 else
273   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
274 endif
276 ifeq ($(findstring %(compiler),host kernel target),)
277   $(error unknown compiler %(compiler))
278 endif
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 endif
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 endif
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 endif
304 ifeq (%(nix),yes)
305   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
306 else
307   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
308 endif
309 $(TMP_TARGETBASE).o : %(basename).c
310         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
312 ifeq (%(dflags),)
313   ifeq (%(nix),yes)
314     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
315   else
316     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317   endif
318 else
319   ifeq (%(nix),yes)
320     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
321   else
322     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
323   endif
324 endif
325 $(TMP_TARGETBASE).d : %(basename).c
326         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
327 %end
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile multiple C source files to an object file and
333 # generate the corresponding dependency files. The generated file will be put
334 # in the object directory without the directory part of the source file.
335 # options
336 # - basenames: the basenames of the files to compile. The names may include
337 #   relative or absolute path names. No wildcard is allowed
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 #   the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 #   it is put in the same directory as the .c file. When targetdir is not
343 #   empty, path names will be stripped from the file names so that all files
344 #   are in that dir and not in subdirectories.
345 # - compiler (default target): compiler to use, target, kernel or host
346 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
347     compiler=target
349 ifeq (%(targetdir),)
350 TMP_TARGETS := $(addsuffix .o,%(basenames))
351 TMP_DTARGETS := $(addsuffix .d,%(basenames))
352 TMP_WILDCARD := %
353 else
354 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
355 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
356 TMP_WILDCARD := %(targetdir)/%
358 # Be sure that all .c files are generated
359 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
361 # Be sure that all .c files are found
362 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
363 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
364 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
365 ifneq ($(TMP_DIRS),)
366     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
367     vpath %.c $(TMP_DIRS)
368 endif
370 endif
372 ifeq ($(findstring %(compiler),host kernel target),)
373   $(error unknown compiler %(compiler))
374 endif
375 ifeq (%(compiler),target)
376 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
377 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
378 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
379 endif
380 ifeq (%(compiler),host)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
382 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
384 endif
385 ifeq (%(compiler),kernel)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
387 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
388 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETS) : CFLAGS := %(cflags)
392 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
393         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
397 else
398 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
399 endif
400 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
401         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
402 %end
403 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407 # Make an alias from one arch specific build to another arch.
408 # arguments:
409 # - mainmmake: the mmake of the module in the main tree
410 # - arch: the current arch
411 # - alias: the alias to which this should point
412 %define rule_archalias mainmmake=\A arch=\A alias=\A
414 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
415 %end
416 #------------------------------------------------------------------------------
419 #------------------------------------------------------------------------------
420 # Generate a rule to compile a C source file to a shared object file with a
421 # .so suffix. Basename may contain a directory part, then the source
422 # file has to be in that directory. The generated file will be put in the
423 # object directory without the directory.
424 # options
425 # - basename: the basename of the file to compile. Use % for a wildcard rule
426 # - cflags (default $(CFLAGS)): the C flags to use for compilation
427 # - targetdir: the directory to put the .o file and the .d file. By default
428 #   it is put in the same directory as the .c file
429 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
431 ifeq (%(targetdir),)
432   TMP_TARGETBASE := %(basename)
433 else
434   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
435 endif
437 ifeq ($(findstring %(compiler),host kernel target),)
438   $(error unknown compiler %(compiler))
439 endif
440 ifeq (%(compiler),target)
441 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
442 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
443 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
444 endif
445 ifeq (%(compiler),host)
446 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
447 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
448 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
449 endif
450 ifeq (%(compiler),kernel)
451 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
452 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
453 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
454 endif
456 $(TMP_TARGETBASE).so : %(basename).c
457         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
458 %end
459 #------------------------------------------------------------------------------
462 #------------------------------------------------------------------------------
463 # Generate a rule to assemble a source file to an object file. Basename may
464 # contain a directory part, then the source file has to be in that directory.
465 # The generated file will be put in the object directory without the directory.
466 # options
467 # - basename: the basename of the file to compile. Use % for a wildcard rule
468 # - flags (default $(AFLAGS)): the asm flags to use for assembling
469 # - targetdir: the directory to put the .o file in. By default it is put in the
470 #   same directory as the .s file
471 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
473 ifeq (%(targetdir),)
474 %(basename).o : AFLAGS := %(aflags)
475 %(basename).o : %(basename).s
476         %assemble_q
477 %(basename).o : %(basename).S
478         %assemble_q
480 else
481 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
482 %(targetdir)/$(notdir %(basename)).o : %(basename).s
483         %assemble_q
484 %(targetdir)/$(notdir %(basename)).o : %(basename).S
485         %assemble_q
487 endif
488 %end
489 #------------------------------------------------------------------------------
492 #------------------------------------------------------------------------------
493 # Generate a rule to assemble multiple source files to an object file. The
494 # generated file will be put in the object directory with the directory part
495 # of the source file stripped off.
496 # options
497 # - basenames: the basenames of the files to compile. The names may include
498 #   relative or absolute path names. No wildcard is allowed
499 # - aflags (default $(AFLAGS)): the flags to use for assembly
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 #   it is put in the same directory as the .c file. When targetdir is not
502 #   empty, path names will be stripped from the file names so that all files
503 #   are in that dir and not in subdirectories.
504 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
506 ifeq (%(targetdir),)
507 TMP_TARGETS := $(addsuffix .o,%(basenames))
508 TMP_WILDCARD := %
509 else
510 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
511 TMP_WILDCARD := %(targetdir)/%
513 # Be sure that all .s files are generated
514 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
516 # Be sure that all .c files are found
517 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
518 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
519 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
520 ifneq ($(TMP_DIRS),)
521     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
522     vpath %%(suffix) $(TMP_DIRS)
523 endif
525 endif
527 ifeq ($(findstring %(compiler),host kernel target),)
528   $(error unknown compiler %(compiler))
529 endif
530 ifeq (%(compiler),target)
531 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
532 endif
533 ifeq (%(compiler),host)
534 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
535 endif
536 ifeq (%(compiler),kernel)
537 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
538 endif
540 $(TMP_TARGETS) : AFLAGS := %(aflags)
541 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
542         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
543 %end
544 #------------------------------------------------------------------------------
547 #------------------------------------------------------------------------------
548 # Link %(objs) to %(prog) using the libraries in %(uselibs)
549 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
550     usehostlibs= usestartup=yes detach=no nix=no linker=target
552 TMP_EXTRA_LDFLAGS := 
553 ifeq (%(nix),yes)
554     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
555 endif
556 ifeq (%(usestartup),no)
557     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
558 endif
559 ifeq (%(detach),yes)
560     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
561 endif
563 # Make a list of the lib files this program depends on.
564 # In LDFLAGS remove white space between -L and directory
565 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
566 # Filter out only the libdirs and remove -L
567 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
568 # Add trailing /
569 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
570 # Add normal linklib path
571 TMP_DIRS += $(LIBDIR)/
572 # add lib and .a to static linklib names
573 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
574 # search for the linklibs in the given path, ignore ones not found
575 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
576     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
579 ifeq (%(linker),target)
580 %(prog) : CMD:=$(TARGET_CC)
581 %(prog) : STRIPCMD:=$(TARGET_STRIP)
582 endif
583 ifeq (%(linker),host)
584 %(prog) : CMD:=$(HOST_CC)
585 %(prog) : STRIPCMD:=$(HOST_STRIP)
586 endif
587 ifeq (%(linker),kernel)
588 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
589 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
590 endif
592 %(prog) : OBJS := %(objs)
593 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
594 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
595 %(prog) : %(objs) $(TMP_DEPLIBS)
596         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
597 %end
598 #------------------------------------------------------------------------------
601 #------------------------------------------------------------------------------
602 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
603 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
604 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
605     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
606     usestartup=yes detach=no
608 TMP_EXTRA_LDFLAGS := 
609 ifeq (%(nix),yes)
610     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
611 endif
612 ifeq (%(usestartup),no)
613     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
614 endif
615 ifeq (%(detach),yes)
616     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
617 endif
619 # Make a list of the lib files the programs depend on.
620 # In LDFLAGS remove white space between -L and directory
621 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
622 # Filter out only the libdirs and remove -L
623 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
624 # Add trailing /
625 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
626 # Add normal linklib path
627 TMP_DIRS += $(LIBDIR)/
628 # add lib and .a to static linklib names
629 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
630 # search for the linklibs in the given path, ignore ones not found
631 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
632     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
635 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
636 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
637 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
638         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
639 %end
640 #------------------------------------------------------------------------------
643 #------------------------------------------------------------------------------
644 # Link the %(objs) to the library %(libdir)/lib%(libname).a
645 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
647 ifeq (%(linker),target)
648 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
649 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
650 endif
651 ifeq (%(linker),host)
652 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
653 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
654 endif
655 ifeq (%(linker),kernel)
656 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
657 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
658 endif
660 %(libdir)/lib%(libname).a : %(objs)
661         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
662 %end
663 #------------------------------------------------------------------------------
666 #------------------------------------------------------------------------------
667 # Link the %(objs) to the library %(libdir)/lib%(libname).so
668 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
670 %(libdir)/lib%(libname).so : %(objs)
671         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
672 %end
673 #------------------------------------------------------------------------------
676 #------------------------------------------------------------------------------
677 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
678 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
679 # The -noarosc flag is added so that modules are not linked with arosc.library
680 # (see /config/specs.in file)
681 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
682     ldflags=$(LDFLAGS) uselibs= usehostlibs=
684 TMP_LDFLAGS  := %(ldflags)
685 # Make a list of the lib files the programs depend on.
686 # In LDFLAGS remove white space between -L and directory
687 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
688 # Filter out only the libdirs and remove -L
689 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
690 # Add trailing /
691 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
692 # Add normal linklib path
693 TMP_DIRS += $(LIBDIR)/
694 # add lib and .a to static linklib names
695 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
696 # search for the linklibs in the given path, ignore ones not found
697 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
698     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
701 %(module) : LIB_NAMES := %(uselibs) \
702                muimaster asl keymap commodities codesets \
703                diskfont datatypes iffparse cybergraphics \
704                icon gadtools intuition layers graphics \
705                keymap locale aros \
706                dos utility expansion \
707                autoinit libinit
708 %(module) : OBJS := %(objs)
709 %(module) : ENDTAG := %(endobj)
710 %(module) : ERR := %(err)
711 %(module) : OBJDIR := %(objdir)
712 %(module) : LDFLAGS := $(TMP_LDFLAGS)
713 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
714                     -L/usr/lib $(addprefix -l,%(usehostlibs))
715 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
716         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
718 %end
719 #------------------------------------------------------------------------------
722 #------------------------------------------------------------------------------
723 # Generate the libdefs.h include file for a module.
724 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
726 TMP_TARGET := %(modname)_libdefs.h
727 TMP_DEPS := $(GENMODULE)
728 TMP_OPTS := 
729 ifneq (%(conffile),)
730     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
731     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
732 else
733     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
734     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
735 endif
736 ifneq (%(modsuffix),)
737     TMP_OPTS += -s %(modsuffix)
738 endif
739 ifneq (%(targetdir),)
740     TMP_OPTS += -d %(targetdir)
741     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
742 endif
744 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
745 $(TMP_TARGET) : MODNAME := %(modname)
746 $(TMP_TARGET) : MODTYPE := %(modtype)
747 $(TMP_TARGET) : $(TMP_DEPS)
748         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
749         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
750 %end
751 #------------------------------------------------------------------------------
753 #------------------------------------------------------------------------------
754 # Generate the _lib.fd file for a module.
755 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
757 TMP_TARGET := %(modname)_lib.fd
758 TMP_DEPS := $(GENMODULE)
759 TMP_OPTS := 
760 ifneq (%(conffile),)
761     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
762     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
763 else
764     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
765     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
766 endif
767 ifneq (%(modsuffix),)
768     TMP_OPTS += -s %(modsuffix)
769 endif
770 ifneq (%(targetdir),)
771     TMP_OPTS += -d %(targetdir)
772     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
773 endif
775 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
776 $(TMP_TARGET) : MODNAME := %(modname)
777 $(TMP_TARGET) : MODTYPE := %(modtype)
778 $(TMP_TARGET) : $(TMP_DEPS)
779         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
780         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
781 %end
782 #------------------------------------------------------------------------------
784 #------------------------------------------------------------------------------
785 # Generate a Makefile.%(modname) with the genmodule program and include this
786 # generated file in this Makefile
787 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
788     targetdir=
790 TMP_TARGET := Makefile.%(modname)
791 TMP_DEPS := $(GENMODULE)
792 TMP_OPTS := 
793 ifneq (%(conffile),)
794     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
795     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
796 else
797     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
798     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
799 endif
800 ifneq (%(modsuffix),)
801     TMP_OPTS += -s %(modsuffix)
802 endif
803 ifneq (%(targetdir),)
804     TMP_OPTS += -d %(targetdir)
805     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
806 endif
808 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
809 $(TMP_TARGET) : MODNAME := %(modname)
810 $(TMP_TARGET) : MODTYPE := %(modtype)
811 $(TMP_TARGET) : $(TMP_DEPS)
812         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
813 %end
814 #------------------------------------------------------------------------------
817 #------------------------------------------------------------------------------
818 # Generate the support files for compiling a module. This includes include
819 # files and source files. This rule has to be preceeded by
820 # %rule_genmodule_makefile
821 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
822     conffile=
824 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
825                $(%(modname)_LINKLIBFILES)
826 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
828 TMP_DEPS := $(GENMODULE)
829 TMP_OPTS :=
831 ifneq (%(conffile),)
832     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
833     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
834 else
835     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
836     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
837 endif
838 ifneq (%(modsuffix),)
839     TMP_OPTS += -s %(modsuffix)
840 endif
841 ifneq (%(targetdir),)
842     TMP_OPTS += -d %(targetdir)
843     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
844     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
845 endif
847 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
848 $(TMP_TARGETS) : MODNAME := %(modname)
849 $(TMP_TARGETS) : MODTYPE := %(modtype)
850 $(TMP_TARGETS) : $(TMP_DEPS)
851         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
852 ifneq (%(conffile),lib.conf)
853         @$(IF) $(TEST) -f lib.conf; then \
854           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
855         fi
856 endif
857         @$(IF) $(TEST) -f libdefs.h; then \
858           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
859         fi
860         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
861 %end
862 #------------------------------------------------------------------------------
865 #------------------------------------------------------------------------------
866 # Generate the support files for compiling a module. This includes include
867 # files and source files.
868 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
869     targetdir= conffile=
871 ifneq ($(%(modname)_INCLUDES),)
872 TMP_TARGETS := $(%(modname)_INCLUDES)
874 TMP_DEPS := $(GENMODULE)
875 TMP_OPTS :=
877 ifneq (%(conffile),)
878     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
879     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
880 else
881     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
882     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
883 endif
884 ifneq (%(modsuffix),)
885     TMP_OPTS += -s %(modsuffix)
886 endif
887 ifneq (%(targetdir),)
888     TMP_OPTS += -d %(targetdir)
889     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
890 endif
892 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
893 $(TMP_TARGETS) : MODNAME := %(modname)
894 $(TMP_TARGETS) : MODTYPE := %(modtype)
895 $(TMP_TARGETS) : $(TMP_DEPS)
896         @$(ECHO) "Generating include files"
897         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
898 endif
899 %end
900 #------------------------------------------------------------------------------
903 #------------------------------------------------------------------------------
904 # Common rules for all makefiles
905 %define common
906 # Delete generated makefiles
908 clean ::
909         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
911 include $(SRCDIR)/config/make.tail
913 BDID := $(BDTARGETID)
914 %end
915 #------------------------------------------------------------------------------
916       
918 #############################################################################
919 #############################################################################
920 ##                                                                         ##
921 ## Here are the mmakefile build macros. These are macros that takes care   ##
922 ## of everything to go from the sources to the generated target. Also all  ##
923 ## intermediate files and directories that are needed are created by these ##
924 ## rules.                                                                  ##
925 ##                                                                         ##
926 #############################################################################
927 #############################################################################
929 #------------------------------------------------------------------------------
930 # Build a program
931 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
932     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
933     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
934     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
935     compiler=target srcdir=
937 .PHONY : %(mmake)
939 BD_PROGNAME  := %(progname)
940 BD_OBJDIR    := %(objdir)
941 BD_TARGETDIR := %(targetdir)
943 BD_FILES     := %(files)
944 BD_ASMFILES  := %(asmfiles)
946 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
947 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
948 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
950 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
951 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
953 BD_CFLAGS    := %(cflags)
954 BD_AFLAGS    := %(aflags)
955 BD_DFLAGS    := %(dflags)
956 BD_LDFLAGS   := %(ldflags)
959 %(mmake)-quick : %(mmake)
961 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
962 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
964 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
965 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
966     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
967 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
968     aflags=$(BD_AFLAGS) compiler=%(compiler)
970 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
971     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
972     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
973     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
974     linker=%(compiler)
976 endif
978 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
980 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
981 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
982 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
984 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
986 %(mmake)-clean ::
987         @$(ECHO) "Cleaning up for metatarget %(mmake)"
988         @$(RM) $(FILES)
990 %end
991 #------------------------------------------------------------------------------
994 #------------------------------------------------------------------------------
995 # Build programs, for every C file an executable will be built with the same
996 # name as the C file
997 %define build_progs mmake=/A files=/A nix=no \
998     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
999     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1000     uselibs= usehostlibs= usestartup=yes detach=no
1002 .PHONY : %(mmake)
1004 BD_OBJDIR    := %(objdir)
1005 BD_TARGETDIR := %(targetdir)
1007 BD_FILES     := %(files)
1008 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1009 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1010 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1012 BD_CFLAGS    := %(cflags)
1013 BD_DFLAGS    := %(dflags)
1014 BD_LDFLAGS   := %(ldflags)
1017 %(mmake)-quick : %(mmake)
1019 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1020 %(mmake) : $(BD_EXES)
1022 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1023 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1024     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1026 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1027     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1028     ldflags=$(BD_LDFLAGS) \
1029     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1030     usestartup="%(usestartup)" detach="%(detach)"
1032 endif
1034 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1036 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1037 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1038 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1040 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1042 %(mmake)-clean ::
1043         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1044         @$(RM) $(FILES)
1046 %end
1047 #------------------------------------------------------------------------------
1050 #------------------------------------------------------------------------------
1051 # Build a module.
1052 # This is a bare version: It just compiles and links the given files. It is
1053 # assumed that all needed boiler plate code is in the files. This should only
1054 # be used for compiling external code. For AROS code use %build_module
1055 %define build_module_simple mmake=/A modname=/A modtype=/A \
1056     files="$(basename $(call WILDCARD, *.c))" \
1057     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1058     objdir=$(OBJDIR) moduledir= \
1059     uselibs= usehostlibs= compiler=target
1061 # Define metamake targets and their dependencies
1062 #MM %(mmake) : core-linklibs includes-generate-deps
1063 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1064 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1065 #MM %(mmake)-kobj-quick
1066 #MM %(mmake)-pkg-quick
1067 #MM %(mmake)-quick
1068 #MM %(mmake)-clean
1070 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1072 .PHONY : $(BD_ALLTARGETS)
1074 ifeq (%(modname),)
1075 $(error using %build_module_simple: modname may not be empty)
1076 endif
1077 ifeq (%(modtype),)
1078 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1079 endif
1081 # Default values for variables and arguments
1082 BD_DEFLINKLIBNAME := %(modname)
1083 BD_DEFDFLAGS := %(cflags)
1084 OBJDIR ?= $(GENDIR)/$(CURDIR)
1085 BD_MODDIR := %(moduledir)
1086 ifeq ($(BD_MODDIR),)
1087   ifeq (%(modtype),library)
1088     BD_MODDIR  := $(AROS_LIBS)
1089   endif
1090   ifeq (%(modtype),gadget)
1091     BD_MODDIR  := $(AROS_GADGETS)
1092   endif
1093   ifeq (%(modtype),datatype)
1094     BD_MODDIR  := $(AROS_DATATYPES)
1095   endif
1096   ifeq (%(modtype),handler)
1097     BD_MODDIR  := $(AROS_FS)
1098   endif
1099   ifeq (%(modtype),device)
1100     BD_MODDIR  := $(AROS_DEVS)
1101   endif
1102   ifeq (%(modtype),resource)
1103     BD_MODDIR  := $(AROS_RESOURCES)
1104   endif
1105   ifeq (%(modtype),hook)
1106     BD_MODDIR  := $(AROS_RESOURCES)
1107   endif
1108   ifeq (%(modtype),mui)
1109     BD_MODDIR  := $(AROS_CLASSES)/Zune
1110   endif
1111   ifeq (%(modtype),mcc)
1112     BD_MODDIR  := $(AROS_CLASSES)/Zune
1113   endif
1114   ifeq (%(modtype),mcp)
1115     BD_MODDIR  := $(AROS_CLASSES)/Zune
1116   endif
1117   ifeq (%(modtype),usbclass)
1118     BD_MODDIR  := $(AROS_CLASSES)/USB
1119   endif
1120   ifeq (%(modtype),hidd)
1121     BD_MODDIR  := $(AROS_DRIVERS)
1122   endif
1123 endif
1124 ifeq ($(BD_MODDIR),)
1125   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1126 endif
1128 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1129 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1130 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1132 %rule_compile_multi \
1133     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1134     cflags="%(cflags)" dflags="%(dflags)" \
1135     compiler=%(compiler)
1137 # Handlers use dash instead of dot in their names
1138 ifeq (%(modtype),handler)
1139 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1140 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1141 else
1142 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1143 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1144 endif
1145 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1147 %(mmake)-quick : %(mmake)
1148 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1149 %(mmake)-kobj-quick : $(BD_KOBJ)
1150 %(mmake)       : $(BD_MODULE)
1151 %(mmake)-pkg   : $(BD_PKGMOD)
1152 %(mmake)-kobj  : $(BD_KOBJ)
1154 # The module is linked from all the compiled .o files
1155 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1157 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1158                  endobj= err=%(modname).err objdir=%(objdir) \
1159                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1161 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1162                  endobj= err=%(modname).err objdir=%(objdir) \
1163                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1165 # Link kernel object file
1166 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1168 # Make these symbols local
1169 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1170             UtilityBase ExpansionBase KeymapBase KernelBase
1172 BD_SYMBOLS := $(BD_KBASE)
1174 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1175 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1176 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1177 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1178 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1179 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1180         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1181         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1182         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1185 ## Dependency fine-tuning
1187 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1188 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1190 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1191 $(BD_MODULE) : | $(BD_MODDIR)
1192 $(BD_KOBJ) : | $(KOBJSDIR)
1193 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1195 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1196 %(mmake)-clean ::
1197         @$(ECHO) "Cleaning up for module %(modname)"
1198         @$(RM) $(FILES)
1199 %end
1200 #------------------------------------------------------------------------------
1203 #------------------------------------------------------------------------------
1204 # Build a module
1205 # Explanation of this macro is done in the developer's manual
1206 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1207   conffile= files="$(basename $(call WILDCARD, *.c))" \
1208   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1209   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1210   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1211   compiler=target
1213 # Define metamake targets and their dependencies
1214 #MM- includes-all : %(mmake)-includes
1215 #MM- linklibs-%(modname): %(mmake)-linklib
1216 #MM- includes-%(modname): %(mmake)-includes
1217 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1218 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1219 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1220 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1221 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1222 #MM %(mmake)-linklib : %(mmake)-includes
1223 #MM %(mmake)-quick : %(mmake)-includes-quick
1224 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1225 #MM     includes-generate-deps %(mmake)-fd
1226 #MM %(mmake)-includes-quick
1227 #MM %(mmake)-includes-dirs
1228 #MM %(mmake)-fd
1229 #MM %(mmake)-makefile
1230 #MM %(mmake)-clean
1232 # All MetaMake targets defined by this macro
1233 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1234     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1235     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1236     %(mmake)-linklib %(mmake)-fd
1238 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1240 ifeq (%(modname),)
1241 $(error using %build_module: modname may not be empty)
1242 endif
1243 ifeq (%(modtype),)
1244 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1245 endif
1247 # Default values for variables and arguments
1248 BD_DEFLINKLIBNAME := %(modname)
1249 BD_DEFDFLAGS := %(cflags)
1250 OBJDIR ?= $(GENDIR)/$(CURDIR)
1252 ## Create genmodule include Makefile for the module
1254 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1256 %rule_genmodule_makefile \
1257     modname=%(modname) modtype=%(modtype) \
1258     modsuffix=%(modsuffix) targetdir=%(objdir) \
1259     conffile=%(conffile)
1261 %(objdir)/Makefile.%(modname) : | %(objdir)
1263 GLOB_MKDIRS += %(objdir)
1265 # Do not parse these statements if metatarget is not appropriate
1266 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1268 include %(objdir)/Makefile.%(modname)
1270 BD_DEFMODDIR := $(%(modname)_MODDIR)
1273 ## include files generation
1275 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1276 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1277 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1279 %(mmake)-includes-quick : %(mmake)-includes
1280 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1281     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1282     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1284 ifneq ($(%(modname)_INCLUDES),)
1285 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1286                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1287                          conffile=%(conffile)
1289 %rule_copy_diff_multi \
1290     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1291     stampfile=%(objdir)/%(modname)_geninc
1293 %rule_copy_diff_multi \
1294     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1295     stampfile=%(objdir)/%(modname)_incs
1297 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1299 TMP%(modname)_INCDIRS := \
1300     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1301     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1302     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1303 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1305 endif
1307 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1308                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1309                            conffile=%(conffile)
1311 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1312 $(BD_DEFLIBDEFSINC) :
1313         @$(ECHO) "generating $@"
1314         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1316 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1317 GLOB_MKDIRS += %(objdir)/include
1319 ## Extra genmodule src files generation
1320 ## 
1321 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1322                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1323                       conffile=%(conffile)
1326 ## Create FD file
1327 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1328 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1330 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1331                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1333 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1335 GLOB_MKDIRS += $(BD_FDDIR)
1338 ## Compilation
1340 BD_FILES      := %(files)
1341 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1342 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1343 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1345 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1346 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1347 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1349 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1350 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1352 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1353 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1354 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1355     BD_LINKLIB :=
1356 else
1357     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1358 endif
1359 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1361 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1362 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1364 %rule_compile_multi \
1365     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1366     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1367     compiler=%(compiler)
1368 %rule_compile_multi \
1369     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1370     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1371     compiler=%(compiler)
1373 ifneq ($(BD_LINKLIBAFILES),)
1374 %rule_assemble_multi \
1375     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1376 endif
1378 ## Linking
1380 ifeq (%(modsuffix),)
1381 BD_SUFFIX := %(modtype)
1382 else
1383 BD_SUFFIX := %(modsuffix)
1384 endif
1386 # Handlers use dash instead of dot in their names
1387 ifeq ($(BD_SUFFIX),handler)
1388 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1389 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1390 else
1391 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1392 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1393 endif
1394 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1396 %(mmake)-quick      : %(mmake)
1397 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB)
1398 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB)
1399 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB)
1400 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB)
1401 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1402 %(mmake)-linklib    : $(BD_LINKLIB)
1404 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1405                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1407 # Handlers always have entry point
1408 ifneq (%(modtype),handler)
1409 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1410 endif
1412 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1413 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1414                  %(linklibobjs)
1416 # The module is linked from all the compiled .o files
1417 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1418                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1419                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1421 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1422                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1423                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1425 # Link static lib
1426 ifneq ($(BD_LINKLIB),)
1427 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1429 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1430 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1431 endif
1433 # Link kernel object file
1434 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1436 # Make these symbols local
1437 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1438             UtilityBase ExpansionBase KeymapBase KernelBase
1440 BD_SYMBOLS := $(BD_KBASE)
1442 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1443 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1444 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1445 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1446 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1447 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1448         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1449         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1450         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1452 ## Dependency fine-tuning
1454 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1455 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1457 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1458 $(BD_MODULE) : | %(prefix)/%(moduledir)
1459 $(BD_PKGMOD) : | $(PKGDIR)
1460 $(BD_KOBJ)   : | $(KOBJSDIR)
1461 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1463 # Some include files need to be generated before the .c can be parsed.
1464 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1466 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1467     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1468 $(BD_DEPS) : $(BD_DFILE_DEPS)
1469 endif
1471 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1472     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1473     %(objdir)/Makefile.%(modname) \
1474     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1475     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1476     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1477     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1478     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1479     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1480     $(BD_ENDOBJS)
1481 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1482 %(mmake)-clean ::
1483         @$(ECHO) "Cleaning up for module %(modname)"
1484         @$(RM) $(FILES)
1486 endif # $(TARGET) in $(BD_ALLTARGETS)
1487 %end
1488 #------------------------------------------------------------------------------
1491 #------------------------------------------------------------------------------
1492 # Build a module skeleton
1493 # This is a stripped-down version of build_module, it only creates include files,
1494 # but no actual object. This is used when for plugins or classes with the same
1495 # API, but no actual implementation here.
1496 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1497   conffile= \
1498   objdir=$(OBJDIR) prefix=$(AROSDIR)
1500 # Define metamake targets and their dependencies
1501 #MM- includes-all : %(mmake)-includes
1502 #MM %(mmake) : %(mmake)-includes core-linklibs
1503 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1504 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1505 #MM %(mmake)-linklib : %(mmake)-includes
1506 #MM %(mmake)-quick : %(mmake)-includes-quick
1507 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1508 #MM     includes-generate-deps
1509 #MM %(mmake)-includes-quick
1510 #MM %(mmake)-includes-dirs
1511 #MM %(mmake)-makefile
1512 #MM %(mmake)-clean
1514 # All MetaMake targets defined by this macro
1515 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1516     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1517     %(mmake)-kobj %(mmake)-pkg
1519 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1521 ifeq (%(modname),)
1522 $(error using %build_module_skeleton: modname may not be empty)
1523 endif
1524 ifeq (%(modtype),)
1525 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1526 endif
1528 # Default values for variables and arguments
1529 BD_DEFLINKLIBNAME := %(modname)
1530 BD_DEFDFLAGS := %(cflags)
1531 OBJDIR ?= $(GENDIR)/$(CURDIR)
1533 ## Create genmodule include Makefile for the module
1535 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1537 %rule_genmodule_makefile \
1538     modname=%(modname) modtype=%(modtype) \
1539     modsuffix=%(modsuffix) targetdir=%(objdir) \
1540     conffile=%(conffile)
1542 %(objdir)/Makefile.%(modname) : | %(objdir)
1544 GLOB_MKDIRS += %(objdir)
1546 # Do not parse these statements if metatarget is not appropriate
1547 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1549 include %(objdir)/Makefile.%(modname)
1551 BD_DEFMODDIR := $(%(modname)_MODDIR)
1554 ## include files generation
1556 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1557 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1558 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1560 %(mmake)-includes-quick : %(mmake)-includes
1561 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1562     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1563     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1565 ifneq ($(%(modname)_INCLUDES),)
1566 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1567                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1568                          conffile=%(conffile)
1570 %rule_copy_diff_multi \
1571     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1572     stampfile=%(objdir)/%(modname)_geninc
1574 %rule_copy_diff_multi \
1575     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1576     stampfile=%(objdir)/%(modname)_incs
1578 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1580 TMP%(modname)_INCDIRS := \
1581     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1582     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1583     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1584 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1586 endif
1588 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1589                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1590                            conffile=%(conffile)
1592 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1593 $(BD_DEFLIBDEFSINC) :
1594         @$(ECHO) "generating $@"
1595         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1597 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1598 GLOB_MKDIRS += %(objdir)/include
1600 ## Extra genmodule src files generation
1601 ## 
1602 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1603                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1604                       conffile=%(conffile)
1606 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1607     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1608     %(objdir)/Makefile.%(modname) \
1609     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1610     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1611     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1612     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1613     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1614     $(BD_DEFLIBDEFSINC)
1615 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1616 %(mmake)-clean ::
1617         @$(ECHO) "Cleaning up for module %(modname)"
1618         @$(RM) $(FILES)
1620 endif # $(TARGET) in $(BD_ALLTARGETS)
1621 %end
1622 #------------------------------------------------------------------------------
1625 #------------------------------------------------------------------------------
1626 # Build a linklib.
1627 # - mmake is the mmaketarget
1628 # - libname is the baselibname e.g. lib%(libname).a will be created
1629 # - files are the C source files to include in the lib. The list of files
1630 #   has to be given without the .c suffix
1631 # - asmfiles are the asm files to include in the lib. The list of files has to
1632 #   be given without the .s suffix
1633 # - objs additional object to link into the linklib. The objects have to be
1634 #   given with full absolute path and the .o suffix.
1635 # - cflags are the flags to compile the source (default $(CFLAGS))
1636 # - dflags are the flags use during makedepend (default equal to cflags)
1637 # - aflags are the flags use during assembling (default $(AFLAGS))
1638 # - objdir is where the .o are generated
1639 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1640 %define build_linklib mmake=/A libname=/A \
1641   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= compiler=target \
1642   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1644 # assign and generate the local variables used in this macro
1645 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1647 BD_FILES      := %(files)
1648 BD_ASMFILES   := %(asmfiles)
1650 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1651 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1652 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1654 BD_OBJS       := $(BD_ARCHOBJS) \
1655                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1656                  %(objs)
1657 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1659 BD_CFLAGS     := %(cflags)
1660 ifeq (%(dflags),)
1661 BD_DFLAGS     := $(BD_CFLAGS)
1662 else
1663 BD_DFLAGS     := %(dflags)
1664 endif
1665 BD_AFLAGS     := %(aflags)
1667 BD_LINKLIB    := %(libdir)/lib%(libname).a
1669 .PHONY : %(mmake) %(mmake)-clean
1671 #MM %(mmake) : includes-generate-deps
1672 %(mmake) : $(BD_LINKLIB)
1675 %(mmake)-clean ::
1676         @$(RM) $(BD_OBJS) $(BD_DEPS)
1678 ifeq ($(TARGET),%(mmake))
1679 ifneq ($(dir $(BD_FILES)),./)
1680 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1681 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1682 endif
1684 %rule_compile basename=% targetdir=%(objdir) compiler=%(compiler) \
1685               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1686 %rule_assemble basename=% targetdir=%(objdir) \
1687               aflags=$(BD_AFLAGS)
1689 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1690 endif
1692 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1694 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1695 $(BD_LINKLIB) : | %(libdir)
1696 GLOB_MKDIRS += %(objdir) %(libdir)
1698 %end
1699 #------------------------------------------------------------------------------
1702 #------------------------------------------------------------------------------
1703 # Build catalogs.
1704 # - mmake is the mmaketarget
1705 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1706 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1707 # - subdir is the destination subdirectory of the catalogs
1708 # - name is the name of the destination catalog, without the .catalog suffix
1709 # - source is the path to the generated source code file
1710 # - dir is the base destination directory (default $(AROS_CATALOGS))
1711 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1712 # - srcdir is the directory in which the *.cd and *.ct files are searched
1714 %define build_catalogs mmake=/A name=/A subdir=/A \
1715  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1716  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1718 ifeq (%(description),)
1719 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1720 else
1721 BD_DESC := %(description)
1722 endif
1724 ifeq (%(catalogs),)
1725 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1726 else
1727 BD_LNGS := %(catalogs)
1728 endif
1730 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1731 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1734 %(mmake) : $(BD_OBJS) %(source)
1736 $(BD_OBJS) : | $(BD_DIRS)
1737 GLOB_MKDIRS += $(BD_DIRS)
1739 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1740         @$(ECHO) "Creating   %(name) catalog for language $*."
1741         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1743 ifneq (%(source),)
1744 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1745 %(source) : $(BD_DESC).cd | $(dir %(source))
1746         @$(ECHO) "Creating   %(name) catalog source file %(source)"
1747         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1748 endif
1751 %(mmake)-clean ::
1752         $(RM) $(BD_OBJS) %(source)
1754 .PHONY: %(mmake) %(mmake)-clean
1756 %end
1757 #-----------------------------------------------------------------------------
1760 #-----------------------------------------------------------------------------
1761 # Build icons.
1762 # - mmake is the mmaketarget
1763 # - icons is a list of icon base names (ie. without the .info suffix)
1764 # - dir is the destination directory
1765 # - srcdir is where *.png and *.info.src are searched
1766 #-----------------------------------------------------------------------------
1768 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1770 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1773 %(mmake) : $(BD_OBJS)
1775 ifeq (%(image),)
1777 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1778         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1779         @$(ILBMTOICON) $+ $@
1781 else
1783 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1784         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1785         @$(ILBMTOICON) $+ $@
1787 endif
1789 $(BD_OBJS) : | %(dir)
1790 GLOB_MKDIRS += %(dir)
1792 %(mmake)-clean : FILES := $(BD_OBJS)
1794 %(mmake)-clean ::
1795         @$(RM) $(FILES)
1797 .PHONY: %(mmake) %(mmake)-clean
1799 %end
1800 #-----------------------------------------------------------------------------
1803 #------------------------------------------------------------------------------
1804 # Compile files for an arch-specific replacement of code for a module
1805 # - files: the basenames of the C files to compile.
1806 # - asmfiles: the basenames of the asm files to assemble.
1807 # - mainmmake: the mmake of the module in the main directory to compile these
1808 #   arch specific files for.
1809 # - maindir: the object directory for the main module
1810 # - arch: the arch for which to compile these files. It can have the form
1811 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1812 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1813 # - dflags: the flags used during creation of dependency file. If not specified
1814 #   the same value as cflags will be used
1815 # - aflags: the flags used during assembling
1816 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1817 #   the target compiler is used
1818 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1819 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1821 ifeq (%(files) %(asmfiles),)
1822   $(error no files or asmfiles given)
1823 endif
1825 %buildid targets="%(mainmmake)-%(arch)"
1827 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1828 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1829 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1830 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1831 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1832 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1833 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1834 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1835 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1836 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1837 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1838 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1839 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1840 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1841 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1842 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1843 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1844 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1845 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1846 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1847 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1849 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1851 ifeq (%(arch),)
1852   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1853 endif
1855 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1856 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1857 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1858 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1859 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1861 ifneq (%(modulename),)
1862 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1863 endif
1865 ifeq ($(TARGET),%(mainmmake)-%(arch))
1866 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1867 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1868 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1869 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1870 endif
1872 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1873 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1876 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1878 ifeq ($(findstring %(compiler),host kernel target),)
1879   $(error unknown compiler %(compiler))
1880 endif
1881 ifeq (%(compiler),target)
1882 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1883 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1884 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1885 endif
1886 ifeq (%(compiler),host)
1887 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1888 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1889 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1890 endif
1891 ifeq (%(compiler),kernel)
1892 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1893 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1894 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1895 endif
1896 ifneq (%(modulename),)
1897 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1898 else
1899 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1900 endif
1901 ifeq ($(TARGET),%(mainmmake)-%(arch))
1902 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
1903         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1904 endif
1906 ifeq (%(dflags),)
1907 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1908 else
1909 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1910 endif
1911 ifeq ($(TARGET),%(mainmmake)-%(arch))
1912 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
1913         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1914 endif
1916 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1918 ifeq ($(TARGET),%(mainmmake)-%(arch))
1919 $(BD_OBJDIR$(BDID))/%.o : %.s
1920         %assemble_q opt=$(AFLAGS)
1921 $(BD_OBJDIR$(BDID))/%.o : %.S
1922         %assemble_q opt=$(AFLAGS)
1923 endif
1925 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1926 %end
1927 #------------------------------------------------------------------------------
1930 #------------------------------------------------------------------------------
1931 # generate asm files from c files (for debugging purposes)
1932 %define ctoasm_q
1933 %.s : %.c
1934         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1935         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1936 %end
1937 #------------------------------------------------------------------------------
1940 #------------------------------------------------------------------------------
1941 # Copy files from one directory to another.
1943 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1945 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1947 GLOB_MKDIRS += %(dst)
1949 .PHONY : %(mmake)
1952 %(mmake) : | %(dst) 
1953         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1955 %end
1956 #------------------------------------------------------------------------------
1959 #------------------------------------------------------------------------------
1960 # Copy a directory recursively to another place, preserving the original 
1961 # hierarchical structure
1963 # src: the source directory whose content will be copied
1964 # dst: the directory where to copy src's content. If not existing, it will be made.
1966 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
1968 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1969 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
1970 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1972 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
1973 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
1975 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
1977 .PHONY : %(mmake)
1980 %(mmake): | $(GENDIR)/$(CURDIR)
1981         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1982         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1983         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1984         for d in $(%(mmake)_DIRS); do                      \
1985             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1986         done
1987         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1988         for f in $(%(mmake)_FILES); do                                            \
1989             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1990         done;  \
1991         for dst in %(dst); do \
1992             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1993         done
1995 %end
1996 #------------------------------------------------------------------------------
1999 #------------------------------------------------------------------------------
2000 #   Copy include files into the includes directories. There are currently
2001 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2002 #   for building tools that need to run on the host system $(GENINCDIR). The
2003 #   $(GENINCDIR) path must not contain any references to the C runtime
2004 #   library header files.
2006 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2007     dir= compiler=target
2009 ifeq ($(findstring %(compiler),host kernel target),)
2010 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2011 endif
2013 ifneq (%(dir),)
2014 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2015 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2016 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2017 else
2018 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2019 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2020 endif
2022 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2023         @$(CP) $< $@
2026 ifeq (%(compiler),target)
2028 ifneq (%(dir),)
2029 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2030 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2031 else
2032 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2033 endif
2035 BD_INCL_FILES += $(BD_INCL_FILES2)
2037 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2038         @$(CP) $< $@
2039 endif
2042 %(mmake) : $(BD_INCL_FILES)
2044 .PHONY: %(mmake)
2046 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2047 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2048 %end
2049 #------------------------------------------------------------------------------
2052 #------------------------------------------------------------------------------
2053 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2054 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2055 STUBS_MEM := $(addsuffix .o,$(STUBS))
2056 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2057 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2058 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2060 #MM- linklibs : hidd-%(hidd)-stubs
2061 #MM- %(parenttarget): hidd-%(hidd)-stubs
2062 #MM hidd-%(hidd)-stubs : includes includes-copy
2063 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2065 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2066         %mklib_q from=$^
2068 $(STUBS_OBJ) : $(STUBS_SRC) 
2069         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2071 $(STUBS_DEP) : $(STUBS_SRC)
2072         %mkdepend_q flags=%(dflags)
2074 setup ::
2075         %mkdirs_q $(OBJDIR) $(LIBDIR)
2078 clean ::
2079         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2081 DEPS := $(DEPS) $(STUBS_DEP)
2083 %end
2084 #------------------------------------------------------------------------------
2087 #------------------------------------------------------------------------------
2088 # Build an imported source tree which uses the configure script from the
2089 # autoconf package.  This rule will try to "integrate" the produced files as
2090 # much as possible in the AROS build, for example by putting libraries in the
2091 # standard library directory, includes in the standard include directory, and
2092 # so on. You can however override this behaviour.
2094 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2095 # be %(bindir) (or its deduced value) when running "make install", and
2096 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2097 # configure script some more parameters whose value depends upon the PROGDIR
2098 # env var, so that the program gets all its stuff installed in the proper place
2099 # when building it, but when running it from inside AROS it can also find that
2100 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2101 # the configuration parameters set when running ./configure
2103 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2104 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2105 # to the name which has to follow it.
2108 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2109     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2110     install_target=install preconfigure= postconfigure= postinstall= \
2111     install_env=
2113 ifneq (%(prefix),)
2114     %(mmake)-prefix := %(prefix)
2115 else
2116     %(mmake)-prefix := $(AROS_CONTRIB)
2117 endif
2119 ifneq (%(aros_prefix),)
2120     %(mmake)-aros_prefix := %(aros_prefix)
2121 else
2122     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2123 endif
2125 ifeq (%(nix),yes)
2126     %(mmake)-nix    := -nix
2127     %(mmake)-volpfx := /
2128     %(mmake)-volsfx := /
2129     
2130     ifeq (%(nix_dir_layout),)
2131         %(mmake)-nix_dir_layout := yes
2132     endif
2133 else
2134     %(mmake)-volsfx := :
2135     
2136     ifeq (%(nix_dir_layout),)
2137         %(mmake)-nix_dir_layout := no
2138     endif
2139 endif
2141 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2143 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2144         exec_prefix=$(%(mmake)-prefix) %(install_env)
2146 # Check if chosen compiler is valid
2147 ifeq ($(findstring %(compiler),host target kernel),)
2148   $(error unknown compiler %(compiler))
2149 endif
2151 # Set legacy 'host' variable based on chosen compiler
2152 ifeq (%(compiler),host)
2153     host := yes
2154         ifeq (%(package),)
2155                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2156         else
2157                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2158         endif
2159 else
2160     host := no
2161         ifeq (%(package),)
2162                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2163         else
2164                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2165         endif
2166 endif
2168 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2169 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2171 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2172     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2173     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2174 else
2175     ifeq (%(nix),yes)
2176         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2177         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2178     else
2179         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2180     endif
2182     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2183     
2184     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2185         sbindir=$(%(mmake)-prefix) \
2186         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2187         oldincludedir=$(AROS_INCLUDES) %(install_env)
2188 endif
2190 ifneq ($(DEBUG),yes)
2191     %(mmake)-s_flag = -s
2192 endif
2194 # Set up build environment, and options for configure script
2195 ifeq (%(compiler),host)
2196     COMPILER_ENV := \
2197         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2198         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2199         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2200         TARGET_RANLIB="$(RANLIB)"
2201     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2202 endif
2203 ifeq (%(compiler),target)
2204     COMPILER_ENV := \
2205         CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2206         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2207         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2208         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2209         TARGET_RANLIB="$(RANLIB)"
2210     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2211         --host=$(AROS_TARGET_CPU)-aros\
2212         --target=$(AROS_TARGET_CPU)-aros\
2213         --disable-nls\
2214         --without-x --without-pic --disable-shared
2215 endif
2216 ifeq (%(compiler),kernel)
2217     COMPILER_ENV := \
2218         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2219         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2220         TARGET_RANLIB="$(RANLIB)"
2221     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2222         --host=$(AROS_TARGET_CPU)-aros\
2223         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2224         --without-x --without-pic --disable-shared
2225 endif
2228 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2230 #MM- %(mmake) : setup includes core-linklibs %(mmake)-quick
2232 # Using -j1 in install_command may result in a warning but finally
2233 # it does its job. make install for gcc does not work reliably for -jN
2234 # where N > 1.
2235 ifneq (%(install_target),)
2236     %(mmake)-install_command = \
2237         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2238         -C $(%(mmake)-pkgdir) %(install_target) -j1
2240     %(mmake)-uninstall_command = \
2241     $(RM) $(%(mmake)-installflag) && \
2242     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2243     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2244 else
2245     %(mmake)-install_command   := true
2246     %(mmake)-uninstall_command := true
2247 endif
2249 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2252 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2254 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2255         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2256             $(RM)  $(%(mmake)-installflag) && \
2257             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2258              -C $(%(mmake)-pkgdir) && \
2259             $(%(mmake)-install_command) && \
2260             $(TOUCH) $@ -r $^; \
2261         fi
2263 $(%(mmake)-pkgdir)/.files-touched:
2264         %mkdirs_q $(%(mmake)-pkgdir)
2265         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2266         $(TOUCH) $@
2269 %(mmake)-uninstall :
2270         $(%(mmake)-uninstall_command)
2273 %(mmake)-configure : $(%(mmake)-configflag)
2275 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2276 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2277         $(RM) $@
2278         %mkdirs_q $(%(mmake)-pkgdir)
2279         cd $(%(mmake)-pkgdir) && \
2280         find . -name config.cache -exec $(RM) '{}' \; && \
2281         $(COMPILER_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2282             %(extraoptions) && \
2283         $(TOUCH) $@
2286 %(mmake)-clean : %(mmake)-uninstall
2287         @$(RM) $(%(mmake)-pkgdir)
2288 %end
2289 #------------------------------------------------------------------------------
2292 #------------------------------------------------------------------------------
2293 # Given an archive name, patches names and locations where to find them, fetch
2294 # the archive and the patches from any of those locations, unpack the archive
2295 # and then apply the patches.
2297 # Locations currently supported are http and ftp sites, plus local filesystem
2298 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2299 # the fetch.sh script needs to be modified, since this macro relies on that script.
2301 # Arguments:
2303 #     - mmake           = mmaketarget
2304 #     - archive_origins = list of locations where to find the archive. They are tried
2305 #                         in sequence, until the archive is found and fetching it 
2306 #                         succeeded. If not specified, the current directory is assumed.
2307 #     - archive         = the archive name. Mandatory.
2308 #     - suffixes        = a list of suffixes to append to the the package name plus the
2309 #                         version. Each one of them is tried until a matching archive is
2310 #                         found. They are appended to patches and these are tried the
2311 #                         same way as packages are.
2312 #     - location        = the local directory where to put the fetched archive and patches.
2313 #                         If not specified, the directory specified by destination is used.
2314 #     - destination     = the directory to unpack the archive to.
2315 #                         If not specified, the current directory is assumed.
2316 #     - patches_origins = list of locations where to find the patches. They are tried
2317 #                         in sequence, until a patch is found and fetching it 
2318 #                         succeeded. If not specified, the current directory is assumed.
2319 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2320 #                         patch_name[:[patch_subdir][:patch_opt]].
2322 #                             - patch_name   = the name of the patch file
2323 #                             - patch_subdir = the directory within \destination\ where to
2324 #                                              apply the patch.
2325 #                             - patch_opt    = any options to pass to the `patch' command
2326 #                                              when applying the patch.
2327 #                         
2328 #                         The patch_subdir and patch_opt fields are optional.
2330 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2331     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2333 .PHONY: %(mmake)
2335 ifneq (%(location),)
2336     %(mmake)-location := %(location)
2337 else
2338     %(mmake)-location := %(destination)
2339 endif
2342 %(mmake) :
2343         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2344         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2345 %end
2346 #------------------------------------------------------------------------------
2349 #------------------------------------------------------------------------------
2350 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2351 # unpatched source tree and runs diff against this and a previously fetched and possibly
2352 # patched tree. Depending on what happens after patching during a normal build it might
2353 # give best results if the new patch is created directly after fetch.
2355 # Arguments:
2357 #     - mmake       = mmaketarget
2358 #     - archive     = archive base name
2359 #     - suffixes    = a list of suffixes to append to the the package name plus the
2360 #                     version. Each one of them is tried until a matching archive is
2361 #                     found.
2362 #     - destination = the directory to unpack the archive to.
2363 #     - excludes    = diff patterns to exclude files or directories from the patch
2365 %define create_patch mmake=/A archive=/A suffixes="tar.bz2 tar.gz" destination=/A excludes=
2367 .PHONY: %(mmake)
2369 ifneq (%(excludes),)
2370     %(mmake)-exclude := -X ./exclude.patterns
2371 endif
2374 %(mmake):
2375         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2376         $(MV) %(destination)/%(archive) %(destination)/tmp/%(archive).aros ; \
2377         cd %(destination)/tmp ; \
2378         $(FOR) f in %(excludes) ; do \
2379             $(ECHO) $$f >> ./exclude.patterns ; \
2380         done ; \
2381         diff -ruN $(%(mmake)-exclude) \
2382             %(archive) \
2383             %(archive).aros \
2384             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2385         $(MV) %(destination)/tmp/%(archive).aros %(destination)/%(archive) ; \
2386         $(RM) %(destination)/tmp
2387 %end
2388 #------------------------------------------------------------------------------
2391 #------------------------------------------------------------------------------
2392 # Joins the features of %fetch and %build_with_configure, taking advantage of
2393 # the naming scheme of GNU packages. GNU packages names are in the form
2395 #     <package name>-<version number>.<archive format suffix>
2397 # If a patch is provided, it *must* be named the following way:
2399 #    <package name>-<version number>-aros.diff
2401 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2402 # CD'ing into the archive's extracted directory.
2404 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2405 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2406 # to make that patch fully comprehensive.
2408 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2410 # Arguments:
2412 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2413 #                     macro.
2414 #    - package      = the GNU package name, sans version and archive format suffixes.
2415 #    - version      = the package's version number, or otherwise any other version string.
2416 #                     It gets appended to the package name to form the basename of the archive.
2417 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2418 #                     version. Each one of them is tried until a matching archive is found.
2419 #                     Defaults to "tar.bz2 tar.gz".
2420 #    - destination  = same meaning as the one for the %fetch macro
2421 #    - location     = same meaning as the one for the %fetch macro
2422 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2423 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2424 #                     fetched or not
2425 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2426 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2427 #                     $(GNUDIR).
2428 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2429 #                     /GNU.
2430 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2431 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2432 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2433 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2435 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2436     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2437     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2439 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2440 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2441 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2442 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2444 %(mmake)-archbase  := %(package)-%(version)
2446 ifeq (%(compiler),host)
2447     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2448 else
2449     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2450 endif
2452 ifeq (%(prefix),)
2453     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2454 else
2455     %(mmake)-prefix := %(prefix)
2456 endif
2458 ifneq (%(subpackage),)
2459     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2460 else
2461     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2462 endif
2464 ifneq (%(srcdir),)
2465     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2466 else
2467     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2468 endif
2470 ifeq (%(patch),yes)
2471     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2472 else
2473     %(mmake)-%(subpackage)-patches_specs := ::
2474 endif
2476 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2477     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2478     archive_origins=". %(package_repo)" \
2479     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2481 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2482     archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" destination=$(%(mmake)-portdir)
2484 #MM- %(mmake) : %(mmake)-%(subpackage)
2486 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2488 %(mmake)-%(subpackage)-package-basename := \
2489     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2491 ifneq (%(create_pkg),no)
2492     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2493 endif
2495 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2496      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2497      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2498      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2499      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2501 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2502 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2505 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2507 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2508 #that $^ and $@ have exactly the same mtime, and in that case make tries
2509 #to rebuild $@ again, which would fail because the directory where
2510 #the package got installed would not exist anymore. 
2511 #We work this around by using an if statement to manually check the mtimes.
2512 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2513         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2514         $(RM) $@ ; \
2515         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2516         mkdir -p "$(DISTDIR)/Packages" ; \
2517         mkdir -p "$(%(mmake)-prefix)" ; \
2518         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2519         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2520         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2521     fi
2522 %end
2523 #------------------------------------------------------------------------------
2526 #------------------------------------------------------------------------------
2527 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2528     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2529     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2531 GNU_REPOSITORY := gnu://
2533 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2534     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2535     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2536     patch="%(patch)" patch_repo="%(patch_repo)" \
2537     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2538     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2540 %end
2541 #------------------------------------------------------------------------------
2544 #------------------------------------------------------------------------------
2545 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2546 # that the package is a "Development" package, and as such it needs to be placed
2547 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2549 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2550 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2551 # "mmake" argument, because the metatarget is implicitely defined as
2553 #     #MM- development-%(package)
2555 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2556     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2557     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2559 #MM- development : development-%(package)
2562 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2563    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2564    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2565    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2566    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2569 postinstall-%(package)-delete-la-files:
2570         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2572 %end
2573 #------------------------------------------------------------------------------
2575 # Builds a kickstart package in PKG format
2576 # mmake   - target name
2577 # file    - Destination file name with path
2578 # startup - The file which will be put first
2579 # Other arguments are self-explanatory
2581 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2583 PKG_CLASSES   := $(addsuffix .class, %(classes))
2584 PKG_DEVICES   := $(addsuffix .device, %(devs))
2585 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2586 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2587 PKG_LIBS      := $(addsuffix .library, %(libs))
2588 PKG_RESOURCES := $(addsuffix .resource, %(res))
2590 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2591 PKG_DIR   := $(dir %(file))
2592 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2595 %(mmake) : %(file)
2598 %(mmake)-quick : %(file)
2600 %(file): PKG_FILES := $(PKG_FILES)
2601 %(file): $(PKG_DEPS) | $(PKG_DIR)
2602         @$(ECHO) Packaging $@...
2603         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2605 GLOB_MKDIRS += $(PKG_DIR)
2607 %end
2608 #------------------------------------------------------------------------------
2610 # Links a kickstart module in ELF format
2611 # Arguments are similar to make_package
2613 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2614     startup= uselibs= ldflags=$(LDFLAGS) map=
2616 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2617 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2618 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2619 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2620 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2621 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2623 ifeq (%(startup),)
2624     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2625 else
2626     KOBJ_STARTUP := %(startup)
2627 endif
2629 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2631 TMP_LDFLAGS := %(ldflags)
2633 # Make a list of the lib files this program depends on.
2634 # In LDFLAGS remove white space between -L and directory
2635 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2636 # Filter out only the libdirs and remove -L
2637 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2638 # Add trailing /
2639 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2640 # Add normal linklib path
2641 TMP_DIRS += $(LIBDIR)/
2642 # add lib and .a to static linklib names
2643 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2644 # search for the linklibs in the given path, ignore ones not found
2645 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2646     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2649 TMP_DIRS += $(dir %(file))
2650 ifneq (%(map),)
2651     TMP_LDFLAGS += $(GENMAP) %(map)
2652     TMP_DIRS    += $(dir %(map))
2653 endif
2656 %(mmake) : %(file)
2659 %(mmake)-quick : %(file)
2661 %(file): KOBJS := $(KOBJS)
2662 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2663 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2664 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2665         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2666         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
2668 GLOB_MKDIRS += $(TMP_DIRS)
2670 %end
2672 #------------------------------------------------------------------------------
2673 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2674 # 'start' is an optional starting address
2675 # 'ldflags' is optional additional flags for the linker
2676 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2678 BD_OUTDIR := $(dir %(file))
2679 BD_TMPDIR  := $(GENDIR)/$(CURDIR)
2681 %(file) : %(objs) $(BD_OUTDIR)
2682         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2683         @$(KERNEL_LD) %(ldflags) --entry=%(start) -oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2684         cd $(BD_TMPDIR) && $(AROS_LD) -r --format binary %(name) -o $@
2686 GLOB_MKDIRS += $(BD_OUTDIR)
2688 %end