Tested and debugged ToolTypes.
[AROS.git] / config / make.tmpl
blobc100d14f7402b7a1592948cbefb5486a5f0b28bf
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 %(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 %(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 $(notdir $@) ..."
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 library %(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)
647 %(libdir)/lib%(libname).a : %(objs)
648         %mklib_q from=$^
649 %end
650 #------------------------------------------------------------------------------
653 #------------------------------------------------------------------------------
654 # Link the %(objs) to the library %(libdir)/lib%(libname).so
655 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
657 %(libdir)/lib%(libname).so : %(objs)
658         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
659 %end
660 #------------------------------------------------------------------------------
663 #------------------------------------------------------------------------------
664 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
665 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
666 # The -noarosc flag is added so that modules are not linked with arosc.library
667 # (see /config/specs.in file)
668 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
669     ldflags=$(LDFLAGS) uselibs= usehostlibs=
671 TMP_LDFLAGS  := %(ldflags)
672 # Make a list of the lib files the programs depend on.
673 # In LDFLAGS remove white space between -L and directory
674 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
675 # Filter out only the libdirs and remove -L
676 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
677 # Add trailing /
678 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
679 # Add normal linklib path
680 TMP_DIRS += $(LIBDIR)/
681 # add lib and .a to static linklib names
682 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
683 # search for the linklibs in the given path, ignore ones not found
684 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
685     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
688 %(module) : OBJS := %(objs)
689 %(module) : ENDTAG := %(endobj)
690 %(module) : ERR := %(err)
691 %(module) : OBJDIR := %(objdir)
692 %(module) : LDFLAGS := $(TMP_LDFLAGS)
693 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
694 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
695         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
697 %end
698 #------------------------------------------------------------------------------
701 #------------------------------------------------------------------------------
702 # Generate the libdefs.h include file for a module.
703 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
705 TMP_TARGET := %(modname)_libdefs.h
706 TMP_DEPS := $(GENMODULE)
707 TMP_OPTS := 
708 ifneq (%(conffile),)
709     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
710     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
711 else
712     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
713     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
714 endif
715 ifneq (%(modsuffix),)
716     TMP_OPTS += -s %(modsuffix)
717 endif
718 ifneq (%(targetdir),)
719     TMP_OPTS += -d %(targetdir)
720     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
721 endif
723 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
724 $(TMP_TARGET) : MODNAME := %(modname)
725 $(TMP_TARGET) : MODTYPE := %(modtype)
726 $(TMP_TARGET) : $(TMP_DEPS)
727         @$(ECHO) "Generating $(notdir $@)"
728         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
729 %end
730 #------------------------------------------------------------------------------
733 #------------------------------------------------------------------------------
734 # Generate a Makefile.%(modname) with the genmodule program and include this
735 # generated file in this Makefile
736 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
737     targetdir=
739 TMP_TARGET := Makefile.%(modname)
740 TMP_DEPS := $(GENMODULE)
741 TMP_OPTS := 
742 ifneq (%(conffile),)
743     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
744     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
745 else
746     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
747     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
748 endif
749 ifneq (%(modsuffix),)
750     TMP_OPTS += -s %(modsuffix)
751 endif
752 ifneq (%(targetdir),)
753     TMP_OPTS += -d %(targetdir)
754     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
755 endif
757 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
758 $(TMP_TARGET) : MODNAME := %(modname)
759 $(TMP_TARGET) : MODTYPE := %(modtype)
760 $(TMP_TARGET) : $(TMP_DEPS)
761         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
762 %end
763 #------------------------------------------------------------------------------
766 #------------------------------------------------------------------------------
767 # Generate the support files for compiling a module. This includes include
768 # files and source files. This rule has to be preceeded by
769 # %rule_genmodule_makefile
770 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
771     conffile=
773 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
774                $(%(modname)_LINKLIBFILES)
775 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
777 TMP_DEPS := $(GENMODULE)
778 TMP_OPTS :=
780 ifneq (%(conffile),)
781     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
782     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
783 else
784     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
785     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
786 endif
787 ifneq (%(modsuffix),)
788     TMP_OPTS += -s %(modsuffix)
789 endif
790 ifneq (%(targetdir),)
791     TMP_OPTS += -d %(targetdir)
792     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
793     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
794 endif
796 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
797 $(TMP_TARGETS) : MODNAME := %(modname)
798 $(TMP_TARGETS) : MODTYPE := %(modtype)
799 $(TMP_TARGETS) : $(TMP_DEPS)
800         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
801 ifneq (%(conffile),lib.conf)
802         @$(IF) $(TEST) -f lib.conf; then \
803           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
804         fi
805 endif
806         @$(IF) $(TEST) -f libdefs.h; then \
807           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
808         fi
809         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
810 %end
811 #------------------------------------------------------------------------------
814 #------------------------------------------------------------------------------
815 # Generate the support files for compiling a module. This includes include
816 # files and source files.
817 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
818     targetdir= conffile=
820 ifneq ($(%(modname)_INCLUDES),)
821 TMP_TARGETS := $(%(modname)_INCLUDES)
823 TMP_DEPS := $(GENMODULE)
824 TMP_OPTS :=
826 ifneq (%(conffile),)
827     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
828     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
829 else
830     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
831     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
832 endif
833 ifneq (%(modsuffix),)
834     TMP_OPTS += -s %(modsuffix)
835 endif
836 ifneq (%(targetdir),)
837     TMP_OPTS += -d %(targetdir)
838     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
839 endif
841 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
842 $(TMP_TARGETS) : MODNAME := %(modname)
843 $(TMP_TARGETS) : MODTYPE := %(modtype)
844 $(TMP_TARGETS) : $(TMP_DEPS)
845         @$(ECHO) "Generating include files"
846         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
847 endif
848 %end
849 #------------------------------------------------------------------------------
852 #------------------------------------------------------------------------------
853 # Common rules for all makefiles
854 %define common
855 # Delete generated makefiles
857 clean ::
858         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
860 include $(SRCDIR)/config/make.tail
862 BDID := $(BDTARGETID)
863 %end
864 #------------------------------------------------------------------------------
865       
867 #############################################################################
868 #############################################################################
869 ##                                                                         ##
870 ## Here are the mmakefile build macros. These are macros that takes care   ##
871 ## of everything to go from the sources to the generated target. Also all  ##
872 ## intermediate files and directories that are needed are created by these ##
873 ## rules.                                                                  ##
874 ##                                                                         ##
875 #############################################################################
876 #############################################################################
878 #------------------------------------------------------------------------------
879 # Build a program
880 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
881     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
882     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
883     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
884     compiler=target srcdir=
886 .PHONY : %(mmake)
888 BD_PROGNAME  := %(progname)
889 BD_OBJDIR    := %(objdir)
890 BD_TARGETDIR := %(targetdir)
892 BD_FILES     := %(files)
893 BD_ASMFILES  := %(asmfiles)
895 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
896 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
897 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
899 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
900 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
902 BD_CFLAGS    := %(cflags)
903 BD_AFLAGS    := %(aflags)
904 BD_DFLAGS    := %(dflags)
905 BD_LDFLAGS   := %(ldflags)
908 %(mmake)-quick : %(mmake)
910 #MM %(mmake) : includes-generate-deps linklibs-core
911 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
913 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
914 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
915     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
916 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
917     aflags=$(BD_AFLAGS) compiler=%(compiler)
919 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
920     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
921     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
922     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
923     linker=%(compiler)
925 endif
927 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
929 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
930 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
931 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
933 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
935 %(mmake)-clean ::
936         @$(ECHO) "Cleaning up for metatarget %(mmake)"
937         @$(RM) $(FILES)
939 %end
940 #------------------------------------------------------------------------------
943 #------------------------------------------------------------------------------
944 # Build programs, for every C file an executable will be built with the same
945 # name as the C file
946 %define build_progs mmake=/A files=/A nix=no \
947     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
948     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
949     uselibs= usehostlibs= usestartup=yes detach=no
951 .PHONY : %(mmake)
953 BD_OBJDIR    := %(objdir)
954 BD_TARGETDIR := %(targetdir)
956 BD_FILES     := %(files)
957 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
958 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
959 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
961 BD_CFLAGS    := %(cflags)
962 BD_DFLAGS    := %(dflags)
963 BD_LDFLAGS   := %(ldflags)
966 %(mmake)-quick : %(mmake)
968 #MM %(mmake) : includes-generate-deps
969 %(mmake) : $(BD_EXES)
971 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
972 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
973     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
975 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
976     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
977     ldflags=$(BD_LDFLAGS) \
978     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
979     usestartup="%(usestartup)" detach="%(detach)"
981 endif
983 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
985 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
986 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
987 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
989 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
991 %(mmake)-clean ::
992         @$(ECHO) "Cleaning up for metatarget %(mmake)"
993         @$(RM) $(FILES)
995 %end
996 #------------------------------------------------------------------------------
999 #------------------------------------------------------------------------------
1000 # Build a module.
1001 # This is a bare version: It just compiles and links the given files. It is
1002 # assumed that all needed boiler plate code is in the files. This should only
1003 # be used for compiling external code. For AROS code use %build_module
1004 %define build_module_simple mmake=/A modname=/A modtype=/A \
1005     files="$(basename $(call WILDCARD, *.c))" \
1006     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1007     objdir=$(OBJDIR) moduledir= \
1008     uselibs= usehostlibs= compiler=target
1010 # Define metamake targets and their dependencies
1011 #MM %(mmake) : core-linklibs includes-generate-deps
1012 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1013 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1014 #MM %(mmake)-quick
1015 #MM %(mmake)-clean
1017 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1019 .PHONY : $(BD_ALLTARGETS)
1021 ifeq (%(modname),)
1022 $(error using %build_module_simple: modname may not be empty)
1023 endif
1024 ifeq (%(modtype),)
1025 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1026 endif
1028 # Default values for variables and arguments
1029 BD_DEFLINKLIBNAME := %(modname)
1030 BD_DEFDFLAGS := %(cflags)
1031 OBJDIR ?= $(GENDIR)/$(CURDIR)
1032 BD_MODDIR := %(moduledir)
1033 ifeq ($(BD_MODDIR),)
1034   ifeq (%(modtype),library)
1035     BD_MODDIR  := $(AROS_LIBS)
1036   endif
1037   ifeq (%(modtype),gadget)
1038     BD_MODDIR  := $(AROS_GADGETS)
1039   endif
1040   ifeq (%(modtype),datatype)
1041     BD_MODDIR  := $(AROS_DATATYPES)
1042   endif
1043   ifeq (%(modtype),handler)
1044     BD_MODDIR  := $(AROS_FS)
1045   endif
1046   ifeq (%(modtype),device)
1047     BD_MODDIR  := $(AROS_DEVS)
1048   endif
1049   ifeq (%(modtype),resource)
1050     BD_MODDIR  := $(AROS_RESOURCES)
1051   endif
1052   ifeq (%(modtype),hook)
1053     BD_MODDIR  := $(AROS_RESOURCES)
1054   endif
1055   ifeq (%(modtype),mui)
1056     BD_MODDIR  := $(AROS_CLASSES)/Zune
1057   endif
1058   ifeq (%(modtype),mcc)
1059     BD_MODDIR  := $(AROS_CLASSES)/Zune
1060   endif
1061   ifeq (%(modtype),mcp)
1062     BD_MODDIR  := $(AROS_CLASSES)/Zune
1063   endif
1064   ifeq (%(modtype),usbclass)
1065     BD_MODDIR  := $(AROS_CLASSES)/USB
1066   endif
1067   ifeq (%(modtype),hidd)
1068     BD_MODDIR  := $(AROS_DRIVERS)
1069   endif
1070 endif
1071 ifeq ($(BD_MODDIR),)
1072   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1073 endif
1075 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1076 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1077 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1079 %rule_compile_multi \
1080     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1081     cflags="%(cflags)" dflags="%(dflags)" \
1082     compiler=%(compiler)
1084 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1085 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1086 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1088 %(mmake)-quick : %(mmake)
1089 %(mmake)       : $(BD_MODULE)
1090 %(mmake)-pkg   : $(BD_PKGMOD)
1091 %(mmake)-kobj  : $(BD_KOBJ)
1093 # The module is linked from all the compiled .o files
1094 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1096 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1097                  endobj= err=%(modname).err objdir=%(objdir) \
1098                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1100 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1101                  endobj= err=%(modname).err objdir=%(objdir) \
1102                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1104 # Link kernel object file
1105 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1107 # Make these symbols local
1108 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1109             UtilityBase ExpansionBase KeymapBase KernelBase
1111 BD_SYMBOLS := $(BD_KBASE)
1113 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1114 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1115 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1116 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1117 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1118 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1119         @$(ECHO) "Linking $@"
1120         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1121         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1124 ## Dependency fine-tuning
1126 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1127 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1129 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1130 $(BD_MODULE) : | $(BD_MODDIR)
1131 $(BD_KOBJ) : | $(KOBJSDIR)
1132 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1134 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1135 %(mmake)-clean ::
1136         @$(ECHO) "Cleaning up for module %(modname)"
1137         @$(RM) $(FILES)
1138 %end
1139 #------------------------------------------------------------------------------
1142 #------------------------------------------------------------------------------
1143 # Build a module
1144 # Explanation of this macro is done in the developer's manual
1145 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1146   conffile= files="$(basename $(call WILDCARD, *.c))" \
1147   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1148   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1149   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1150   compiler=target
1152 # Define metamake targets and their dependencies
1153 #MM- includes-all : %(mmake)-includes
1154 #MM %(mmake) : %(mmake)-includes core-linklibs
1155 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1156 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1157 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1158 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1159 #MM %(mmake)-linklib : %(mmake)-includes
1160 #MM %(mmake)-quick : %(mmake)-includes-quick
1161 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1162 #MM     includes-generate-deps
1163 #MM %(mmake)-includes-quick
1164 #MM %(mmake)-includes-dirs
1165 #MM %(mmake)-makefile
1166 #MM %(mmake)-clean
1168 # All MetaMake targets defined by this macro
1169 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1170     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1171     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick %(mmake)-linklib
1173 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1175 ifeq (%(modname),)
1176 $(error using %build_module: modname may not be empty)
1177 endif
1178 ifeq (%(modtype),)
1179 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1180 endif
1182 # Default values for variables and arguments
1183 BD_DEFLINKLIBNAME := %(modname)
1184 BD_DEFDFLAGS := %(cflags)
1185 OBJDIR ?= $(GENDIR)/$(CURDIR)
1187 ## Create genmodule include Makefile for the module
1189 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1191 %rule_genmodule_makefile \
1192     modname=%(modname) modtype=%(modtype) \
1193     modsuffix=%(modsuffix) targetdir=%(objdir) \
1194     conffile=%(conffile)
1196 %(objdir)/Makefile.%(modname) : | %(objdir)
1198 GLOB_MKDIRS += %(objdir)
1200 # Do not parse these statements if metatarget is not appropriate
1201 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1203 include %(objdir)/Makefile.%(modname)
1205 BD_DEFMODDIR := $(%(modname)_MODDIR)
1208 ## include files generation
1210 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1211 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1212 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1214 %(mmake)-includes-quick : %(mmake)-includes
1215 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1216     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1217     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1219 ifneq ($(%(modname)_INCLUDES),)
1220 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1221                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1222                          conffile=%(conffile)
1224 %rule_copy_diff_multi \
1225     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1226     stampfile=%(objdir)/%(modname)_geninc
1228 %rule_copy_diff_multi \
1229     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1230     stampfile=%(objdir)/%(modname)_incs
1232 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1234 TMP%(modname)_INCDIRS := \
1235     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1236     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1237     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1238 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1240 endif
1242 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1243                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1244                            conffile=%(conffile)
1246 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1247 $(BD_DEFLIBDEFSINC) :
1248         @$(ECHO) "generating $@"
1249         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1251 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1252 GLOB_MKDIRS += %(objdir)/include
1254 ## Extra genmodule src files generation
1255 ## 
1256 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1257                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1258                       conffile=%(conffile)
1260 ## Compilation
1262 BD_FILES      := %(files)
1263 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1264 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1265 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1267 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1268 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1269 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1271 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1272 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1274 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1275 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1276 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1277     BD_LINKLIB :=
1278 else
1279     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1280 endif
1281 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1283 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1284 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1286 %rule_compile_multi \
1287     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1288     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1289     compiler=%(compiler)
1290 %rule_compile_multi \
1291     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1292     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1293     compiler=%(compiler)
1295 ifneq ($(BD_LINKLIBAFILES),)
1296 %rule_assemble_multi \
1297     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1298 endif
1300 ## Linking
1302 ifeq (%(modsuffix),)
1303 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1304 BD_PKGMOD    := $(PKGDIR)/%(modname).%(modtype)
1305 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1306 else
1307 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1308 BD_PKGMOD    := $(PKGDIR)/%(modname).%(modsuffix)
1309 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1310 endif
1312 %(mmake)-quick      : %(mmake)
1313 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB)
1314 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB)
1315 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB)
1316 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB)
1317 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1318 %(mmake)-linklib    : $(BD_LINKLIB)
1320 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1321                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1322 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1323 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1324 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1325                  %(linklibobjs)
1327 # The module is linked from all the compiled .o files
1328 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1329                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1330                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1332 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1333                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1334                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1336 # Link static lib
1337 ifneq ($(BD_LINKLIB),)
1338 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1340 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1341 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1342 endif
1344 # Link kernel object file
1345 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1347 # Make these symbols local
1348 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1349             UtilityBase ExpansionBase KeymapBase KernelBase
1351 BD_SYMBOLS := $(BD_KBASE)
1353 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1354 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1355 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1356 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1357 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1358 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1359         @$(ECHO) "Linking $@"
1360         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1361         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1363 ## Dependency fine-tuning
1365 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1366 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1368 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1369 $(BD_MODULE) : | %(prefix)/%(moduledir)
1370 $(BD_PKGMOD) : | $(PKGDIR)
1371 $(BD_KOBJ)   : | $(KOBJSDIR)
1372 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1374 # Some include files need to be generated before the .c can be parsed.
1375 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
1377 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1378     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1379 $(BD_DEPS) : $(BD_DFILE_DEPS)
1380 endif
1382 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1383     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1384     %(objdir)/Makefile.%(modname) \
1385     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1386     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1387     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1388     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1389     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1390     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1391     $(BD_ENDOBJS)
1392 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1393 %(mmake)-clean ::
1394         @$(ECHO) "Cleaning up for module %(modname)"
1395         @$(RM) $(FILES)
1397 endif # $(TARGET) in $(BD_ALLTARGETS)
1398 %end
1399 #------------------------------------------------------------------------------
1402 #------------------------------------------------------------------------------
1403 # Build a module skeleton
1404 # This is a stripped-down version of build_module, it only creates include files,
1405 # but no actual object. This is used when for plugins or classes with the same
1406 # API, but no actual implementation here.
1407 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1408   conffile= \
1409   objdir=$(OBJDIR) prefix=$(AROSDIR)
1411 # Define metamake targets and their dependencies
1412 #MM- includes-all : %(mmake)-includes
1413 #MM %(mmake) : %(mmake)-includes core-linklibs
1414 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1415 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1416 #MM %(mmake)-linklib : %(mmake)-includes
1417 #MM %(mmake)-quick : %(mmake)-includes-quick
1418 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1419 #MM     includes-generate-deps
1420 #MM %(mmake)-includes-quick
1421 #MM %(mmake)-includes-dirs
1422 #MM %(mmake)-makefile
1423 #MM %(mmake)-clean
1425 # All MetaMake targets defined by this macro
1426 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1427     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1428     %(mmake)-kobj %(mmake)-pkg
1430 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1432 ifeq (%(modname),)
1433 $(error using %build_module_skeleton: modname may not be empty)
1434 endif
1435 ifeq (%(modtype),)
1436 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1437 endif
1439 # Default values for variables and arguments
1440 BD_DEFLINKLIBNAME := %(modname)
1441 BD_DEFDFLAGS := %(cflags)
1442 OBJDIR ?= $(GENDIR)/$(CURDIR)
1444 ## Create genmodule include Makefile for the module
1446 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1448 %rule_genmodule_makefile \
1449     modname=%(modname) modtype=%(modtype) \
1450     modsuffix=%(modsuffix) targetdir=%(objdir) \
1451     conffile=%(conffile)
1453 %(objdir)/Makefile.%(modname) : | %(objdir)
1455 GLOB_MKDIRS += %(objdir)
1457 # Do not parse these statements if metatarget is not appropriate
1458 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1460 include %(objdir)/Makefile.%(modname)
1462 BD_DEFMODDIR := $(%(modname)_MODDIR)
1465 ## include files generation
1467 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1468 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1469 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1471 %(mmake)-includes-quick : %(mmake)-includes
1472 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1473     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1474     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1476 ifneq ($(%(modname)_INCLUDES),)
1477 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1478                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1479                          conffile=%(conffile)
1481 %rule_copy_diff_multi \
1482     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1483     stampfile=%(objdir)/%(modname)_geninc
1485 %rule_copy_diff_multi \
1486     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1487     stampfile=%(objdir)/%(modname)_incs
1489 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1491 TMP%(modname)_INCDIRS := \
1492     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1493     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1494     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1495 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1497 endif
1499 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1500                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1501                            conffile=%(conffile)
1503 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1504 $(BD_DEFLIBDEFSINC) :
1505         @$(ECHO) "generating $@"
1506         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1508 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1509 GLOB_MKDIRS += %(objdir)/include
1511 ## Extra genmodule src files generation
1512 ## 
1513 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1514                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1515                       conffile=%(conffile)
1517 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1518     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1519     %(objdir)/Makefile.%(modname) \
1520     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1521     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1522     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1523     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1524     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1525     $(BD_DEFLIBDEFSINC)
1526 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1527 %(mmake)-clean ::
1528         @$(ECHO) "Cleaning up for module %(modname)"
1529         @$(RM) $(FILES)
1531 endif # $(TARGET) in $(BD_ALLTARGETS)
1532 %end
1533 #------------------------------------------------------------------------------
1536 #------------------------------------------------------------------------------
1537 # Build a linklib.
1538 # - mmake is the mmaketarget
1539 # - libname is the baselibname e.g. lib%(libname).a will be created
1540 # - files are the C source files to include in the lib. The list of files
1541 #   has to be given without the .c suffix
1542 # - asmfiles are the asm files to include in the lib. The list of files has to
1543 #   be given without the .s suffix
1544 # - objs additional object to link into the linklib. The objects have to be
1545 #   given with full absolute path and the .o suffix.
1546 # - cflags are the flags to compile the source (default $(CFLAGS))
1547 # - dflags are the flags use during makedepend (default equal to cflags)
1548 # - aflags are the flags use during assembling (default $(AFLAGS))
1549 # - objdir is where the .o are generated
1550 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1551 %define build_linklib mmake=/A libname=/A \
1552   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1553   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1555 # assign and generate the local variables used in this macro
1556 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1558 BD_FILES      := %(files)
1559 BD_ASMFILES   := %(asmfiles)
1561 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1562 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1563 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1565 BD_OBJS       := $(BD_ARCHOBJS) \
1566                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1567                  %(objs)
1568 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1570 BD_CFLAGS     := %(cflags)
1571 ifeq (%(dflags),)
1572 BD_DFLAGS     := $(BD_CFLAGS)
1573 else
1574 BD_DFLAGS     := %(dflags)
1575 endif
1576 BD_AFLAGS     := %(aflags)
1578 BD_LINKLIB    := %(libdir)/lib%(libname).a
1580 .PHONY : %(mmake) %(mmake)-clean
1582 #MM %(mmake) : includes-generate-deps
1583 %(mmake) : $(BD_LINKLIB)
1586 %(mmake)-clean ::
1587         @$(RM) $(BD_OBJS) $(BD_DEPS)
1589 ifeq ($(TARGET),%(mmake))
1590 ifneq ($(dir $(BD_FILES)),./)
1591 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1592 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1593 endif
1595 %rule_compile basename=% targetdir=%(objdir) \
1596               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1597 %rule_assemble basename=% targetdir=%(objdir) \
1598               aflags=$(BD_AFLAGS)
1599 endif
1601 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1603 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1605 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1606 $(BD_LINKLIB) : | %(libdir)
1607 GLOB_MKDIRS += %(objdir) %(libdir)
1609 %end
1610 #------------------------------------------------------------------------------
1613 #------------------------------------------------------------------------------
1614 # Build catalogs.
1615 # - mmake is the mmaketarget
1616 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1617 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1618 # - subdir is the destination subdirectory of the catalogs
1619 # - name is the name of the destination catalog, without the .catalog suffix
1620 # - source is the path to the generated source code file
1621 # - dir is the base destination directory (default $(AROS_CATALOGS))
1622 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1623 # - srcdir is the directory in which the *.cd and *.ct files are searched
1625 %define build_catalogs mmake=/A name=/A subdir=/A \
1626  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1627  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1629 ifeq (%(description),)
1630 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1631 else
1632 BD_DESC := %(description)
1633 endif
1635 ifeq (%(catalogs),)
1636 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1637 else
1638 BD_LNGS := %(catalogs)
1639 endif
1641 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1642 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1645 %(mmake) : $(BD_OBJS) %(source)
1647 $(BD_OBJS) : | $(BD_DIRS)
1648 GLOB_MKDIRS += $(BD_DIRS)
1650 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1651         @$(ECHO) "Creating %(name) catalog for language $*."
1652         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1654 ifneq (%(source),)
1655 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1656 %(source) : $(BD_DESC).cd | $(dir %(source))
1657         @$(ECHO) "Creating %(name) catalog source file %(source)"
1658         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1659 endif
1662 %(mmake)-clean ::
1663         $(RM) $(BD_OBJS) %(source)
1665 .PHONY: %(mmake) %(mmake)-clean
1667 %end
1668 #-----------------------------------------------------------------------------
1671 #-----------------------------------------------------------------------------
1672 # Build icons.
1673 # - mmake is the mmaketarget
1674 # - icons is a list of icon base names (ie. without the .info suffix)
1675 # - dir is the destination directory
1676 # - srcdir is where *.png and *.info.src are searched
1677 #-----------------------------------------------------------------------------
1679 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1681 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1684 %(mmake) : $(BD_OBJS)
1686 ifeq (%(image),)
1688 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1689         @$(ECHO) Creating $(notdir $@)...
1690         @$(ILBMTOICON) $+ $@
1692 else
1694 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1695         @$(ECHO) Creating $(notdir $@)...
1696         @$(ILBMTOICON) $+ $@
1698 endif
1700 $(BD_OBJS) : | %(dir)
1701 GLOB_MKDIRS += %(dir)
1703 %(mmake)-clean : FILES := $(BD_OBJS)
1705 %(mmake)-clean ::
1706         @$(RM) $(FILES)
1708 .PHONY: %(mmake) %(mmake)-clean
1710 %end
1711 #-----------------------------------------------------------------------------
1714 #------------------------------------------------------------------------------
1715 # Compile files for an arch-specific replacement of code for a module
1716 # - files: the basenames of the C files to compile.
1717 # - asmfiles: the basenames of the asm files to assemble.
1718 # - mainmmake: the mmake of the module in the main directory to compile these
1719 #   arch specific files for.
1720 # - maindir: the object directory for the main module
1721 # - arch: the arch for which to compile these files. It can have the form
1722 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1723 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1724 # - dflags: the flags used during creation of dependency file. If not specified
1725 #   the same value as cflags will be used
1726 # - aflags: the flags used during assembling
1727 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1728 #   the target compiler is used
1729 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1730 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1732 ifeq (%(files) %(asmfiles),)
1733   $(error no files or asmfiles given)
1734 endif
1736 %buildid targets="%(mainmmake)-%(arch)"
1738 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1739 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1740 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1741 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1742 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1743 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1744 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1745 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1746 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1747 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1748 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1749 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1750 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1751 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1752 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1753 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1754 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1755 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1756 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1757 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1758 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1760 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1762 ifeq (%(arch),)
1763   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1764 endif
1766 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1767 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1768 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1769 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1770 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1772 ifneq (%(modulename),)
1773 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1774 endif
1776 ifeq ($(TARGET),%(mainmmake)-%(arch))
1777 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1778 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1779 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1780 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1781 endif
1783 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1784 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1787 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1789 ifeq ($(findstring %(compiler),host kernel target),)
1790   $(error unknown compiler %(compiler))
1791 endif
1792 ifeq (%(compiler),target)
1793 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1794 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1795 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1796 endif
1797 ifeq (%(compiler),host)
1798 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1799 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1800 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1801 endif
1802 ifeq (%(compiler),kernel)
1803 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1804 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1805 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1806 endif
1807 ifneq (%(modulename),)
1808 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1809 else
1810 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1811 endif
1812 ifeq ($(TARGET),%(mainmmake)-%(arch))
1813 $(BD_OBJDIR$(BDID))/%.o : %.c
1814         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1815 endif
1817 ifeq (%(dflags),)
1818 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1819 else
1820 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1821 endif
1822 ifeq ($(TARGET),%(mainmmake)-%(arch))
1823 $(BD_OBJDIR$(BDID))/%.d : %.c
1824         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1825 endif
1827 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1829 ifeq ($(TARGET),%(mainmmake)-%(arch))
1830 $(BD_OBJDIR$(BDID))/%.o : %.s
1831         %assemble_q opt=$(AFLAGS)
1832 $(BD_OBJDIR$(BDID))/%.o : %.S
1833         %assemble_q opt=$(AFLAGS)
1834 endif
1836 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1837 %end
1838 #------------------------------------------------------------------------------
1841 #------------------------------------------------------------------------------
1842 # generate asm files from c files (for debugging purposes)
1843 %define ctoasm_q
1844 %.s : %.c
1845         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1846         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1847 %end
1848 #------------------------------------------------------------------------------
1851 #------------------------------------------------------------------------------
1852 # Copy files from one directory to another.
1854 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1856 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1858 GLOB_MKDIRS += %(dst)
1860 .PHONY : %(mmake)
1863 %(mmake) : | %(dst) 
1864         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1866 %end
1867 #------------------------------------------------------------------------------
1870 #------------------------------------------------------------------------------
1871 # Copy a directory recursively to another place, preserving the original 
1872 # hierarchical structure
1874 # src: the source directory whose content will be copied
1875 # dst: the directory where to copy src's content. If not existing, it will be made.
1877 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
1879 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1880 %(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)
1881 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1883 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
1884 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
1886 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
1888 .PHONY : %(mmake)
1891 %(mmake): | $(GENDIR)/$(CURDIR)
1892         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1893         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1894         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1895         for d in $(%(mmake)_DIRS); do                      \
1896             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1897         done
1898         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1899         for f in $(%(mmake)_FILES); do                                            \
1900             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1901         done;  \
1902         for dst in %(dst); do \
1903             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1904         done
1906 %end
1907 #------------------------------------------------------------------------------
1910 #------------------------------------------------------------------------------
1911 #   Copy include files into the includes directories. There are currently
1912 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1913 #   for building tools that need to run on the host system $(GENINCDIR). The
1914 #   $(GENINCDIR) path must not contain any references to the C runtime
1915 #   library header files.
1917 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1918     dir= compiler=target
1920 ifeq ($(findstring %(compiler),host kernel target),)
1921 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1922 endif
1924 ifneq (%(dir),)
1925 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
1926 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
1927 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1928 else
1929 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1930 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1931 endif
1933 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1934         @$(CP) $< $@
1937 ifeq (%(compiler),target)
1939 ifneq (%(dir),)
1940 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
1941 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
1942 else
1943 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1944 endif
1946 BD_INCL_FILES += $(BD_INCL_FILES2)
1948 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1949         @$(CP) $< $@
1950 endif
1953 %(mmake) : $(BD_INCL_FILES)
1955 .PHONY: %(mmake)
1957 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1958 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1959 %end
1960 #------------------------------------------------------------------------------
1963 #------------------------------------------------------------------------------
1964 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1965 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1966 STUBS_MEM := $(addsuffix .o,$(STUBS))
1967 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1968 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1969 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1971 #MM- linklibs : hidd-%(hidd)-stubs
1972 #MM- %(parenttarget): hidd-%(hidd)-stubs
1973 #MM hidd-%(hidd)-stubs : includes includes-copy
1974 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1976 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1977         %mklib_q from=$^
1979 $(STUBS_OBJ) : $(STUBS_SRC) 
1980         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
1982 $(STUBS_DEP) : $(STUBS_SRC)
1983         %mkdepend_q flags=%(dflags)
1985 setup ::
1986         %mkdirs_q $(OBJDIR) $(LIBDIR)
1989 clean ::
1990         -@$(RM) $(HIDD_LIB) $(OBJDIR)
1992 DEPS := $(DEPS) $(STUBS_DEP)
1994 %end
1995 #------------------------------------------------------------------------------
1998 #------------------------------------------------------------------------------
1999 # Build an imported source tree which uses the configure script from the
2000 # autoconf package.  This rule will try to "integrate" the produced files as
2001 # much as possible in the AROS build, for example by putting libraries in the
2002 # standard library directory, includes in the standard include directory, and
2003 # so on. You can however override this behaviour.
2005 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2006 # be %(bindir) (or its deduced value) when running "make install", and
2007 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2008 # configure script some more parameters whose value depends upon the PROGDIR
2009 # env var, so that the program gets all its stuff installed in the proper place
2010 # when building it, but when running it from inside AROS it can also find that
2011 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2012 # the configuration parameters set when running ./configure
2014 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2015 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2016 # to the name which has to follow it.
2019 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2020     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2021     install_target=install preconfigure= postconfigure= postinstall= \
2022     install_env=
2024 ifneq (%(prefix),)
2025     %(mmake)-prefix := %(prefix)
2026 else
2027     %(mmake)-prefix := $(AROS_CONTRIB)
2028 endif
2030 ifneq (%(aros_prefix),)
2031     %(mmake)-aros_prefix := %(aros_prefix)
2032 else
2033     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2034 endif
2036 ifeq (%(nix),yes)
2037     %(mmake)-nix    := -nix
2038     %(mmake)-volpfx := /
2039     %(mmake)-volsfx := /
2040     
2041     ifeq (%(nix_dir_layout),)
2042         %(mmake)-nix_dir_layout := yes
2043     endif
2044 else
2045     %(mmake)-volsfx := :
2046     
2047     ifeq (%(nix_dir_layout),)
2048         %(mmake)-nix_dir_layout := no
2049     endif
2050 endif
2052 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2054 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2055         exec_prefix=$(%(mmake)-prefix) %(install_env)
2057 # Check if chosen compiler is valid
2058 ifeq ($(findstring %(compiler),host target kernel),)
2059   $(error unknown compiler %(compiler))
2060 endif
2062 # Set legacy 'host' variable based on chosen compiler
2063 ifeq (%(compiler),host)
2064     host := yes
2065         ifeq (%(package),)
2066                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2067         else
2068                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2069         endif
2070 else
2071     host := no
2072         ifeq (%(package),)
2073                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2074         else
2075                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2076         endif
2077 endif
2079 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2080 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2082 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2083     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2084     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2085 else
2086     ifeq (%(nix),yes)
2087         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2088         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2089     else
2090         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2091     endif
2093     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2094     
2095     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2096         sbindir=$(%(mmake)-prefix) \
2097         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2098         oldincludedir=$(AROS_INCLUDES) %(install_env)
2099 endif
2101 ifneq ($(DEBUG),yes)
2102     %(mmake)-s_flag = -s
2103 endif
2105 # Set up build environment, and options for configure script
2106 ifeq (%(compiler),host)
2107     COMPILER_ENV := \
2108         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2109         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2110         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2111         TARGET_RANLIB="$(RANLIB)"
2112     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2113 endif
2114 ifeq (%(compiler),target)
2115     COMPILER_ENV := \
2116         CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2117         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2118         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2119         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2120         TARGET_RANLIB="$(RANLIB)"
2121     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2122         --host=$(AROS_TARGET_CPU)-aros\
2123         --target=$(AROS_TARGET_CPU)-aros\
2124         --disable-nls\
2125         --without-x --without-pic --disable-shared
2126 endif
2127 ifeq (%(compiler),kernel)
2128     COMPILER_ENV := \
2129         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2130         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2131         TARGET_RANLIB="$(RANLIB)"
2132     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2133         --host=$(AROS_TARGET_CPU)-aros\
2134         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2135         --without-x --without-pic --disable-shared
2136 endif
2139 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2141 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2143 # Using -j1 in install_command may result in a warning but finally
2144 # it does its job. make install for gcc does not work reliably for -jN
2145 # where N > 1.
2146 ifneq (%(install_target),)
2147     %(mmake)-install_command = \
2148         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2149         -C $(%(mmake)-pkgdir) %(install_target) -j1
2151     %(mmake)-uninstall_command = \
2152     $(RM) $(%(mmake)-installflag) && \
2153     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2154     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2155 else
2156     %(mmake)-install_command   := true
2157     %(mmake)-uninstall_command := true
2158 endif
2160 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2163 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2165 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2166         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2167             $(RM)  $(%(mmake)-installflag) && \
2168             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2169              -C $(%(mmake)-pkgdir) && \
2170             $(%(mmake)-install_command) && \
2171             $(TOUCH) $@ -r $^; \
2172         fi
2174 $(%(mmake)-pkgdir)/.files-touched:
2175         %mkdirs_q $(%(mmake)-pkgdir)
2176         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2177         $(TOUCH) $@
2180 %(mmake)-uninstall :
2181         $(%(mmake)-uninstall_command)
2184 %(mmake)-configure : $(%(mmake)-configflag)
2186 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2187 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2188         $(RM) $@
2189         %mkdirs_q $(%(mmake)-pkgdir)
2190         cd $(%(mmake)-pkgdir) && \
2191         find . -name config.cache -exec $(RM) '{}' \; && \
2192         $(COMPILER_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2193             %(extraoptions) && \
2194         $(TOUCH) $@
2197 %(mmake)-clean : %(mmake)-uninstall
2198         @$(RM) $(%(mmake)-pkgdir)
2199 %end
2200 #------------------------------------------------------------------------------
2203 #------------------------------------------------------------------------------
2204 # Given an archive name, patches names and locations where to find them, fetch
2205 # the archive and the patches from any of those locations, unpack the archive
2206 # and then apply the patches.
2208 # Locations currently supported are http and ftp sites, plus local filesystem
2209 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2210 # the fetch.sh script needs to be modified, since this macro relies on that script.
2212 # Arguments:
2214 #     - mmake           = mmaketarget
2215 #     - archive_origins = list of locations where to find the archive. They are tried
2216 #                         in sequence, until the archive is found and fetching it 
2217 #                         succeeded. If not specified, the current directory is assumed.
2218 #     - archive         = the archive name. Mandatory.
2219 #     - suffixes        = a list of suffixes to append to the the package name plus the
2220 #                         version. Each one of them is tried until a matching archive is
2221 #                         found. They are appended to patches and these are tried the
2222 #                         same way as packages are.
2223 #     - location        = the local directory where to put the fetched archive and patches.
2224 #                         If not specified, the directory specified by destination is used.
2225 #     - destination     = the directory to unpack the archive to.
2226 #                         If not specified, the current directory is assumed.
2227 #     - patches_origins = list of locations where to find the patches. They are tried
2228 #                         in sequence, until a patch is found and fetching it 
2229 #                         succeeded. If not specified, the current directory is assumed.
2230 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2231 #                         patch_name[:[patch_subdir][:patch_opt]].
2233 #                             - patch_name   = the name of the patch file
2234 #                             - patch_subdir = the directory within \destination\ where to
2235 #                                              apply the patch.
2236 #                             - patch_opt    = any options to pass to the `patch' command
2237 #                                              when applying the patch.
2238 #                         
2239 #                         The patch_subdir and patch_opt fields are optional.
2241 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2242     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2244 .PHONY: %(mmake)
2246 ifneq (%(location),)
2247     %(mmake)-location := %(location)
2248 else
2249     %(mmake)-location := %(destination)
2250 endif
2253 %(mmake) :
2254         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2255         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2256 %end
2257 #------------------------------------------------------------------------------
2260 #------------------------------------------------------------------------------
2261 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2262 # unpatched source tree and runs diff against this and a previously fetched and possibly
2263 # patched tree. Depending on what happens after patching during a normal build it might
2264 # give best results if the new patch is created directly after fetch.
2266 # Arguments:
2268 #     - mmake       = mmaketarget
2269 #     - archive     = archive base name
2270 #     - suffixes    = a list of suffixes to append to the the package name plus the
2271 #                     version. Each one of them is tried until a matching archive is
2272 #                     found.
2273 #     - destination = the directory to unpack the archive to.
2274 #     - excludes    = diff patterns to exclude files or directories from the patch
2276 %define create_patch mmake=/A archive=/A suffixes="tar.bz2 tar.gz" destination=/A excludes=
2278 .PHONY: %(mmake)
2280 ifneq (%(excludes),)
2281     %(mmake)-exclude := -X ./exclude.patterns
2282 endif
2285 %(mmake):
2286         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2287         $(MV) %(destination)/%(archive) %(destination)/tmp/%(archive).aros ; \
2288         cd %(destination)/tmp ; \
2289         $(FOR) f in %(excludes) ; do \
2290             $(ECHO) $$f >> ./exclude.patterns ; \
2291         done ; \
2292         diff -ruN $(%(mmake)-exclude) \
2293             %(archive) \
2294             %(archive).aros \
2295             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2296         $(MV) %(destination)/tmp/%(archive).aros %(destination)/%(archive) ; \
2297         $(RM) %(destination)/tmp
2298 %end
2299 #------------------------------------------------------------------------------
2302 #------------------------------------------------------------------------------
2303 # Joins the features of %fetch and %build_with_configure, taking advantage of
2304 # the naming scheme of GNU packages. GNU packages names are in the form
2306 #     <package name>-<version number>.<archive format suffix>
2308 # If a patch is provided, it *must* be named the following way:
2310 #    <package name>-<version number>-aros.diff
2312 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2313 # CD'ing into the archive's extracted directory.
2315 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2316 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2317 # to make that patch fully comprehensive.
2319 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2321 # Arguments:
2323 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2324 #                     macro.
2325 #    - package      = the GNU package name, sans version and archive format suffixes.
2326 #    - version      = the package's version number, or otherwise any other version string.
2327 #                     It gets appended to the package name to form the basename of the archive.
2328 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2329 #                     version. Each one of them is tried until a matching archive is found.
2330 #                     Defaults to "tar.bz2 tar.gz".
2331 #    - destination  = same meaning as the one for the %fetch macro
2332 #    - location     = same meaning as the one for the %fetch macro
2333 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2334 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2335 #                     fetched or not
2336 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2337 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2338 #                     $(GNUDIR).
2339 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2340 #                     /GNU.
2341 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2342 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2343 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2344 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2346 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2347     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2348     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2350 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2351 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2352 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2353 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2355 %(mmake)-archbase  := %(package)-%(version)
2357 ifeq (%(compiler),host)
2358     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2359 else
2360     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2361 endif
2363 ifeq (%(prefix),)
2364     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2365 else
2366     %(mmake)-prefix := %(prefix)
2367 endif
2369 ifneq (%(subpackage),)
2370     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2371 else
2372     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2373 endif
2375 ifneq (%(srcdir),)
2376     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2377 else
2378     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2379 endif
2381 ifeq (%(patch),yes)
2382     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2383 else
2384     %(mmake)-%(subpackage)-patches_specs := ::
2385 endif
2387 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2388     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2389     archive_origins=". %(package_repo)" \
2390     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2392 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2393     archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" destination=$(%(mmake)-portdir)
2395 #MM- %(mmake) : %(mmake)-%(subpackage)
2397 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2399 %(mmake)-%(subpackage)-package-basename := \
2400     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2402 ifneq (%(create_pkg),no)
2403     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2404 endif
2406 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2407      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2408      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2409      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2410      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2412 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2413 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2416 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2418 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2419 #that $^ and $@ have exactly the same mtime, and in that case make tries
2420 #to rebuild $@ again, which would fail because the directory where
2421 #the package got installed would not exist anymore. 
2422 #We work this around by using an if statement to manually check the mtimes.
2423 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2424         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2425         $(RM) $@ ; \
2426         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2427         mkdir -p "$(DISTDIR)/Packages" ; \
2428         mkdir -p "$(%(mmake)-prefix)" ; \
2429         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2430         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2431         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2432     fi
2433 %end
2434 #------------------------------------------------------------------------------
2437 #------------------------------------------------------------------------------
2438 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2439     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2440     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2442 GNU_REPOSITORY := gnu://
2444 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2445     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2446     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2447     patch="%(patch)" patch_repo="%(patch_repo)" \
2448     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2449     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2451 %end
2452 #------------------------------------------------------------------------------
2455 #------------------------------------------------------------------------------
2456 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2457 # that the package is a "Development" package, and as such it needs to be placed
2458 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2460 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2461 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2462 # "mmake" argument, because the metatarget is implicitely defined as
2464 #     #MM- development-%(package)
2466 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2467     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2468     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2470 #MM- development : development-%(package)
2473 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2474    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2475    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2476    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2477    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2478     
2479 %end
2480 #------------------------------------------------------------------------------
2482 # Builds a kickstart package in PKG format
2483 # mmake   - target name
2484 # file    - Destination file name with path
2485 # startup - The file which will be put first
2486 # Other arguments are self-explanatory
2488 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2490 PKG_CLASSES   := $(addsuffix .class, %(classes))
2491 PKG_DEVICES   := $(addsuffix .device, %(devs))
2492 PKG_HANDLERS  := $(addsuffix .handler, %(handlers))
2493 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2494 PKG_LIBS      := $(addsuffix .library, %(libs))
2495 PKG_RESOURCES := $(addsuffix .resource, %(res))
2497 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2498 PKG_DIR   := $(dir %(file))
2499 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2502 %(mmake) : %(file)
2505 %(mmake)-quick : %(file)
2507 %(file): PKG_FILES := $(PKG_FILES)
2508 %(file): $(PKG_DEPS) | $(PKG_DIR)
2509         @$(ECHO) Packaging $@...
2510         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2512 GLOB_MKDIRS += $(PKG_DIR)
2514 %end
2515 #------------------------------------------------------------------------------
2517 # Links a kickstart module in ELF format
2518 # Arguments are similar to make_package
2520 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2521     startup= uselibs= ldflags=$(LDFLAGS) map=
2523 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2524 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2525 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2526 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2527 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2528 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2530 ifeq (%(startup),)
2531     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2532 else
2533     KOBJ_STARTUP := %(startup)
2534 endif
2536 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2538 TMP_LDFLAGS := %(ldflags)
2540 # Make a list of the lib files this program depends on.
2541 # In LDFLAGS remove white space between -L and directory
2542 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2543 # Filter out only the libdirs and remove -L
2544 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2545 # Add trailing /
2546 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2547 # Add normal linklib path
2548 TMP_DIRS += $(LIBDIR)/
2549 # add lib and .a to static linklib names
2550 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2551 # search for the linklibs in the given path, ignore ones not found
2552 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2553     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2556 TMP_DIRS += $(dir %(file))
2557 ifneq (%(map),)
2558     TMP_LDFLAGS += $(GENMAP) %(map)
2559     TMP_DIRS    += $(dir %(map))
2560 endif
2563 %(mmake) : %(file)
2566 %(mmake)-quick : %(file)
2568 %(file): KOBJS := $(KOBJS)
2569 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2570 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2571 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2572         @$(ECHO) Linking $@...
2573         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
2575 GLOB_MKDIRS += $(TMP_DIRS)
2577 %end
2579 #------------------------------------------------------------------------------
2580 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2581 # 'start' is an optional starting address
2582 # 'ldflags' is optional additional flags for the linker
2583 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2585 BD_OUTDIR := $(dir %(file))
2586 BD_TMPDIR  := $(GENDIR)/$(CURDIR)
2588 %(file) : %(objs) $(BD_OUTDIR)
2589         @$(ECHO) Linking $@...
2590         @$(KERNEL_LD) -melf_i386 --oformat=binary -e %(start) -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2591         @cd $(BD_TMPDIR) && $(KERNEL_LD) -r --format binary %(ldflags) %(name) -o $@
2593 GLOB_MKDIRS += $(BD_OUTDIR)
2595 %end