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