- Set a default PCM volume so that something can be heard when driver is
[AROS.git] / config / make.tmpl
blob08ee205aac9a84fc0e92babeed82b254f9f1cf47
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling %(from)"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56         @$(ECHO) "Linking %(to)..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         %(strip) %(to)
70 %end
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building $(notdir $@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating library %(to)..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
121 %end
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128         @$(FOR) dir in %(dirs) ; do \
129             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
130         done
131 %end
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
137 ##                                                                         ##
138 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
139 ## mmakefile. They consist of one or more full makefile rules.             ##
140 ## In general the files generated in these macros are also defined as      ##
141 ## make targets so that they can be used as a dependency in other rules    ##
142 ##                                                                         ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
149 BDID := $(BDID)_
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
152 endif
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
160 %(to) : %(from)
161         @$(CP) $< $@
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
170 # present.
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
174         @$(CP) $< $@
175 %end
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by 
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186     stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196         @for f in $(FILES); do \
197              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
199              fi ; \
200         done
201         @$(TOUCH) $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
208 # be displayed.
209 # Restriction: at the moment when using a non-empty target dir %(from) may
210 # not have 
211 %define rule_join to=/A from=/A text=
213 %(to) : %(from)
214 ifneq (%(text),)
215         @$(ECHO) %(text)
216 endif
217         @$(CAT) $^ >$@
218 %end
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean 
227 %define include_deps deps=$(DEPS)/M  depstargets=
228 ifneq (%(deps),)
229   ifneq (%(depstargets),)
230     ifneq ($(findstring $(TARGET),%(depstargets)),)
231       -include %(deps)
232     endif
233   else
234     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
235       -include %(deps)
236     endif
237   endif
238 endif
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default. 
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
252 %end
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
261 # options
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 #   the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 #   it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
270 ifeq (%(targetdir),)
271   TMP_TARGETBASE := %(basename)
272 else
273   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
274 endif
276 ifeq ($(findstring %(compiler),host kernel target),)
277   $(error unknown compiler %(compiler))
278 endif
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 endif
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 endif
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 endif
304 ifeq (%(nix),yes)
305   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
306 else
307   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
308 endif
309 $(TMP_TARGETBASE).o : %(basename).c
310         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
312 ifeq (%(dflags),)
313   ifeq (%(nix),yes)
314     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
315   else
316     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317   endif
318 else
319   ifeq (%(nix),yes)
320     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
321   else
322     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
323   endif
324 endif
325 $(TMP_TARGETBASE).d : %(basename).c
326         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
327 %end
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile multiple C source files to an object file and
333 # generate the corresponding dependency files. The generated file will be put
334 # in the object directory without the directory part of the source file.
335 # options
336 # - basenames: the basenames of the files to compile. The names may include
337 #   relative or absolute path names. No wildcard is allowed
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 #   the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 #   it is put in the same directory as the .c file. When targetdir is not
343 #   empty, path names will be stripped from the file names so that all files
344 #   are in that dir and not in subdirectories.
345 # - compiler (default target): compiler to use, target, kernel or host
346 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
347     compiler=target
349 ifeq (%(targetdir),)
350 TMP_TARGETS := $(addsuffix .o,%(basenames))
351 TMP_DTARGETS := $(addsuffix .d,%(basenames))
352 TMP_WILDCARD := %
353 else
354 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
355 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
356 TMP_WILDCARD := %(targetdir)/%
358 # Be sure that all .c files are generated
359 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
361 # Be sure that all .c files are found
362 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
363 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
364 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
365 ifneq ($(TMP_DIRS),)
366     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
367     vpath %.c $(TMP_DIRS)
368 endif
370 endif
372 ifeq ($(findstring %(compiler),host kernel target),)
373   $(error unknown compiler %(compiler))
374 endif
375 ifeq (%(compiler),target)
376 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
377 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
378 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
379 endif
380 ifeq (%(compiler),host)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
382 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
384 endif
385 ifeq (%(compiler),kernel)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
387 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
388 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETS) : CFLAGS := %(cflags)
392 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
393         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
397 else
398 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
399 endif
400 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
401         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
402 %end
403 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407 # Make an alias from one arch specific build to another arch.
408 # arguments:
409 # - mainmmake: the mmake of the module in the main tree
410 # - arch: the current arch
411 # - alias: the alias to which this should point
412 %define rule_archalias mainmmake=\A arch=\A alias=\A
414 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
415 %end
416 #------------------------------------------------------------------------------
419 #------------------------------------------------------------------------------
420 # Generate a rule to compile a C source file to a shared object file with a
421 # .so suffix. Basename may contain a directory part, then the source
422 # file has to be in that directory. The generated file will be put in the
423 # object directory without the directory.
424 # options
425 # - basename: the basename of the file to compile. Use % for a wildcard rule
426 # - cflags (default $(CFLAGS)): the C flags to use for compilation
427 # - targetdir: the directory to put the .o file and the .d file. By default
428 #   it is put in the same directory as the .c file
429 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
431 ifeq (%(targetdir),)
432   TMP_TARGETBASE := %(basename)
433 else
434   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
435 endif
437 ifeq ($(findstring %(compiler),host kernel target),)
438   $(error unknown compiler %(compiler))
439 endif
440 ifeq (%(compiler),target)
441 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
442 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
443 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
444 endif
445 ifeq (%(compiler),host)
446 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
447 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
448 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
449 endif
450 ifeq (%(compiler),kernel)
451 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
452 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
453 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
454 endif
456 $(TMP_TARGETBASE).so : %(basename).c
457         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
458 %end
459 #------------------------------------------------------------------------------
462 #------------------------------------------------------------------------------
463 # Generate a rule to assemble a source file to an object file. Basename may
464 # contain a directory part, then the source file has to be in that directory.
465 # The generated file will be put in the object directory without the directory.
466 # options
467 # - basename: the basename of the file to compile. Use % for a wildcard rule
468 # - flags (default $(AFLAGS)): the asm flags to use for assembling
469 # - targetdir: the directory to put the .o file in. By default it is put in the
470 #   same directory as the .s file
471 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
473 ifeq (%(targetdir),)
474 %(basename).o : AFLAGS := %(aflags)
475 %(basename).o : %(basename).s
476         %assemble_q
477 %(basename).o : %(basename).S
478         %assemble_q
480 else
481 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
482 %(targetdir)/$(notdir %(basename)).o : %(basename).s
483         %assemble_q
484 %(targetdir)/$(notdir %(basename)).o : %(basename).S
485         %assemble_q
487 endif
488 %end
489 #------------------------------------------------------------------------------
492 #------------------------------------------------------------------------------
493 # Generate a rule to assemble multiple source files to an object file. The
494 # generated file will be put in the object directory with the directory part
495 # of the source file stripped off.
496 # options
497 # - basenames: the basenames of the files to compile. The names may include
498 #   relative or absolute path names. No wildcard is allowed
499 # - aflags (default $(AFLAGS)): the flags to use for assembly
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 #   it is put in the same directory as the .c file. When targetdir is not
502 #   empty, path names will be stripped from the file names so that all files
503 #   are in that dir and not in subdirectories.
504 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
506 ifeq (%(targetdir),)
507 TMP_TARGETS := $(addsuffix .o,%(basenames))
508 TMP_WILDCARD := %
509 else
510 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
511 TMP_WILDCARD := %(targetdir)/%
513 # Be sure that all .s files are generated
514 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
516 # Be sure that all .c files are found
517 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
518 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
519 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
520 ifneq ($(TMP_DIRS),)
521     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
522     vpath %%(suffix) $(TMP_DIRS)
523 endif
525 endif
527 ifeq ($(findstring %(compiler),host kernel target),)
528   $(error unknown compiler %(compiler))
529 endif
530 ifeq (%(compiler),target)
531 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
532 endif
533 ifeq (%(compiler),host)
534 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
535 endif
536 ifeq (%(compiler),kernel)
537 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
538 endif
540 $(TMP_TARGETS) : AFLAGS := %(aflags)
541 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
542         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
543 %end
544 #------------------------------------------------------------------------------
547 #------------------------------------------------------------------------------
548 # Link %(objs) to %(prog) using the libraries in %(uselibs)
549 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
550     usehostlibs= usestartup=yes detach=no nix=no linker=target
552 TMP_EXTRA_LDFLAGS := 
553 ifeq (%(nix),yes)
554     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
555 endif
556 ifeq (%(usestartup),no)
557     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
558 endif
559 ifeq (%(detach),yes)
560     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
561 endif
563 # Make a list of the lib files this program depends on.
564 ifneq (%(uselibs),)
565 # In LDFLAGS remove white space between -L and directory
566 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
567 # Filter out only the libdirs and remove -L
568 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
569 # Add trailing /
570 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
571 # Add normal linklib path
572 TMP_DIRS += $(LIBDIR)/
573 # add lib and .a to static linklib names
574 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
575 # search for the linklibs in the given path, ignore ones not found
576 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
577     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
579 else
580 TMP_DEPLIBS :=
581 endif
583 ifeq (%(linker),target)
584 %(prog) : CMD:=$(TARGET_CC)
585 %(prog) : STRIPCMD:=$(TARGET_STRIP)
586 endif
587 ifeq (%(linker),host)
588 %(prog) : CMD:=$(HOST_CC)
589 %(prog) : STRIPCMD:=$(HOST_STRIP)
590 endif
591 ifeq (%(linker),kernel)
592 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
593 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
594 endif
596 %(prog) : OBJS := %(objs)
597 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
598 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
599 %(prog) : %(objs) $(TMP_DEPLIBS)
600         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
601 %end
602 #------------------------------------------------------------------------------
605 #------------------------------------------------------------------------------
606 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
607 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
608 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
609     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
610     usestartup=yes detach=no
612 TMP_EXTRA_LDFLAGS := 
613 ifeq (%(nix),yes)
614     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
615 endif
616 ifeq (%(usestartup),no)
617     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
618 endif
619 ifeq (%(detach),yes)
620     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
621 endif
623 # Make a list of the lib files the programs depend on.
624 ifneq (%(uselibs),)
625 # In LDFLAGS remove white space between -L and directory
626 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
627 # Filter out only the libdirs and remove -L
628 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
629 # Add trailing /
630 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
631 # Add normal linklib path
632 TMP_DIRS += $(LIBDIR)/lib/
633 # add lib and .a to static linklib names
634 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
635 # search for the linklibs in the given path, ignore ones not found
636 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
637     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
639 else
640 TMP_DEPLIBS :=
641 endif
643 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
644 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
645 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
646         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
647 %end
648 #------------------------------------------------------------------------------
651 #------------------------------------------------------------------------------
652 # Link the %(objs) to the library %(libdir)/lib%(libname).a
653 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
655 %(libdir)/lib%(libname).a : %(objs)
656         %mklib_q from=$^
657 %end
658 #------------------------------------------------------------------------------
661 #------------------------------------------------------------------------------
662 # Link the %(objs) to the library %(libdir)/lib%(libname).so
663 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
665 %(libdir)/lib%(libname).so : %(objs)
666         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
667 %end
668 #------------------------------------------------------------------------------
671 #------------------------------------------------------------------------------
672 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
673 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
674 # The -noarosc flag is added so that modules are not linked with arosc.library
675 # (see /config/specs.in file)
676 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
677     uselibs= usehostlibs=
679 %(module) : OBJS := %(objs)
680 %(module) : ENDTAG := %(endobj)
681 %(module) : ERR := %(err)
682 %(module) : OBJDIR := %(objdir)
683 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
685 TMP_DEPLIBS  := $(addprefix lib,$(addsuffix .a, %(uselibs) autoinit libinit))
686 TMP_LDFLAGS  :=
687 USER_DEPLIBS :=
689 ifneq ($(USER_LIBDIR),)
690     ALL_USERLIBS := $(notdir $(wildcard $(USER_LIBDIR)/lib*.a))
691     USER_DEPLIBS := $(addprefix $(USER_LIBDIR)/, $(filter $(ALL_USERLIBS),$(TMP_DEPLIBS)))
692     TMP_DEPLIBS  := $(filter-out $(ALL_USERLIBS),$(TMP_DEPLIBS))
693     TMP_LDFLAGS  := -L$(USER_LIBDIR)
694 endif
696 TMP_DEPLIBS := $(addprefix $(LIBDIR)/, $(TMP_DEPLIBS))
698 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
699         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) $(TMP_LDFLAGS) -noarosc"
701 %end
702 #------------------------------------------------------------------------------
705 #------------------------------------------------------------------------------
706 # Generate the libdefs.h include file for a module.
707 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
709 TMP_TARGET := %(modname)_libdefs.h
710 TMP_DEPS := $(GENMODULE)
711 TMP_OPTS := 
712 ifneq (%(conffile),)
713     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
714     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
715 else
716     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
717     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
718 endif
719 ifneq (%(modsuffix),)
720     TMP_OPTS += -s %(modsuffix)
721 endif
722 ifneq (%(targetdir),)
723     TMP_OPTS += -d %(targetdir)
724     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
725 endif
727 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
728 $(TMP_TARGET) : MODNAME := %(modname)
729 $(TMP_TARGET) : MODTYPE := %(modtype)
730 $(TMP_TARGET) : $(TMP_DEPS)
731         @$(ECHO) "Generating $(notdir $@)"
732         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
733 %end
734 #------------------------------------------------------------------------------
737 #------------------------------------------------------------------------------
738 # Generate a Makefile.%(modname) with the genmodule program and include this
739 # generated file in this Makefile
740 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
741     targetdir=
743 TMP_TARGET := Makefile.%(modname)
744 TMP_DEPS := $(GENMODULE)
745 TMP_OPTS := 
746 ifneq (%(conffile),)
747     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
748     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
749 else
750     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
751     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
752 endif
753 ifneq (%(modsuffix),)
754     TMP_OPTS += -s %(modsuffix)
755 endif
756 ifneq (%(targetdir),)
757     TMP_OPTS += -d %(targetdir)
758     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
759 endif
761 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
762 $(TMP_TARGET) : MODNAME := %(modname)
763 $(TMP_TARGET) : MODTYPE := %(modtype)
764 $(TMP_TARGET) : $(TMP_DEPS)
765         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
766 %end
767 #------------------------------------------------------------------------------
770 #------------------------------------------------------------------------------
771 # Generate the support files for compiling a module. This includes include
772 # files and source files. This rule has to be preceeded by
773 # %rule_genmodule_makefile
774 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
775     conffile=
777 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
778                $(%(modname)_LINKLIBFILES)
779 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
781 TMP_DEPS := $(GENMODULE)
782 TMP_OPTS :=
784 ifneq (%(conffile),)
785     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
786     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
787 else
788     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
789     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
790 endif
791 ifneq (%(modsuffix),)
792     TMP_OPTS += -s %(modsuffix)
793 endif
794 ifneq (%(targetdir),)
795     TMP_OPTS += -d %(targetdir)
796     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
797     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
798 endif
800 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
801 $(TMP_TARGETS) : MODNAME := %(modname)
802 $(TMP_TARGETS) : MODTYPE := %(modtype)
803 $(TMP_TARGETS) : $(TMP_DEPS)
804         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
805 ifneq (%(conffile),lib.conf)
806         @$(IF) $(TEST) -f lib.conf; then \
807           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
808         fi
809 endif
810         @$(IF) $(TEST) -f libdefs.h; then \
811           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
812         fi
813         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
814 %end
815 #------------------------------------------------------------------------------
818 #------------------------------------------------------------------------------
819 # Generate the support files for compiling a module. This includes include
820 # files and source files.
821 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
822     targetdir= conffile=
824 ifneq ($(%(modname)_INCLUDES),)
825 TMP_TARGETS := $(%(modname)_INCLUDES)
827 TMP_DEPS := $(GENMODULE)
828 TMP_OPTS :=
830 ifneq (%(conffile),)
831     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
832     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
833 else
834     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
835     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
836 endif
837 ifneq (%(modsuffix),)
838     TMP_OPTS += -s %(modsuffix)
839 endif
840 ifneq (%(targetdir),)
841     TMP_OPTS += -d %(targetdir)
842     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
843 endif
845 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
846 $(TMP_TARGETS) : MODNAME := %(modname)
847 $(TMP_TARGETS) : MODTYPE := %(modtype)
848 $(TMP_TARGETS) : $(TMP_DEPS)
849         @$(ECHO) "Generating include files"
850         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
851 endif
852 %end
853 #------------------------------------------------------------------------------
856 #------------------------------------------------------------------------------
857 # Common rules for all makefiles
858 %define common
859 # Delete generated makefiles
861 clean ::
862         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
864 include $(SRCDIR)/config/make.tail
866 BDID := $(BDTARGETID)
867 %end
868 #------------------------------------------------------------------------------
869       
871 #############################################################################
872 #############################################################################
873 ##                                                                         ##
874 ## Here are the mmakefile build macros. These are macros that takes care   ##
875 ## of everything to go from the sources to the generated target. Also all  ##
876 ## intermediate files and directories that are needed are created by these ##
877 ## rules.                                                                  ##
878 ##                                                                         ##
879 #############################################################################
880 #############################################################################
882 #------------------------------------------------------------------------------
883 # Build a program
884 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
885     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
886     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
887     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
888     compiler=target srcdir=
890 .PHONY : %(mmake)
892 BD_PROGNAME  := %(progname)
893 BD_OBJDIR    := %(objdir)
894 BD_TARGETDIR := %(targetdir)
896 BD_FILES     := %(files)
897 BD_ASMFILES  := %(asmfiles)
899 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
900 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
901 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
903 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
904 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
906 BD_CFLAGS    := %(cflags)
907 BD_AFLAGS    := %(aflags)
908 BD_DFLAGS    := %(dflags)
909 BD_LDFLAGS   := %(ldflags)
912 %(mmake)-quick : %(mmake)
914 #MM %(mmake) : includes-generate-deps linklibs-core
915 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
917 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
918 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
919     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
920 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
921     aflags=$(BD_AFLAGS) compiler=%(compiler)
923 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
924     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
925     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
926     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
927     linker=%(compiler)
929 endif
931 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
933 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
934 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
935 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
937 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
939 %(mmake)-clean ::
940         @$(ECHO) "Cleaning up for metatarget %(mmake)"
941         @$(RM) $(FILES)
943 %end
944 #------------------------------------------------------------------------------
947 #------------------------------------------------------------------------------
948 # Build programs, for every C file an executable will be built with the same
949 # name as the C file
950 %define build_progs mmake=/A files=/A nix=no \
951     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
952     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
953     uselibs= usehostlibs= usestartup=yes detach=no
955 .PHONY : %(mmake)
957 BD_OBJDIR    := %(objdir)
958 BD_TARGETDIR := %(targetdir)
960 BD_FILES     := %(files)
961 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
962 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
963 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
965 BD_CFLAGS    := %(cflags)
966 BD_DFLAGS    := %(dflags)
967 BD_LDFLAGS   := %(ldflags)
970 %(mmake)-quick : %(mmake)
972 #MM %(mmake) : includes-generate-deps
973 %(mmake) : $(BD_EXES)
975 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
976 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
977     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
979 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
980     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
981     ldflags=$(BD_LDFLAGS) \
982     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
983     usestartup="%(usestartup)" detach="%(detach)"
985 endif
987 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
989 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
990 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
991 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
993 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
995 %(mmake)-clean ::
996         @$(ECHO) "Cleaning up for metatarget %(mmake)"
997         @$(RM) $(FILES)
999 %end
1000 #------------------------------------------------------------------------------
1003 #------------------------------------------------------------------------------
1004 # Build a module.
1005 # This is a bare version: It just compiles and links the given files. It is
1006 # assumed that all needed boiler plate code is in the files. This should only
1007 # be used for compiling external code. For AROS code use %build_module
1008 %define build_module_simple mmake=/A modname=/A modtype=/A \
1009     files="$(basename $(call WILDCARD, *.c))" \
1010     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1011     objdir=$(OBJDIR) moduledir= \
1012     uselibs= usehostlibs= compiler=target
1014 # Define metamake targets and their dependencies
1015 #MM %(mmake) : core-linklibs includes-generate-deps
1016 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1017 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1018 #MM %(mmake)-quick
1019 #MM %(mmake)-clean
1021 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1023 .PHONY : $(BD_ALLTARGETS)
1025 ifeq (%(modname),)
1026 $(error using %build_module_simple: modname may not be empty)
1027 endif
1028 ifeq (%(modtype),)
1029 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1030 endif
1032 # Default values for variables and arguments
1033 BD_DEFLINKLIBNAME := %(modname)
1034 BD_DEFDFLAGS := %(cflags)
1035 OBJDIR ?= $(GENDIR)/$(CURDIR)
1036 BD_MODDIR := %(moduledir)
1037 ifeq ($(BD_MODDIR),)
1038   ifeq (%(modtype),library)
1039     BD_MODDIR  := $(AROS_LIBS)
1040   endif
1041   ifeq (%(modtype),gadget)
1042     BD_MODDIR  := $(AROS_GADGETS)
1043   endif
1044   ifeq (%(modtype),datatype)
1045     BD_MODDIR  := $(AROS_DATATYPES)
1046   endif
1047   ifeq (%(modtype),handler)
1048     BD_MODDIR  := $(AROS_FS)
1049   endif
1050   ifeq (%(modtype),device)
1051     BD_MODDIR  := $(AROS_DEVS)
1052   endif
1053   ifeq (%(modtype),resource)
1054     BD_MODDIR  := $(AROS_RESOURCES)
1055   endif
1056   ifeq (%(modtype),hook)
1057     BD_MODDIR  := $(AROS_RESOURCES)
1058   endif
1059   ifeq (%(modtype),mui)
1060     BD_MODDIR  := $(AROS_CLASSES)/Zune
1061   endif
1062   ifeq (%(modtype),mcc)
1063     BD_MODDIR  := $(AROS_CLASSES)/Zune
1064   endif
1065   ifeq (%(modtype),mcp)
1066     BD_MODDIR  := $(AROS_CLASSES)/Zune
1067   endif
1068   ifeq (%(modtype),usbclass)
1069     BD_MODDIR  := $(AROS_CLASSES)/USB
1070   endif
1071   ifeq (%(modtype),hidd)
1072     BD_MODDIR  := $(AROS_DRIVERS)
1073   endif
1074 endif
1075 ifeq ($(BD_MODDIR),)
1076   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1077 endif
1079 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1080 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1081 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1083 %rule_compile_multi \
1084     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1085     cflags="%(cflags)" dflags="%(dflags)" \
1086     compiler=%(compiler)
1088 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1089 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1090 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1092 %(mmake)-quick : %(mmake)
1093 %(mmake)       : $(BD_MODULE)
1094 %(mmake)-pkg   : $(BD_PKGMOD)
1095 %(mmake)-kobj  : $(BD_KOBJ)
1097 # The module is linked from all the compiled .o files
1098 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1100 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1101                  endobj= err=%(modname).err objdir=%(objdir) \
1102                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1104 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1105                  endobj= err=%(modname).err objdir=%(objdir) \
1106                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1108 # Link kernel object file
1109 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1111 # Make these symbols local
1112 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1113             UtilityBase ExpansionBase KeymapBase KernelBase
1115 BD_SYMBOLS := $(BD_KBASE)
1117 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1118 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1119 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1120 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1121 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1122         @$(ECHO) "Linking $@"
1123         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1124         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1127 ## Dependency fine-tuning
1129 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1130 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1132 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1133 $(BD_MODULE) : | $(BD_MODDIR)
1134 $(BD_KOBJ) : | $(KOBJSDIR)
1135 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1137 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1138 %(mmake)-clean ::
1139         @$(ECHO) "Cleaning up for module %(modname)"
1140         @$(RM) $(FILES)
1141 %end
1142 #------------------------------------------------------------------------------
1145 #------------------------------------------------------------------------------
1146 # Build a module
1147 # Explanation of this macro is done in the developer's manual
1148 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1149   conffile= files="$(basename $(call WILDCARD, *.c))" \
1150   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1151   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1152   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1153   compiler=target
1155 # Define metamake targets and their dependencies
1156 #MM- includes-all : %(mmake)-includes
1157 #MM %(mmake) : %(mmake)-includes core-linklibs
1158 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1159 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1160 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1161 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1162 #MM %(mmake)-linklib : %(mmake)-includes
1163 #MM %(mmake)-quick : %(mmake)-includes-quick
1164 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1165 #MM     includes-generate-deps
1166 #MM %(mmake)-includes-quick
1167 #MM %(mmake)-includes-dirs
1168 #MM %(mmake)-makefile
1169 #MM %(mmake)-clean
1171 # All MetaMake targets defined by this macro
1172 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1173     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1174     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick %(mmake)-linklib
1176 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1178 ifeq (%(modname),)
1179 $(error using %build_module: modname may not be empty)
1180 endif
1181 ifeq (%(modtype),)
1182 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1183 endif
1185 # Default values for variables and arguments
1186 BD_DEFLINKLIBNAME := %(modname)
1187 BD_DEFDFLAGS := %(cflags)
1188 OBJDIR ?= $(GENDIR)/$(CURDIR)
1190 ## Create genmodule include Makefile for the module
1192 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1194 %rule_genmodule_makefile \
1195     modname=%(modname) modtype=%(modtype) \
1196     modsuffix=%(modsuffix) targetdir=%(objdir) \
1197     conffile=%(conffile)
1199 %(objdir)/Makefile.%(modname) : | %(objdir)
1201 GLOB_MKDIRS += %(objdir)
1203 # Do not parse these statements if metatarget is not appropriate
1204 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1206 include %(objdir)/Makefile.%(modname)
1208 BD_DEFMODDIR := $(%(modname)_MODDIR)
1211 ## include files generation
1213 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1214 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1215 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1217 %(mmake)-includes-quick : %(mmake)-includes
1218 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1219     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1220     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1222 ifneq ($(%(modname)_INCLUDES),)
1223 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1224                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1225                          conffile=%(conffile)
1227 %rule_copy_diff_multi \
1228     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1229     stampfile=%(objdir)/%(modname)_geninc
1231 %rule_copy_diff_multi \
1232     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1233     stampfile=%(objdir)/%(modname)_incs
1235 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1237 TMP%(modname)_INCDIRS := \
1238     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1239     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1240     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1241 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1243 endif
1245 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1246                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1247                            conffile=%(conffile)
1249 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1250 $(BD_DEFLIBDEFSINC) :
1251         @$(ECHO) "generating $@"
1252         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1254 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1255 GLOB_MKDIRS += %(objdir)/include
1257 ## Extra genmodule src files generation
1258 ## 
1259 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1260                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1261                       conffile=%(conffile)
1263 ## Compilation
1265 BD_FILES      := %(files)
1266 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1267 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1268 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1270 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1271 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1272 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1274 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1275 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1277 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1278 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1279 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1280     BD_LINKLIB :=
1281 else
1282     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1283 endif
1284 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1286 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1287 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) 
1289 %rule_compile_multi \
1290     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1291     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1292     compiler=%(compiler)
1293 %rule_compile_multi \
1294     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1295     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1296     compiler=%(compiler)
1298 ifneq ($(BD_LINKLIBAFILES),)
1299 %rule_assemble_multi \
1300     basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1301 endif
1303 ## Linking
1305 ifeq (%(modsuffix),)
1306 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modtype)
1307 BD_PKGMOD    := $(PKGDIR)/%(modname).%(modtype)
1308 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modtype).o
1309 else
1310 BD_MODULE    := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1311 BD_PKGMOD    := $(PKGDIR)/%(modname).%(modsuffix)
1312 BD_KOBJ      := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1313 endif
1315 %(mmake)-quick      : %(mmake)
1316 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB)
1317 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB)
1318 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB)
1319 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB)
1320 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1321 %(mmake)-linklib    : $(BD_LINKLIB)
1323 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1324                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1325 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1326 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1327 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1328                  %(linklibobjs)
1330 # The module is linked from all the compiled .o files
1331 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1332                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1333                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1335 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1336                  endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1337                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1339 # Link static lib
1340 ifneq ($(BD_LINKLIB),)
1341 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1343 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1344 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1345 endif
1347 # Link kernel object file
1348 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1350 # Make these symbols local
1351 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1352             UtilityBase ExpansionBase KeymapBase KernelBase
1354 BD_SYMBOLS := $(BD_KBASE)
1356 ifeq ($(USER_LIBDIR),)
1357 $(BD_KOBJ) : TMP_LDFLAGS :=
1358 else
1359 $(BD_KOBJ) : TMP_LDFLAGS := -L$(USER_LIBDIR)
1360 endif
1362 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1363 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1364 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1365 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1366 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1367         @$(ECHO) "Linking $@"
1368         @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(TMP_LDFLAGS) $(addprefix -l,$(LINKLIBS))
1369         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1371 ## Dependency fine-tuning
1373 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1374 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1376 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1377 $(BD_MODULE) : | %(prefix)/%(moduledir)
1378 $(BD_PKGMOD) : | $(PKGDIR)
1379 $(BD_KOBJ)   : | $(KOBJSDIR)
1380 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1382 # Some include files need to be generated before the .c can be parsed.
1383 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1385 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1386     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1387 $(BD_DEPS) : $(BD_DFILE_DEPS)
1388 endif
1390 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1391     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1392     %(objdir)/Makefile.%(modname) \
1393     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1394     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1395     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1396     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1397     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1398     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1399     $(BD_ENDOBJS)
1400 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1401 %(mmake)-clean ::
1402         @$(ECHO) "Cleaning up for module %(modname)"
1403         @$(RM) $(FILES)
1405 endif # $(TARGET) in $(BD_ALLTARGETS)
1406 %end
1407 #------------------------------------------------------------------------------
1410 #------------------------------------------------------------------------------
1411 # Build a module skeleton
1412 # This is a stripped-down version of build_module, it only creates include files,
1413 # but no actual object. This is used when for plugins or classes with the same
1414 # API, but no actual implementation here.
1415 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1416   conffile= \
1417   objdir=$(OBJDIR) prefix=$(AROSDIR)
1419 # Define metamake targets and their dependencies
1420 #MM- includes-all : %(mmake)-includes
1421 #MM %(mmake) : %(mmake)-includes core-linklibs
1422 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1423 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1424 #MM %(mmake)-linklib : %(mmake)-includes
1425 #MM %(mmake)-quick : %(mmake)-includes-quick
1426 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1427 #MM     includes-generate-deps
1428 #MM %(mmake)-includes-quick
1429 #MM %(mmake)-includes-dirs
1430 #MM %(mmake)-makefile
1431 #MM %(mmake)-clean
1433 # All MetaMake targets defined by this macro
1434 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1435     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1436     %(mmake)-kobj %(mmake)-pkg
1438 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1440 ifeq (%(modname),)
1441 $(error using %build_module_skeleton: modname may not be empty)
1442 endif
1443 ifeq (%(modtype),)
1444 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1445 endif
1447 # Default values for variables and arguments
1448 BD_DEFLINKLIBNAME := %(modname)
1449 BD_DEFDFLAGS := %(cflags)
1450 OBJDIR ?= $(GENDIR)/$(CURDIR)
1452 ## Create genmodule include Makefile for the module
1454 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1456 %rule_genmodule_makefile \
1457     modname=%(modname) modtype=%(modtype) \
1458     modsuffix=%(modsuffix) targetdir=%(objdir) \
1459     conffile=%(conffile)
1461 %(objdir)/Makefile.%(modname) : | %(objdir)
1463 GLOB_MKDIRS += %(objdir)
1465 # Do not parse these statements if metatarget is not appropriate
1466 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1468 include %(objdir)/Makefile.%(modname)
1470 BD_DEFMODDIR := $(%(modname)_MODDIR)
1473 ## include files generation
1475 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1476 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1477 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1479 %(mmake)-includes-quick : %(mmake)-includes
1480 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1481     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1482     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1484 ifneq ($(%(modname)_INCLUDES),)
1485 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1486                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1487                          conffile=%(conffile)
1489 %rule_copy_diff_multi \
1490     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1491     stampfile=%(objdir)/%(modname)_geninc
1493 %rule_copy_diff_multi \
1494     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1495     stampfile=%(objdir)/%(modname)_incs
1497 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1499 TMP%(modname)_INCDIRS := \
1500     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1501     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1502     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1503 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1505 endif
1507 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1508                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1509                            conffile=%(conffile)
1511 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1512 $(BD_DEFLIBDEFSINC) :
1513         @$(ECHO) "generating $@"
1514         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1516 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1517 GLOB_MKDIRS += %(objdir)/include
1519 ## Extra genmodule src files generation
1520 ## 
1521 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1522                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1523                       conffile=%(conffile)
1525 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1526     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1527     %(objdir)/Makefile.%(modname) \
1528     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1529     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1530     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1531     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1532     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1533     $(BD_DEFLIBDEFSINC)
1534 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1535 %(mmake)-clean ::
1536         @$(ECHO) "Cleaning up for module %(modname)"
1537         @$(RM) $(FILES)
1539 endif # $(TARGET) in $(BD_ALLTARGETS)
1540 %end
1541 #------------------------------------------------------------------------------
1544 #------------------------------------------------------------------------------
1545 # Build a linklib.
1546 # - mmake is the mmaketarget
1547 # - libname is the baselibname e.g. lib%(libname).a will be created
1548 # - files are the C source files to include in the lib. The list of files
1549 #   has to be given without the .c suffix
1550 # - asmfiles are the asm files to include in the lib. The list of files has to
1551 #   be given without the .s suffix
1552 # - objs additional object to link into the linklib. The objects have to be
1553 #   given with full absolute path and the .o suffix.
1554 # - cflags are the flags to compile the source (default $(CFLAGS))
1555 # - dflags are the flags use during makedepend (default equal to cflags)
1556 # - aflags are the flags use during assembling (default $(AFLAGS))
1557 # - objdir is where the .o are generated
1558 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1559 %define build_linklib mmake=/A libname=/A \
1560   files="$(basename $(call WILDCARD, *.c))" asmfiles=  objs= \
1561   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1563 # assign and generate the local variables used in this macro
1564 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1566 BD_FILES      := %(files)
1567 BD_ASMFILES   := %(asmfiles)
1569 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1570 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1571 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1573 BD_OBJS       := $(BD_ARCHOBJS) \
1574                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1575                  %(objs)
1576 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1578 BD_CFLAGS     := %(cflags)
1579 ifeq (%(dflags),)
1580 BD_DFLAGS     := $(BD_CFLAGS)
1581 else
1582 BD_DFLAGS     := %(dflags)
1583 endif
1584 BD_AFLAGS     := %(aflags)
1586 BD_LINKLIB    := %(libdir)/lib%(libname).a
1588 .PHONY : %(mmake) %(mmake)-clean
1590 #MM %(mmake) : includes-generate-deps
1591 %(mmake) : $(BD_LINKLIB)
1594 %(mmake)-clean ::
1595         @$(RM) $(BD_OBJS) $(BD_DEPS)
1597 ifeq ($(TARGET),%(mmake))
1598 ifneq ($(dir $(BD_FILES)),./)
1599 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1600 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1601 endif
1603 %rule_compile basename=% targetdir=%(objdir) \
1604               cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1605 %rule_assemble basename=% targetdir=%(objdir) \
1606               aflags=$(BD_AFLAGS)
1607 endif
1609 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1611 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1613 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1614 $(BD_LINKLIB) : | %(libdir)
1615 GLOB_MKDIRS += %(objdir) %(libdir)
1617 %end
1618 #------------------------------------------------------------------------------
1621 #------------------------------------------------------------------------------
1622 # Build catalogs.
1623 # - mmake is the mmaketarget
1624 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1625 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1626 # - subdir is the destination subdirectory of the catalogs
1627 # - name is the name of the destination catalog, without the .catalog suffix
1628 # - source is the path to the generated source code file
1629 # - dir is the base destination directory (default $(AROS_CATALOGS))
1630 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1631 # - srcdir is the directory in which the *.cd and *.ct files are searched
1633 %define build_catalogs mmake=/A name=/A subdir=/A \
1634  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1635  sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1637 ifeq (%(description),)
1638 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1639 else
1640 BD_DESC := %(description)
1641 endif
1643 ifeq (%(catalogs),)
1644 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1645 else
1646 BD_LNGS := %(catalogs)
1647 endif
1649 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1650 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1653 %(mmake) : $(BD_OBJS) %(source)
1655 $(BD_OBJS) : | $(BD_DIRS)
1656 GLOB_MKDIRS += $(BD_DIRS)
1658 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1659         @$(ECHO) "Creating %(name) catalog for language $*."
1660         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1662 ifneq (%(source),)
1663 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1664 %(source) : $(BD_DESC).cd | $(dir %(source))
1665         @$(ECHO) "Creating %(name) catalog source file %(source)"
1666         @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1667 endif
1670 %(mmake)-clean ::
1671         $(RM) $(BD_OBJS) %(source)
1673 .PHONY: %(mmake) %(mmake)-clean
1675 %end
1676 #-----------------------------------------------------------------------------
1679 #-----------------------------------------------------------------------------
1680 # Build icons.
1681 # - mmake is the mmaketarget
1682 # - icons is a list of icon base names (ie. without the .info suffix)
1683 # - dir is the destination directory
1684 # - srcdir is where *.png and *.info.src are searched
1685 #-----------------------------------------------------------------------------
1687 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1689 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1692 %(mmake) : $(BD_OBJS)
1694 ifeq (%(image),)
1696 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1697         @$(ECHO) Creating $(notdir $@)...
1698         @$(ILBMTOICON) $+ $@
1700 else
1702 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1703         @$(ECHO) Creating $(notdir $@)...
1704         @$(ILBMTOICON) $+ $@
1706 endif
1708 $(BD_OBJS) : | %(dir)
1709 GLOB_MKDIRS += %(dir)
1711 %(mmake)-clean : FILES := $(BD_OBJS)
1713 %(mmake)-clean ::
1714         @$(RM) $(FILES)
1716 .PHONY: %(mmake) %(mmake)-clean
1718 %end
1719 #-----------------------------------------------------------------------------
1722 #------------------------------------------------------------------------------
1723 # Compile files for an arch-specific replacement of code for a module
1724 # - files: the basenames of the C files to compile.
1725 # - asmfiles: the basenames of the asm files to assemble.
1726 # - mainmmake: the mmake of the module in the main directory to compile these
1727 #   arch specific files for.
1728 # - maindir: the object directory for the main module
1729 # - arch: the arch for which to compile these files. It can have the form
1730 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1731 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1732 # - dflags: the flags used during creation of dependency file. If not specified
1733 #   the same value as cflags will be used
1734 # - aflags: the flags used during assembling
1735 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1736 #   the target compiler is used
1737 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1738 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1740 ifeq (%(files) %(asmfiles),)
1741   $(error no files or asmfiles given)
1742 endif
1744 %buildid targets="%(mainmmake)-%(arch)"
1746 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1747 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1748 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1749 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1750 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1751 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1752 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1753 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1754 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1755 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1756 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1757 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1758 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1759 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1760 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1761 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1762 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1763 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1764 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1765 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1766 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1768 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1770 ifeq (%(arch),)
1771   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1772 endif
1774 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1775 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1776 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1777 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1778 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1780 ifneq (%(modulename),)
1781 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1782 endif
1784 ifeq ($(TARGET),%(mainmmake)-%(arch))
1785 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1786 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1787 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1788 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1789 endif
1791 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1792 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1795 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1797 ifeq ($(findstring %(compiler),host kernel target),)
1798   $(error unknown compiler %(compiler))
1799 endif
1800 ifeq (%(compiler),target)
1801 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1802 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1803 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1804 endif
1805 ifeq (%(compiler),host)
1806 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1807 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1808 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1809 endif
1810 ifeq (%(compiler),kernel)
1811 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1812 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1813 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1814 endif
1815 ifneq (%(modulename),)
1816 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1817 else
1818 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1819 endif
1820 ifeq ($(TARGET),%(mainmmake)-%(arch))
1821 $(BD_OBJDIR$(BDID))/%.o : %.c
1822         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1823 endif
1825 ifeq (%(dflags),)
1826 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1827 else
1828 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1829 endif
1830 ifeq ($(TARGET),%(mainmmake)-%(arch))
1831 $(BD_OBJDIR$(BDID))/%.d : %.c
1832         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1833 endif
1835 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1837 ifeq ($(TARGET),%(mainmmake)-%(arch))
1838 $(BD_OBJDIR$(BDID))/%.o : %.s
1839         %assemble_q opt=$(AFLAGS)
1840 $(BD_OBJDIR$(BDID))/%.o : %.S
1841         %assemble_q opt=$(AFLAGS)
1842 endif
1844 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1845 %end
1846 #------------------------------------------------------------------------------
1849 #------------------------------------------------------------------------------
1850 # generate asm files from c files (for debugging purposes)
1851 %define ctoasm_q
1852 %.s : %.c
1853         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1854         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1855 %end
1856 #------------------------------------------------------------------------------
1859 #------------------------------------------------------------------------------
1860 # Copy files from one directory to another.
1862 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1864 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1866 GLOB_MKDIRS += %(dst)
1868 .PHONY : %(mmake)
1871 %(mmake) : | %(dst) 
1872         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1874 %end
1875 #------------------------------------------------------------------------------
1878 #------------------------------------------------------------------------------
1879 # Copy a directory recursively to another place, preserving the original 
1880 # hierarchical structure
1882 # src: the source directory whose content will be copied
1883 # dst: the directory where to copy src's content. If not existing, it will be made.
1885 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
1887 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1888 %(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)
1889 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
1891 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
1892 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
1894 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
1896 .PHONY : %(mmake)
1899 %(mmake): | $(GENDIR)/$(CURDIR)
1900         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1901         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1902         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1903         for d in $(%(mmake)_DIRS); do                      \
1904             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1905         done
1906         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1907         for f in $(%(mmake)_FILES); do                                            \
1908             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1909         done;  \
1910         for dst in %(dst); do \
1911             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1912         done
1914 %end
1915 #------------------------------------------------------------------------------
1918 #------------------------------------------------------------------------------
1919 #   Copy include files into the includes directories. There are currently
1920 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1921 #   for building tools that need to run on the host system $(GENINCDIR). The
1922 #   $(GENINCDIR) path must not contain any references to the C runtime
1923 #   library header files.
1925 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1926     dir= compiler=target
1928 ifeq ($(findstring %(compiler),host kernel target),)
1929 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1930 endif
1932 ifneq (%(dir),)
1933 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
1934 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
1935 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1936 else
1937 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1938 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1939 endif
1941 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1942         @$(CP) $< $@
1945 ifeq (%(compiler),target)
1947 ifneq (%(dir),)
1948 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
1949 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
1950 else
1951 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1952 endif
1954 BD_INCL_FILES += $(BD_INCL_FILES2)
1956 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1957         @$(CP) $< $@
1958 endif
1961 %(mmake) : $(BD_INCL_FILES)
1963 .PHONY: %(mmake)
1965 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1966 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1967 %end
1968 #------------------------------------------------------------------------------
1971 #------------------------------------------------------------------------------
1972 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1973 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1974 STUBS_MEM := $(addsuffix .o,$(STUBS))
1975 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1976 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1977 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1979 #MM- linklibs : hidd-%(hidd)-stubs
1980 #MM- %(parenttarget): hidd-%(hidd)-stubs
1981 #MM hidd-%(hidd)-stubs : includes includes-copy
1982 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1984 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1985         %mklib_q from=$^
1987 $(STUBS_OBJ) : $(STUBS_SRC) 
1988         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
1990 $(STUBS_DEP) : $(STUBS_SRC)
1991         %mkdepend_q flags=%(dflags)
1993 setup ::
1994         %mkdirs_q $(OBJDIR) $(LIBDIR)
1997 clean ::
1998         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2000 DEPS := $(DEPS) $(STUBS_DEP)
2002 %end
2003 #------------------------------------------------------------------------------
2006 #------------------------------------------------------------------------------
2007 # Build an imported source tree which uses the configure script from the
2008 # autoconf package.  This rule will try to "integrate" the produced files as
2009 # much as possible in the AROS build, for example by putting libraries in the
2010 # standard library directory, includes in the standard include directory, and
2011 # so on. You can however override this behaviour.
2013 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2014 # be %(bindir) (or its deduced value) when running "make install", and
2015 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2016 # configure script some more parameters whose value depends upon the PROGDIR
2017 # env var, so that the program gets all its stuff installed in the proper place
2018 # when building it, but when running it from inside AROS it can also find that
2019 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2020 # the configuration parameters set when running ./configure
2022 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2023 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2024 # to the name which has to follow it.
2027 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2028     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2029     install_target=install preconfigure= postconfigure= postinstall= \
2030     install_env=
2032 ifneq (%(prefix),)
2033     %(mmake)-prefix := %(prefix)
2034 else
2035     %(mmake)-prefix := $(AROS_CONTRIB)
2036 endif
2038 ifneq (%(aros_prefix),)
2039     %(mmake)-aros_prefix := %(aros_prefix)
2040 else
2041     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2042 endif
2044 ifeq (%(nix),yes)
2045     %(mmake)-nix    := -nix
2046     %(mmake)-volpfx := /
2047     %(mmake)-volsfx := /
2048     
2049     ifeq (%(nix_dir_layout),)
2050         %(mmake)-nix_dir_layout := yes
2051     endif
2052 else
2053     %(mmake)-volsfx := :
2054     
2055     ifeq (%(nix_dir_layout),)
2056         %(mmake)-nix_dir_layout := no
2057     endif
2058 endif
2060 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2062 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2063         exec_prefix=$(%(mmake)-prefix) %(install_env)
2065 # Check if chosen compiler is valid
2066 ifeq ($(findstring %(compiler),host target kernel),)
2067   $(error unknown compiler %(compiler))
2068 endif
2070 # Set legacy 'host' variable based on chosen compiler
2071 ifeq (%(compiler),host)
2072     host := yes
2073         ifeq (%(package),)
2074                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2075         else
2076                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2077         endif
2078 else
2079     host := no
2080         ifeq (%(package),)
2081                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2082         else
2083                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2084         endif
2085 endif
2087 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2088 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2090 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2091     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2092     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2093 else
2094     ifeq (%(nix),yes)
2095         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2096         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2097     else
2098         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2099     endif
2101     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2102     
2103     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2104         sbindir=$(%(mmake)-prefix) \
2105         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2106         oldincludedir=$(AROS_INCLUDES) %(install_env)
2107 endif
2109 ifneq ($(DEBUG),yes)
2110     %(mmake)-s_flag = -s
2111 endif
2113 # Set up build environment, and options for configure script
2114 ifeq (%(compiler),host)
2115     COMPILER_ENV := \
2116         CC="$(HOST_CC) $(HOST_CFLAGS)" \
2117         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2118         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2119         TARGET_RANLIB="$(RANLIB)"
2120     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2121 endif
2122 ifeq (%(compiler),target)
2123     COMPILER_ENV := \
2124         CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2125         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2126         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2127         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2128         TARGET_RANLIB="$(RANLIB)"
2129     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2130         --host=$(AROS_TARGET_CPU)-aros\
2131         --target=$(AROS_TARGET_CPU)-aros\
2132         --disable-nls\
2133         --without-x --without-pic --disable-shared
2134 endif
2135 ifeq (%(compiler),kernel)
2136     COMPILER_ENV := \
2137         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2138         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2139         TARGET_RANLIB="$(RANLIB)"
2140     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2141         --host=$(AROS_TARGET_CPU)-aros\
2142         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2143         --without-x --without-pic --disable-shared
2144 endif
2147 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2149 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2151 # Using -j1 in install_command may result in a warning but finally
2152 # it does its job. make install for gcc does not work reliably for -jN
2153 # where N > 1.
2154 ifneq (%(install_target),)
2155     %(mmake)-install_command = \
2156         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2157         -C $(%(mmake)-pkgdir) %(install_target) -j1
2159     %(mmake)-uninstall_command = \
2160     $(RM) $(%(mmake)-installflag) && \
2161     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2162     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2163 else
2164     %(mmake)-install_command   := true
2165     %(mmake)-uninstall_command := true
2166 endif
2168 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2171 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2173 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2174         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2175             $(RM)  $(%(mmake)-installflag) && \
2176             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2177              -C $(%(mmake)-pkgdir) && \
2178             $(%(mmake)-install_command) && \
2179             $(TOUCH) $@ -r $^; \
2180         fi
2182 $(%(mmake)-pkgdir)/.files-touched:
2183         %mkdirs_q $(%(mmake)-pkgdir)
2184         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2185         $(TOUCH) $@
2188 %(mmake)-uninstall :
2189         $(%(mmake)-uninstall_command)
2192 %(mmake)-configure : $(%(mmake)-configflag)
2194 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2195 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2196         $(RM) $@
2197         %mkdirs_q $(%(mmake)-pkgdir)
2198         cd $(%(mmake)-pkgdir) && \
2199         find . -name config.cache -exec $(RM) '{}' \; && \
2200         $(COMPILER_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2201             %(extraoptions) && \
2202         $(TOUCH) $@
2205 %(mmake)-clean : %(mmake)-uninstall
2206         @$(RM) $(%(mmake)-pkgdir)
2207 %end
2208 #------------------------------------------------------------------------------
2211 #------------------------------------------------------------------------------
2212 # Given an archive name, patches names and locations where to find them, fetch
2213 # the archive and the patches from any of those locations, unpack the archive
2214 # and then apply the patches.
2216 # Locations currently supported are http and ftp sites, plus local filesystem
2217 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2218 # the fetch.sh script needs to be modified, since this macro relies on that script.
2220 # Arguments:
2222 #     - mmake           = mmaketarget
2223 #     - archive_origins = list of locations where to find the archive. They are tried
2224 #                         in sequence, until the archive is found and fetching it 
2225 #                         succeeded. If not specified, the current directory is assumed.
2226 #     - archive         = the archive name. Mandatory.
2227 #     - suffixes        = a list of suffixes to append to the the package name plus the
2228 #                         version. Each one of them is tried until a matching archive is
2229 #                         found. They are appended to patches and these are tried the
2230 #                         same way as packages are.
2231 #     - location        = the local directory where to put the fetched archive and patches.
2232 #                         If not specified, the directory specified by destination is used.
2233 #     - destination     = the directory to unpack the archive to.
2234 #                         If not specified, the current directory is assumed.
2235 #     - patches_origins = list of locations where to find the patches. They are tried
2236 #                         in sequence, until a patch is found and fetching it 
2237 #                         succeeded. If not specified, the current directory is assumed.
2238 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2239 #                         patch_name[:[patch_subdir][:patch_opt]].
2241 #                             - patch_name   = the name of the patch file
2242 #                             - patch_subdir = the directory within \destination\ where to
2243 #                                              apply the patch.
2244 #                             - patch_opt    = any options to pass to the `patch' command
2245 #                                              when applying the patch.
2246 #                         
2247 #                         The patch_subdir and patch_opt fields are optional.
2249 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2250     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2252 .PHONY: %(mmake)
2254 ifneq (%(location),)
2255     %(mmake)-location := %(location)
2256 else
2257     %(mmake)-location := %(destination)
2258 endif
2261 %(mmake) :
2262         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2263         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2264 %end
2265 #------------------------------------------------------------------------------
2268 #------------------------------------------------------------------------------
2269 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2270 # unpatched source tree and runs diff against this and a previously fetched and possibly
2271 # patched tree. Depending on what happens after patching during a normal build it might
2272 # give best results if the new patch is created directly after fetch.
2274 # Arguments:
2276 #     - mmake       = mmaketarget
2277 #     - archive     = archive base name
2278 #     - suffixes    = a list of suffixes to append to the the package name plus the
2279 #                     version. Each one of them is tried until a matching archive is
2280 #                     found.
2281 #     - destination = the directory to unpack the archive to.
2282 #     - excludes    = diff patterns to exclude files or directories from the patch
2284 %define create_patch mmake=/A archive=/A suffixes="tar.bz2 tar.gz" destination=/A excludes=
2286 .PHONY: %(mmake)
2288 ifneq (%(excludes),)
2289     %(mmake)-exclude := -X ./exclude.patterns
2290 endif
2293 %(mmake):
2294         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2295         $(MV) %(destination)/%(archive) %(destination)/tmp/%(archive).aros ; \
2296         cd %(destination)/tmp ; \
2297         $(FOR) f in %(excludes) ; do \
2298             $(ECHO) $$f >> ./exclude.patterns ; \
2299         done ; \
2300         diff -ruN $(%(mmake)-exclude) \
2301             %(archive) \
2302             %(archive).aros \
2303             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2304         $(MV) %(destination)/tmp/%(archive).aros %(destination)/%(archive) ; \
2305         $(RM) %(destination)/tmp
2306 %end
2307 #------------------------------------------------------------------------------
2310 #------------------------------------------------------------------------------
2311 # Joins the features of %fetch and %build_with_configure, taking advantage of
2312 # the naming scheme of GNU packages. GNU packages names are in the form
2314 #     <package name>-<version number>.<archive format suffix>
2316 # If a patch is provided, it *must* be named the following way:
2318 #    <package name>-<version number>-aros.diff
2320 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2321 # CD'ing into the archive's extracted directory.
2323 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2324 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2325 # to make that patch fully comprehensive.
2327 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2329 # Arguments:
2331 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2332 #                     macro.
2333 #    - package      = the GNU package name, sans version and archive format suffixes.
2334 #    - version      = the package's version number, or otherwise any other version string.
2335 #                     It gets appended to the package name to form the basename of the archive.
2336 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2337 #                     version. Each one of them is tried until a matching archive is found.
2338 #                     Defaults to "tar.bz2 tar.gz".
2339 #    - destination  = same meaning as the one for the %fetch macro
2340 #    - location     = same meaning as the one for the %fetch macro
2341 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2342 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2343 #                     fetched or not
2344 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2345 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2346 #                     $(GNUDIR).
2347 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2348 #                     /GNU.
2349 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2350 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2351 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2352 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2354 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2355     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2356     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2358 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2359 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2360 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2361 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2363 %(mmake)-archbase  := %(package)-%(version)
2365 ifeq (%(compiler),host)
2366     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2367 else
2368     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2369 endif
2371 ifeq (%(prefix),)
2372     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2373 else
2374     %(mmake)-prefix := %(prefix)
2375 endif
2377 ifneq (%(subpackage),)
2378     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2379 else
2380     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2381 endif
2383 ifneq (%(srcdir),)
2384     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2385 else
2386     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2387 endif
2389 ifeq (%(patch),yes)
2390     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
2391 else
2392     %(mmake)-%(subpackage)-patches_specs := ::
2393 endif
2395 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2396     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2397     archive_origins=". %(package_repo)" \
2398     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2400 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2401     archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" destination=$(%(mmake)-portdir)
2403 #MM- %(mmake) : %(mmake)-%(subpackage)
2405 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2407 %(mmake)-%(subpackage)-package-basename := \
2408     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2410 ifneq (%(create_pkg),no)
2411     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2412 endif
2414 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2415      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2416      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2417      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2418      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2420 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2421 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2424 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2426 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2427 #that $^ and $@ have exactly the same mtime, and in that case make tries
2428 #to rebuild $@ again, which would fail because the directory where
2429 #the package got installed would not exist anymore. 
2430 #We work this around by using an if statement to manually check the mtimes.
2431 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2432         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2433         $(RM) $@ ; \
2434         $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2435         mkdir -p "$(DISTDIR)/Packages" ; \
2436         mkdir -p "$(%(mmake)-prefix)" ; \
2437         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2438         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2439         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2440     fi
2441 %end
2442 #------------------------------------------------------------------------------
2445 #------------------------------------------------------------------------------
2446 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2447     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2448     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2450 GNU_REPOSITORY := gnu://
2452 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2453     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2454     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2455     patch="%(patch)" patch_repo="%(patch_repo)" \
2456     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2457     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2459 %end
2460 #------------------------------------------------------------------------------
2463 #------------------------------------------------------------------------------
2464 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2465 # that the package is a "Development" package, and as such it needs to be placed
2466 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2468 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2469 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2470 # "mmake" argument, because the metatarget is implicitely defined as
2472 #     #MM- development-%(package)
2474 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2475     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2476     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2478 #MM- development : development-%(package)
2481 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2482    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2483    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2484    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2485    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2486     
2487 %end
2488 #------------------------------------------------------------------------------
2490 # Builds a kickstart package in PKG format
2491 # mmake   - target name
2492 # file    - Destination file name with path
2493 # startup - The file which will be put first
2494 # Other arguments are self-explanatory
2496 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2498 PKG_CLASSES   := $(addsuffix .class, %(classes))
2499 PKG_DEVICES   := $(addsuffix .device, %(devs))
2500 PKG_HANDLERS  := $(addsuffix .handler, %(handlers))
2501 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2502 PKG_LIBS      := $(addsuffix .library, %(libs))
2503 PKG_RESOURCES := $(addsuffix .resource, %(res))
2505 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2506 PKG_DIR   := $(dir %(file))
2507 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2510 %(mmake) : %(file)
2513 %(mmake)-quick : %(file)
2515 %(file): $(PKG_DIR) $(PKG_DEPS)
2516         @$(ECHO) Packaging $@...
2517         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2519 GLOB_MKDIRS += $(PKG_DIR)
2521 %end
2522 #------------------------------------------------------------------------------
2524 # Links a kickstart module in ELF format
2525 # Arguments are similar to make_package
2527 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup= uselibs= map=
2529 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2530 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2531 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2532 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2533 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2534 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2536 ifeq (%(startup),)
2537     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2538 else
2539     KOBJ_STARTUP := %(startup)
2540 endif
2542 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2543 LDLIBS       := $(addprefix -l, %(uselibs))
2544 DEPDIRS      := $(dir %(file))
2545 DEPLIBS      := $(addprefix lib,$(addsuffix .a, %(uselibs)))
2546 USER_DEPLIBS :=
2547 TMP_LDFLAGS  := -L$(LIBDIR)
2549 ifneq ($(USER_LIBDIR),)
2550     ALL_USERLIBS := $(notdir $(wildcard $(USER_LIBDIR)/lib*.a))
2551     USER_DEPLIBS := $(addprefix $(USER_LIBDIR)/, $(filter $(ALL_USERLIBS),$(DEPLIBS)))
2552     DEPLIBS      := $(filter-out $(ALL_USERLIBS),$(DEPLIBS))
2553     TMP_LDFLAGS  := -L$(USER_LIBDIR) $(TMP_LDFLAGS)
2554 endif
2556 DEPLIBS := $(addprefix $(LIBDIR)/, $(DEPLIBS))
2558 ifneq (%(map),)
2559     TMP_LDFLAGS += $(GENMAP) %(map)
2560     DEPDIRS     += $(dir %(map))
2561 endif
2564 %(mmake) : %(file)
2567 %(mmake)-quick : %(file)
2569 %(file): $(KOBJS) $(DEPDIRS) $(DEPLIBS) $(USER_DEPLIBS)
2570         @$(ECHO) Linking $@...
2571         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(NOSTARTUP_LDFLAGS) $(TMP_LDFLAGS) $(LDLIBS)
2573 GLOB_MKDIRS += $(DEPDIRS)
2575 %end
2577 #------------------------------------------------------------------------------
2578 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2579 # 'start' is an optional starting address
2580 # 'ldflags' is optional additional flags for the linker
2581 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2583 BD_OUTDIR := $(dir %(file))
2584 BD_TMPDIR  := $(GENDIR)/$(CURDIR)
2586 %(file) : %(objs) $(BD_OUTDIR)
2587         @$(ECHO) Linking $@...
2588         @$(KERNEL_LD) -melf_i386 --oformat=binary -e %(start) -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2589         @cd $(BD_TMPDIR) && $(KERNEL_LD) -r --format binary %(ldflags) %(name) -o $@
2591 GLOB_MKDIRS += $(BD_OUTDIR)
2593 %end