Try to make balance object behave more like MUI
[AROS.git] / config / make.tmpl
blobbb69c77d3c89d28b086db8f3d9b910ce0c6f147c
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling %(from)"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56         @$(ECHO) "Linking %(to)..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         %(strip) %(to)
70 %end
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building $(notdir $@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating library %(to)..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create the function reference file %(to) to %(from)
119 %define mkref_q cc=$(AROS_CC) cppflags="-E -C -dD -D__CXREF__" cflags=$(CFLAGS) from=$< to=$@
120         @$(ECHO) "Generating ref for $(notdir %(from))..."
121         @$(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to) 2>$(GENDIR)/cerrors
122         @$(IF) $(TEST) -s %(to) ; \
123         then \
124             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
125                 $(ECHO) "%(from): $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" >> $(GENDIR)/errors ; \
126                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
127             fi ; \
128         else \
129             $(ECHO) "Reference generation failed: $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" 1>&2 ; \
130             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
131             $(RM) %(to) ; \
132             exit 1 ; \
133         fi
134 %end
135 #------------------------------------------------------------------------------
138 #------------------------------------------------------------------------------
139 # Create one directory without any output
140 %define mkdir_q dir=.
141         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
142 %end
143 #------------------------------------------------------------------------------
146 #------------------------------------------------------------------------------
147 # Create several directories without any output
148 %define mkdirs_q dirs=/M
149         @$(FOR) dir in %(dirs) ; do \
150             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
151         done
152 %end
153 #------------------------------------------------------------------------------
156 #############################################################################
157 #############################################################################
158 ##                                                                         ##
159 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
160 ## mmakefile. They consist of one or more full makefile rules.             ##
161 ## In general the files generated in these macros are also defined as      ##
162 ## make targets so that they can be used as a dependency in other rules    ##
163 ##                                                                         ##
164 #############################################################################
165 #############################################################################
167 #------------------------------------------------------------------------------
168 # Generate a unique id for each of the %build... rules
169 %define buildid targets=/A
170 BDID := $(BDID)_
171 ifneq ($(filter $(TARGET),%(targets)),)
172 BDTARGETID := $(BDID)
173 endif
174 %end
175 #------------------------------------------------------------------------------
178 #------------------------------------------------------------------------------
179 # Copy file %(from) to %(to) in a makefile rule
180 %define rule_copy from=/A to=/A
181 %(to) : %(from)
182         @$(CP) $< $@
183 %end
184 #------------------------------------------------------------------------------
187 #------------------------------------------------------------------------------
188 # Copy the files %(files) to %(targetdir). For each file in %(files),
189 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
190 # appropriate subdirs are not generated by this rule so they have to be
191 # present.
192 %define rule_copy_multi files=/A targetdir=/A srcdir=.
194 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
195         @$(CP) $< $@
196 %end
197 #------------------------------------------------------------------------------
200 #------------------------------------------------------------------------------
201 # Copy the files %(files) to %(targetdir). For each file in %(files),
202 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
203 # %(stampfile) is used to keep track of when the last time the comparison has
204 # been done. The targetdir and the appropriate subdirs are not generated by 
205 # this rule so they have to be present.
206 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
207     stampfile=$(TMP_SRCDIR)/.copy_stamp
209 TMP_SRCDIR := %(srcdir)
211 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
213 %(stampfile) : COPYSRCDIR := %(srcdir)
214 %(stampfile) : TGTDIR := %(targetdir)
215 %(stampfile) : FILES := %(files)
216 %(stampfile) : $(addprefix %(srcdir)/,%(files))
217         @for f in $(FILES); do \
218              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
219                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
220              fi ; \
221         done
222         @$(TOUCH) $@
223 %end
224 #------------------------------------------------------------------------------
227 #------------------------------------------------------------------------------
228 # Will join all the files in %(from) to %(to). When text is specified it will
229 # be displayed.
230 # Restriction: at the moment when using a non-empty target dir %(from) may
231 # not have 
232 %define rule_join to=/A from=/A text=
234 %(to) : %(from)
235 ifneq (%(text),)
236         @$(ECHO) %(text)
237 endif
238         @$(CAT) $^ >$@
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Include the dependency files and add some internal rules
245 # When depstargets is provided the depencies will only be included when one of
246 # these targets is the $(TARGET). Otherwise the dependencies will only be
247 # included when the $(TARGET) is not for setup or clean 
248 %define include_deps deps=$(DEPS)/M  depstargets=
249 ifneq (%(deps),)
250   ifneq (%(depstargets),)
251     ifneq ($(findstring $(TARGET),%(depstargets)),)
252       -include %(deps)
253     endif
254   else
255     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
256       -include %(deps)
257     endif
258   endif
259 endif
260 %end
261 #------------------------------------------------------------------------------
264 #------------------------------------------------------------------------------
265 # Create the directories %(dirs). The creation will be done by adding rules to
266 # the %(setuptarget) make target with setup as the default. 
267 %define rule_makedirs dirs=/A setuptarget=setup
269 %(setuptarget) :: %(dirs)
271 GLOB_MKDIRS += %(dirs)
273 %end
274 #------------------------------------------------------------------------------
277 #------------------------------------------------------------------------------
278 # Generate a rule to compile a C source file to an object file and generate
279 # the dependency file. Basename may contain a directory part, then the source
280 # file has to be in that directory. The generated file will be put in the
281 # object directory without the directory.
282 # options
283 # - basename: the basename of the file to compile. Use % for a wildcard rule
284 # - cflags (default $(CFLAGS)): the C flags to use for compilation
285 # - dflags: the flags used during creation of dependency file. If not specified
286 #   the same value as cflags will be used
287 # - targetdir: the directory to put the .o file and the .d file. By default
288 #   it is put in the same directory as the .c file
289 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
291 ifeq (%(targetdir),)
292   TMP_TARGETBASE := %(basename)
293 else
294   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
295 endif
297 ifeq ($(findstring %(compiler),host kernel target),)
298   $(error unknown compiler %(compiler))
299 endif
300 ifeq (%(compiler),target)
301 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
302 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
305 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
306 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
307 endif
308 ifeq (%(compiler),host)
309 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
310 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
313 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
315 endif
316 ifeq (%(compiler),kernel)
317 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
318 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
319 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
320 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
321 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
322 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
323 endif
325 ifeq (%(nix),yes)
326   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
327 else
328   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
329 endif
330 $(TMP_TARGETBASE).o : %(basename).c
331         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
333 ifeq (%(dflags),)
334   ifeq (%(nix),yes)
335     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
336   else
337     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
338   endif
339 else
340   ifeq (%(nix),yes)
341     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
342   else
343     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
344   endif
345 endif
346 $(TMP_TARGETBASE).d : %(basename).c
347         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
348 %end
349 #------------------------------------------------------------------------------
352 #------------------------------------------------------------------------------
353 # Generate a rule to compile multiple C source files to an object file and
354 # generate the corresponding dependency files. The generated file will be put
355 # in the object directory without the directory part of the source file.
356 # options
357 # - basenames: the basenames of the files to compile. The names may include
358 #   relative or absolute path names. No wildcard is allowed
359 # - cflags (default $(CFLAGS)): the C flags to use for compilation
360 # - dflags: the flags used during creation of dependency file. If not specified
361 #   the same value as cflags will be used
362 # - targetdir: the directory to put the .o file and the .d file. By default
363 #   it is put in the same directory as the .c file. When targetdir is not
364 #   empty, path names will be stripped from the file names so that all files
365 #   are in that dir and not in subdirectories.
366 # - compiler (default target): compiler to use, target, kernel or host
367 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
368     compiler=target
370 ifeq (%(targetdir),)
371 TMP_TARGETS := $(addsuffix .o,%(basenames))
372 TMP_DTARGETS := $(addsuffix .d,%(basenames))
373 TMP_WILDCARD := %
374 else
375 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
376 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
377 TMP_WILDCARD := %(targetdir)/%
379 # Be sure that all .c files are generated
380 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
382 # Be sure that all .c files are found
383 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
384 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
385 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
386 ifneq ($(TMP_DIRS),)
387     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
388     vpath %.c $(TMP_DIRS)
389 endif
391 endif
393 ifeq ($(findstring %(compiler),host kernel target),)
394   $(error unknown compiler %(compiler))
395 endif
396 ifeq (%(compiler),target)
397 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
398 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
399 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
400 endif
401 ifeq (%(compiler),host)
402 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
403 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
404 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
405 endif
406 ifeq (%(compiler),kernel)
407 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
408 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
409 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
410 endif
412 $(TMP_TARGETS) : CFLAGS := %(cflags)
413 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
414         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
416 ifeq (%(dflags),)
417 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
418 else
419 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
420 endif
421 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
422         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
423 %end
424 #------------------------------------------------------------------------------
427 #------------------------------------------------------------------------------
428 # Make an alias from one arch specific build to another arch.
429 # arguments:
430 # - mainmmake: the mmake of the module in the main tree
431 # - arch: the current arch
432 # - alias: the alias to which this should point
433 %define rule_archalias mainmmake=\A arch=\A alias=\A
435 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
436 %end
437 #------------------------------------------------------------------------------
440 #------------------------------------------------------------------------------
441 # Generate a rule to compile a C source file to a shared object file with a
442 # .so suffix. Basename may contain a directory part, then the source
443 # file has to be in that directory. The generated file will be put in the
444 # object directory without the directory.
445 # options
446 # - basename: the basename of the file to compile. Use % for a wildcard rule
447 # - cflags (default $(CFLAGS)): the C flags to use for compilation
448 # - targetdir: the directory to put the .o file and the .d file. By default
449 #   it is put in the same directory as the .c file
450 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
452 ifeq (%(targetdir),)
453   TMP_TARGETBASE := %(basename)
454 else
455   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
456 endif
458 ifeq ($(findstring %(compiler),host kernel target),)
459   $(error unknown compiler %(compiler))
460 endif
461 ifeq (%(compiler),target)
462 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
463 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
464 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
465 endif
466 ifeq (%(compiler),host)
467 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
468 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
469 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
470 endif
471 ifeq (%(compiler),kernel)
472 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
473 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
474 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
475 endif
477 $(TMP_TARGETBASE).so : %(basename).c
478         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
479 %end
480 #------------------------------------------------------------------------------
483 #------------------------------------------------------------------------------
484 # Generate a rule to assemble a source file to an object file. Basename may
485 # contain a directory part, then the source file has to be in that directory.
486 # The generated file will be put in the object directory without the directory.
487 # options
488 # - basename: the basename of the file to compile. Use % for a wildcard rule
489 # - flags (default $(AFLAGS)): the asm flags to use for assembling
490 # - targetdir: the directory to put the .o file in. By default it is put in the
491 #   same directory as the .s file
492 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
494 ifeq (%(targetdir),)
495 %(basename).o : AFLAGS := %(aflags)
496 %(basename).o : %(basename).s
497         %assemble_q
498 %(basename).o : %(basename).S
499         %assemble_q
501 else
502 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
503 %(targetdir)/$(notdir %(basename)).o : %(basename).s
504         %assemble_q
505 %(targetdir)/$(notdir %(basename)).o : %(basename).S
506         %assemble_q
508 endif
509 %end
510 #------------------------------------------------------------------------------
513 #------------------------------------------------------------------------------
514 # Generate a rule to assemble multiple source files to an object file. The
515 # generated file will be put in the object directory with the directory part
516 # of the source file stripped off.
517 # options
518 # - basenames: the basenames of the files to compile. The names may include
519 #   relative or absolute path names. No wildcard is allowed
520 # - aflags (default $(AFLAGS)): the flags to use for assembly
521 # - targetdir: the directory to put the .o file and the .d file. By default
522 #   it is put in the same directory as the .c file. When targetdir is not
523 #   empty, path names will be stripped from the file names so that all files
524 #   are in that dir and not in subdirectories.
525 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
527 ifeq (%(targetdir),)
528 TMP_TARGETS := $(addsuffix .o,%(basenames))
529 TMP_WILDCARD := %
530 else
531 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
532 TMP_WILDCARD := %(targetdir)/%
534 # Be sure that all .s files are generated
535 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
537 # Be sure that all .c files are found
538 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
539 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
540 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
541 ifneq ($(TMP_DIRS),)
542     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
543     vpath %%(suffix) $(TMP_DIRS)
544 endif
546 endif
548 ifeq ($(findstring %(compiler),host kernel target),)
549   $(error unknown compiler %(compiler))
550 endif
551 ifeq (%(compiler),target)
552 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
553 endif
554 ifeq (%(compiler),host)
555 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
556 endif
557 ifeq (%(compiler),kernel)
558 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
559 endif
561 $(TMP_TARGETS) : AFLAGS := %(aflags)
562 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
563         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
564 %end
565 #------------------------------------------------------------------------------
568 #------------------------------------------------------------------------------
569 # Link %(objs) to %(prog) using the libraries in %(uselibs)
570 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
571     usehostlibs= usestartup=yes detach=no nix=no linker=target
573 TMP_EXTRA_LDFLAGS := 
574 ifeq (%(nix),yes)
575     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
576 endif
577 ifeq (%(usestartup),no)
578     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
579 endif
580 ifeq (%(detach),yes)
581     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
582 endif
584 # Make a list of the lib files this program depends on.
585 ifneq (%(uselibs),)
586 # In LDFLAGS remove white space between -L and directory
587 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
588 # Filter out only the libdirs and remove -L
589 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
590 # Add trailing /
591 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
592 # Add normal linklib path
593 TMP_DIRS += $(LIBDIR)/
594 # add lib and .a to static linklib names
595 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
596 # search for the linklibs in the given path, ignore ones not found
597 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
598     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
600 else
601 TMP_DEPLIBS :=
602 endif
604 ifeq (%(linker),target)
605 %(prog) : CMD:=$(TARGET_CC)
606 %(prog) : STRIPCMD:=$(TARGET_STRIP)
607 endif
608 ifeq (%(linker),host)
609 %(prog) : CMD:=$(HOST_CC)
610 %(prog) : STRIPCMD:=$(HOST_STRIP)
611 endif
612 ifeq (%(linker),kernel)
613 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
614 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
615 endif
617 %(prog) : OBJS := %(objs)
618 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
619 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
620 %(prog) : %(objs) $(TMP_DEPLIBS)
621         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
622 %end
623 #------------------------------------------------------------------------------
626 #------------------------------------------------------------------------------
627 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
628 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
629 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
630     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
631     usestartup=yes detach=no
633 TMP_EXTRA_LDFLAGS := 
634 ifeq (%(nix),yes)
635     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
636 endif
637 ifeq (%(usestartup),no)
638     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
639 endif
640 ifeq (%(detach),yes)
641     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
642 endif
644 # Make a list of the lib files the programs depend on.
645 ifneq (%(uselibs),)
646 # In LDFLAGS remove white space between -L and directory
647 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
648 # Filter out only the libdirs and remove -L
649 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
650 # Add trailing /
651 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
652 # Add normal linklib path
653 TMP_DIRS += $(LIBDIR)/lib/
654 # add lib and .a to static linklib names
655 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
656 # search for the linklibs in the given path, ignore ones not found
657 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
658     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
660 else
661 TMP_DEPLIBS :=
662 endif
664 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
665 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
666 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
667         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
668 %end
669 #------------------------------------------------------------------------------
672 #------------------------------------------------------------------------------
673 # Link the %(objs) to the library %(libdir)/lib%(libname).a
674 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
676 %(libdir)/lib%(libname).a : %(objs)
677         %mklib_q from=$^
678 %end
679 #------------------------------------------------------------------------------
682 #------------------------------------------------------------------------------
683 # Link the %(objs) to the library %(libdir)/lib%(libname).so
684 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
686 %(libdir)/lib%(libname).so : %(objs)
687         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
688 %end
689 #------------------------------------------------------------------------------
692 #------------------------------------------------------------------------------
693 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
694 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
695 # The -noarosc flag is added so that modules are not linked with arosc.library
696 # (see /config/specs.in file)
697 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
698     uselibs= usehostlibs=
700 %(module) : OBJS := %(objs)
701 %(module) : ENDTAG := %(endobj)
702 %(module) : ERR := %(err)
703 %(module) : OBJDIR := %(objdir)
704 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
705 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
706         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
708 %end
709 #------------------------------------------------------------------------------
712 #------------------------------------------------------------------------------
713 # Generate a rule to generate a function reference file from a C source file.
714 # Basename may contain a directory part, then the source file has to be in that
715 # directory. The generated file will be put in the object directory without the
716 # directory.
717 # options
718 # - basename: the basename of the file to compile. Use % for a wildcard rule
719 # - cflags (default $(CFLAGS)): the C flags to use for compilation
720 # - targetdir: the directory to put the generated .ref file. By default the
721 #   .ref file will be put in the same directory as the .c file.
722 # - includefile: This file will be included at the head of the source file
723 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
725 ifeq (%(targetdir),)
726 GENFILE_TMP := %(basename).ref
727 else
728 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
729 endif
731 ifeq ($(filter %(compiler),target kernel host),)
732 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
733 endif
735 ifeq (%(compiler),target)
736 $(GENFILE_TMP) : CC:=$(TARGET_CC) $(TARGET_CFLAGS)
737 endif
738 ifeq (%(compiler),host)
739 $(GENFILE_TMP) : CC:=$(HOST_CC)
740 endif
741 ifeq(%(compiler),kernel)
742 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
743 endif
745 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
746 ifeq (%(includefile),)
747         %mkref_q cc=$(CC) cflags="%(cflags)"
748 else
749         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
750 endif
752 %end
753 #------------------------------------------------------------------------------
756 #------------------------------------------------------------------------------
757 # Generate a rule to generate a function reference file from a C source file.
758 # Basename may contain a directory part, then the source file has to be in that
759 # directory. The generated file will be put in the object directory without the
760 # directory.
761 # options
762 # - basenames: the basenames of the files to compile. No wildcard is allowed
763 # - cflags (default $(CFLAGS)): the C flags to use for compilation
764 # - targetdir: the directory to put the generated .ref file. By default the
765 #   .ref file will be put in the same directory as the .c file. When targetdir
766 #   is not empty all files will be put there and path parts in the basenames
767 #   will be stripped off.
768 # - includefile: This file will be included at the head of the source file
769 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
770     compiler=target
772 ifeq (%(targetdir),)
773 TMP_TARGETS := $(addsuffix .ref,%(basenames))
774 TMP_WILDCARD := %.ref
775 else
776 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
777 TMP_WILDCARD := %(targetdir)/%.ref
779 # Be sure that all .c files are generated
780 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
782 # Be sure that all .c files are found
783 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
784 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
785 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
786 ifneq ($(TMP_DIRS),)
787     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
788     vpath %.c $(TMP_DIRS)
789 endif
791 endif
793 ifeq ($(filter %(compiler),target kernel host),)
794 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
795 endif
797 ifeq (%(compiler),target)
798 $(TMP_TARGETS) : CC:=$(TARGET_CC) $(TARGET_CFLAGS)
799 endif
800 ifeq (%(compiler),host)
801 $(TMP_TARGETS) : CC:=$(HOST_CC)
802 endif
803 ifeq (%(compiler),kernel)
804 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
805 endif
806 ifeq (%(includefile),)
807 $(TMP_TARGETS) : CFLAGS:=%(cflags)
808 else
809 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
810 $(TMP_TARGETS) : %(includefile)
811 endif
812 $(TMP_TARGETS) : $(CXREF)
813 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
814         %mkref_q cc=$(CC)
815 %end
816 #------------------------------------------------------------------------------
819 #------------------------------------------------------------------------------
820 # Generate the libdefs.h include file for a module.
821 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
823 TMP_TARGET := %(modname)_libdefs.h
824 TMP_DEPS := $(GENMODULE)
825 TMP_OPTS := 
826 ifneq (%(conffile),)
827     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
828     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
829 else
830     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
831     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
832 endif
833 ifneq (%(modsuffix),)
834     TMP_OPTS += -s %(modsuffix)
835 endif
836 ifneq (%(targetdir),)
837     TMP_OPTS += -d %(targetdir)
838     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
839 endif
841 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
842 $(TMP_TARGET) : MODNAME := %(modname)
843 $(TMP_TARGET) : MODTYPE := %(modtype)
844 $(TMP_TARGET) : $(TMP_DEPS)
845         @$(ECHO) "Generating $(notdir $@)"
846         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
847 %end
848 #------------------------------------------------------------------------------
851 #------------------------------------------------------------------------------
852 # Generate the funclist file for a module.
853 %define rule_genmodule_funclist \
854     modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
856 TMP_TARGET := %(modname).funclist
857 TMP_DEPS := $(GENMODULE)
858 TMP_OPTS := 
859 ifeq (%(reffile),)
860     $(error reffile needed in rule_genmodule_funclist but none specified)
861 endif
862 TMP_OPTS := -r %(reffile)
863 TMP_DEPS += %(reffile)
864 ifneq (%(conffile),)
865     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
866     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
867 else
868     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
869     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
870 endif
871 ifneq (%(modsuffix),)
872     TMP_OPTS += -s %(modsuffix)
873 endif
874 ifneq (%(targetdir),)
875     TMP_OPTS += -d %(targetdir)
876     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
877 endif
879 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
880 $(TMP_TARGET) : MODNAME := %(modname)
881 $(TMP_TARGET) : MODTYPE := %(modtype)
882 $(TMP_TARGET) : $(TMP_DEPS)
883         @$(ECHO) "Generating $(notdir $@)"
884         @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
885 %end
886 #------------------------------------------------------------------------------
889 #------------------------------------------------------------------------------
890 # Generate a Makefile.%(modname) with the genmodule program and include this
891 # generated file in this Makefile
892 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
893     targetdir=
895 TMP_TARGET := Makefile.%(modname)
896 TMP_DEPS := $(GENMODULE)
897 TMP_OPTS := 
898 ifneq (%(conffile),)
899     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
900     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
901 else
902     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
903     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
904 endif
905 ifneq (%(modsuffix),)
906     TMP_OPTS += -s %(modsuffix)
907 endif
908 ifneq (%(targetdir),)
909     TMP_OPTS += -d %(targetdir)
910     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
911 endif
913 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
914 $(TMP_TARGET) : MODNAME := %(modname)
915 $(TMP_TARGET) : MODTYPE := %(modtype)
916 $(TMP_TARGET) : $(TMP_DEPS)
917         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
918 %end
919 #------------------------------------------------------------------------------
922 #------------------------------------------------------------------------------
923 # Generate dummy support files so cxref when used on the a module source file
924 # will find something to include. This rule has to be preceeded by
925 # %rule_genmodule_makefile
926 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
928 ifneq ($(%(modname)_INCLUDES),)
929 TMP_TARGETS := $(%(modname)_INCLUDES)
931 TMP_DEPS := $(GENMODULE)
932 TMP_OPTS := 
933 ifneq (%(conffile),)
934     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
935     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
936 else
937     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
938     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
939 endif
940 ifneq (%(modsuffix),)
941     TMP_OPTS += -s %(modsuffix)
942 endif
943 ifneq (%(targetdir),)
944     TMP_OPTS += -d %(targetdir)
945     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
946 endif
948 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
949 $(TMP_TARGETS) : MODNAME := %(modname)
950 $(TMP_TARGETS) : MODTYPE := %(modtype)
951 $(TMP_TARGETS) : $(TMP_DEPS)
952         @$(ECHO) "Generating dummy include files"
953         @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
954 endif
955 %end
956 #------------------------------------------------------------------------------
959 #------------------------------------------------------------------------------
960 # Generate the support files for compiling a module. This includes include
961 # files and source files. This rule has to be preceeded by
962 # %rule_genmodule_makefile
963 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
964     conffile= reffile=
966 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
967                $(%(modname)_LINKLIBFILES)
968 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
970 TMP_DEPS := $(GENMODULE)
971 ifeq ($(%(modname)_NEEDREF), yes)
972     ifeq (%(reffile),)
973         $(error reffile needed in rule_genmodule_files but none specified)
974     endif
975     TMP_OPTS := -r %(reffile)
976     TMP_DEPS += %(reffile)
977 else
978     TMP_OPTS :=
979 endif
980 ifneq (%(conffile),)
981     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
982     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
983 else
984     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
985     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
986 endif
987 ifneq (%(modsuffix),)
988     TMP_OPTS += -s %(modsuffix)
989 endif
990 ifneq (%(targetdir),)
991     TMP_OPTS += -d %(targetdir)
992     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
993     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
994 endif
996 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
997 $(TMP_TARGETS) : MODNAME := %(modname)
998 $(TMP_TARGETS) : MODTYPE := %(modtype)
999 $(TMP_TARGETS) : $(TMP_DEPS)
1000         @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
1001 ifneq (%(conffile),lib.conf)
1002         @$(IF) $(TEST) -f lib.conf; then \
1003           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1004         fi
1005 endif
1006         @$(IF) $(TEST) -f libdefs.h; then \
1007           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1008         fi
1009         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1010 %end
1011 #------------------------------------------------------------------------------
1014 #------------------------------------------------------------------------------
1015 # Generate the support files for compiling a module. This includes include
1016 # files and source files.
1017 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1018     targetdir= conffile= reffile=
1021 ifneq ($(%(modname)_INCLUDES),)
1022 TMP_TARGETS := $(%(modname)_INCLUDES)
1024 TMP_DEPS := $(GENMODULE)
1025 ifeq ($(%(modname)_NEEDREF), yes)
1026     ifeq (%(reffile),)
1027         $(error reffile needed in rule_genmodule_files but none specified)
1028     endif
1029     TMP_OPTS := -r %(reffile)
1030     TMP_DEPS += %(reffile)
1031 else
1032     TMP_OPTS :=
1033 endif
1034 ifneq (%(conffile),)
1035     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1036     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1037 else
1038     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1039     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1040 endif
1041 ifneq (%(modsuffix),)
1042     TMP_OPTS += -s %(modsuffix)
1043 endif
1044 ifneq (%(targetdir),)
1045     TMP_OPTS += -d %(targetdir)
1046     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1047 endif
1049 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1050 $(TMP_TARGETS) : MODNAME := %(modname)
1051 $(TMP_TARGETS) : MODTYPE := %(modtype)
1052 $(TMP_TARGETS) : $(TMP_DEPS)
1053         @$(ECHO) "Generating include files"
1054         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1055 endif
1056 %end
1057 #------------------------------------------------------------------------------
1060 #------------------------------------------------------------------------------
1061 # Common rules for all makefiles
1062 %define common
1063 # Delete generated makefiles
1065 clean ::
1066         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1068 include $(SRCDIR)/config/make.tail
1070 BDID := $(BDTARGETID)
1071 %end
1072 #------------------------------------------------------------------------------
1073       
1075 #############################################################################
1076 #############################################################################
1077 ##                                                                         ##
1078 ## Here are the mmakefile build macros. These are macros that takes care   ##
1079 ## of everything to go from the sources to the generated target. Also all  ##
1080 ## intermediate files and directories that are needed are created by these ##
1081 ## rules.                                                                  ##
1082 ##                                                                         ##
1083 #############################################################################
1084 #############################################################################
1086 #------------------------------------------------------------------------------
1087 # Build a program
1088 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1089     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1090     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1091     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1092     compiler=target srcdir=
1094 .PHONY : %(mmake)
1096 BD_PROGNAME  := %(progname)
1097 BD_OBJDIR    := %(objdir)
1098 BD_TARGETDIR := %(targetdir)
1100 BD_FILES     := %(files)
1101 BD_ASMFILES  := %(asmfiles)
1103 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1104 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1105 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1107 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
1108 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
1110 BD_CFLAGS    := %(cflags)
1111 BD_AFLAGS    := %(aflags)
1112 BD_DFLAGS    := %(dflags)
1113 BD_LDFLAGS   := %(ldflags)
1116 %(mmake)-quick : %(mmake)
1118 #MM %(mmake) : includes-generate-deps linklibs-core
1119 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1121 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1122 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1123     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1124 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1125     aflags=$(BD_AFLAGS) compiler=%(compiler)
1127 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1128     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1129     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1130     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1131     linker=%(compiler)
1133 endif
1135 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1137 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1138 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1139 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1141 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1143 %(mmake)-clean ::
1144         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1145         @$(RM) $(FILES)
1147 %end
1148 #------------------------------------------------------------------------------
1151 #------------------------------------------------------------------------------
1152 # Build programs, for every C file an executable will be built with the same
1153 # name as the C file
1154 %define build_progs mmake=/A files=/A nix=no \
1155     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1156     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1157     uselibs= usehostlibs= usestartup=yes detach=no
1159 .PHONY : %(mmake)
1161 BD_OBJDIR    := %(objdir)
1162 BD_TARGETDIR := %(targetdir)
1164 BD_FILES     := %(files)
1165 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1166 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1167 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1169 BD_CFLAGS    := %(cflags)
1170 BD_DFLAGS    := %(dflags)
1171 BD_LDFLAGS   := %(ldflags)
1174 %(mmake)-quick : %(mmake)
1176 #MM %(mmake) : includes-generate-deps
1177 %(mmake) : $(BD_EXES)
1179 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1180 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1181     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1183 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1184     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1185     ldflags=$(BD_LDFLAGS) \
1186     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1187     usestartup="%(usestartup)" detach="%(detach)"
1189 endif
1191 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1193 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1194 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1195 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1197 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1199 %(mmake)-clean ::
1200         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1201         @$(RM) $(FILES)
1203 %end
1204 #------------------------------------------------------------------------------
1207 #------------------------------------------------------------------------------
1208 # Build a module.
1209 # This is a bare version: It just compiles and links the given files. It is
1210 # assumed that all needed boiler plate code is in the files. This should only
1211 # be used for compiling external code. For AROS code use %build_module
1212 %define build_module_simple mmake=/A modname=/A modtype=/A \
1213     files="$(basename $(call WILDCARD, *.c))" \
1214     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1215     objdir=$(OBJDIR) moduledir= \
1216     uselibs= usehostlibs= compiler=target
1218 # Define metamake targets and their dependencies
1219 #MM %(mmake) : core-linklibs includes-generate-deps
1220 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1221 #MM %(mmake)-quick
1222 #MM %(mmake)-clean
1224 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1226 .PHONY : $(BD_ALLTARGETS)
1228 ifeq (%(modname),)
1229 $(error using %build_module_simple: modname may not be empty)
1230 endif
1231 ifeq (%(modtype),)
1232 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1233 endif
1235 # Default values for variables and arguments
1236 BD_DEFLINKLIBNAME := %(modname)
1237 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1238 BD_DEFDFLAGS := %(cflags)
1239 OBJDIR ?= $(GENDIR)/$(CURDIR)
1240 BD_MODDIR := %(moduledir)
1241 ifeq ($(BD_MODDIR),)
1242   ifeq (%(modtype),library)
1243     BD_MODDIR  := $(AROS_LIBS)
1244   endif
1245   ifeq (%(modtype),gadget)
1246     BD_MODDIR  := $(AROS_GADGETS)
1247   endif
1248   ifeq (%(modtype),datatype)
1249     BD_MODDIR  := $(AROS_DATATYPES)
1250   endif
1251   ifeq (%(modtype),handler)
1252     BD_MODDIR  := $(AROS_FS)
1253   endif
1254   ifeq (%(modtype),device)
1255     BD_MODDIR  := $(AROS_DEVS)
1256   endif
1257   ifeq (%(modtype),resource)
1258     BD_MODDIR  := $(AROS_RESOURCES)
1259   endif
1260   ifeq (%(modtype),mui)
1261     BD_MODDIR  := $(AROS_CLASSES)/Zune
1262   endif
1263   ifeq (%(modtype),mcc)
1264     BD_MODDIR  := $(AROS_CLASSES)/Zune
1265   endif
1266   ifeq (%(modtype),mcp)
1267     BD_MODDIR  := $(AROS_CLASSES)/Zune
1268   endif
1269   ifeq (%(modtype),usbclass)
1270     BD_MODDIR  := $(AROS_CLASSES)/USB
1271   endif
1272   ifeq (%(modtype),hidd)
1273     BD_MODDIR  := $(AROS_DRIVERS)
1274   endif
1275 endif
1276 ifeq ($(BD_MODDIR),)
1277   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1278 endif
1280 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1281 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1282 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1284 %rule_compile_multi \
1285     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1286     cflags="%(cflags)" dflags="%(dflags)" \
1287     compiler=%(compiler)
1289 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1290 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1292 %(mmake)-quick : %(mmake)
1293 %(mmake) : $(BD_MODULE)
1294 %(mmake)-kobj : $(BD_KOBJ)
1296 # The module is linked from all the compiled .o files
1297 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1298 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1299                  endobj= err=%(modname).err objdir=%(objdir) \
1300                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1302 # Link kernel object file
1303 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1305 # Make these symbols local
1306 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1307             UtilityBase ExpansionBase KeymapBase KernelBase
1309 BD_SYMBOLS := $(BD_KBASE)
1311 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1312 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1313 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1314 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1315 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1316         @$(ECHO) "Linking $@"
1317         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1318         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1321 ## Dependency fine-tuning
1323 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1324 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1326 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1327 $(BD_MODULE) : | $(BD_MODDIR)
1328 $(BD_KOBJ) : | $(KOBJSDIR)
1329 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1331 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1332 %(mmake)-clean ::
1333         @$(ECHO) "Cleaning up for module %(modname)"
1334         @$(RM) $(FILES)
1335 %end
1336 #------------------------------------------------------------------------------
1339 #------------------------------------------------------------------------------
1340 # Build a module
1341 # Explanation of this macro is done in the developer's manual
1342 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1343   conffile= files="$(basename $(call WILDCARD, *.c))" \
1344   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1345   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1346   reffile=$(BD_DEFREFFILE) noref= \
1347   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1348   compiler=target
1350 # Define metamake targets and their dependencies
1351 #MM- includes-all : %(mmake)-includes
1352 #MM %(mmake) : %(mmake)-includes core-linklibs
1353 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1354 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1355 #MM %(mmake)-linklib : %(mmake)-includes
1356 #MM %(mmake)-quick : %(mmake)-includes-quick
1357 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1358 #MM     includes-generate-deps
1359 #MM %(mmake)-includes-quick
1360 #MM %(mmake)-includes-dirs
1361 #MM %(mmake)-makefile
1362 #MM %(mmake)-funclist
1363 #MM %(mmake)-clean
1365 # All MetaMake targets defined by this macro
1366 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1367     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1368     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-funclist %(mmake)-linklib
1370 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1372 ifeq (%(modname),)
1373 $(error using %build_module: modname may not be empty)
1374 endif
1375 ifeq (%(modtype),)
1376 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1377 endif
1379 # Default values for variables and arguments
1380 BD_DEFLINKLIBNAME := %(modname)
1381 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1382 BD_DEFDFLAGS := %(cflags)
1383 OBJDIR ?= $(GENDIR)/$(CURDIR)
1385 ## Create genmodule include Makefile for the module
1387 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1389 %rule_genmodule_makefile \
1390     modname=%(modname) modtype=%(modtype) \
1391     modsuffix=%(modsuffix) targetdir=%(objdir) \
1392     conffile=%(conffile)
1394 %(objdir)/Makefile.%(modname) : | %(objdir)
1396 GLOB_MKDIRS += %(objdir)
1398 # Do not parse these statements if metatarget is not appropriate
1399 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1401 include %(objdir)/Makefile.%(modname)
1403 BD_DEFMODDIR := $(%(modname)_MODDIR)
1406 ## include files generation
1408 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1409 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1410 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1412 %(mmake)-includes-quick : %(mmake)-includes
1413 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1414     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1415     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1417 ifneq ($(%(modname)_INCLUDES),)
1418 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1419                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1420                          conffile=%(conffile) reffile=%(reffile)
1422 %rule_copy_diff_multi \
1423     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1424     stampfile=%(objdir)/%(modname)_geninc
1426 %rule_copy_diff_multi \
1427     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1428     stampfile=%(objdir)/%(modname)_incs
1430 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1431                       modsuffix=%(modsuffix) \
1432                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1434 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1436 TMP%(modname)_INCDIRS := \
1437     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1438     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1439     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1440 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1442 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1443 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1445 endif
1447 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1448                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1449                            conffile=%(conffile)
1451 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1452 $(BD_DEFLIBDEFSINC) :
1453         @$(ECHO) "generating $@"
1454         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1456 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1457 GLOB_MKDIRS += %(objdir)/include
1459 ## Generation of the funclist file
1461 %(mmake)-funclist : %(modname).funclist
1463 %rule_genmodule_funclist \
1464     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1465     conffile=%(conffile) reffile=%(reffile)
1468 ## Extra genmodule src files generation
1469 ## 
1470 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1471                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1472                       conffile=%(conffile) reffile=%(reffile)
1474 ## Compilation
1476 BD_FILES      := %(files)
1477 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1478 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1479 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1481 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1482 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1483 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1485 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1486 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1488 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1489 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1490 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1491     BD_LINKLIB :=
1492 else
1493     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1494 endif
1495 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1497 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1498 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1500 %rule_compile_multi \
1501     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1502     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1503     compiler=%(compiler)
1504 %rule_compile_multi \
1505     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1506     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1507     compiler=%(compiler)
1509 ifneq ($(BD_LINKLIBAFILES),)
1510 %rule_assemble_multi \
1511     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1512 endif
1514 ## function reference files generation
1516 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1517 %rule_ref_multi \
1518     basenames=$(BD_FILES) targetdir=%(objdir) \
1519     cflags=$(BD_CFLAGS_REF) \
1520     compiler=%(compiler)
1522 ifeq (%(noref),)
1523 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1524 else
1525 BD_REFS   := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1526 endif
1528 %rule_join from=$(BD_REFS) to=%(reffile) \
1529            text="Collecting function references for module %(modname)"
1532 ## Linking
1534 ifeq (%(modsuffix),)
1535 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1536 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1537 else
1538 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1539 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1540 endif
1542 %(mmake)-quick : %(mmake)
1543 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1544 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1545 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1546 %(mmake)-linklib : $(BD_LINKLIB)
1548 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1549                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1550 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1551 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1552                  %(linklibobjs)
1554 # The module is linked from all the compiled .o files
1555 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1556                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1557                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1559 # Link static lib
1560 ifneq ($(BD_LINKLIB),)
1561 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1563 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1564 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1565 endif
1567 # Link kernel object file
1568 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1570 # Make these symbols local
1571 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1572             UtilityBase ExpansionBase KeymapBase KernelBase
1574 BD_SYMBOLS := $(BD_KBASE)
1576 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1577 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1578 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1579 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1580 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1581         @$(ECHO) "Linking $@"
1582         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1583         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1585 ## Dependency fine-tuning
1587 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1588 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1590 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1591 $(BD_MODULE) : | %(prefix)/%(moduledir)
1592 $(BD_KOBJ) : | $(KOBJSDIR)
1593 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1595 # Some include files need to be generated before the .c can be parsed.
1596 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
1597 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1598     $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1599 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1601 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1602     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1603 $(BD_DEPS) : $(BD_DFILE_DEPS)
1604 endif
1606 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1607     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1608     %(objdir)/Makefile.%(modname) \
1609     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1610     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1611     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1612     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1613     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1614     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1615     $(BD_ENDOBJS)
1616 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1617 %(mmake)-clean ::
1618         @$(ECHO) "Cleaning up for module %(modname)"
1619         @$(RM) $(FILES)
1621 endif # $(TARGET) in $(BD_ALLTARGETS)
1622 %end
1623 #------------------------------------------------------------------------------
1626 #------------------------------------------------------------------------------
1627 # Build a module skeleton
1628 # This is a stripped-down version of build_module, it only creates include files,
1629 # but no actual object. This is used when for plugins or classes with the same
1630 # API, but no actual implementation here.
1631 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1632   conffile= \
1633   objdir=$(OBJDIR) prefix=$(AROSDIR) \
1634   reffile=$(BD_DEFREFFILE)
1636 # Define metamake targets and their dependencies
1637 #MM- includes-all : %(mmake)-includes
1638 #MM %(mmake) : %(mmake)-includes core-linklibs
1639 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1640 #MM %(mmake)-linklib : %(mmake)-includes
1641 #MM %(mmake)-quick : %(mmake)-includes-quick
1642 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1643 #MM     includes-generate-deps
1644 #MM %(mmake)-includes-quick
1645 #MM %(mmake)-includes-dirs
1646 #MM %(mmake)-makefile
1647 #MM %(mmake)-funclist
1648 #MM %(mmake)-clean
1650 # All MetaMake targets defined by this macro
1651 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1652     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1653     %(mmake)-kobj %(mmake)-funclist
1655 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1657 ifeq (%(modname),)
1658 $(error using %build_module_skeleton: modname may not be empty)
1659 endif
1660 ifeq (%(modtype),)
1661 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1662 endif
1664 # Default values for variables and arguments
1665 BD_DEFLINKLIBNAME := %(modname)
1666 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1667 BD_DEFDFLAGS := %(cflags)
1668 OBJDIR ?= $(GENDIR)/$(CURDIR)
1670 ## Create genmodule include Makefile for the module
1672 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1674 %rule_genmodule_makefile \
1675     modname=%(modname) modtype=%(modtype) \
1676     modsuffix=%(modsuffix) targetdir=%(objdir) \
1677     conffile=%(conffile)
1679 %(objdir)/Makefile.%(modname) : | %(objdir)
1681 GLOB_MKDIRS += %(objdir)
1683 # Do not parse these statements if metatarget is not appropriate
1684 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1686 include %(objdir)/Makefile.%(modname)
1688 BD_DEFMODDIR := $(%(modname)_MODDIR)
1691 ## include files generation
1693 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1694 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1695 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1697 %(mmake)-includes-quick : %(mmake)-includes
1698 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1699     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1700     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1702 ifneq ($(%(modname)_INCLUDES),)
1703 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1704                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1705                          conffile=%(conffile) reffile=%(reffile)
1707 %rule_copy_diff_multi \
1708     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1709     stampfile=%(objdir)/%(modname)_geninc
1711 %rule_copy_diff_multi \
1712     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1713     stampfile=%(objdir)/%(modname)_incs
1715 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1716                       modsuffix=%(modsuffix) \
1717                       targetdir=%(objdir)/dummyinc conffile=%(conffile)
1719 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1721 TMP%(modname)_INCDIRS := \
1722     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1723     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1724     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1725 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1727 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1728 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1730 endif
1732 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1733                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1734                            conffile=%(conffile)
1736 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1737 $(BD_DEFLIBDEFSINC) :
1738         @$(ECHO) "generating $@"
1739         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1741 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1742 GLOB_MKDIRS += %(objdir)/include
1744 ## Generation of the funclist file
1746 %(mmake)-funclist : %(modname).funclist
1748 %rule_genmodule_funclist \
1749     modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1750     conffile=%(conffile) reffile=%(reffile)
1753 ## Extra genmodule src files generation
1754 ## 
1755 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1756                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1757                       conffile=%(conffile) reffile=%(reffile)
1759 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1760     $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1761     %(objdir)/Makefile.%(modname) \
1762     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1763     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1764     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1765     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1766     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1767     $(BD_DEFLIBDEFSINC)
1768 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1769 %(mmake)-clean ::
1770         @$(ECHO) "Cleaning up for module %(modname)"
1771         @$(RM) $(FILES)
1773 endif # $(TARGET) in $(BD_ALLTARGETS)
1774 %end
1775 #------------------------------------------------------------------------------
1778 #------------------------------------------------------------------------------
1779 # Build a linklib.
1780 # - mmake is the mmaketarget
1781 # - libname is the baselibname e.g. lib%(libname).a will be created
1782 # - files are the C source files to include in the lib. The list of files
1783 #   has to be given without the .c suffix
1784 # - asmfiles are the asm files to include in the lib. The list of files has to
1785 #   be given without the .s suffix
1786 # - objs additional object to link into the linklib. The objects have to be
1787 #   given with full absolute path and the .o suffix.
1788 # - cflags are the flags to compile the source (default $(CFLAGS))
1789 # - dflags are the flags use during makedepend (default equal to cflags)
1790 # - aflags are the flags use during assembling (default $(AFLAGS))
1791 # - objdir is where the .o are generated
1792 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1793 %define build_linklib mmake=/A libname=/A \
1794   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1795   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1797 # assign and generate the local variables used in this macro
1798 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1800 BD_FILES      := %(files)
1801 BD_ASMFILES   := %(asmfiles)
1803 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1804 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1805 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1807 BD_OBJS       := $(BD_ARCHOBJS) \
1808                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1809                  %(objs)
1810 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1812 BD_CFLAGS     := %(cflags)
1813 ifeq (%(dflags),)
1814 BD_DFLAGS     := $(BD_CFLAGS)
1815 else
1816 BD_DFLAGS     := %(dflags)
1817 endif
1818 BD_AFLAGS     := %(aflags)
1820 BD_LINKLIB    := %(libdir)/lib%(libname).a
1822 .PHONY : %(mmake) %(mmake)-clean
1824 #MM %(mmake) : includes-generate-deps
1825 %(mmake) : $(BD_LINKLIB)
1828 %(mmake)-clean ::
1829         @$(RM) $(BD_OBJS) $(BD_DEPS)
1831 ifeq ($(TARGET),%(mmake))
1832 ifneq ($(dir $(BD_FILES)),./)
1833 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1834 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1835 endif
1837 %rule_compile basename=% targetdir=%(objdir) \
1838               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1839 %rule_assemble basename=% targetdir=%(objdir) \
1840               aflags=$(BD_AFLAGS)
1841 endif
1843 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1845 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1847 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1848 $(BD_LINKLIB) : | %(libdir)
1849 GLOB_MKDIRS += %(objdir) %(libdir)
1851 %end
1852 #------------------------------------------------------------------------------
1857 #------------------------------------------------------------------------------
1858 # Build catalogs.
1859 # - mmake is the mmaketarget
1860 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1861 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1862 # - subdir is the destination subdirectory of the catalogs
1863 # - name is the name of the destination catalog, without the .catalog suffix
1864 # - source is the path to the generated source code file
1865 # - dir is the base destination directory (default $(AROS_CATALOGS))
1866 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1867 # - srcdir is the directory in which the *.cd and *.ct files are searched
1869 %define build_catalogs mmake=/A name=/A subdir=/A \
1870  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1871  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1873 ifeq (%(description),)
1874 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1875 else
1876 BD_DESC := %(description)
1877 endif
1879 ifeq (%(catalogs),)
1880 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1881 else
1882 BD_LNGS := %(catalogs)
1883 endif
1885 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1886 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1889 %(mmake) : $(BD_OBJS) %(source)
1891 $(BD_OBJS) : | $(BD_DIRS)
1892 GLOB_MKDIRS += $(BD_DIRS)
1894 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1895         @$(ECHO) "Creating %(name) catalog for language $*."
1896         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1898 ifneq (%(source),)
1899 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1900 %(source) : $(BD_DESC).cd | $(dir %(source))
1901         @$(ECHO) "Creating %(name) catalog source file %(source)"
1902         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1903 endif
1906 %(mmake)-clean ::
1907         $(RM) $(BD_OBJS) %(source)
1909 .PHONY: %(mmake) %(mmake)-clean
1911 %end
1912 #-----------------------------------------------------------------------------
1915 #-----------------------------------------------------------------------------
1916 # Build icons.
1917 # - mmake is the mmaketarget
1918 # - icons is a list of icon base names (ie. without the .info suffix)
1919 # - dir is the destination directory
1920 # - srcdir is where *.png and *.info.src are searched
1921 #-----------------------------------------------------------------------------
1923 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1925 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1928 %(mmake) : $(BD_OBJS)
1930 ifeq (%(image),)
1932 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1933         @$(ECHO) Creating $(notdir $@)...
1934         @$(ILBMTOICON) $+ $@
1936 else
1938 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1939         @$(ECHO) Creating $(notdir $@)...
1940         @$(ILBMTOICON) $+ $@
1942 endif
1944 $(BD_OBJS) : | %(dir)
1945 GLOB_MKDIRS += %(dir)
1947 %(mmake)-clean : FILES := $(BD_OBJS)
1949 %(mmake)-clean ::
1950         @$(RM) $(FILES)
1952 .PHONY: %(mmake) %(mmake)-clean
1954 %end
1955 #-----------------------------------------------------------------------------
1958 #------------------------------------------------------------------------------
1959 # Compile files for an arch-specific replacement of code for a module
1960 # - files: the basenames of the C files to compile.
1961 # - asmfiles: the basenames of the asm files to assemble.
1962 # - mainmmake: the mmake of the module in the main directory to compile these
1963 #   arch specific files for.
1964 # - maindir: the object directory for the main module
1965 # - arch: the arch for which to compile these files. It can have the form
1966 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1967 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1968 # - dflags: the flags used during creation of dependency file. If not specified
1969 #   the same value as cflags will be used
1970 # - aflags: the flags used during assembling
1971 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1972 #   the target compiler is used
1973 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1974 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1976 ifeq (%(files) %(asmfiles),)
1977   $(error no files or asmfiles given)
1978 endif
1980 %buildid targets="%(mainmmake)-%(arch)"
1982 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1983 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1984 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1985 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1986 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1987 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1988 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1989 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1990 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1991 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1992 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1993 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1994 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1995 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1996 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1998 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2000 ifeq (%(arch),)
2001   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
2002 endif
2004 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2005 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2006 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2007 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2008 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2010 ifeq ($(TARGET),%(mainmmake)-%(arch))
2011 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2012 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2013 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2014 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2015 endif
2017 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2018 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2021 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2023 ifeq ($(findstring %(compiler),host kernel target),)
2024   $(error unknown compiler %(compiler))
2025 endif
2026 ifeq (%(compiler),target)
2027 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2028 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2029 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2030 endif
2031 ifeq (%(compiler),host)
2032 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2033 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2034 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2035 endif
2036 ifeq (%(compiler),kernel)
2037 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2038 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2039 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2040 endif
2041 ifneq (%(modulename),)
2042 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
2043                      -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2044 else
2045 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2046 endif
2047 ifeq ($(TARGET),%(mainmmake)-%(arch))
2048 $(BD_OBJDIR$(BDID))/%.o : %.c
2049         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2050 endif
2052 ifeq (%(dflags),)
2053 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
2054 else
2055 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2056 endif
2057 ifeq ($(TARGET),%(mainmmake)-%(arch))
2058 $(BD_OBJDIR$(BDID))/%.d : %.c
2059         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2060 endif
2062 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2064 ifeq ($(TARGET),%(mainmmake)-%(arch))
2065 $(BD_OBJDIR$(BDID))/%.o : %.s
2066         %assemble_q opt=$(AFLAGS)
2067 $(BD_OBJDIR$(BDID))/%.o : %.S
2068         %assemble_q opt=$(AFLAGS)
2069 endif
2071 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
2072 %end
2073 #------------------------------------------------------------------------------
2076 #------------------------------------------------------------------------------
2077 # generate asm files from c files (for debugging purposes)
2078 %define ctoasm_q
2079 %.s : %.c
2080         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2081         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2082 %end
2083 #------------------------------------------------------------------------------
2086 #------------------------------------------------------------------------------
2087 # Copy files from one directory to another.
2089 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2091 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2093 GLOB_MKDIRS += %(dst)
2095 .PHONY : %(mmake)
2098 %(mmake) : | %(dst) 
2099         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2101 %end
2102 #------------------------------------------------------------------------------
2105 #------------------------------------------------------------------------------
2106 # Copy a directory recursively to another place, preserving the original 
2107 # hierarchical structure
2109 # src: the source directory whose content will be copied
2110 # dst: the directory where to copy src's content. If not existing, it will be made.
2112 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2114 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2115 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
2116 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2118 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2119 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2121 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2123 .PHONY : %(mmake)
2126 %(mmake): | $(GENDIR)/$(CURDIR)
2127         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2128         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2129         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2130         for d in $(%(mmake)_DIRS); do                      \
2131             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2132         done
2133         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2134         for f in $(%(mmake)_FILES); do                                            \
2135             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2136         done;  \
2137         for dst in %(dst); do \
2138             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2139         done
2141 %end
2142 #------------------------------------------------------------------------------
2145 #------------------------------------------------------------------------------
2146 #   Copy include files into the includes directories. There are currently
2147 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2148 #   for building tools that need to run on the host system $(GENINCDIR). The
2149 #   $(GENINCDIR) path must not contain any references to the C runtime
2150 #   library header files.
2152 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2153     dir= compiler=target
2155 ifeq ($(findstring %(compiler),host kernel target),)
2156 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2157 endif
2159 ifneq (%(dir),)
2160 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
2161 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2162 else
2163 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2164 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2165 endif
2167 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2168         @$(CP) $< $@
2171 ifeq (%(compiler),target)
2173 ifneq (%(dir),)
2174 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
2175 else
2176 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2177 endif
2179 BD_INCL_FILES += $(BD_INCL_FILES2)
2181 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2182         @$(CP) $< $@
2183 endif
2186 %(mmake) : $(BD_INCL_FILES)
2188 .PHONY: %(mmake)
2190 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2191 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2192 %end
2193 #------------------------------------------------------------------------------
2196 #------------------------------------------------------------------------------
2197 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2198 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2199 STUBS_MEM := $(addsuffix .o,$(STUBS))
2200 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2201 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2202 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2204 #MM- linklibs : hidd-%(hidd)-stubs
2205 #MM- %(parenttarget): hidd-%(hidd)-stubs
2206 #MM hidd-%(hidd)-stubs : includes includes-copy
2207 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2209 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2210         %mklib_q from=$^
2212 $(STUBS_OBJ) : $(STUBS_SRC) 
2213         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2215 $(STUBS_DEP) : $(STUBS_SRC)
2216         %mkdepend_q flags=%(dflags)
2218 setup ::
2219         %mkdirs_q $(OBJDIR) $(LIBDIR)
2222 clean ::
2223         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2225 DEPS := $(DEPS) $(STUBS_DEP)
2227 %end
2228 #------------------------------------------------------------------------------
2231 #------------------------------------------------------------------------------
2232 # Build an imported source tree which uses the configure script from the
2233 # autoconf package.  This rule will try to "integrate" the produced files as
2234 # much as possible in the AROS build, for example by putting libraries in the
2235 # standard library directory, includes in the standard include directory, and
2236 # so on. You can however override this behaviour.
2238 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2239 # be %(bindir) (or its deduced value) when running "make install", and
2240 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2241 # configure script some more parameters whose value depends upon the PROGDIR
2242 # env var, so that the program gets all its stuff installed in the proper place
2243 # when building it, but when running it from inside AROS it can also find that
2244 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2245 # the configuration parameters set when running ./configure
2247 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2248 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2249 # to the name which has to follow it.
2252 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2253     aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
2254     install_target=install preconfigure= postconfigure= postinstall= \
2255     install_env=
2257 ifneq (%(prefix),)
2258     %(mmake)-prefix := %(prefix)
2259 else
2260     %(mmake)-prefix := $(AROS_CONTRIB)
2261 endif
2263 ifneq (%(aros_prefix),)
2264     %(mmake)-aros_prefix := %(aros_prefix)
2265 else
2266     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2267 endif
2269 ifeq (%(nix),yes)
2270     %(mmake)-nix    := -nix
2271     %(mmake)-volpfx := /
2272     %(mmake)-volsfx := /
2273     
2274     ifeq (%(nix_dir_layout),)
2275         %(mmake)-nix_dir_layout := yes
2276     endif
2277 else
2278     %(mmake)-volsfx := :
2279     
2280     ifeq (%(nix_dir_layout),)
2281         %(mmake)-nix_dir_layout := no
2282     endif
2283 endif
2285 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2287 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2288         exec_prefix=$(%(mmake)-prefix) %(install_env)
2290 # Check if chosen compiler is valid
2291 ifeq ($(findstring %(compiler),host target kernel),)
2292   $(error unknown compiler %(compiler))
2293 endif
2295 # Set legacy 'host' variable based on chosen compiler
2296 ifeq (%(compiler),host)
2297     host := yes
2298         ifeq (%(package),)
2299                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2300         else
2301                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2302         endif
2303 else
2304     host := no
2305         ifeq (%(package),)
2306                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2307         else
2308                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2309         endif
2310 endif
2312 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2313 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2315 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2316     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2317     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2318 else
2319     ifeq (%(nix),yes)
2320         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2321         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2322     else
2323         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2324     endif
2326     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2327     
2328     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2329         sbindir=$(%(mmake)-prefix) \
2330         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2331         oldincludedir=$(AROS_INCLUDES) %(install_env)
2332 endif
2335 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2337 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2339 # Using -j1 in install_command may result in a warning but finally
2340 # it does its job. make install for gcc does not work reliable for -jN
2341 # where N > 1.
2342 ifneq (%(install_target),)
2343     %(mmake)-install_command = \
2344         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2345         -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2346         $(TOUCH) $(%(mmake)-installflag)
2348     %(mmake)-uninstall_command = \
2349     $(RM) $(%(mmake)-installflag) && \
2350     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2351     -C $(%(mmake)-pkgdir) uninstall
2352 else
2353     %(mmake)-install_command   := true
2354     %(mmake)-uninstall_command := true
2355 endif
2357 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2360 %(mmake)-build_and_install-quick :  $(%(mmake)-configflag)
2361         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2362             $(RM)  $(%(mmake)-installflag) && \
2363             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2364             $(%(mmake)-install_command); \
2365         fi
2367 %(srcdir)/.files-touched:
2368         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2369         $(TOUCH) $@
2372 %(mmake)-uninstall :
2373         $(%(mmake)-uninstall_command)
2375 ifneq ($(DEBUG),yes)
2376     %(mmake)-s_flag = -s
2377 endif
2380 %(mmake)-configure : $(%(mmake)-configflag)
2382 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2383 ifeq (%(compiler),host)
2384 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2385         $(RM) $@ 
2386         %mkdirs_q $(%(mmake)-pkgdir)
2387         cd $(%(mmake)-pkgdir) && \
2388         find . -name config.cache -exec $(RM) '{}' \; && \
2389         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2390             TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2391             TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2392             $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2393             --target=$(AROS_TARGET_CPU)-aros && \
2394             $(TOUCH) $@
2395 endif
2396 ifeq (%(compiler),target)
2397 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2398         $(RM) $@
2399         %mkdirs_q $(%(mmake)-pkgdir)
2400         cd $(%(mmake)-pkgdir) && \
2401         find . -name config.cache -exec $(RM) '{}' \; && \
2402         CC="$(TARGET_CC) $(TARGET_CFLAGS) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2403             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2404             $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2405             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2406             --host=$(AROS_TARGET_CPU)-aros \
2407             --target=$(AROS_TARGET_CPU)-aros \
2408             --disable-nls \
2409             --without-x --without-pic --disable-shared && \
2410             $(TOUCH) $@
2411 endif
2412 ifeq (%(compiler),kernel)
2413 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2414         $(RM) $@
2415         %mkdirs_q $(%(mmake)-pkgdir)
2416         cd $(%(mmake)-pkgdir) && \
2417         find . -name config.cache -exec $(RM) '{}' \; && \
2418         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2419             AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2420             $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2421             --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2422             --host=$(AROS_TARGET_CPU)-aros \
2423             --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2424             --without-x --without-pic --disable-shared && \
2425             $(TOUCH) $@
2426 endif
2427         
2429 %(mmake)-clean : %(mmake)-uninstall
2430         @$(RM) $(%(mmake)-pkgdir)
2431 %end
2432 #------------------------------------------------------------------------------
2435 #------------------------------------------------------------------------------
2436 # Given an archive name, patches names and locations where to find them, fetch
2437 # the archive and the patches from any of those locations, unpack the archive
2438 # and then apply the patches.
2440 # Locations currently supported are http and ftp sites, plus local filesystem
2441 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2442 # the fetch.sh script needs to be modified, since this macro relies on that script.
2444 # Arguments:
2446 #     - mmake           = mmaketarget
2447 #     - archive_origins = list of locations where to find the archive. They are tried
2448 #                         in sequence, until the archive is found and fetching it 
2449 #                         succeeded. If not specified, the current directory is assumed.
2450 #     - archive         = the archive name. Mandatory.
2451 #     - suffixes        = a list of suffixes to append to the the package name plus the
2452 #                         version. Each one of them is tried until a matching archive is
2453 #                         found. They are appended to patches and these are tried the
2454 #                         same way as packages are.
2455 #     - location        = the local directory where to put the fetched archive and patches.
2456 #                         If not specified, the directory specified by destination is used.
2457 #     - destination     = the directory to unpack the archive to.
2458 #                         If not specified, the current directory is assumed.
2459 #     - patches_origins = list of locations where to find the patches. They are tried
2460 #                         in sequence, until a patch is found and fetching it 
2461 #                         succeeded. If not specified, the current directory is assumed.
2462 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2463 #                         patch_name[:[patch_subdir][:patch_opt]].
2465 #                             - patch_name   = the name of the patch file
2466 #                             - patch_subdir = the directory within \destination\ where to
2467 #                                              apply the patch.
2468 #                             - patch_opt    = any options to pass to the `patch' command
2469 #                                              when applying the patch.
2470 #                         
2471 #                         The patch_subdir and patch_opt fields are optional.
2473 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2474     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2476 .PHONY: %(mmake)
2478 ifneq (%(location),)
2479     %(mmake)-location := %(location)
2480 else
2481     %(mmake)-location := %(destination)
2482 endif
2485 %(mmake) :
2486         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2487         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2488 %end
2489 #------------------------------------------------------------------------------
2492 #------------------------------------------------------------------------------
2493 # Joins the features of %fetch and %build_with_configure, taking advantage of
2494 # the naming scheme of GNU packages. GNU packages names are in the form
2496 #     <package name>-<version number>.<archive format suffix>
2498 # If a patch is provided, it *must* be named the following way:
2500 #    <package name>-<version number>-aros.diff
2502 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2503 # CD'ing into the archive's extracted directory.
2505 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2506 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2507 # to make that patch fully comprehensive.
2509 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2511 # Arguments:
2513 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2514 #                     macro.
2515 #    - package      = the GNU package name, sans version and archive format suffixes.
2516 #    - version      = the package's version number, or otherwise any other version string.
2517 #                     It gets appended to the package name to form the basename of the archive.
2518 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2519 #                     version. Each one of them is tried until a matching archive is found.
2520 #                     Defaults to "tar.bz2 tar.gz".
2521 #    - destination  = same meaning as the one for the %fetch macro
2522 #    - location     = same meaning as the one for the %fetch macro
2523 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2524 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2525 #                     fetched or not
2526 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2527 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2528 #                     $(GNUDIR).
2529 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2530 #                     /GNU.
2531 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2532 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2533 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2535 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2536     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= \
2537     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2539 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2540 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2541 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2543 %(mmake)-archbase  := %(package)-%(version)
2545 ifeq (%(compiler),host)
2546     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2547 else
2548     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2549 endif
2551 ifeq (%(prefix),)
2552     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2553 else
2554     %(mmake)-prefix := %(prefix)
2555 endif
2557 ifneq (%(subpackage),)
2558     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2559 else
2560     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2561 endif
2563 ifneq (%(srcdir),)
2564     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2565 else
2566     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2567 endif
2569 ifeq (%(patch),yes)
2570     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2571 else
2572     %(mmake)-%(subpackage)-patches_specs := ::
2573 endif
2575 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2576     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2577     archive_origins=". %(package_repo)" \
2578     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2580 #MM- %(mmake) : %(mmake)-%(subpackage)
2582 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2584 %(mmake)-%(subpackage)-package-basename := \
2585     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2587 ifneq (%(create_pkg),no)
2588     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2589 endif
2591 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2592      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2593      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2594      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2595      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2597 .PHONY : %(mmake)-%(subpackage)-make-package
2598 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2601 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2603 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2604 #that $^ and $@ have exactly the same mtime, and in that case make tries
2605 #to rebuild $@ again, which would fail because the directory where
2606 #the package got installed would not exist anymore. 
2607 #We work this around by using an if statement to manually check the mtimes.
2608 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2609         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2610         $(RM) $@ ; \
2611         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2612         mkdir -p "$(DISTDIR)/Packages" ; \
2613         mkdir -p "$(%(mmake)-prefix)" ; \
2614         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2615         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2616         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2617     fi
2618 %end
2619 #------------------------------------------------------------------------------
2622 #------------------------------------------------------------------------------
2623 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2624     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2625     aros_prefix=/GNU extraoptions= preconfigure= postconfigure= postinstall= 
2627 GNU_REPOSITORY := gnu://
2629 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2630     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2631     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2632     patch="%(patch)" patch_repo="%(patch_repo)" \
2633     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2634     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2636 %end
2637 #------------------------------------------------------------------------------
2640 #------------------------------------------------------------------------------
2641 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2642 # that the package is a "Development" package, and as such it needs to be placed
2643 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2645 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2646 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2647 # "mmake" argument, because the metatarget is implicitely defined as
2649 #     #MM- development-%(package)
2651 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2652     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2653     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= 
2655 #MM- development : development-%(package)
2658 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2659    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2660    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2661    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2662    extraoptions="%(extraoptions)"
2663     
2664 %end
2665 #------------------------------------------------------------------------------