Added dummy type for usbhardware driver devices. Feel free to change it to something...
[cake.git] / config / make.tmpl
blob3835704387c5a096342e86b2742ccd4ba6a1e884
1 ############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd=$(TARGET_CC) opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling %(from)"
17         @$(IF) %(cmd) %(iquote) $(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)
56         @$(ECHO) "Linking %(to)..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         $(STRIP) %(to)
70 %end
72 #-------------------------------------------------------------------------
73 # Link a module based upon a number of arguments and the standard $(LIBS)
74 # and $(DEPLIBS) make variables.
76 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
77         @$(ECHO) "Building $(notdir $@) ..."
78         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
79             $(GENMAP) %(objdir)/%(module).map \
80             %(objs) %(libs) %(endtag) \
81             -o $@ 2>&1 > %(objdir)/%(err); \
82         then \
83             cat %(objdir)/%(err); \
84         else \
85             cat %(objdir)/%(err); \
86             exit 1; \
87         fi
89         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
90         @$(STRIP) $@
91 %end
92 #------------------------------------------------------------------------------
94 #------------------------------------------------------------------------------
95 # Create the library
96 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
97         @$(ECHO) "Creating library %(to)..."
98         @%(ar) %(to) %(from)
99         @%(ranlib) %(to)
100 %end
102 #------------------------------------------------------------------------------
103 # Create the dependency file %(to) for %(from)
104 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
105         %mkdir_q dir="$(dir %(to))"
106         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
107         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
108 %end
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the function reference file %(to) to %(from)
113 %define mkref_q cc=$(AROS_CC) cppflags="-E -C -dD -D__CXREF__" cflags=$(CFLAGS) from=$< to=$@
114         @$(ECHO) "Generating ref for $(notdir %(from))..."
115         @$(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to) 2>$(GENDIR)/cerrors
116         @$(IF) $(TEST) -s %(to) ; \
117         then \
118             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
119                 $(ECHO) "%(from): $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" >> $(GENDIR)/errors ; \
120                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
121             fi ; \
122         else \
123             $(ECHO) "Reference generation failed: $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" 1>&2 ; \
124             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
125             $(RM) %(to) ; \
126             exit 1 ; \
127         fi
128 %end
130 #------------------------------------------------------------------------------
131 # Create one directory without any output
132 %define mkdir_q dir=.
133         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
134 %end
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
144 #############################################################################
145 #############################################################################
146 ##                                                                         ##
147 ## Here are the mmakefile macro's that are used to do certain tasks in a   ##
148 ## mmakefile. They consist of one or more full makefile rules.             ##
149 ## In general the files generated in these macro's are also defined as     ##
150 ## make targets so that they can be used as a dependency in other rules    ##
151 ##                                                                         ##
152 #############################################################################
153 #############################################################################
155 #------------------------------------------------------------------------------
156 # Generate a unique id for each of the %build... rules
157 %define buildid targets=/A
158 BDID := $(BDID)_
159 ifneq ($(filter $(TARGET),%(targets)),)
160 BDTARGETID := $(BDID)
161 endif
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy file %(from) to %(to) in a makefile rule
168 %define rule_copy from=/A to=/A
169 %(to) : %(from)
170         @$(CP) $< $@
171 %end
172 #------------------------------------------------------------------------------
175 #------------------------------------------------------------------------------
176 # Copy the files %(files) to %(targetdir). For each file in %(files),
177 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
178 # appropriate subdirs are not generated by this rule so they have to be
179 # present.
180 %define rule_copy_multi files=/A targetdir=/A srcdir=.
182 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
183         @$(CP) $< $@
184 %end
185 #------------------------------------------------------------------------------
187 #------------------------------------------------------------------------------
188 # Copy the files %(files) to %(targetdir). For each file in %(files),
189 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
190 # %(stampfile) is used to keep track of when the last time the comparison has
191 # been done. The targetdir and the appropriate subdirs are not generated by 
192 # this rule so they have to be present.
193 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
194     stampfile=$(TMP_SRCDIR)/.copy_stamp
196 TMP_SRCDIR := %(srcdir)
198 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
200 %(stampfile) : COPYSRCDIR := %(srcdir)
201 %(stampfile) : TGTDIR := %(targetdir)
202 %(stampfile) : FILES := %(files)
203 %(stampfile) : $(addprefix %(srcdir)/,%(files))
204         @for f in $(FILES); do \
205              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
206                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
207              fi ; \
208         done
209         @$(TOUCH) $@
210 %end
211 #------------------------------------------------------------------------------
213 #------------------------------------------------------------------------------
214 # Will join all the files in %(from) to %(to). When text is specified it will
215 # be displayed.
216 # Restriction: at the moment when using a non-empty target dir %(from) may
217 # not have 
218 %define rule_join to=/A from=/A text=
220 %(to) : %(from)
221 ifneq (%(text),)
222         @$(ECHO) %(text)
223 endif
224         @$(CAT) $^ >$@
225 %end
226 #------------------------------------------------------------------------------
229 #------------------------------------------------------------------------------
230 # Include the dependency files and add some internal rules
231 # When depstargets is provided the depencies will only be included when one of
232 # these targets is the $(TARGET). Otherwise the dependencies will only be
233 # include when the $(TARGET) is not for setup or clean 
234 %define include_deps deps=$(DEPS)/M  depstargets=
235 ifneq (%(deps),)
236   ifneq (%(depstargets),)
237     ifneq ($(findstring $(TARGET),%(depstargets)),)
238       -include %(deps)
239     endif
240   else
241     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
242       -include %(deps)
243     endif
244   endif
245 endif
246 %end
247 #------------------------------------------------------------------------------
250 #------------------------------------------------------------------------------
251 # Create the directories %(dirs). The creation will be done by adding rules to
252 # the %(setuptarget) make target with setup as the default. 
253 %define rule_makedirs dirs=/A setuptarget=setup
255 %(setuptarget) :: %(dirs)
257 GLOB_MKDIRS += %(dirs)
259 %end
260 #------------------------------------------------------------------------------
263 #------------------------------------------------------------------------------
264 # Generate a rule to compile a C source file to an object file and generate
265 # the dependency file. Basename may contain a directory part, then the source
266 # file has to be in that directory. The generated file will be put in the
267 # object directory without the directory.
268 # options
269 # - basename: the basename of the file to compile. Use % for a wildcard rule
270 # - cflags (default $(CFLAGS)): the C flags to use for compilation
271 # - dflags: the flags used during creation of dependency file. If not specified
272 #   the same value as cflags will be used
273 # - targetdir: the directory to put the .o file and the .d file. By default
274 #   it is put in the same directory as the .c file
275 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
277 ifeq (%(targetdir),)
278   TMP_TARGETBASE := %(basename)
279 else
280   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
281 endif
283 ifeq ($(findstring %(compiler),host kernel target),)
284   $(error unknown compiler %(compiler))
285 endif
286 ifeq (%(compiler),target)
287 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC)
288 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC)
289 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
290 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
291 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
292 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
293 endif
294 ifeq (%(compiler),host)
295 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
296 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
297 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
298 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
301 endif
302 ifeq (%(compiler),kernel)
303 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
304 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
305 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
306 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
307 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
308 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
309 endif
311 ifeq (%(nix),yes)
312   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
313 else
314   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
315 endif
316 $(TMP_TARGETBASE).o : %(basename).c
317         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
319 ifeq (%(dflags),)
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
324   endif
325 else
326   ifeq (%(nix),yes)
327     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
328   else
329     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
330   endif
331 endif
332 $(TMP_TARGETBASE).d : %(basename).c
333         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
334 %end
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile multiple C source files to an object file and
340 # generate the corresponding dependency files. The generated file will be put
341 # in the object directory without the directory part of the source file.
342 # options
343 # - basenames: the basenames of the files to compile. The names may include
344 #   relative or absolute path names. No wildcard is allowed
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 #   the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 #   it is put in the same directory as the .c file. When targetdir is not
350 #   empty, path names will be stripped from the file names so that all files
351 #   are in that dir and not in subdirectories.
352 # - compiler (default target): compiler to use, target, kernel or host
353 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
354     compiler=target
356 ifeq (%(targetdir),)
357 TMP_TARGETS := $(addsuffix .o,%(basenames))
358 TMP_DTARGETS := $(addsuffix .d,%(basenames))
359 TMP_WILDCARD := %
360 else
361 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
362 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
363 TMP_WILDCARD := %(targetdir)/%
365 # Be sure that all .c files are generated
366 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
368 # Be sure that all .c files are found
369 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
370 ifneq ($(TMP_DIRS),)
371     vpath %.c $(TMP_DIRS)
372 endif
374 endif
376 ifeq ($(findstring %(compiler),host kernel target),)
377   $(error unknown compiler %(compiler))
378 endif
379 ifeq (%(compiler),target)
380 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
382 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
383 endif
384 ifeq (%(compiler),host)
385 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
387 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
388 endif
389 ifeq (%(compiler),kernel)
390 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
391 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
392 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
393 endif
395 $(TMP_TARGETS) : CFLAGS := %(cflags)
396 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
397         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
399 ifeq (%(dflags),)
400 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
401 else
402 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
403 endif
404 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
405         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
406 %end
407 #------------------------------------------------------------------------------
410 #------------------------------------------------------------------------------
411 # Make an alias from one arch specific build to another arch.
412 # arguments:
413 # - mainmmake: the mmake of the module in the main tree
414 # - arch: the current arch
415 # - alias: the alias to which this should point
416 %define rule_archalias mainmmake=\A arch=\A alias=\A
418 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
419 %end
420 #------------------------------------------------------------------------------
423 #------------------------------------------------------------------------------
424 # Generate a rule to compile a C source file to a shared object file with a
425 # .so suffix. Basename may contain a directory part, then the source
426 # file has to be in that directory. The generated file will be put in the
427 # object directory without the directory.
428 # options
429 # - basename: the basename of the file to compile. Use % for a wildcard rule
430 # - cflags (default $(CFLAGS)): the C flags to use for compilation
431 # - targetdir: the directory to put the .o file and the .d file. By default
432 #   it is put in the same directory as the .c file
433 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
435 ifeq (%(targetdir),)
436   TMP_TARGETBASE := %(basename)
437 else
438   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
439 endif
441 ifeq ($(findstring %(compiler),host kernel target),)
442   $(error unknown compiler %(compiler))
443 endif
444 ifeq (%(compiler),target)
445 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
446 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
447 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
448 endif
449 ifeq (%(compiler),host)
450 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
451 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
452 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
453 endif
454 ifeq (%(compiler),kernel)
455 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
456 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
457 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
458 endif
460 $(TMP_TARGETBASE).so : %(basename).c
461         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
462 %end
463 #------------------------------------------------------------------------------
466 #------------------------------------------------------------------------------
467 # Generate a rule to assemble a source file to an object file. Basename may
468 # contain a directory part, then the source file has to be in that directory.
469 # The generated file will be put in the object directory without the directory.
470 # options
471 # - basename: the basename of the file to compile. Use % for a wildcard rule
472 # - flags (default $(AFLAGS)): the asm flags to use for assembling
473 # - targetdir: the directory to put the .o file in. By default it is put in the
474 #   same directory as the .s file
475 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
477 ifeq (%(targetdir),)
478 %(basename).o : AFLAGS := %(aflags)
479 %(basename).o : %(basename).s
480         %assemble_q
482 else
483 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
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
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_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
518 ifneq ($(TMP_DIRS),)
519     vpath %%(suffix) $(TMP_DIRS)
520 endif
522 endif
524 $(TMP_TARGETS) : AFLAGS := %(aflags)
525 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
526         %assemble_q opt=$(AFLAGS)
527 %end
528 #------------------------------------------------------------------------------
531 #------------------------------------------------------------------------------
532 # Link %(objs) to %(prog) using the libraries in %(uselibs)
533 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
534     usehostlibs= usestartup=yes detach=no nix=no
536 TMP_EXTRA_LDFLAGS := 
537 ifeq (%(nix),yes)
538     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
539 endif
540 ifeq (%(usestartup),no)
541     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
542 endif
543 ifeq (%(detach),yes)
544     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
545 endif
547 # Make a list of the lib files this program depends on.
548 ifneq (%(uselibs),)
549 # In LDFLAGS remove white space between -L and directory
550 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
551 # Filter out only the libdirs and remove -L
552 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
553 # Add trailing /
554 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
555 # Add normal linklib path
556 TMP_DIRS += $(LIBDIR)/
557 # add lib and .a to static linklib names
558 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
559 # search for the linklibs in the given path, ignore ones not found
560 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
561     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
563 else
564 TMP_DEPLIBS :=
565 endif
567 %(prog) : OBJS := %(objs)
568 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
569 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
570 %(prog) : %(objs) $(TMP_DEPLIBS)
571         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
572 %end
573 #------------------------------------------------------------------------------
576 #------------------------------------------------------------------------------
577 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
578 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
579 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
580     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
581     usestartup=yes detach=no
583 TMP_EXTRA_LDFLAGS := 
584 ifeq (%(nix),yes)
585     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
586 endif
587 ifeq (%(usestartup),no)
588     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
589 endif
590 ifeq (%(detach),yes)
591     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
592 endif
594 # Make a list of the lib files the programs depend on.
595 ifneq (%(uselibs),)
596 # In LDFLAGS remove white space between -L and directory
597 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
598 # Filter out only the libdirs and remove -L
599 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
600 # Add trailing /
601 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
602 # Add normal linklib path
603 TMP_DIRS += $(LIBDIR)/lib/
604 # add lib and .a to static linklib names
605 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
606 # search for the linklibs in the given path, ignore ones not found
607 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
608     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
610 else
611 TMP_DEPLIBS :=
612 endif
614 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
615 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
616 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
617         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
618 %end
619 #------------------------------------------------------------------------------
622 #------------------------------------------------------------------------------
623 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
624 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
626 %(libdir)/lib%(libname).a : %(objs)
627         %mklib_q from=$^
628 %end
629 #------------------------------------------------------------------------------
632 #------------------------------------------------------------------------------
633 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
634 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
636 %(libdir)/lib%(libname).so : %(objs)
637         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
638 %end
639 #------------------------------------------------------------------------------
642 #------------------------------------------------------------------------------
643 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
644 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
645 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
646     uselibs= usehostlibs=
648 %(module) : OBJS := %(objs)
649 %(module) : ENDTAG := %(endobj)
650 %(module) : ERR := %(err)
651 %(module) : OBJDIR := %(objdir)
652 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
653 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
654         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR)
656 %end
657 #------------------------------------------------------------------------------
660 #------------------------------------------------------------------------------
661 # Generate a rule to generate a function reference file from a C source file.
662 # Basename may contain a directory part, then the source file has to be in that
663 # directory. The generated file will be put in the object directory without the
664 # directory.
665 # options
666 # - basename: the basename of the file to compile. Use % for a wildcard rule
667 # - cflags (default $(CFLAGS)): the C flags to use for compilation
668 # - targetdir: the directory to put the generated .ref file. By default the
669 #   .ref file will be put in the same directory as the .c file.
670 # - includefile: This file will be included at the head of the source file
671 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
673 ifeq (%(targetdir),)
674 GENFILE_TMP := %(basename).ref
675 else
676 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
677 endif
679 ifeq ($(filter %(compiler),target kernel host),)
680 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
681 endif
683 ifeq (%(compiler),target)
684 $(GENFILE_TMP) : CC:=$(TARGET_CC)
685 endif
686 ifeq (%(compiler),host)
687 $(GENFILE_TMP) : CC:=$(HOST_CC)
688 endif
689 ifeq(%(compiler),kernel)
690 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
691 endif
693 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
694 ifeq (%(includefile),)
695         %mkref_q cc=$(CC) cflags="%(cflags)"
696 else
697         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
698 endif
700 %end
701 #------------------------------------------------------------------------------
704 #------------------------------------------------------------------------------
705 # Generate a rule to generate a function reference file from a C source file.
706 # Basename may contain a directory part, then the source file has to be in that
707 # directory. The generated file will be put in the object directory without the
708 # directory.
709 # options
710 # - basenames: the basenames of the files to compile. No wildcard is allowed
711 # - cflags (default $(CFLAGS)): the C flags to use for compilation
712 # - targetdir: the directory to put the generated .ref file. By default the
713 #   .ref file will be put in the same directory as the .c file. When targetdir
714 #   is not empty all files will be put there and path parts in the basenames
715 #   will be stripped off.
716 # - includefile: This file will be included at the head of the source file
717 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
718     compiler=target
720 ifeq (%(targetdir),)
721 TMP_TARGETS := $(addsuffix .ref,%(basenames))
722 TMP_WILDCARD := %.ref
723 else
724 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
725 TMP_WILDCARD := %(targetdir)/%.ref
727 # Be sure that all .c files are generated
728 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
730 # Be sure that all .c files are found
731 TMP_DIRS := $(filter-out ./,$(sort $(dir %(basenames)) $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(basenames)))))
732 ifneq ($(TMP_DIRS),)
733     vpath %.c $(TMP_DIRS)
734 endif
736 endif
738 ifeq ($(filter %(compiler),target kernel host),)
739 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
740 endif
742 ifeq (%(compiler),target)
743 $(TMP_TARGETS) : CC:=$(TARGET_CC)
744 endif
745 ifeq (%(compiler),host)
746 $(TMP_TARGETS) : CC:=$(HOST_CC)
747 endif
748 ifeq (%(compiler),kernel)
749 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
750 endif
751 ifeq (%(includefile),)
752 $(TMP_TARGETS) : CFLAGS:=%(cflags)
753 else
754 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
755 $(TMP_TARGETS) : %(includefile)
756 endif
757 $(TMP_TARGETS) : $(CXREF)
758 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
759         %mkref_q cc=$(CC)
760 %end
761 #------------------------------------------------------------------------------
764 #------------------------------------------------------------------------------
765 # Generate the libdefs.h include file for a module.
766 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
768 TMP_TARGET := %(modname)_libdefs.h
769 TMP_DEPS := $(GENMODULE)
770 TMP_OPTS := 
771 ifneq (%(conffile),)
772     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
773     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
774 else
775     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
776     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
777 endif
778 ifneq (%(modsuffix),)
779     TMP_OPTS += -s %(modsuffix)
780 endif
781 ifneq (%(targetdir),)
782     TMP_OPTS += -d %(targetdir)
783     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
784 endif
786 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
787 $(TMP_TARGET) : MODNAME := %(modname)
788 $(TMP_TARGET) : MODTYPE := %(modtype)
789 $(TMP_TARGET) : $(TMP_DEPS)
790         @$(ECHO) "Generating $(notdir $@)"
791         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
792 %end
793 #------------------------------------------------------------------------------
796 #------------------------------------------------------------------------------
797 # Generate the libdefs.h include file for a module.
798 %define rule_genmodule_funclist \
799     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
801 TMP_TARGET := %(modname).funclist
802 TMP_DEPS := $(GENMODULE)
803 TMP_OPTS := 
804 ifeq (%(reffile),)
805     $(error reffile needed in rule_genmodule_funclist but none specified)
806 endif
807 TMP_OPTS := -r %(reffile)
808 TMP_DEPS += %(reffile)
809 ifneq (%(conffile),)
810     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
811     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
812 else
813     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
814     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
815 endif
816 ifneq (%(modsuffix),)
817     TMP_OPTS += -s %(modsuffix)
818 endif
819 ifneq (%(targetdir),)
820     TMP_OPTS += -d %(targetdir)
821     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
822 endif
824 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
825 $(TMP_TARGET) : MODNAME := %(modname)
826 $(TMP_TARGET) : MODTYPE := %(modtype)
827 $(TMP_TARGET) : $(TMP_DEPS)
828         @$(ECHO) "Generating $(notdir $@)"
829         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
830 %end
831 #------------------------------------------------------------------------------
834 #------------------------------------------------------------------------------
835 # Generate a Makefile.%(modname) with the genmodule program and include this
836 # generated file in this Makefile
837 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
838     targetdir=
840 TMP_TARGET := Makefile.%(modname)
841 TMP_DEPS := $(GENMODULE)
842 TMP_OPTS := 
843 ifneq (%(conffile),)
844     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
845     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
846 else
847     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
848     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
849 endif
850 ifneq (%(modsuffix),)
851     TMP_OPTS += -s %(modsuffix)
852 endif
853 ifneq (%(targetdir),)
854     TMP_OPTS += -d %(targetdir)
855     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
856 endif
858 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
859 $(TMP_TARGET) : MODNAME := %(modname)
860 $(TMP_TARGET) : MODTYPE := %(modtype)
861 $(TMP_TARGET) : $(TMP_DEPS)
862         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
863 %end
864 #------------------------------------------------------------------------------
866 #------------------------------------------------------------------------------
867 # Generate dummy support files so cxref when used on the a module source file
868 # will find something to include. This rule has to be preceeded by
869 # %rule_genmodule_makefile
870 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
872 ifneq ($(%(modname)_INCLUDES),)
873 TMP_TARGETS := $(%(modname)_INCLUDES)
875 TMP_DEPS := $(GENMODULE)
876 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 dummy include files"
897         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
898 endif
899 %end
900 #------------------------------------------------------------------------------
903 #------------------------------------------------------------------------------
904 # Generate the support files for compiling a module. This includes include
905 # files and source files. This rule has to be preceeded by
906 # %rule_genmodule_makefile
907 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
908     conffile= reffile=
910 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
911                $(%(modname)_LINKLIBFILES)
912 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
914 TMP_DEPS := $(GENMODULE)
915 ifeq ($(%(modname)_NEEDREF), yes)
916     ifeq (%(reffile),)
917         $(error reffile needed in rule_genmodule_files but none specified)
918     endif
919     TMP_OPTS := -r %(reffile)
920     TMP_DEPS += %(reffile)
921 else
922     TMP_OPTS :=
923 endif
924 ifneq (%(conffile),)
925     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
926     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
927 else
928     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
929     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
930 endif
931 ifneq (%(modsuffix),)
932     TMP_OPTS += -s %(modsuffix)
933 endif
934 ifneq (%(targetdir),)
935     TMP_OPTS += -d %(targetdir)
936     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
937 endif
939 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
940 $(TMP_TARGETS) : MODNAME := %(modname)
941 $(TMP_TARGETS) : MODTYPE := %(modtype)
942 $(TMP_TARGETS) : $(TMP_DEPS)
943         @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
944 ifneq (%(conffile),lib.conf)
945         @$(IF) $(TEST) -f lib.conf; then \
946           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
947         fi
948 endif
949         @$(IF) $(TEST) -f libdefs.h; then \
950           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
951         fi
952         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
953 %end
954 #------------------------------------------------------------------------------
956 #------------------------------------------------------------------------------
957 # Generate the support files for compiling a module. This includes include
958 # files and source files.
959 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
960     targetdir= conffile= reffile=
963 ifneq ($(%(modname)_INCLUDES),)
964 TMP_TARGETS := $(%(modname)_INCLUDES)
966 TMP_DEPS := $(GENMODULE)
967 ifeq ($(%(modname)_NEEDREF), yes)
968     ifeq (%(reffile),)
969         $(error reffile needed in rule_genmodule_files but none specified)
970     endif
971     TMP_OPTS := -r %(reffile)
972     TMP_DEPS += %(reffile)
973 else
974     TMP_OPTS :=
975 endif
976 ifneq (%(conffile),)
977     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
978     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
979 else
980     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
981     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
982 endif
983 ifneq (%(modsuffix),)
984     TMP_OPTS += -s %(modsuffix)
985 endif
986 ifneq (%(targetdir),)
987     TMP_OPTS += -d %(targetdir)
988     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
989 endif
991 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
992 $(TMP_TARGETS) : MODNAME := %(modname)
993 $(TMP_TARGETS) : MODTYPE := %(modtype)
994 $(TMP_TARGETS) : $(TMP_DEPS)
995         @$(ECHO) "Generating include files"
996         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
997 endif
998 %end
999 #------------------------------------------------------------------------------
1001 #------------------------------------------------------------------------------
1002 # Common rules for all makefiles
1003 %define common
1004 # Delete generated makefiles
1006 clean ::
1007         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1009 include $(SRCDIR)/config/make.tail
1011 BDID := $(BDTARGETID)
1012 %end
1013 #------------------------------------------------------------------------------
1014       
1016 #############################################################################
1017 #############################################################################
1018 ##                                                                         ##
1019 ## Here are the mmakefile build macro's. These are macro's that takes care ##
1020 ## of everything to go from the sources to the generated target. Also all  ##
1021 ## intermediate files and directories that are needed are created by these ##
1022 ## rules.                                                                  ##
1023 ##                                                                         ##
1024 #############################################################################
1025 #############################################################################
1027 #------------------------------------------------------------------------------
1028 # Build a program
1029 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1030     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1031     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1032     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1033     srcdir=
1035 .PHONY : %(mmake)
1037 BD_PROGNAME  := %(progname)
1038 BD_OBJDIR    := %(objdir)
1039 BD_TARGETDIR := %(targetdir)
1041 BD_FILES     := %(files)
1042 BD_ASMFILES  := %(asmfiles)
1043 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES) $(BD_ASMFILES)))
1044 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1046 BD_CFLAGS    := %(cflags)
1047 BD_AFLAGS    := %(aflags)
1048 BD_DFLAGS    := %(dflags)
1049 BD_LDFLAGS   := %(ldflags)
1052 %(mmake)-quick : %(mmake)
1054 #MM %(mmake) : includes-generate-deps
1055 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1057 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1058 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1059     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1060 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1061     aflags=$(BD_AFLAGS)
1063 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1064     objs=$(BD_OBJS) ldflags=$(BD_LDFLAGS) \
1065     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1066     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
1068 endif
1070 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1072 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1073 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1074 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1076 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1078 %(mmake)-clean ::
1079         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1080         @$(RM) $(FILES)
1082 %end
1083 #------------------------------------------------------------------------------
1086 #------------------------------------------------------------------------------
1087 # Build programs, for every C file an executable will be built with the same
1089 %define build_progs mmake=/A files=/A nix=no \
1090     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1091     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1092     uselibs= usehostlibs= usestartup=yes detach=no
1094 .PHONY : %(mmake)
1096 BD_OBJDIR    := %(objdir)
1097 BD_TARGETDIR := %(targetdir)
1099 BD_FILES     := %(files)
1100 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1101 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1102 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1104 BD_CFLAGS    := %(cflags)
1105 BD_DFLAGS    := %(dflags)
1106 BD_LDFLAGS   := %(ldflags)
1109 %(mmake)-quick : %(mmake)
1111 #MM %(mmake) : includes-generate-deps
1112 %(mmake) : $(BD_EXES)
1114 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1115 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1116     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1118 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1119     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1120     ldflags=$(BD_LDFLAGS) \
1121     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1122     usestartup="%(usestartup)" detach="%(detach)"
1124 endif
1126 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1128 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1129 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1130 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1132 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1134 %(mmake)-clean ::
1135         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1136         @$(RM) $(FILES)
1138 %end
1139 #------------------------------------------------------------------------------
1142 #------------------------------------------------------------------------------
1143 # Build a module.
1144 # This is a bare version: It just compiles and links the given files. It is
1145 # assumed that all needed boiler plate code is in the files. This should only
1146 # be used for compiling external code. For AROS code use %build_module
1147 %define build_module_simple mmake=/A modname=/A modtype=/A \
1148     files="$(basename $(call WILDCARD, *.c))" \
1149     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1150     objdir=$(OBJDIR) moduledir= \
1151     uselibs= usehostlibs= compiler=target
1153 # Define metamake targets and their dependencies
1154 #MM %(mmake) : core-linklibs includes-generate-deps
1155 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1156 #MM %(mmake)-quick
1157 #MM %(mmake)-clean
1159 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1161 .PHONY : $(BD_ALLTARGETS)
1163 ifeq (%(modname),)
1164 $(error using %build_module_simple: modname may not be empty)
1165 endif
1166 ifeq (%(modtype),)
1167 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1168 endif
1170 # Default values for variables and arguments
1171 BD_DEFLINKLIBNAME := %(modname)
1172 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1173 BD_DEFDFLAGS := %(cflags)
1174 OBJDIR ?= $(GENDIR)/$(CURDIR)
1175 BD_MODDIR := %(moduledir)
1176 ifeq ($(BD_MODDIR),)
1177   ifeq (%(modtype),library)
1178     BD_MODDIR  := $(AROS_LIBS)
1179   endif
1180   ifeq (%(modtype),gadget)
1181     BD_MODDIR  := $(AROS_GADGETS)
1182   endif
1183   ifeq (%(modtype),datatype)
1184     BD_MODDIR  := $(AROS_DATATYPES)
1185   endif
1186   ifeq (%(modtype),handler)
1187     BD_MODDIR  := $(AROS_FS)
1188   endif
1189   ifeq (%(modtype),device)
1190     BD_MODDIR  := $(AROS_DEVS)
1191   endif
1192   ifeq (%(modtype),resource)
1193     BD_MODDIR  := $(AROS_RESOURCES)
1194   endif
1195   ifeq (%(modtype),mui)
1196     BD_MODDIR  := $(AROS_CLASSES)/Zune
1197   endif
1198   ifeq (%(modtype),mcc)
1199     BD_MODDIR  := $(AROS_CLASSES)/Zune
1200   endif
1201   ifeq (%(modtype),mcp)
1202     BD_MODDIR  := $(AROS_CLASSES)/Zune
1203   endif
1204   ifeq (%(modtype),usbclass)
1205     BD_MODDIR  := $(AROS_CLASSES)/USB
1206   endif
1207   ifeq (%(modtype),hidd)
1208     BD_MODDIR  := $(AROS_DRIVERS)
1209   endif
1210 endif
1211 ifeq ($(BD_MODDIR),)
1212   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1213 endif
1215 %rule_compile_multi \
1216     basenames="%(files)" targetdir="%(objdir)" \
1217     cflags="%(cflags)" dflags="%(dflags)" \
1218     compiler=%(compiler)
1220 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1221 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1223 %(mmake)-quick : %(mmake)
1224 %(mmake) : $(BD_MODULE)
1225 %(mmake)-kobj : $(BD_KOBJ)
1227 # The module is linked from all the compiled .o files
1228 BD_OBJS       := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1229 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1230                  endobj= err=%(modname).err objdir=%(objdir) \
1231                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1233 # Link kernel object file
1234 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1235     expansion keymap
1236 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1237     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1238 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1239 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1240 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1241 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1242 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1243         @$(ECHO) "Linking $@"
1244         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1245         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1248 ## Dependency fine-tuning
1250 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1251 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1253 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1254 $(BD_MODULE) : | $(BD_MODDIR)
1255 $(BD_KOBJ) : | $(KOBJSDIR)
1256 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1258 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1259 %(mmake)-clean ::
1260         @$(ECHO) "Cleaning up for module %(modname)"
1261         @$(RM) $(FILES)
1262 %end
1265 #------------------------------------------------------------------------------
1266 # Build a module
1267 # Explanation of this macro is done in the developer's manual
1268 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1269   conffile= files="$(basename $(call WILDCARD, *.c))" \
1270   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1271   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1272   reffile=$(BD_DEFREFFILE) noref= \
1273   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1274   compiler=target
1276 # Define metamake targets and their dependencies
1277 #MM- includes-all : %(mmake)-includes
1278 #MM %(mmake) : %(mmake)-includes core-linklibs
1279 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1280 #MM %(mmake)-linklib : %(mmake)-includes
1281 #MM %(mmake)-quick : %(mmake)-includes-quick
1282 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1283 #MM     includes-generate-deps
1284 #MM %(mmake)-includes-quick
1285 #MM %(mmake)-includes-dirs
1286 #MM %(mmake)-makefile
1287 #MM %(mmake)-funclist
1288 #MM %(mmake)-clean
1290 # All MetaMake targets defined by this macro
1291 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1292     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1293     %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1295 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1297 ifeq (%(modname),)
1298 $(error using %build_module: modname may not be empty)
1299 endif
1300 ifeq (%(modtype),)
1301 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1302 endif
1304 # Default values for variables and arguments
1305 BD_DEFLINKLIBNAME := %(modname)
1306 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1307 BD_DEFDFLAGS := %(cflags)
1308 OBJDIR ?= $(GENDIR)/$(CURDIR)
1310 ## Create genmodule include Makefile for the module
1312 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1314 %rule_genmodule_makefile \
1315     modname=%(modname) modtype=%(modtype) \
1316     modsuffix=%(modsuffix) targetdir=%(objdir) \
1317     conffile=%(conffile)
1319 %(objdir)/Makefile.%(modname) : | %(objdir)
1321 GLOB_MKDIRS += %(objdir)
1323 # Do not parse these statements if metatarget is not appropriate
1324 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1326 include %(objdir)/Makefile.%(modname)
1328 BD_DEFMODDIR := $(%(modname)_MODDIR)
1331 ## include files generation
1333 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1334 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1335 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1337 %(mmake)-includes-quick : %(mmake)-includes
1338 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1339     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1340     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1342 ifneq ($(%(modname)_INCLUDES),)
1343 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1344                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1345                          conffile=%(conffile) reffile=%(reffile)
1347 %rule_copy_diff_multi \
1348     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1349     stampfile=%(objdir)/%(modname)_geninc
1351 %rule_copy_diff_multi \
1352     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1353     stampfile=%(objdir)/%(modname)_incs
1355 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1356                       modsuffix=%(modsuffix) \
1357                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1359 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1361 TMP%(modname)_INCDIRS := \
1362     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1363     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1364     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1365 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1367 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1368 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1370 endif
1372 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1373                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1374                            conffile=%(conffile)
1376 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1377 $(BD_DEFLIBDEFSINC) :
1378         @$(ECHO) "generating $@"
1379         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1381 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1382 GLOB_MKDIRS += %(objdir)/include
1384 ## Generation of the funclist file
1386 %(mmake)-funclist : %(modname).funclist
1388 %rule_genmodule_funclist \
1389     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1390     conffile=%(conffile) reffile=%(reffile)
1393 ## Extra genmodule src files generation
1394 ## 
1395 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1396                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1397                       conffile=%(conffile) reffile=%(reffile)
1399 ## Compilation
1401 BD_FILES      := %(files)
1402 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1403 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1404 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1406 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1407 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1408 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1410 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1411 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1413 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1414 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1415 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1416     BD_LINKLIB :=
1417 else
1418     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1419 endif
1420 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1422 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1423 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1425 %rule_compile_multi \
1426     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1427     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1428     compiler=%(compiler)
1429 %rule_compile_multi \
1430     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1431     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1432     compiler=%(compiler)
1434 ifneq ($(BD_LINKLIBAFILES),)
1435 %rule_assemble_multi \
1436     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1437 endif
1439 ## function reference files generation
1441 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1442 %rule_ref_multi \
1443     basenames=$(BD_FILES) targetdir=%(objdir) \
1444     cflags=$(BD_CFLAGS_REF) \
1445     compiler=%(compiler)
1447 ifeq (%(noref),)
1448 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1449 else
1450 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1451 endif
1453 %rule_join from=$(BD_REFS) to=%(reffile) \
1454            text="Collecting function references for module %(modname)"
1457 ## Linking
1459 ifeq (%(modsuffix),)
1460 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1461 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1462 else
1463 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1464 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1465 endif
1467 %(mmake)-quick : %(mmake)
1468 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1469 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1470 %(mmake)-linklib : $(BD_LINKLIB)
1472 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1473                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1474 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1475 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1476                  %(linklibobjs)
1478 # The module is linked from all the compiled .o files
1479 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1480                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1481                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1483 # Link static lib
1484 ifneq ($(BD_LINKLIB),)
1485 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1487 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1488 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1489 endif
1491 # Link kernel object file
1492 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1493     expansion keymap
1494 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1495     GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1496 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1497 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1498 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1499 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1500 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1501         @$(ECHO) "Linking $@"
1502         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1503         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1505 ## Dependency fine-tuning
1507 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1508 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1510 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1511 $(BD_MODULE) : | %(prefix)/%(moduledir)
1512 $(BD_KOBJ) : | $(KOBJSDIR)
1513 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1515 # Some include files need to be generated before the .c can be parsed.
1516 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1517 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1518     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1519 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1521 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1522     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1523 $(BD_DEPS) : $(BD_DFILE_DEPS)
1524 endif
1526 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1527     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1528     %(objdir)/Makefile.%(modname) \
1529     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1530     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1531     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1532     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1533     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1534     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1535     $(BD_ENDOBJS)
1536 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1537 %(mmake)-clean ::
1538         @$(ECHO) "Cleaning up for module %(modname)"
1539         @$(RM) $(FILES)
1541 endif # $(TARGET) in $(BD_ALLTARGETS)
1542 %end
1543 #------------------------------------------------------------------------------
1546 #------------------------------------------------------------------------------
1547 # Build a linklib.
1548 # - mmake is the mmaketarget
1549 # - libname is the baselibname e.g. lib%(libname).a will be created
1550 # - files are the C source files to include in the lib. The list of files
1551 #   has to be given without the .c suffix
1552 # - asmfiles are the asm files to include in the lib. The list of files has to
1553 #   be given without the .s suffix
1554 # - objs additional object to link into the linklib. The objects have to be
1555 #   given with full absolute path and the .o suffix.
1556 # - cflags are the flags to compile the source (default $(CFLAGS))
1557 # - dflags are the flags use during makedepend (default equal to cflags)
1558 # - aflags are the flags use during assembling (default $(AFLAGS))
1559 # - objdir is where the .o are generated
1560 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1561 %define build_linklib mmake=/A libname=/A \
1562   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1563   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1565 # assign and generate the local variables used in this macro
1566 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1568 BD_FILES      := %(files)
1569 BD_ASMFILES   := %(asmfiles)
1571 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1572 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1573 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1575 BD_OBJS       := $(BD_ARCHOBJS) \
1576                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1577                  %(objs)
1578 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1580 BD_CFLAGS     := %(cflags)
1581 ifeq (%(dflags),)
1582 BD_DFLAGS     := $(BD_CFLAGS)
1583 else
1584 BD_DFLAGS     := %(dflags)
1585 endif
1586 BD_AFLAGS     := %(aflags)
1588 BD_LINKLIB    := %(libdir)/lib%(libname).a
1590 .PHONY : %(mmake) %(mmake)-clean
1592 #MM %(mmake) : includes-generate-deps
1593 %(mmake) : $(BD_LINKLIB)
1596 %(mmake)-clean ::
1597         @$(RM) $(BD_OBJS) $(BD_DEPS)
1599 ifeq ($(TARGET),%(mmake))
1600 ifneq ($(dir $(BD_FILES)),./)
1601 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1602 endif
1604 %rule_compile basename=% targetdir=%(objdir) \
1605               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1606 %rule_assemble basename=% targetdir=%(objdir) \
1607               aflags=$(BD_AFLAGS)
1608 endif
1610 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1612 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1614 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1615 $(BD_LINKLIB) : | %(libdir)
1616 GLOB_MKDIRS += %(objdir) %(libdir)
1618 %end
1619 #------------------------------------------------------------------------------
1622 #------------------------------------------------------------------------------
1623 # Build catalogs.
1624 # - mmake is the mmaketarget
1625 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1626 # - description is the catalog description file (.cd) (default *.cd)
1627 # - subdir is the destination subdir of the catalogs
1628 # - name is the name of the destination catalog, without the .catalog suffix
1629 # - source is the path to the generated source code file
1630 # - dir is the base destination directory (default $(AROS_CATALOGS))
1631 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1633 %define build_catalogs mmake=/A name=/A subdir=/A \
1634  catalogs="$(basename $(call WILDCARD, *.ct))" source="../strings.h" \
1635  description="$(basename $(call WILDCARD, *.cd))" dir=$(AROS_CATALOGS) \
1636  sourcedescription="$(TOOLDIR)/C_h_orig"
1638 BD_SRCS := $(addsuffix .ct, %(catalogs))
1639 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1640 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1643 %(mmake) : $(BD_OBJS) %(source)
1645 $(BD_OBJS) : | $(BD_DIRS)
1646 GLOB_MKDIRS += $(BD_DIRS)
1648 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1649         @$(ECHO) "Creating %(name) catalog for language $*."
1650         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1652 ifneq (%(source),)
1653 %(source) : %(description).cd
1654         @$(ECHO) "Creating %(name) catalog source file %(source)"
1655         @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd %(source)=%(sourcedescription).sd
1656 endif
1658 %(mmake)-clean : FILES := $(BD_OJS) %(source)
1660 %(mmake)-clean ::
1661         $(RM) $(FILES)
1663 .PHONY: %(mmake) %(mmake)-clean
1665 %end
1667 #-----------------------------------------------------------------------------
1669 #-----------------------------------------------------------------------------
1670 # Build icons.
1671 # - mmake is the mmaketarget
1672 # - icons is a list of icon base names (ie. without the .info suffix)
1673 # - dir is the destination directory
1674 #-----------------------------------------------------------------------------
1676 %define build_icons mmake=/A icons=/A dir=/A
1678 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1681 %(mmake) : $(BD_OBJS)
1683 %(dir)/%.info : %.info.src %.png
1684         @$(ECHO) Creating $(notdir $@)...
1685         @$(ILBMTOICON) $+ $@
1687 $(BD_OBJS) : | %(dir)
1688 GLOB_MKDIRS += %(dir)
1690 %(mmake)-clean : FILES := $(BD_OBJS)
1692 %(mmake)-clean ::
1693         @$(RM) $(FILES)
1695 .PHONY: %(mmake) %(mmake)-clean
1697 %end
1699 #-----------------------------------------------------------------------------
1701 #------------------------------------------------------------------------------
1702 # Compile files for an arch-specific replacement of code for a module
1703 # - files: the basenames of the C files to compile.
1704 # - asmfiles: the basenames of the asm files to assemble.
1705 # - mainmmake: the mmake of the module in the main directory to compile these
1706 #   arch specific files for.
1707 # - maindir: the object directory for the main module
1708 # - arch: the arch for which to compile these files. It can have the form
1709 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1710 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1711 # - dflags: the flags used during creation of dependency file. If not specified
1712 #   the same value as cflags will be used
1713 # - aflags: the flags used during assembling
1714 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1715 #   the target compiler is used
1716 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1717 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1719 ifeq (%(files) %(asmfiles),)
1720   $(error no files or asmfiles given)
1721 endif
1723 %buildid targets="%(mainmmake)-%(arch)"
1725 ifeq ($(AROS_TARGET_VARIANT),)
1726 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1727 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1728 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1729 else
1730 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1731 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1732 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1733 endif
1735 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1737 ifeq (%(arch),)
1738   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1739 endif
1741 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1742 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1743 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1744 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1745 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1747 ifeq ($(TARGET),%(mainmmake)-%(arch))
1748 vpath %.c $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(files)))
1749 vpath %.s $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1750 vpath %.S $(addprefix $(SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1751 endif
1753 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1754 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1757 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1759 ifeq ($(findstring %(compiler),host kernel target),)
1760   $(error unknown compiler %(compiler))
1761 endif
1762 ifeq (%(compiler),target)
1763 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1764 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1765 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1766 endif
1767 ifeq (%(compiler),host)
1768 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1769 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1770 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1771 endif
1772 ifeq (%(compiler),kernel)
1773 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1774 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1775 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1776 endif
1777 ifneq (%(modulename),)
1778 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1779                      -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1780 else
1781 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1782 endif
1783 ifeq ($(TARGET),%(mainmmake)-%(arch))
1784 $(BD_OBJDIR$(BDID))/%.o : %.c
1785         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1786 endif
1788 ifeq (%(dflags),)
1789 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1790 else
1791 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1792 endif
1793 ifeq ($(TARGET),%(mainmmake)-%(arch))
1794 $(BD_OBJDIR$(BDID))/%.d : %.c
1795         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1796 endif
1798 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1800 ifeq ($(TARGET),%(mainmmake)-%(arch))
1801 $(BD_OBJDIR$(BDID))/%.o : %.s
1802         %assemble_q opt=$(AFLAGS)
1803 $(BD_OBJDIR$(BDID))/%.o : %.S
1804         %assemble_q opt=$(AFLAGS)
1805 endif
1807 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1808 %end
1809 #------------------------------------------------------------------------------
1817 # ======================
1818 # Old stuff, will probably be removed in the future
1823 # GNU Make automatic variables
1824 # $@ current target
1825 # $< First dependency
1826 # $? All newer dependencies
1827 # $^ All dependencies
1828 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1829 #    a.%.b, then the stem is dir/foo)
1831 #------------------------------------------------------------------------------
1832 # rule to generate libdefs.h with archtool (options may go away!)
1833 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1834 %(dest) : %(conffile) %(genlibdefstool)
1835         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1836         @%(genlibdefstool) -c -o $@ %(conffile)
1837 %end
1840 #------------------------------------------------------------------------------
1841 # generate asm files from c files (for debugging purposes)
1842 %define ctoasm_q
1843 %.s : %.c
1844         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1845         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1846 %end
1848 #------------------------------------------------------------------------------
1849 # Convert two png images to an Amiga icon file based on the description
1850 # file %(from), with outputfile going to %(to).
1851 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1852         @$(ECHO) "Creating icon %(to)..."
1853         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1854         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1855         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1856 %end
1858 #------------------------------------------------------------------------------
1859 # NOTE: The following are all part of Iain's build changes, please don't use
1860 # or change anything below this line until you know what you are doing. This
1861 # is so that I don't conflict with the semantics of any of the above macros.
1862 #------------------------------------------------------------------------------
1864 #------------------------------------------------------------------------------
1865 # Copy files from one directory to another.
1867 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1869 %(maketarget) : setup 
1870         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src))/, $(file)) $(addprefix %(dst)/, $(file))))
1872 setup ::
1873         %mkdirs_q %(dst)
1875 %end
1877 #----------------------------------------------------------------------------------
1878 # Copy a directory recursively to another place, preserving the original 
1879 # hierarchical structure
1881 # src: the source directory whose content will be copied
1882 # dst: the directory where to copy src's content. If not existing, it will be made.
1884 %define copy_dir_recursive mmake=/A src=. dst=/A
1886 %(mmake)_FILES := $(shell cd $(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune -o -type f -print)
1887 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1889 define %(mmake)_mkdir
1890 $(1):
1891         $(MKDIR) $$@
1892 endef
1894 define %(mmake)_copy
1895 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1896         $(CP) $$< $$@
1897 endef
1899 .PHONY : %(mmake)
1902 %(mmake): | $(GENDIR)/$(CURDIR)
1903         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1904         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1905         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1906         for d in $(%(mmake)_DIRS); do                      \
1907             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1908         done
1909         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1910         for f in $(%(mmake)_FILES); do                                            \
1911             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1912         done;  \
1913         for dst in %(dst); do \
1914             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,%(src)),%(src),$(SRCDIR)/$(CURDIR)/%(src)) all; \
1915         done
1917 $(GENDIR)/$(CURDIR):
1918         $(MKDIR) $@
1920 %end
1922 #------------------------------------------------------------------------------
1923 #   Copy include files into the includes directories. There are currently
1924 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1925 #   for building tools that need to run on the host system $(GENINCDIR). The
1926 #   $(GENINCDIR) path must not contain any references to the C runtime
1927 #   library header files.
1929 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1930     dir= compiler=target
1932 ifeq ($(findstring %(compiler),host kernel target),)
1933 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1934 endif
1936 ifneq (%(dir),)
1937 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1938 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1939 else
1940 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1941 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1942 endif
1944 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1945         @$(CP) $< $@
1948 ifeq (%(compiler),target)
1950 ifneq (%(dir),)
1951 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1952 else
1953 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1954 endif
1956 BD_INCL_FILES += $(BD_INCL_FILES2)
1958 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1959         @$(CP) $< $@
1960 endif
1963 %(mmake) : $(BD_INCL_FILES)
1965 .PHONY: %(mmake)
1967 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1968 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1969 %end
1972 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1973 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1974 STUBS_MEM := $(addsuffix .o,$(STUBS))
1975 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1976 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1977 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1979 #MM- linklibs : hidd-%(hidd)-stubs
1980 #MM- %(parenttarget): hidd-%(hidd)-stubs
1981 #MM hidd-%(hidd)-stubs : includes includes-copy
1982 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1984 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1985         %mklib_q from=$^
1987 $(STUBS_OBJ) : $(STUBS_SRC) 
1988         %compile_q cmd=$(TARGET_CC) opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
1990 $(STUBS_DEP) : $(STUBS_SRC)
1991         %mkdepend_q flags=%(dflags)
1993 setup ::
1994         %mkdirs_q $(OBJDIR) $(LIBDIR)
1997 clean ::
1998         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2000 DEPS := $(DEPS) $(STUBS_DEP)
2002 %end
2003       
2004 #------------------------------------------------------------------------------
2005 # Build an imported source tree which uses the configure script from the
2006 # autoconf package.  This rule will try to "integrate" the produced files as
2007 # much as possible in the AROS build, for example by putting libraries in the
2008 # standard library directory, includes in the standard include directory, and
2009 # so on. You can however override this behaviour.
2011 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2012 # be %(bindir) (or its deduced value) when running "make install", and
2013 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2014 # configure script some more parameters whose value depends upon the PROGDIR
2015 # env var, so that the program gets all its stuff installed in the proper place
2016 # when building it, but when running it from inside AROS it can also find that
2017 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2018 # the configuration parameters set when running ./configure
2020 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2021 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2022 # to the name which has to follow it.
2025 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2026     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
2027     install_target=install postconfigure= postinstall= \
2028     install_env=
2030 ifneq (%(prefix),)
2031     %(mmake)-prefix := %(prefix)
2032 else
2033     %(mmake)-prefix := $(AROS_CONTRIB)
2034 endif
2036 ifneq (%(aros_prefix),)
2037     %(mmake)-aros_prefix := %(aros_prefix)
2038 else
2039     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2040 endif
2042 ifeq (%(nix),yes)
2043     %(mmake)-nix    := -nix
2044     %(mmake)-volpfx := /
2045     %(mmake)-volsfx := /
2046     
2047     ifeq (%(nix_dir_layout),)
2048         %(mmake)-nix_dir_layout := yes
2049     endif
2050 else
2051     %(mmake)-volsfx := :
2052     
2053     ifeq (%(nix_dir_layout),)
2054         %(mmake)-nix_dir_layout := no
2055     endif
2056 endif
2058 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2060 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2061         exec_prefix=$(%(mmake)-prefix) %(install_env)
2063 # Check if chosen compiler is valid
2064 ifeq ($(findstring %(compiler),host target kernel),)
2065   $(error unknown compiler %(compiler))
2066 endif
2068 # Set legacy 'host' variable based on chosen compiler
2069 ifeq (%(compiler),host)
2070     host := yes
2071         ifeq (%(package),)
2072                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2073         else
2074                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2075         endif
2076 else
2077     host := no
2078         ifeq (%(package),)
2079                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2080         else
2081                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2082         endif
2083 endif
2085 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2086 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2088 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2089     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2090     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2091 else
2092     ifeq (%(nix),yes)
2093         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2094         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2095     else
2096         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2097     endif
2099     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2100     
2101     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2102         sbindir=$(%(mmake)-prefix) \
2103         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2104         oldincludedir=$(AROS_INCLUDES) %(install_env)
2105 endif
2108 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2110 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2112 # Using -j1 in install_command may result in a warning but finally
2113 # it does its job. make install for gcc does not work reliable for -jN
2114 # where N > 1.
2115 ifneq (%(install_target),)
2116     %(mmake)-install_command = \
2117         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2118         -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2119         $(TOUCH) $(%(mmake)-installflag)
2121     %(mmake)-uninstall_command = \
2122     $(RM) $(%(mmake)-installflag) && \
2123     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2124     -C $(%(mmake)-pkgdir) uninstall
2125 else
2126     %(mmake)-install_command   := true
2127     %(mmake)-uninstall_command := true
2128 endif
2130 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2133 %(mmake)-build_and_install-quick :  $(%(mmake)-configflag)
2134         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2135             $(RM)  $(%(mmake)-installflag) && \
2136             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2137             $(%(mmake)-install_command); \
2138         fi
2140 %(srcdir)/.files-touched:
2141         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
2142         $(TOUCH) $@
2145 %(mmake)-uninstall :
2146         $(%(mmake)-uninstall_command)
2148 ifneq ($(DEBUG),yes)
2149     %(mmake)-s_flag = -s
2150 endif
2153 %(mmake)-configure : $(%(mmake)-configflag)
2155 ifeq (%(compiler),host)
2156 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2157         $(RM) $@ 
2158         %mkdirs_q $(%(mmake)-pkgdir)
2159         cd $(%(mmake)-pkgdir) && \
2160         find . -name config.cache -exec $(RM) '{}' \; && \
2161         CC="$(HOST_CC)" \
2162             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
2163             $(TOUCH) $@
2164 endif
2165 ifeq (%(compiler),target)
2166 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2167         $(RM) $@
2168         %mkdirs_q $(%(mmake)-pkgdir)
2169         cd $(%(mmake)-pkgdir) && \
2170         find . -name config.cache -exec $(RM) '{}' \; && \
2171         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2172             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2173             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2174             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2175             --host=$(AROS_TARGET_CPU)-aros \
2176             --target=$(AROS_TARGET_CPU)-aros \
2177             --disable-nls \
2178             --without-x --without-pic --disable-shared && \
2179             $(TOUCH) $@
2180 endif
2181 ifeq (%(compiler),kernel)
2182 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2183         $(RM) $@
2184         %mkdirs_q $(%(mmake)-pkgdir)
2185         cd $(%(mmake)-pkgdir) && \
2186         find . -name config.cache -exec $(RM) '{}' \; && \
2187         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2188             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2189             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) \
2190             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2191             --host=$(AROS_TARGET_CPU)-aros \
2192             --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2193             --without-x --without-pic --disable-shared && \
2194             $(TOUCH) $@
2195 endif
2196         
2198 %(mmake)-clean : %(mmake)-uninstall
2199         @$(RM) $(%(mmake)-pkgdir)
2200 %end
2202 #############################################################################
2203 #############################################################################
2204 ##                                                                         ##
2205 ## Miscellaneous macros. Everything that doesn't fit above should be put   ##
2206 ## here.                                                                   ##
2207 ##                                                                         ##
2208 #############################################################################
2209 #############################################################################
2211 #----------------------------------------------------------------------------------
2212 # Given an archive name, patches names and locations where to find them, fetch
2213 # the archive and the patches from any of those locations, unpack the archive
2214 # and then apply the patches.
2216 # Locations currently supported are http and ftp sites, plus local filesystem
2217 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2218 # the fetch.sh script needs to be modified, since this macro relies on that script.
2220 # Arguments:
2222 #     - archive_origins = list of locations where to find the archive. They are tried
2223 #                         in sequence, until the archive is found and fetching it 
2224 #                         succeeded. If not specified, the current directory is assumed.
2225 #     - archive         = the archive name. Mandatory.
2226 #     - suffixes        = a list of suffixes to append to the the package name plus the
2227 #                         version. Each one of them is tried until a matching archive is
2228 #                         found. They are appended to patches and these are tried the
2229 #                         same way as packages are.
2230 #     - destination     = the local directory where to put the archive and patches.
2231 #                         If not specified, the current directory is assumed.
2232 #     - patches_origins = list of locations where to find the patches. They are tried
2233 #                         in sequence, until a patch is found and fetching it 
2234 #                         succeeded. If not specified, the current directory is assumed.
2235 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2236 #                         patch_name[:[patch_subdir][:patch_opt]].
2237 #                         
2238 #                             - patch_name   = the name of the patch file
2239 #                             - patch_subdir = the directory within \destination\ where to
2240 #                                              apply the patch.
2241 #                             - patch_opt    = any options to pass to the `patch' command
2242 #                                              when applying the patch.
2243 #                         
2244 #                         The patch_subdir and patch_opt fields are optional.
2246 %define fetch archive_origins=. archive=/A suffixes= location=%destination destination=. patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2247         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l %(location) -d %(destination) \
2248         -po "%(patches_origins)" -p %(patches_specs)
2249 %end
2251 #-----------------------------------------------------------------------------------------
2252 # Joins the features of %fetch and %build_with_configure, taking advantage of
2253 # the naming scheme of GNU packages. GNU packages names are in the form
2255 #     <package name>-<version number>.<archive format suffix>
2257 # If a patch is provided, it *must* be named the following way:
2259 #    <package name>-<version number>-aros.diff
2261 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2262 # CD'ing into the archive's extracted directory.
2264 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2265 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2266 # to make that patch fully comprehensive.
2268 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2270 # Arguments:
2272 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2273 #                     macro.
2274 #    - package      = the GNU package name, sans version and archive format suffixes.
2275 #    - version      = the package's version number, or otherwise any other version string.
2276 #                     It gets appended to the package name to form the basename of the archive.
2277 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2278 #                     version. Each one of them is tried until a matching archive is found.
2279 #                     Defaults to "tar.bz2 tar.gz".
2280 #    - destination  = same meaning as the one for the %fetch macro
2281 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2282 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2283 #                     fetched or not
2284 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2285 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2286 #                     $(GNUDIR).
2287 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2288 #                     /GNU.
2289 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2290 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2292 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2293     srcdir= package_repo= patch=no patch_repo= prefix= \
2294     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
2296 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2297 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2298 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2300 %(mmake)-archbase  := %(package)-%(version)
2302 ifeq (%(compiler),host)
2303     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2304 else
2305     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2306 endif
2308 ifeq (%(prefix),)
2309     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2310 else
2311     %(mmake)-prefix := %(prefix)
2312 endif
2314 ifneq (%(subpackage),)
2315     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2316 else
2317     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2318 endif
2320 ifneq (%(srcdir),)
2321     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2322 else
2323     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2324 endif
2326 ifeq (%(patch),yes)
2327     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2328 else
2329     %(mmake)-%(subpackage)-patches_specs := ::
2330 endif
2332 .PHONY : %(mmake)-%(subpackage)-fetch
2334 %(mmake)-%(subpackage)-fetch :
2335         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2336             location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2337             archive_origins=". %(package_repo)" \
2338             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2340 #MM- %(mmake) : %(mmake)-%(subpackage)
2342 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2344 %(mmake)-%(subpackage)-package-basename := \
2345     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2347 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2348      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2349      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2350      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2351      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2353 .PHONY : %(mmake)-%(subpackage)-make-package
2354 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2357 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2359 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2360 #that $^ and $@ have exactly the same mtime, and in that case make tries
2361 #to rebuild $@ again, which would fail because the directory where
2362 #the package got installed would not exist anymore. 
2363 #We work this around by using an if statement to manually check the mtimes.
2364 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2365         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2366         $(RM) $@ ; \
2367         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2368         mkdir -p "$(DISTDIR)/Packages" ; \
2369         mkdir -p "$(%(mmake)-prefix)" ; \
2370         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2371         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2372         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2373     fi
2374 %end
2376 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2377     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2378     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2380 GNU_REPOSITORY := gnu://
2382 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2383     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2384     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2385     patch="%(patch)" patch_repo="%(patch_repo)" \
2386     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2387     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2389 %end
2391 #-----------------------------------------------------------------------------------------
2392 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2393 # that the package is a "Development" package, and as such it needs to be placed
2394 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2396 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2397 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2398 # "mmake" argument, because the metatarget is implicitely defined as
2400 #     #MM- development-%(package)
2402 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2403     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2404     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2406 #MM- development : development-%(package)
2409 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2410    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2411    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2412    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2413    extraoptions="%(extraoptions)"
2414     
2415 %end
2418 #------------------------------------------------------------------------------
2419 # NOTE: The following are all part of platon42's build changes, please don't use
2420 # or change anything below this line until you know what you are doing.
2421 #------------------------------------------------------------------------------
2424 #------------------------------------------------------------------------------
2425 # Build a module skeleton
2426 # This is a stripped-down version of build_module, it only creates include files,
2427 # but no actual object. This is used when for plugins or classes with the same
2428 # API, but no actual implementation here.
2429 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
2430   conffile= \
2431   objdir=$(OBJDIR) prefix=$(AROSDIR) \
2432   reffile=$(BD_DEFREFFILE)
2434 # Define metamake targets and their dependencies
2435 #MM- includes-all : %(mmake)-includes
2436 #MM %(mmake) : %(mmake)-includes core-linklibs
2437 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
2438 #MM %(mmake)-linklib : %(mmake)-includes
2439 #MM %(mmake)-quick : %(mmake)-includes-quick
2440 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
2441 #MM     includes-generate-deps
2442 #MM %(mmake)-includes-quick
2443 #MM %(mmake)-includes-dirs
2444 #MM %(mmake)-makefile
2445 #MM %(mmake)-funclist
2446 #MM %(mmake)-clean
2448 # All MetaMake targets defined by this macro
2449 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
2450     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
2451     %(mmake)-kobj %(mmake)-funclist
2453 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
2455 ifeq (%(modname),)
2456 $(error using %build_module_skeleton: modname may not be empty)
2457 endif
2458 ifeq (%(modtype),)
2459 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
2460 endif
2462 # Default values for variables and arguments
2463 BD_DEFLINKLIBNAME := %(modname)
2464 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
2465 BD_DEFDFLAGS := %(cflags)
2466 OBJDIR ?= $(GENDIR)/$(CURDIR)
2468 ## Create genmodule include Makefile for the module
2470 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
2472 %rule_genmodule_makefile \
2473     modname=%(modname) modtype=%(modtype) \
2474     modsuffix=%(modsuffix) targetdir=%(objdir) \
2475     conffile=%(conffile)
2477 %(objdir)/Makefile.%(modname) : | %(objdir)
2479 GLOB_MKDIRS += %(objdir)
2481 # Do not parse these statements if metatarget is not appropriate
2482 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
2484 include %(objdir)/Makefile.%(modname)
2486 BD_DEFMODDIR := $(%(modname)_MODDIR)
2489 ## include files generation
2491 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
2492 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2493 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2495 %(mmake)-includes-quick : %(mmake)-includes
2496 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2497     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2498     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2500 ifneq ($(%(modname)_INCLUDES),)
2501 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2502                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2503                          conffile=%(conffile) reffile=%(reffile)
2505 %rule_copy_diff_multi \
2506     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2507     stampfile=%(objdir)/%(modname)_geninc
2509 %rule_copy_diff_multi \
2510     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2511     stampfile=%(objdir)/%(modname)_incs
2513 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
2514                       modsuffix=%(modsuffix) \
2515                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
2517 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2519 TMP%(modname)_INCDIRS := \
2520     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2521     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2522     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2523 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2525 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2526 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2528 endif
2530 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2531                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2532                            conffile=%(conffile)
2534 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2535 $(BD_DEFLIBDEFSINC) :
2536         @$(ECHO) "generating $@"
2537         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2539 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2540 GLOB_MKDIRS += %(objdir)/include
2542 ## Generation of the funclist file
2544 %(mmake)-funclist : %(modname).funclist
2546 %rule_genmodule_funclist \
2547     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
2548     conffile=%(conffile) reffile=%(reffile)
2551 ## Extra genmodule src files generation
2552 ## 
2553 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2554                       modsuffix=%(modsuffix) targetdir=%(objdir) \
2555                       conffile=%(conffile) reffile=%(reffile)
2557 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
2558     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2559     %(objdir)/Makefile.%(modname) \
2560     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2561     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2562     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2563     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2564     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2565     $(BD_DEFLIBDEFSINC)
2566 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2567 %(mmake)-clean ::
2568         @$(ECHO) "Cleaning up for module %(modname)"
2569         @$(RM) $(FILES)
2571 endif # $(TARGET) in $(BD_ALLTARGETS)
2572 %end
2573 #------------------------------------------------------------------------------