update
[AROS.git] / config / make.tmpl
blobc6d6515d287b1cc0c10847de670ffc6ad9c1ef08
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling  $(CURDIR)/$(notdir %(from))"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         %(strip) %(to)
70 %end
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
121 %end
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128         @$(FOR) dir in %(dirs) ; do \
129             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
130         done
131 %end
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
137 ##                                                                         ##
138 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
139 ## mmakefile. They consist of one or more full makefile rules.             ##
140 ## In general the files generated in these macros are also defined as      ##
141 ## make targets so that they can be used as a dependency in other rules    ##
142 ##                                                                         ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
149 BDID := $(BDID)_
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
152 endif
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
160 %(to) : %(from)
161         @$(CP) $< $@
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
170 # present.
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
174         @$(CP) $< $@
175 %end
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by 
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186     stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196         @for f in $(FILES); do \
197              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
199              fi ; \
200         done
201         @$(TOUCH) $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
208 # be displayed.
209 # Restriction: at the moment when using a non-empty target dir %(from) may
210 # not have 
211 %define rule_join to=/A from=/A text=
213 %(to) : %(from)
214 ifneq (%(text),)
215         @$(ECHO) %(text)
216 endif
217         @$(CAT) $^ >$@
218 %end
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean 
227 %define include_deps deps=$(DEPS)/M  depstargets=
228 ifneq (%(deps),)
229   ifneq (%(depstargets),)
230     ifneq ($(findstring $(TARGET),%(depstargets)),)
231       -include %(deps)
232     endif
233   else
234     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
235       -include %(deps)
236     endif
237   endif
238 endif
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default. 
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
252 %end
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
261 # options
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 #   the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 #   it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
270 ifeq (%(targetdir),)
271   TMP_TARGETBASE := %(basename)
272 else
273   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
274 endif
276 ifeq ($(findstring %(compiler),host kernel target),)
277   $(error unknown compiler %(compiler))
278 endif
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 endif
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 endif
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 endif
304 ifeq (%(nix),yes)
305   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
306 else
307   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
308 endif
309 $(TMP_TARGETBASE).o : %(basename).c
310         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
312 ifeq (%(dflags),)
313   ifeq (%(nix),yes)
314     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
315   else
316     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317   endif
318 else
319   ifeq (%(nix),yes)
320     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
321   else
322     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
323   endif
324 endif
325 $(TMP_TARGETBASE).d : %(basename).c
326         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
327 %end
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile multiple C source files to an object file and
333 # generate the corresponding dependency files. The generated file will be put
334 # in the object directory without the directory part of the source file.
335 # options
336 # - basenames: the basenames of the files to compile. The names may include
337 #   relative or absolute path names. No wildcard is allowed
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 #   the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 #   it is put in the same directory as the .c file. When targetdir is not
343 #   empty, path names will be stripped from the file names so that all files
344 #   are in that dir and not in subdirectories.
345 # - compiler (default target): compiler to use, target, kernel or host
346 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
347     compiler=target
349 ifeq (%(targetdir),)
350 TMP_TARGETS := $(addsuffix .o,%(basenames))
351 TMP_DTARGETS := $(addsuffix .d,%(basenames))
352 TMP_WILDCARD := %
353 else
354 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
355 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
356 TMP_WILDCARD := %(targetdir)/%
358 # Be sure that all .c files are generated
359 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
361 # Be sure that all .c files are found
362 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
363 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
364 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
365 ifneq ($(TMP_DIRS),)
366     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
367     vpath %.c $(TMP_DIRS)
368 endif
370 endif
372 ifeq ($(findstring %(compiler),host kernel target),)
373   $(error unknown compiler %(compiler))
374 endif
375 ifeq (%(compiler),target)
376 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
377 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
378 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
379 endif
380 ifeq (%(compiler),host)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
382 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
384 endif
385 ifeq (%(compiler),kernel)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
387 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
388 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETS) : CFLAGS := %(cflags)
392 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
393         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
397 else
398 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
399 endif
400 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
401         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
402 %end
403 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407 # Make an alias from one arch specific build to another arch.
408 # arguments:
409 # - mainmmake: the mmake of the module in the main tree
410 # - arch: the current arch
411 # - alias: the alias to which this should point
412 %define rule_archalias mainmmake=\A arch=\A alias=\A
414 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
415 %end
416 #------------------------------------------------------------------------------
419 #------------------------------------------------------------------------------
420 # Generate a rule to compile a C source file to a shared object file with a
421 # .so suffix. Basename may contain a directory part, then the source
422 # file has to be in that directory. The generated file will be put in the
423 # object directory without the directory.
424 # options
425 # - basename: the basename of the file to compile. Use % for a wildcard rule
426 # - cflags (default $(CFLAGS)): the C flags to use for compilation
427 # - targetdir: the directory to put the .o file and the .d file. By default
428 #   it is put in the same directory as the .c file
429 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
431 ifeq (%(targetdir),)
432   TMP_TARGETBASE := %(basename)
433 else
434   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
435 endif
437 ifeq ($(findstring %(compiler),host kernel target),)
438   $(error unknown compiler %(compiler))
439 endif
440 ifeq (%(compiler),target)
441 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
442 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
443 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
444 endif
445 ifeq (%(compiler),host)
446 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
447 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
448 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
449 endif
450 ifeq (%(compiler),kernel)
451 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
452 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
453 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
454 endif
456 $(TMP_TARGETBASE).so : %(basename).c
457         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
458 %end
459 #------------------------------------------------------------------------------
462 #------------------------------------------------------------------------------
463 # Generate a rule to assemble a source file to an object file. Basename may
464 # contain a directory part, then the source file has to be in that directory.
465 # The generated file will be put in the object directory without the directory.
466 # options
467 # - basename: the basename of the file to compile. Use % for a wildcard rule
468 # - flags (default $(AFLAGS)): the asm flags to use for assembling
469 # - targetdir: the directory to put the .o file in. By default it is put in the
470 #   same directory as the .s file
471 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
473 ifeq (%(targetdir),)
474 %(basename).o : AFLAGS := %(aflags)
475 %(basename).o : %(basename).s
476         %assemble_q
477 %(basename).o : %(basename).S
478         %assemble_q
480 else
481 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
482 %(targetdir)/$(notdir %(basename)).o : %(basename).s
483         %assemble_q
484 %(targetdir)/$(notdir %(basename)).o : %(basename).S
485         %assemble_q
487 endif
488 %end
489 #------------------------------------------------------------------------------
492 #------------------------------------------------------------------------------
493 # Generate a rule to assemble multiple source files to an object file. The
494 # generated file will be put in the object directory with the directory part
495 # of the source file stripped off.
496 # options
497 # - basenames: the basenames of the files to compile. The names may include
498 #   relative or absolute path names. No wildcard is allowed
499 # - aflags (default $(AFLAGS)): the flags to use for assembly
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 #   it is put in the same directory as the .c file. When targetdir is not
502 #   empty, path names will be stripped from the file names so that all files
503 #   are in that dir and not in subdirectories.
504 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
506 ifeq (%(targetdir),)
507 TMP_TARGETS := $(addsuffix .o,%(basenames))
508 TMP_WILDCARD := %
509 else
510 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
511 TMP_WILDCARD := %(targetdir)/%
513 # Be sure that all .s files are generated
514 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
516 # Be sure that all .c files are found
517 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
518 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
519 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
520 ifneq ($(TMP_DIRS),)
521     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
522     vpath %%(suffix) $(TMP_DIRS)
523 endif
525 endif
527 ifeq ($(findstring %(compiler),host kernel target),)
528   $(error unknown compiler %(compiler))
529 endif
530 ifeq (%(compiler),target)
531 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
532 endif
533 ifeq (%(compiler),host)
534 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
535 endif
536 ifeq (%(compiler),kernel)
537 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
538 endif
540 $(TMP_TARGETS) : AFLAGS := %(aflags)
541 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
542         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
543 %end
544 #------------------------------------------------------------------------------
547 #------------------------------------------------------------------------------
548 # Link %(objs) to %(prog) using the libraries in %(uselibs)
549 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
550     usehostlibs= usestartup=yes detach=no nix=no linker=target
552 TMP_EXTRA_LDFLAGS := 
553 ifeq (%(nix),yes)
554     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
555 endif
556 ifeq (%(usestartup),no)
557     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
558 endif
559 ifeq (%(detach),yes)
560     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
561 endif
563 # Make a list of the lib files this program depends on.
564 # In LDFLAGS remove white space between -L and directory
565 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
566 # Filter out only the libdirs and remove -L
567 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
568 # Add trailing /
569 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
570 # Add normal linklib path
571 TMP_DIRS += $(LIBDIR)/
572 # add lib and .a to static linklib names
573 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
574 # search for the linklibs in the given path, ignore ones not found
575 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
576     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
579 ifeq (%(linker),target)
580 %(prog) : CMD:=$(TARGET_CC)
581 %(prog) : STRIPCMD:=$(TARGET_STRIP)
582 endif
583 ifeq (%(linker),host)
584 %(prog) : CMD:=$(HOST_CC)
585 %(prog) : STRIPCMD:=$(HOST_STRIP)
586 endif
587 ifeq (%(linker),kernel)
588 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
589 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
590 endif
592 %(prog) : OBJS := %(objs)
593 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
594 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
595 %(prog) : %(objs) $(TMP_DEPLIBS)
596         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
597 %end
598 #------------------------------------------------------------------------------
601 #------------------------------------------------------------------------------
602 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
603 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
604 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
605     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
606     usestartup=yes detach=no
608 TMP_EXTRA_LDFLAGS := 
609 ifeq (%(nix),yes)
610     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
611 endif
612 ifeq (%(usestartup),no)
613     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
614 endif
615 ifeq (%(detach),yes)
616     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
617 endif
619 # Make a list of the lib files the programs depend on.
620 # In LDFLAGS remove white space between -L and directory
621 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
622 # Filter out only the libdirs and remove -L
623 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
624 # Add trailing /
625 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
626 # Add normal linklib path
627 TMP_DIRS += $(LIBDIR)/
628 # add lib and .a to static linklib names
629 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
630 # search for the linklibs in the given path, ignore ones not found
631 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
632     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
635 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
636 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
637 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
638         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
639 %end
640 #------------------------------------------------------------------------------
643 #------------------------------------------------------------------------------
644 # Link the %(objs) to the library %(libdir)/lib%(libname).a
645 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
647 ifeq (%(linker),target)
648 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
649 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
650 endif
651 ifeq (%(linker),host)
652 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
653 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
654 endif
655 ifeq (%(linker),kernel)
656 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
657 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
658 endif
660 %(libdir)/lib%(libname).a : %(objs)
661         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
662 %end
663 #------------------------------------------------------------------------------
666 #------------------------------------------------------------------------------
667 # Link the %(objs) to the library %(libdir)/lib%(libname).so
668 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
670 %(libdir)/lib%(libname).so : %(objs)
671         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
672 %end
673 #------------------------------------------------------------------------------
676 #------------------------------------------------------------------------------
677 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
678 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
679 # The -noarosc flag is added so that modules are not linked with arosc.library
680 # (see /config/specs.in file)
681 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
682     ldflags=$(LDFLAGS) uselibs= usehostlibs=
684 TMP_LDFLAGS  := %(ldflags)
685 # Make a list of the lib files the programs depend on.
686 # In LDFLAGS remove white space between -L and directory
687 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
688 # Filter out only the libdirs and remove -L
689 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
690 # Add trailing /
691 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
692 # Add normal linklib path
693 TMP_DIRS += $(LIBDIR)/
694 # add lib and .a to static linklib names
695 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
696 # search for the linklibs in the given path, ignore ones not found
697 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
698     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
701 %(module) : LIB_NAMES := %(uselibs)
702 %(module) : OBJS := %(objs)
703 %(module) : ENDTAG := %(endobj)
704 %(module) : ERR := %(err)
705 %(module) : OBJDIR := %(objdir)
706 %(module) : LDFLAGS := $(TMP_LDFLAGS)
707 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
708                     -L/usr/lib $(addprefix -l,%(usehostlibs))
709 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
710         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
712 %end
713 #------------------------------------------------------------------------------
716 #------------------------------------------------------------------------------
717 # Generate the libdefs.h include file for a module.
718 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
720 TMP_TARGET := %(modname)_libdefs.h
721 TMP_DEPS := $(GENMODULE)
722 TMP_OPTS := 
723 ifneq (%(conffile),)
724     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
725     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
726 else
727     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
728     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
729 endif
730 ifneq (%(modsuffix),)
731     TMP_OPTS += -s %(modsuffix)
732 endif
733 ifneq (%(targetdir),)
734     TMP_OPTS += -d %(targetdir)
735     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
736 endif
737 ifneq (%(version),)
738     TMP_OPTS += -v %(version)
739 endif
741 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
742 $(TMP_TARGET) : MODNAME := %(modname)
743 $(TMP_TARGET) : MODTYPE := %(modtype)
744 $(TMP_TARGET) : $(TMP_DEPS)
745         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
746         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
747 %end
748 #------------------------------------------------------------------------------
750 #------------------------------------------------------------------------------
751 # Generate the _lib.fd file for a module.
752 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
754 TMP_TARGET := %(modname)_lib.fd
755 TMP_DEPS := $(GENMODULE)
756 TMP_OPTS := 
757 ifneq (%(conffile),)
758     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
759     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
760 else
761     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
762     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
763 endif
764 ifneq (%(modsuffix),)
765     TMP_OPTS += -s %(modsuffix)
766 endif
767 ifneq (%(targetdir),)
768     TMP_OPTS += -d %(targetdir)
769     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
770 endif
772 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
773 $(TMP_TARGET) : MODNAME := %(modname)
774 $(TMP_TARGET) : MODTYPE := %(modtype)
775 $(TMP_TARGET) : $(TMP_DEPS)
776         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
777         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
778 %end
779 #------------------------------------------------------------------------------
781 #------------------------------------------------------------------------------
782 # Generate a Makefile.%(modname) with the genmodule program and include this
783 # generated file in this Makefile
784 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
785     targetdir=
787 TMP_TARGET := Makefile.%(modname)
788 TMP_DEPS := $(GENMODULE)
789 TMP_OPTS := 
790 ifneq (%(conffile),)
791     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
792     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
793 else
794     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
795     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
796 endif
797 ifneq (%(modsuffix),)
798     TMP_OPTS += -s %(modsuffix)
799 endif
800 ifneq (%(targetdir),)
801     TMP_OPTS += -d %(targetdir)
802     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
803 endif
805 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
806 $(TMP_TARGET) : MODNAME := %(modname)
807 $(TMP_TARGET) : MODTYPE := %(modtype)
808 $(TMP_TARGET) : $(TMP_DEPS)
809         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
810 %end
811 #------------------------------------------------------------------------------
814 #------------------------------------------------------------------------------
815 # Generate the support files for compiling a module. This includes include
816 # files and source files. This rule has to be preceeded by
817 # %rule_genmodule_makefile
818 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
819     conffile=
821 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
822                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
823 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
824                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
826 TMP_DEPS := $(GENMODULE)
827 TMP_OPTS :=
829 ifneq (%(conffile),)
830     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
831     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
832 else
833     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
834     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
835 endif
836 ifneq (%(modsuffix),)
837     TMP_OPTS += -s %(modsuffix)
838 endif
839 ifneq (%(targetdir),)
840     TMP_OPTS += -d %(targetdir)
841     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
842     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
843 endif
845 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
846 $(TMP_TARGETS) : MODNAME := %(modname)
847 $(TMP_TARGETS) : MODTYPE := %(modtype)
848 $(TMP_TARGETS) : $(TMP_DEPS)
849         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
850 ifneq (%(conffile),lib.conf)
851         @$(IF) $(TEST) -f lib.conf; then \
852           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
853         fi
854 endif
855         @$(IF) $(TEST) -f libdefs.h; then \
856           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
857         fi
858         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
859 %end
860 #------------------------------------------------------------------------------
863 #------------------------------------------------------------------------------
864 # Generate the support files for compiling a module. This includes include
865 # files and source files.
866 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
867     targetdir= conffile=
869 ifneq ($(%(modname)_INCLUDES),)
870 TMP_TARGETS := $(%(modname)_INCLUDES)
872 TMP_DEPS := $(GENMODULE)
873 TMP_OPTS :=
875 ifneq (%(conffile),)
876     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
877     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
878 else
879     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
880     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
881 endif
882 ifneq (%(modsuffix),)
883     TMP_OPTS += -s %(modsuffix)
884 endif
885 ifneq (%(targetdir),)
886     TMP_OPTS += -d %(targetdir)
887     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
888 endif
890 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
891 $(TMP_TARGETS) : MODNAME := %(modname)
892 $(TMP_TARGETS) : MODTYPE := %(modtype)
893 $(TMP_TARGETS) : $(TMP_DEPS)
894         @$(ECHO) "Generating include files"
895         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
896 endif
897 %end
898 #------------------------------------------------------------------------------
901 #------------------------------------------------------------------------------
902 # Common rules for all makefiles
903 %define common
904 # Delete generated makefiles
906 clean ::
907         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
909 include $(SRCDIR)/config/make.tail
911 BDID := $(BDTARGETID)
912 %end
913 #------------------------------------------------------------------------------
914       
916 #############################################################################
917 #############################################################################
918 ##                                                                         ##
919 ## Here are the mmakefile build macros. These are macros that takes care   ##
920 ## of everything to go from the sources to the generated target. Also all  ##
921 ## intermediate files and directories that are needed are created by these ##
922 ## rules.                                                                  ##
923 ##                                                                         ##
924 #############################################################################
925 #############################################################################
927 #------------------------------------------------------------------------------
928 # Build a program
929 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
930     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
931     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
932     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
933     compiler=target linker= srcdir=
935 .PHONY : %(mmake)
937 BD_PROGNAME  := %(progname)
938 BD_OBJDIR    := %(objdir)
939 BD_TARGETDIR := %(targetdir)
940 BD_LINKER    := %(linker)
942 # If not supplied, linker is equal to compiler
943 ifeq ($(BD_LINKER),)
944     BD_LINKER := %(compiler)
945 endif
947 BD_FILES     := %(files)
948 BD_ASMFILES  := %(asmfiles)
950 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
951 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
952 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
954 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
955 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
957 BD_CFLAGS    := %(cflags)
958 BD_AFLAGS    := %(aflags)
959 BD_DFLAGS    := %(dflags)
960 BD_LDFLAGS   := %(ldflags)
963 %(mmake)-quick : %(mmake)
965 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
966 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
968 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
969 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
970     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
971 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
972     aflags=$(BD_AFLAGS) compiler=%(compiler)
974 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
975     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
976     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
977     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
978     linker=$(BD_LINKER)
980 endif
982 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
984 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
985 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
986 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
988 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
990 %(mmake)-clean ::
991         @$(ECHO) "Cleaning up for metatarget %(mmake)"
992         @$(RM) $(FILES)
994 %end
995 #------------------------------------------------------------------------------
998 #------------------------------------------------------------------------------
999 # Build programs, for every C file an executable will be built with the same
1000 # name as the C file
1001 %define build_progs mmake=/A files=/A nix=no \
1002     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1003     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1004     uselibs= usehostlibs= usestartup=yes detach=no
1006 .PHONY : %(mmake)
1008 BD_OBJDIR    := %(objdir)
1009 BD_TARGETDIR := %(targetdir)
1011 BD_FILES     := %(files)
1012 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1013 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1014 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1016 BD_CFLAGS    := %(cflags)
1017 BD_DFLAGS    := %(dflags)
1018 BD_LDFLAGS   := %(ldflags)
1021 %(mmake)-quick : %(mmake)
1023 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1024 %(mmake) : $(BD_EXES)
1026 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1027 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1028     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1030 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1031     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1032     ldflags=$(BD_LDFLAGS) \
1033     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1034     usestartup="%(usestartup)" detach="%(detach)"
1036 endif
1038 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1040 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1041 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1042 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1044 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1046 %(mmake)-clean ::
1047         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1048         @$(RM) $(FILES)
1050 %end
1051 #------------------------------------------------------------------------------
1054 #------------------------------------------------------------------------------
1055 # Build a module.
1056 # This is a bare version: It just compiles and links the given files. It is
1057 # assumed that all needed boiler plate code is in the files. This should only
1058 # be used for compiling external code. For AROS code use %build_module
1059 %define build_module_simple mmake=/A modname=/A modtype=/A \
1060     files="$(basename $(call WILDCARD, *.c))" \
1061     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1062     objdir=$(OBJDIR) moduledir= \
1063     uselibs= usehostlibs= compiler=target
1065 # Define metamake targets and their dependencies
1066 #MM %(mmake) : core-linklibs includes-generate-deps
1067 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1068 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1069 #MM %(mmake)-kobj-quick
1070 #MM %(mmake)-pkg-quick
1071 #MM %(mmake)-quick
1072 #MM %(mmake)-clean
1074 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1076 .PHONY : $(BD_ALLTARGETS)
1078 ifeq (%(modname),)
1079 $(error using %build_module_simple: modname may not be empty)
1080 endif
1081 ifeq (%(modtype),)
1082 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1083 endif
1085 # Default values for variables and arguments
1086 BD_DEFLINKLIBNAME := %(modname)
1087 BD_DEFDFLAGS := %(cflags)
1088 OBJDIR ?= $(GENDIR)/$(CURDIR)
1089 BD_MODDIR := %(moduledir)
1090 ifeq ($(BD_MODDIR),)
1091   ifeq (%(modtype),library)
1092     BD_MODDIR  := $(AROS_LIBS)
1093   endif
1094   ifeq (%(modtype),gadget)
1095     BD_MODDIR  := $(AROS_GADGETS)
1096   endif
1097   ifeq (%(modtype),datatype)
1098     BD_MODDIR  := $(AROS_DATATYPES)
1099   endif
1100   ifeq (%(modtype),handler)
1101     BD_MODDIR  := $(AROS_FS)
1102   endif
1103   ifeq (%(modtype),device)
1104     BD_MODDIR  := $(AROS_DEVS)
1105   endif
1106   ifeq (%(modtype),resource)
1107     BD_MODDIR  := $(AROS_RESOURCES)
1108   endif
1109   ifeq (%(modtype),hook)
1110     BD_MODDIR  := $(AROS_RESOURCES)
1111   endif
1112   ifeq (%(modtype),mui)
1113     BD_MODDIR  := $(AROS_CLASSES)/Zune
1114   endif
1115   ifeq (%(modtype),mcc)
1116     BD_MODDIR  := $(AROS_CLASSES)/Zune
1117   endif
1118   ifeq (%(modtype),mcp)
1119     BD_MODDIR  := $(AROS_CLASSES)/Zune
1120   endif
1121   ifeq (%(modtype),usbclass)
1122     BD_MODDIR  := $(AROS_CLASSES)/USB
1123   endif
1124   ifeq (%(modtype),hidd)
1125     BD_MODDIR  := $(AROS_DRIVERS)
1126   endif
1127 endif
1128 ifeq ($(BD_MODDIR),)
1129   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1130 endif
1132 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1133 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1134 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1136 %rule_compile_multi \
1137     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1138     cflags="%(cflags)" dflags="%(dflags)" \
1139     compiler=%(compiler)
1141 # Handlers use dash instead of dot in their names
1142 ifeq (%(modtype),handler)
1143 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1144 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1145 else
1146 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1147 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1148 endif
1149 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1151 %(mmake)-quick : %(mmake)
1152 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1153 %(mmake)-kobj-quick : $(BD_KOBJ)
1154 %(mmake)       : $(BD_MODULE)
1155 %(mmake)-pkg   : $(BD_PKGMOD)
1156 %(mmake)-kobj  : $(BD_KOBJ)
1158 # The module is linked from all the compiled .o files
1159 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1161 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1162 # This breaks con-handler build. Here we work around this
1163 ifeq (%(modname),con)
1164     BD_ERR := $(notdir $(BD_MODULE)).err
1165 else
1166     BD_ERR := %(modname).err
1167 endif
1169 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1170                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1171                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1173 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1174                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1175                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1177 # Link kernel object file
1178 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1180 # Make these symbols local
1181 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1182             UtilityBase ExpansionBase KeymapBase KernelBase
1184 BD_SYMBOLS := $(BD_KBASE)
1186 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1187 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1188 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1189 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1190 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1191 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1192         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1193         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1194         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1197 ## Dependency fine-tuning
1199 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1200 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1202 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1203 $(BD_MODULE) : | $(BD_MODDIR)
1204 $(BD_KOBJ) : | $(KOBJSDIR)
1205 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1207 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1208 %(mmake)-clean ::
1209         @$(ECHO) "Cleaning up for module %(modname)"
1210         @$(RM) $(FILES)
1211 %end
1212 #------------------------------------------------------------------------------
1215 #------------------------------------------------------------------------------
1216 # Build a module
1217 # Explanation of this macro is done in the developer's manual
1218 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1219   conffile= files="$(basename $(call WILDCARD, *.c))" \
1220   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1221   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1222   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1223   compiler=target nostartup=yes
1225 # Define metamake targets and their dependencies
1226 #MM- includes-all : %(mmake)-includes
1227 #MM- linklibs-%(modname): %(mmake)-linklib
1228 #MM- includes-%(modname): %(mmake)-includes
1229 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1230 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1231 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1232 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1233 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1234 #MM %(mmake)-linklib : %(mmake)-includes
1235 #MM %(mmake)-quick : %(mmake)-includes-quick
1236 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1237 #MM     includes-generate-deps %(mmake)-fd
1238 #MM %(mmake)-includes-quick
1239 #MM %(mmake)-includes-dirs
1240 #MM %(mmake)-fd
1241 #MM %(mmake)-makefile
1242 #MM %(mmake)-clean
1244 # All MetaMake targets defined by this macro
1245 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1246     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1247     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1248     %(mmake)-linklib %(mmake)-fd
1250 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1252 ifeq (%(modname),)
1253 $(error using %build_module: modname may not be empty)
1254 endif
1255 ifeq (%(modtype),)
1256 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1257 endif
1259 # Default values for variables and arguments
1260 BD_DEFLINKLIBNAME := %(modname)
1261 BD_DEFDFLAGS := %(cflags)
1262 OBJDIR ?= $(GENDIR)/$(CURDIR)
1264 ## Create genmodule include Makefile for the module
1266 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1268 %rule_genmodule_makefile \
1269     modname=%(modname) modtype=%(modtype) \
1270     modsuffix=%(modsuffix) targetdir=%(objdir) \
1271     conffile=%(conffile)
1273 %(objdir)/Makefile.%(modname) : | %(objdir)
1275 GLOB_MKDIRS += %(objdir)
1277 # Do not parse these statements if metatarget is not appropriate
1278 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1280 include %(objdir)/Makefile.%(modname)
1282 BD_DEFMODDIR := $(%(modname)_MODDIR)
1285 ## include files generation
1287 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1288 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1289 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1291 %(mmake)-includes-quick : %(mmake)-includes
1292 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1293     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1294     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1296 ifneq ($(%(modname)_INCLUDES),)
1297 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1298                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1299                          conffile=%(conffile)
1301 %rule_copy_diff_multi \
1302     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1303     stampfile=%(objdir)/%(modname)_geninc
1305 %rule_copy_diff_multi \
1306     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1307     stampfile=%(objdir)/%(modname)_incs
1309 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1311 TMP%(modname)_INCDIRS := \
1312     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1313     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1314     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1315 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1317 endif
1319 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1320                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1321                            conffile=%(conffile) version=%(version)
1323 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1324 $(BD_DEFLIBDEFSINC) :
1325         @$(ECHO) "generating $@"
1326         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1328 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1329 GLOB_MKDIRS += %(objdir)/include
1331 ## Extra genmodule src files generation
1332 ## 
1333 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1334                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1335                       conffile=%(conffile)
1338 ## Create FD file
1339 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1340 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1342 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1343                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1345 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1347 GLOB_MKDIRS += $(BD_FDDIR)
1350 ## Compilation
1352 BD_FILES      := %(files)
1353 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1354 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1355 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1357 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1358 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1359 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1361 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1362 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1364 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1365 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1366 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1367     BD_LINKLIB :=
1368 else
1369     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1370 endif
1371 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1373 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1374 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1375 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1376     BD_RELLINKLIB :=
1377 else
1378     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel.a
1379 endif
1380 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1382 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1383 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1384     $(BD_RELLINKLIBCFILES)
1386 %rule_compile_multi \
1387     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1388     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1389     compiler=%(compiler)
1390 %rule_compile_multi \
1391     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1392     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1393     compiler=%(compiler)
1395 ifneq ($(BD_LINKLIBAFILES),)
1396 %rule_assemble_multi \
1397     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1398 endif
1400 ## Linking
1402 ifeq (%(modsuffix),)
1403 BD_SUFFIX := %(modtype)
1404 else
1405 BD_SUFFIX := %(modsuffix)
1406 endif
1408 # Handlers use dash instead of dot in their names
1409 ifeq ($(BD_SUFFIX),handler)
1410 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1411 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1412 else
1413 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1414 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1415 endif
1416 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1418 %(mmake)-quick      : %(mmake)
1419 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1420 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1421 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1422 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1423 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1424 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1426 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1427                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1429 ifeq (%(nostartup),yes)
1430 # Handlers always have entry point
1431 ifneq (%(modtype),handler)
1432 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1433 endif
1434 endif
1436 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1437 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1438                  %(linklibobjs)
1439 BD_RELLINKLIBOBJS \
1440               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1441                  %(linklibobjs)
1443 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1444 # This breaks con-handler build. Here we work around this
1445 ifeq (%(modname),con)
1446     BD_ERR := $(notdir $(BD_MODULE)).err
1447 else
1448     BD_ERR := %(modname).err
1449 endif
1451 # The module is linked from all the compiled .o files
1452 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1453                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1454                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1456 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1457                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1458                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1460 # Link static lib
1461 ifneq ($(BD_LINKLIB),)
1462 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1464 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1465 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1466 endif
1468 ifneq ($(BD_RELLINKLIB),)
1469 %rule_link_linklib libname=%(linklibname)_rel objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1471 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1472 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1473 endif
1475 # Link kernel object file
1476 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1478 # Make these symbols local
1479 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1480             UtilityBase ExpansionBase KeymapBase KernelBase
1482 BD_SYMBOLS := $(BD_KBASE)
1484 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1485 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1486 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1487 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1488 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1489 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1490         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1491         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1492         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1494 ## Dependency fine-tuning
1496 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1497 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1499 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1500 $(BD_MODULE) : | %(prefix)/%(moduledir)
1501 $(BD_PKGMOD) : | $(PKGDIR)
1502 $(BD_KOBJ)   : | $(KOBJSDIR)
1503 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1505 # Some include files need to be generated before the .c can be parsed.
1506 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
1508 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1509     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1510 $(BD_DEPS) : $(BD_DFILE_DEPS)
1511 endif
1513 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1514     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1515     %(objdir)/Makefile.%(modname) \
1516     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1517     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1518     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1519     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1520     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1521     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1522     $(BD_ENDOBJS)
1523 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1524 %(mmake)-clean ::
1525         @$(ECHO) "Cleaning up for module %(modname)"
1526         @$(RM) $(FILES)
1528 endif # $(TARGET) in $(BD_ALLTARGETS)
1529 %end
1530 #------------------------------------------------------------------------------
1533 #------------------------------------------------------------------------------
1534 # Build a module skeleton
1535 # This is a stripped-down version of build_module, it only creates include files,
1536 # but no actual object. This is used when for plugins or classes with the same
1537 # API, but no actual implementation here.
1538 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1539   conffile= \
1540   objdir=$(OBJDIR) prefix=$(AROSDIR)
1542 # Define metamake targets and their dependencies
1543 #MM- includes-all : %(mmake)-includes
1544 #MM %(mmake) : %(mmake)-includes core-linklibs
1545 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1546 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1547 #MM %(mmake)-linklib : %(mmake)-includes
1548 #MM %(mmake)-quick : %(mmake)-includes-quick
1549 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1550 #MM     includes-generate-deps
1551 #MM %(mmake)-includes-quick
1552 #MM %(mmake)-includes-dirs
1553 #MM %(mmake)-makefile
1554 #MM %(mmake)-clean
1556 # All MetaMake targets defined by this macro
1557 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1558     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1559     %(mmake)-kobj %(mmake)-pkg
1561 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1563 ifeq (%(modname),)
1564 $(error using %build_module_skeleton: modname may not be empty)
1565 endif
1566 ifeq (%(modtype),)
1567 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1568 endif
1570 # Default values for variables and arguments
1571 BD_DEFLINKLIBNAME := %(modname)
1572 BD_DEFDFLAGS := %(cflags)
1573 OBJDIR ?= $(GENDIR)/$(CURDIR)
1575 ## Create genmodule include Makefile for the module
1577 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1579 %rule_genmodule_makefile \
1580     modname=%(modname) modtype=%(modtype) \
1581     modsuffix=%(modsuffix) targetdir=%(objdir) \
1582     conffile=%(conffile)
1584 %(objdir)/Makefile.%(modname) : | %(objdir)
1586 GLOB_MKDIRS += %(objdir)
1588 # Do not parse these statements if metatarget is not appropriate
1589 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1591 include %(objdir)/Makefile.%(modname)
1593 BD_DEFMODDIR := $(%(modname)_MODDIR)
1596 ## include files generation
1598 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1599 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1600 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1602 %(mmake)-includes-quick : %(mmake)-includes
1603 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1604     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1605     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1607 ifneq ($(%(modname)_INCLUDES),)
1608 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1609                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1610                          conffile=%(conffile)
1612 %rule_copy_diff_multi \
1613     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1614     stampfile=%(objdir)/%(modname)_geninc
1616 %rule_copy_diff_multi \
1617     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1618     stampfile=%(objdir)/%(modname)_incs
1620 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1622 TMP%(modname)_INCDIRS := \
1623     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1624     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1625     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1626 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1628 endif
1630 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1631                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1632                            conffile=%(conffile)
1634 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1635 $(BD_DEFLIBDEFSINC) :
1636         @$(ECHO) "generating $@"
1637         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1639 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1640 GLOB_MKDIRS += %(objdir)/include
1642 ## Extra genmodule src files generation
1643 ## 
1644 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1645                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1646                       conffile=%(conffile)
1648 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1649     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1650     %(objdir)/Makefile.%(modname) \
1651     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1652     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1653     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1654     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1655     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1656     $(BD_DEFLIBDEFSINC)
1657 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1658 %(mmake)-clean ::
1659         @$(ECHO) "Cleaning up for module %(modname)"
1660         @$(RM) $(FILES)
1662 endif # $(TARGET) in $(BD_ALLTARGETS)
1663 %end
1664 #------------------------------------------------------------------------------
1667 #------------------------------------------------------------------------------
1668 # Build a linklib.
1669 # - mmake is the mmaketarget
1670 # - libname is the baselibname e.g. lib%(libname).a will be created
1671 # - files are the C source files to include in the lib. The list of files
1672 #   has to be given without the .c suffix
1673 # - asmfiles are the asm files to include in the lib. The list of files has to
1674 #   be given without the .s suffix
1675 # - objs additional object to link into the linklib. The objects have to be
1676 #   given with full absolute path and the .o suffix.
1677 # - cflags are the flags to compile the source (default $(CFLAGS))
1678 # - dflags are the flags use during makedepend (default equal to cflags)
1679 # - aflags are the flags use during assembling (default $(AFLAGS))
1680 # - objdir is where the .o are generated
1681 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1682 %define build_linklib mmake=/A libname=/A \
1683   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= compiler=target \
1684   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1686 # assign and generate the local variables used in this macro
1687 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1689 BD_FILES      := %(files)
1690 BD_ASMFILES   := %(asmfiles)
1692 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1693 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1694 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1696 BD_OBJS       := $(BD_ARCHOBJS) \
1697                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1698                  %(objs)
1699 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1701 BD_CFLAGS     := %(cflags)
1702 ifeq (%(dflags),)
1703 BD_DFLAGS     := $(BD_CFLAGS)
1704 else
1705 BD_DFLAGS     := %(dflags)
1706 endif
1707 BD_AFLAGS     := %(aflags)
1709 BD_LINKLIB    := %(libdir)/lib%(libname).a
1711 .PHONY : %(mmake) %(mmake)-clean
1713 #MM %(mmake) : includes-generate-deps
1714 %(mmake) : $(BD_LINKLIB)
1717 %(mmake)-clean ::
1718         @$(RM) $(BD_OBJS) $(BD_DEPS)
1720 ifeq ($(TARGET),%(mmake))
1721 ifneq ($(dir $(BD_FILES)),./)
1722 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1723 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1724 endif
1726 %rule_compile basename=% targetdir=%(objdir) compiler=%(compiler) \
1727               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1728 %rule_assemble basename=% targetdir=%(objdir) \
1729               aflags=$(BD_AFLAGS)
1731 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1732 endif
1734 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1736 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1737 $(BD_LINKLIB) : | %(libdir)
1738 GLOB_MKDIRS += %(objdir) %(libdir)
1740 %end
1741 #------------------------------------------------------------------------------
1744 #------------------------------------------------------------------------------
1745 # Build catalogs.
1746 # - mmake is the mmaketarget
1747 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1748 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1749 # - subdir is the destination subdirectory of the catalogs
1750 # - name is the name of the destination catalog, without the .catalog suffix
1751 # - source is the path to the generated source code file
1752 # - dir is the base destination directory (default $(AROS_CATALOGS))
1753 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1754 # - srcdir is the directory in which the *.cd and *.ct files are searched
1756 %define build_catalogs mmake=/A name=/A subdir=/A \
1757  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1758  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1760 ifeq (%(description),)
1761 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1762 else
1763 BD_DESC := %(description)
1764 endif
1766 ifeq (%(catalogs),)
1767 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1768 else
1769 BD_LNGS := %(catalogs)
1770 endif
1772 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1773 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1776 %(mmake) : $(BD_OBJS) %(source)
1778 $(BD_OBJS) : | $(BD_DIRS)
1779 GLOB_MKDIRS += $(BD_DIRS)
1781 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1782         @$(ECHO) "Creating   %(name) catalog for language $*."
1783         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1785 ifneq (%(source),)
1786 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1787 %(source) : $(BD_DESC).cd | $(dir %(source))
1788         @$(ECHO) "Creating   %(name) catalog source file %(source)"
1789         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1790 endif
1793 %(mmake)-clean ::
1794         $(RM) $(BD_OBJS) %(source)
1796 .PHONY: %(mmake) %(mmake)-clean
1798 %end
1799 #-----------------------------------------------------------------------------
1802 #-----------------------------------------------------------------------------
1803 # Build icons.
1804 # - mmake is the mmaketarget
1805 # - icons is a list of icon base names (ie. without the .info suffix)
1806 # - dir is the destination directory
1807 # - srcdir is where *.png and *.info.src are searched
1808 #-----------------------------------------------------------------------------
1810 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1812 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1815 %(mmake) : $(BD_OBJS)
1817 ifeq (%(image),)
1819 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1820         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1821         @$(ILBMTOICON) $+ $@
1823 else
1825 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1826         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1827         @$(ILBMTOICON) $+ $@
1829 endif
1831 $(BD_OBJS) : | %(dir)
1832 GLOB_MKDIRS += %(dir)
1834 %(mmake)-clean : FILES := $(BD_OBJS)
1836 %(mmake)-clean ::
1837         @$(RM) $(FILES)
1839 .PHONY: %(mmake) %(mmake)-clean
1841 %end
1842 #-----------------------------------------------------------------------------
1845 #------------------------------------------------------------------------------
1846 # Compile files for an arch-specific replacement of code for a module
1847 # - files: the basenames of the C files to compile.
1848 # - asmfiles: the basenames of the asm files to assemble.
1849 # - mainmmake: the mmake of the module in the main directory to compile these
1850 #   arch specific files for.
1851 # - maindir: the object directory for the main module
1852 # - arch: the arch for which to compile these files. It can have the form
1853 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1854 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1855 # - dflags: the flags used during creation of dependency file. If not specified
1856 #   the same value as cflags will be used
1857 # - aflags: the flags used during assembling
1858 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1859 #   the target compiler is used
1860 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1861 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1863 ifeq (%(files) %(asmfiles),)
1864   $(error no files or asmfiles given)
1865 endif
1867 %buildid targets="%(mainmmake)-%(arch)"
1869 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1870 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1871 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1872 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1873 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1874 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1875 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1876 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1877 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1878 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1879 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1880 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1881 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1882 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1883 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1884 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1885 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1886 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1887 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1888 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1889 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1891 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1893 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1894 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1895 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1896 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1897 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1899 ifneq (%(modulename),)
1900 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1901 endif
1903 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
1904     BD_TARGET := %(mainmmake)-%(arch)-quick
1905 else
1906     BD_TARGET := %(mainmmake)-%(arch)
1907 endif
1910 ifeq ($(TARGET),$(BD_TARGET))
1911 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1912 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1913 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1914 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1915 endif
1917 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1918 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1921 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1924 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
1926 ifeq ($(findstring %(compiler),host kernel target),)
1927   $(error unknown compiler %(compiler))
1928 endif
1929 ifeq (%(compiler),target)
1930 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1931 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1932 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1933 endif
1934 ifeq (%(compiler),host)
1935 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1936 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1937 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1938 endif
1939 ifeq (%(compiler),kernel)
1940 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1941 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1942 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1943 endif
1944 ifneq (%(modulename),)
1945 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1946 else
1947 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1948 endif
1949 ifeq ($(TARGET),$(BD_TARGET))
1950 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
1951         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1952 endif
1954 ifeq (%(dflags),)
1955 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1956 else
1957 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1958 endif
1959 ifeq ($(TARGET),$(BD_TARGET))
1960 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
1961         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1962 endif
1964 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1966 ifeq ($(TARGET),$(BD_TARGET))
1967 $(BD_OBJDIR$(BDID))/%.o : %.s
1968         %assemble_q opt=$(AFLAGS)
1969 $(BD_OBJDIR$(BDID))/%.o : %.S
1970         %assemble_q opt=$(AFLAGS)
1971 endif
1973 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
1974 %end
1975 #------------------------------------------------------------------------------
1978 #------------------------------------------------------------------------------
1979 # generate asm files from c files (for debugging purposes)
1980 %define ctoasm_q
1981 %.s : %.c
1982         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1983         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1984 %end
1985 #------------------------------------------------------------------------------
1988 #------------------------------------------------------------------------------
1989 # Copy files from one directory to another.
1991 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1993 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1995 GLOB_MKDIRS += %(dst)
1997 .PHONY : %(mmake)
2000 %(mmake) : | %(dst) 
2001         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2003 %end
2004 #------------------------------------------------------------------------------
2007 #------------------------------------------------------------------------------
2008 # Copy a directory recursively to another place, preserving the original 
2009 # hierarchical structure
2011 # src: the source directory whose content will be copied
2012 # dst: the directory where to copy src's content. If not existing, it will be made.
2014 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2016 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2017 %(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)
2018 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2020 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2021 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2023 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2025 .PHONY : %(mmake)
2028 %(mmake): | $(GENDIR)/$(CURDIR)
2029         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2030         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2031         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2032         for d in $(%(mmake)_DIRS); do                      \
2033             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2034         done
2035         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2036         for f in $(%(mmake)_FILES); do                                            \
2037             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2038         done;  \
2039         for dst in %(dst); do \
2040             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2041         done
2043 %end
2044 #------------------------------------------------------------------------------
2047 #------------------------------------------------------------------------------
2048 #   Copy include files into the includes directories. There are currently
2049 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2050 #   for building tools that need to run on the host system $(GENINCDIR). The
2051 #   $(GENINCDIR) path must not contain any references to the C runtime
2052 #   library header files.
2054 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2055     dir= compiler=target
2057 ifeq ($(findstring %(compiler),host kernel target),)
2058 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2059 endif
2061 ifneq (%(dir),)
2062 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2063 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2064 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2065 else
2066 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2067 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2068 endif
2070 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2071         @$(CP) $< $@
2074 ifeq (%(compiler),target)
2076 ifneq (%(dir),)
2077 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2078 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2079 else
2080 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2081 endif
2083 BD_INCL_FILES += $(BD_INCL_FILES2)
2085 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2086         @$(CP) $< $@
2087 endif
2090 %(mmake) : $(BD_INCL_FILES)
2092 .PHONY: %(mmake)
2094 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2095 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2096 %end
2097 #------------------------------------------------------------------------------
2100 #------------------------------------------------------------------------------
2101 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2102 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2103 STUBS_MEM := $(addsuffix .o,$(STUBS))
2104 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2105 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2106 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2108 #MM- linklibs : hidd-%(hidd)-stubs
2109 #MM- %(parenttarget): hidd-%(hidd)-stubs
2110 #MM hidd-%(hidd)-stubs : includes includes-copy
2111 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2113 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2114         %mklib_q from=$^
2116 $(STUBS_OBJ) : $(STUBS_SRC) 
2117         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2119 $(STUBS_DEP) : $(STUBS_SRC)
2120         %mkdepend_q flags=%(dflags)
2122 setup ::
2123         %mkdirs_q $(OBJDIR) $(LIBDIR)
2126 clean ::
2127         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2129 DEPS := $(DEPS) $(STUBS_DEP)
2131 %end
2132 #------------------------------------------------------------------------------
2135 #------------------------------------------------------------------------------
2136 # Build an imported source tree which uses the configure script from the
2137 # autoconf package.  This rule will try to "integrate" the produced files as
2138 # much as possible in the AROS build, for example by putting libraries in the
2139 # standard library directory, includes in the standard include directory, and
2140 # so on. You can however override this behaviour.
2142 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2143 # be %(bindir) (or its deduced value) when running "make install", and
2144 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2145 # configure script some more parameters whose value depends upon the PROGDIR
2146 # env var, so that the program gets all its stuff installed in the proper place
2147 # when building it, but when running it from inside AROS it can also find that
2148 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2149 # the configuration parameters set when running ./configure
2151 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2152 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2153 # to the name which has to follow it.
2156 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2157     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2158     install_target=install preconfigure= postconfigure= postinstall= \
2159     install_env= use_build_env=no
2161 ifneq (%(prefix),)
2162     %(mmake)-prefix := %(prefix)
2163 else
2164     %(mmake)-prefix := $(AROS_CONTRIB)
2165 endif
2167 ifneq (%(aros_prefix),)
2168     %(mmake)-aros_prefix := %(aros_prefix)
2169 else
2170     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2171 endif
2173 ifeq (%(nix),yes)
2174     %(mmake)-nix    := -nix
2175     %(mmake)-volpfx := /
2176     %(mmake)-volsfx := /
2177     
2178     ifeq (%(nix_dir_layout),)
2179         %(mmake)-nix_dir_layout := yes
2180     endif
2181 else
2182     %(mmake)-volsfx := :
2183     
2184     ifeq (%(nix_dir_layout),)
2185         %(mmake)-nix_dir_layout := no
2186     endif
2187 endif
2189 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2191 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2192         exec_prefix=$(%(mmake)-prefix) %(install_env)
2194 # Check if chosen compiler is valid
2195 ifeq ($(findstring %(compiler),host target kernel),)
2196   $(error unknown compiler %(compiler))
2197 endif
2199 # Set legacy 'host' variable based on chosen compiler
2200 ifeq (%(compiler),host)
2201     host := yes
2202         ifeq (%(package),)
2203                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2204         else
2205                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2206         endif
2207 else
2208     host := no
2209         ifeq (%(package),)
2210                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2211         else
2212                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2213         endif
2214 endif
2216 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2217 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2219 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2220     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2221     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2222 else
2223     ifeq (%(nix),yes)
2224         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2225         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2226     else
2227         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2228     endif
2230     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2231     
2232     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2233         sbindir=$(%(mmake)-prefix) \
2234         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2235         oldincludedir=$(AROS_INCLUDES) %(install_env)
2236 endif
2238 ifneq ($(DEBUG),yes)
2239     %(mmake)-s_flag = -s
2240 endif
2242 # Set up build environment, and options for configure script
2243 ifeq (%(compiler),host)
2244     CONFIG_ENV := \
2245         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2246         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2247         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2248         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2249     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2250 endif
2251 ifeq (%(compiler),target)
2252     CONFIG_ENV := \
2253         CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2254         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2255         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2256         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2257         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2258     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2259         --host=$(AROS_TARGET_CPU)-aros\
2260         --target=$(AROS_TARGET_CPU)-aros\
2261         --disable-nls\
2262         --without-x --without-pic --disable-shared
2263 endif
2264 ifeq (%(compiler),kernel)
2265     CONFIG_ENV := \
2266         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2267         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2268         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2269     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2270         --host=$(AROS_TARGET_CPU)-aros\
2271         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2272         --without-x --without-pic --disable-shared
2273 endif
2275 ifeq (%(use_build_env),yes)
2276     BUILD_ENV := $(CONFIG_ENV)
2277 endif
2280 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2282 #MM- %(mmake) : setup includes core-linklibs %(mmake)-quick
2284 # Using -j1 in install_command may result in a warning but finally
2285 # it does its job. make install for gcc does not work reliably for -jN
2286 # where N > 1.
2287 ifneq (%(install_target),)
2288     %(mmake)-install_command = \
2289         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2290         -C $(%(mmake)-pkgdir) %(install_target) -j1
2292     %(mmake)-uninstall_command = \
2293     $(RM) $(%(mmake)-installflag) && \
2294     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2295     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2296 else
2297     %(mmake)-install_command   := true
2298     %(mmake)-uninstall_command := true
2299 endif
2301 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2304 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2306 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2307         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2308             $(RM)  $(%(mmake)-installflag) && \
2309             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2310              -C $(%(mmake)-pkgdir) && \
2311             $(%(mmake)-install_command) && \
2312             $(TOUCH) $@ -r $^; \
2313         fi
2315 $(%(mmake)-pkgdir)/.files-touched:
2316         %mkdirs_q $(%(mmake)-pkgdir)
2317         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2318         $(TOUCH) $@
2321 %(mmake)-uninstall :
2322         $(%(mmake)-uninstall_command)
2325 %(mmake)-configure : $(%(mmake)-configflag)
2327 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2328 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2329         $(RM) $@
2330         %mkdirs_q $(%(mmake)-pkgdir)
2331         cd $(%(mmake)-pkgdir) && \
2332         find . -name config.cache -exec $(RM) '{}' \; && \
2333         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2334             %(extraoptions) && \
2335         $(TOUCH) $@
2338 %(mmake)-clean : %(mmake)-uninstall
2339         @$(RM) $(%(mmake)-pkgdir)
2340 %end
2341 #------------------------------------------------------------------------------
2344 #------------------------------------------------------------------------------
2345 # Given an archive name, patches names and locations where to find them, fetch
2346 # the archive and the patches from any of those locations, unpack the archive
2347 # and then apply the patches.
2349 # Locations currently supported are http and ftp sites, plus local filesystem
2350 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2351 # the fetch.sh script needs to be modified, since this macro relies on that script.
2353 # Arguments:
2355 #     - mmake           = mmaketarget
2356 #     - archive_origins = list of locations where to find the archive. They are tried
2357 #                         in sequence, until the archive is found and fetching it 
2358 #                         succeeded. If not specified, the current directory is assumed.
2359 #     - archive         = the archive name. Mandatory.
2360 #     - suffixes        = a list of suffixes to append to the the package name plus the
2361 #                         version. Each one of them is tried until a matching archive is
2362 #                         found. They are appended to patches and these are tried the
2363 #                         same way as packages are.
2364 #     - location        = the local directory where to put the fetched archive and patches.
2365 #                         If not specified, the directory specified by destination is used.
2366 #     - destination     = the directory to unpack the archive to.
2367 #                         If not specified, the current directory is assumed.
2368 #     - patches_origins = list of locations where to find the patches. They are tried
2369 #                         in sequence, until a patch is found and fetching it 
2370 #                         succeeded. If not specified, the current directory is assumed.
2371 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2372 #                         patch_name[:[patch_subdir][:patch_opt]].
2374 #                             - patch_name   = the name of the patch file
2375 #                             - patch_subdir = the directory within \destination\ where to
2376 #                                              apply the patch.
2377 #                             - patch_opt    = any options to pass to the `patch' command
2378 #                                              when applying the patch.
2379 #                         
2380 #                         The patch_subdir and patch_opt fields are optional.
2382 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2383     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2385 .PHONY: %(mmake)
2387 ifneq (%(location),)
2388     %(mmake)-location := %(location)
2389 else
2390     %(mmake)-location := %(destination)
2391 endif
2394 %(mmake) :
2395         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2396         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2397 %end
2398 #------------------------------------------------------------------------------
2401 #------------------------------------------------------------------------------
2402 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2403 # unpatched source tree and runs diff against this and a previously fetched and possibly
2404 # patched tree. Depending on what happens after patching during a normal build it might
2405 # give best results if the new patch is created directly after fetch.
2407 # Arguments:
2409 #     - mmake       = mmaketarget
2410 #     - archive     = archive base name
2411 #     - srcdir      = directory the package is unpacked to, useful if archive unpacks to
2412 #                     a directory other than its name suggests.
2413 #     - suffixes    = a list of suffixes to append to the the package name plus the
2414 #                     version. Each one of them is tried until a matching archive is
2415 #                     found.
2416 #     - destination = the directory to unpack the archive to.
2417 #     - excludes    = diff patterns to exclude files or directories from the patch
2419 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2421 .PHONY: %(mmake)
2423 ifneq (%(excludes),)
2424     %(mmake)-exclude := -X ./exclude.patterns
2425 endif
2427 ifneq (%srcdir),)
2428     %(mmake)-srcdir := %(srcdir)
2429 else
2430     %(mmake)-srcdir := %(archive)
2431 endif
2434 %(mmake):
2435         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2436         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2437         cd %(destination)/tmp ; \
2438         $(FOR) f in %(excludes) ; do \
2439             $(ECHO) $$f >> ./exclude.patterns ; \
2440         done ; \
2441         diff -ruN $(%(mmake)-exclude) \
2442             $(%(mmake)-srcdir) \
2443             $(%(mmake)-srcdir).aros \
2444             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2445         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2446         $(RM) %(destination)/tmp
2447 %end
2448 #------------------------------------------------------------------------------
2451 #------------------------------------------------------------------------------
2452 # Joins the features of %fetch and %build_with_configure, taking advantage of
2453 # the naming scheme of GNU packages. GNU packages names are in the form
2455 #     <package name>-<version number>.<archive format suffix>
2457 # If a patch is provided, it *must* be named the following way:
2459 #    <package name>-<version number>-aros.diff
2461 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2462 # CD'ing into the archive's extracted directory.
2464 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2465 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2466 # to make that patch fully comprehensive.
2468 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2470 # Arguments:
2472 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2473 #                     macro.
2474 #    - package      = the GNU package name, sans version and archive format suffixes.
2475 #    - version      = the package's version number, or otherwise any other version string.
2476 #                     It gets appended to the package name to form the basename of the archive.
2477 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2478 #                     version. Each one of them is tried until a matching archive is found.
2479 #                     Defaults to "tar.bz2 tar.gz".
2480 #    - destination  = same meaning as the one for the %fetch macro
2481 #    - location     = same meaning as the one for the %fetch macro
2482 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2483 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2484 #                     fetched or not
2485 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2486 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2487 #                     $(GNUDIR).
2488 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2489 #                     /GNU.
2490 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2491 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2492 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2493 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2495 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2496     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2497     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2499 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2500 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2501 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2502 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2504 %(mmake)-archbase  := %(package)-%(version)
2506 ifeq (%(compiler),host)
2507     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2508 else
2509     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2510 endif
2512 ifeq (%(prefix),)
2513     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2514 else
2515     %(mmake)-prefix := %(prefix)
2516 endif
2518 ifneq (%(subpackage),)
2519     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2520 else
2521     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2522 endif
2524 ifneq (%(srcdir),)
2525     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2526 else
2527     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2528 endif
2530 ifeq (%(patch),yes)
2531     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2532 else
2533     %(mmake)-%(subpackage)-patches_specs := ::
2534 endif
2536 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2537     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2538     archive_origins=". %(package_repo)" \
2539     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2541 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2542     archive=$(%(mmake)-%(subpackage)-archbase) \
2543     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2544     suffixes="%(suffixes)" \
2545     destination=$(%(mmake)-portdir)
2547 #MM- %(mmake) : %(mmake)-%(subpackage)
2549 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2551 %(mmake)-%(subpackage)-package-basename := \
2552     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2554 ifneq (%(create_pkg),no)
2555     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2556 endif
2558 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2559      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2560      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2561      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2562      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2564 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2565 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2568 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2570 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2571 #that $^ and $@ have exactly the same mtime, and in that case make tries
2572 #to rebuild $@ again, which would fail because the directory where
2573 #the package got installed would not exist anymore. 
2574 #We work this around by using an if statement to manually check the mtimes.
2575 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2576         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2577         $(RM) $@ ; \
2578         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2579         mkdir -p "$(DISTDIR)/Packages" ; \
2580         mkdir -p "$(%(mmake)-prefix)" ; \
2581         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2582         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2583         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2584     fi
2585 %end
2586 #------------------------------------------------------------------------------
2589 #------------------------------------------------------------------------------
2590 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2591     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2592     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2594 GNU_REPOSITORY := gnu://
2596 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2597     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2598     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2599     patch="%(patch)" patch_repo="%(patch_repo)" \
2600     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2601     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2603 %end
2604 #------------------------------------------------------------------------------
2607 #------------------------------------------------------------------------------
2608 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2609 # that the package is a "Development" package, and as such it needs to be placed
2610 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2612 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2613 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2614 # "mmake" argument, because the metatarget is implicitely defined as
2616 #     #MM- development-%(package)
2618 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2619     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2620     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2622 #MM- development : development-%(package)
2625 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2626    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2627    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2628    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2629    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2632 postinstall-%(package)-delete-la-files:
2633         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2635 %end
2636 #------------------------------------------------------------------------------
2638 # Builds a kickstart package in PKG format
2639 # mmake   - target name
2640 # file    - Destination file name with path
2641 # startup - The file which will be put first
2642 # Other arguments are self-explanatory
2644 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2646 PKG_CLASSES   := $(addsuffix .class, %(classes))
2647 PKG_DEVICES   := $(addsuffix .device, %(devs))
2648 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2649 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2650 PKG_LIBS      := $(addsuffix .library, %(libs))
2651 PKG_RESOURCES := $(addsuffix .resource, %(res))
2653 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2654 PKG_DIR   := $(dir %(file))
2655 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2658 %(mmake) : %(file)
2661 %(mmake)-quick : %(file)
2663 %(file): PKG_FILES := $(PKG_FILES)
2664 %(file): $(PKG_DEPS) | $(PKG_DIR)
2665         @$(ECHO) Packaging $@...
2666         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2668 %compress_file mmake=%(mmake) file=%(file)
2670 GLOB_MKDIRS += $(PKG_DIR)
2672 %end
2674 #------------------------------------------------------------------------------
2675 # Compresses %(file) with a gzip.
2676 # Good in conjunction with for example %build_prog
2678 %define compress_file mmake=/A file=/A
2680 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2683 %(mmake)-gz-quick : %(file).gz
2685 %(file).gz: %(file)
2686         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2687         @gzip -9 -f $^
2689 %end
2691 #------------------------------------------------------------------------------
2692 # Links a kickstart module in ELF format
2693 # Arguments are similar to make_package
2695 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2696     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2698 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2699 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2700 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2701 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2702 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2703 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2705 ifeq (%(startup),)
2706     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2707 else
2708     KOBJ_STARTUP := %(startup)
2709 endif
2711 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2713 TMP_LDFLAGS := %(ldflags)
2715 # Make a list of the lib files this program depends on.
2716 # In LDFLAGS remove white space between -L and directory
2717 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2718 # Filter out only the libdirs and remove -L
2719 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2720 # Add trailing /
2721 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2722 # Add normal linklib path
2723 TMP_DIRS += $(LIBDIR)/
2724 # add lib and .a to static linklib names
2725 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2726 # search for the linklibs in the given path, ignore ones not found
2727 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2728     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2731 TMP_DIRS += $(dir %(file))
2732 ifneq (%(map),)
2733     TMP_LDFLAGS += $(GENMAP) %(map)
2734     TMP_DIRS    += $(dir %(map))
2735 endif
2737 #MM %(mmake) : %(deps)
2740 %(mmake) : %(file)
2743 %(mmake)-quick : %(file)
2745 %(file): KOBJS := $(KOBJS)
2746 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2747 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2748 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2749         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2750         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS) -noarosc
2751         @$(STRIP) $@
2753 %compress_file mmake=%(mmake) file=%(file)
2755 GLOB_MKDIRS += $(TMP_DIRS)
2757 %end
2759 #------------------------------------------------------------------------------
2760 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2761 # 'start' is an optional starting address
2762 # 'ldflags' is optional additional flags for the linker
2763 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2765 BD_OUTDIR := $(dir %(file))
2766 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2767 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2768 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2770 %(file) : %(objs) $(BD_OUTDIR)
2771         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2772         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2773         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2775 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2776     GLOB_MKDIRS += $(BD_OUTDIR)
2777 endif
2779 %end