1 #############################################################################
2 #############################################################################
4 ## Here are the mmakefile macros that are used as commands in the body ##
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. ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16 @$(ECHO) "Compiling $(CURDIR)/$(notdir %(from))"
17 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
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 ; \
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 ; \
45 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,%(to))..."
57 @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
65 $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
80 @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81 $(GENMAP) %(objdir)/%(module).map \
82 %(objs) %(libs) %(endtag) \
83 -o $@ 2>&1 > %(objdir)/%(err); \
85 cat %(objdir)/%(err); \
87 cat %(objdir)/%(err); \
91 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
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)
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
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 ; \
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
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 ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
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
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
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 ; \
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
209 # Restriction: at the moment when using a non-empty target dir %(from) may
211 %define rule_join to=/A from=/A text=
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=
229 ifneq (%(depstargets),)
230 ifneq ($(findstring $(TARGET),%(depstargets)),)
234 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
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)
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.
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
271 TMP_TARGETBASE := %(basename)
273 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
276 ifeq ($(findstring %(compiler),host kernel target),)
277 $(error unknown compiler %(compiler))
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)
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)
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)
305 $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
307 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
309 $(TMP_TARGETBASE).o : %(basename).c
310 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
316 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
320 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
322 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
325 $(TMP_TARGETBASE).d : %(basename).c
326 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
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.
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= \
350 TMP_TARGETS := $(addsuffix .o,%(basenames))
351 TMP_DTARGETS := $(addsuffix .d,%(basenames))
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)))
366 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
367 vpath %.c $(TMP_DIRS)
372 ifeq ($(findstring %(compiler),host kernel target),)
373 $(error unknown compiler %(compiler))
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)
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)
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)
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)
396 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
398 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
400 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
401 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
403 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407 # Make an alias from one arch specific build to another arch.
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)
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.
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
432 TMP_TARGETBASE := %(basename)
434 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
437 ifeq ($(findstring %(compiler),host kernel target),)
438 $(error unknown compiler %(compiler))
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)
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)
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)
456 $(TMP_TARGETBASE).so : %(basename).c
457 %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_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.
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=
474 %(basename).o : AFLAGS := %(aflags)
475 %(basename).o : %(basename).s
477 %(basename).o : %(basename).S
481 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
482 %(targetdir)/$(notdir %(basename)).o : %(basename).s
484 %(targetdir)/$(notdir %(basename)).o : %(basename).S
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.
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
507 TMP_TARGETS := $(addsuffix .o,%(basenames))
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)))
521 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
522 vpath %%(suffix) $(TMP_DIRS)
527 ifeq ($(findstring %(compiler),host kernel target),)
528 $(error unknown compiler %(compiler))
530 ifeq (%(compiler),target)
531 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
533 ifeq (%(compiler),host)
534 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
536 ifeq (%(compiler),kernel)
537 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
540 $(TMP_TARGETS) : AFLAGS := %(aflags)
541 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
542 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
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
554 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
556 ifeq (%(usestartup),no)
557 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
560 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
563 # Make a list of the lib files this program depends on.
564 # In LDFLAGS remove white space between -L and directory
565 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
566 # Filter out only the libdirs and remove -L
567 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
569 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
570 # Add normal linklib path
571 TMP_DIRS += $(LIBDIR)/
572 # add lib and .a to static linklib names
573 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
574 # search for the linklibs in the given path, ignore ones not found
575 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
576 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
579 ifeq (%(linker),target)
580 %(prog) : CMD:=$(TARGET_CC)
581 %(prog) : STRIPCMD:=$(TARGET_STRIP)
583 ifeq (%(linker),host)
584 %(prog) : CMD:=$(HOST_CC)
585 %(prog) : STRIPCMD:=$(HOST_STRIP)
587 ifeq (%(linker),kernel)
588 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
589 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
592 %(prog) : OBJS := %(objs)
593 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
594 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
595 %(prog) : %(objs) $(TMP_DEPLIBS)
596 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
598 #------------------------------------------------------------------------------
601 #------------------------------------------------------------------------------
602 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
603 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
604 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
605 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
606 usestartup=yes detach=no
610 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
612 ifeq (%(usestartup),no)
613 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
616 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
619 # Make a list of the lib files the programs depend on.
620 # In LDFLAGS remove white space between -L and directory
621 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
622 # Filter out only the libdirs and remove -L
623 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
625 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
626 # Add normal linklib path
627 TMP_DIRS += $(LIBDIR)/
628 # add lib and .a to static linklib names
629 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
630 # search for the linklibs in the given path, ignore ones not found
631 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
632 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
635 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
636 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
637 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
638 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
640 #------------------------------------------------------------------------------
643 #------------------------------------------------------------------------------
644 # Link the %(objs) to the library %(libdir)/lib%(libname).a
645 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
647 ifeq (%(linker),target)
648 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
649 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
651 ifeq (%(linker),host)
652 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
653 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
655 ifeq (%(linker),kernel)
656 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
657 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
660 %(libdir)/lib%(libname).a : %(objs)
661 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
663 #------------------------------------------------------------------------------
666 #------------------------------------------------------------------------------
667 # Link the %(objs) to the library %(libdir)/lib%(libname).so
668 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
670 %(libdir)/lib%(libname).so : %(objs)
671 @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
673 #------------------------------------------------------------------------------
676 #------------------------------------------------------------------------------
677 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
678 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
679 # The -noarosc flag is added so that modules are not linked with arosc.library
680 # (see /config/specs.in file)
681 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
682 ldflags=$(LDFLAGS) uselibs= usehostlibs=
684 TMP_LDFLAGS := %(ldflags)
685 # Make a list of the lib files the programs depend on.
686 # In LDFLAGS remove white space between -L and directory
687 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
688 # Filter out only the libdirs and remove -L
689 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
691 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
692 # Add normal linklib path
693 TMP_DIRS += $(LIBDIR)/
694 # add lib and .a to static linklib names
695 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
696 # search for the linklibs in the given path, ignore ones not found
697 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
698 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
701 %(module) : LIB_NAMES := %(uselibs)
702 %(module) : OBJS := %(objs)
703 %(module) : ENDTAG := %(endobj)
704 %(module) : ERR := %(err)
705 %(module) : OBJDIR := %(objdir)
706 %(module) : LDFLAGS := $(TMP_LDFLAGS)
707 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
708 -L/usr/lib $(addprefix -l,%(usehostlibs))
709 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
710 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
713 #------------------------------------------------------------------------------
716 #------------------------------------------------------------------------------
717 # Generate the libdefs.h include file for a module.
718 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
720 TMP_TARGET := %(modname)_libdefs.h
721 TMP_DEPS := $(GENMODULE)
724 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
725 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
727 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
728 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
730 ifneq (%(modsuffix),)
731 TMP_OPTS += -s %(modsuffix)
733 ifneq (%(targetdir),)
734 TMP_OPTS += -d %(targetdir)
735 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
738 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
739 $(TMP_TARGET) : MODNAME := %(modname)
740 $(TMP_TARGET) : MODTYPE := %(modtype)
741 $(TMP_TARGET) : $(TMP_DEPS)
742 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
743 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
745 #------------------------------------------------------------------------------
747 #------------------------------------------------------------------------------
748 # Generate the _lib.fd file for a module.
749 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
751 TMP_TARGET := %(modname)_lib.fd
752 TMP_DEPS := $(GENMODULE)
755 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
756 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
758 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
759 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
761 ifneq (%(modsuffix),)
762 TMP_OPTS += -s %(modsuffix)
764 ifneq (%(targetdir),)
765 TMP_OPTS += -d %(targetdir)
766 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
769 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
770 $(TMP_TARGET) : MODNAME := %(modname)
771 $(TMP_TARGET) : MODTYPE := %(modtype)
772 $(TMP_TARGET) : $(TMP_DEPS)
773 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
774 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
776 #------------------------------------------------------------------------------
778 #------------------------------------------------------------------------------
779 # Generate a Makefile.%(modname) with the genmodule program and include this
780 # generated file in this Makefile
781 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
784 TMP_TARGET := Makefile.%(modname)
785 TMP_DEPS := $(GENMODULE)
788 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
789 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
791 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
792 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
794 ifneq (%(modsuffix),)
795 TMP_OPTS += -s %(modsuffix)
797 ifneq (%(targetdir),)
798 TMP_OPTS += -d %(targetdir)
799 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
802 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
803 $(TMP_TARGET) : MODNAME := %(modname)
804 $(TMP_TARGET) : MODTYPE := %(modtype)
805 $(TMP_TARGET) : $(TMP_DEPS)
806 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
808 #------------------------------------------------------------------------------
811 #------------------------------------------------------------------------------
812 # Generate the support files for compiling a module. This includes include
813 # files and source files. This rule has to be preceeded by
814 # %rule_genmodule_makefile
815 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
818 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
819 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
820 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
821 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
823 TMP_DEPS := $(GENMODULE)
827 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
828 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
830 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
831 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
833 ifneq (%(modsuffix),)
834 TMP_OPTS += -s %(modsuffix)
836 ifneq (%(targetdir),)
837 TMP_OPTS += -d %(targetdir)
838 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
839 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
842 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
843 $(TMP_TARGETS) : MODNAME := %(modname)
844 $(TMP_TARGETS) : MODTYPE := %(modtype)
845 $(TMP_TARGETS) : $(TMP_DEPS)
846 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
847 ifneq (%(conffile),lib.conf)
848 @$(IF) $(TEST) -f lib.conf; then \
849 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
852 @$(IF) $(TEST) -f libdefs.h; then \
853 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
855 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
857 #------------------------------------------------------------------------------
860 #------------------------------------------------------------------------------
861 # Generate the support files for compiling a module. This includes include
862 # files and source files.
863 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
866 ifneq ($(%(modname)_INCLUDES),)
867 TMP_TARGETS := $(%(modname)_INCLUDES)
869 TMP_DEPS := $(GENMODULE)
873 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
874 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
876 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
877 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
879 ifneq (%(modsuffix),)
880 TMP_OPTS += -s %(modsuffix)
882 ifneq (%(targetdir),)
883 TMP_OPTS += -d %(targetdir)
884 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
887 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
888 $(TMP_TARGETS) : MODNAME := %(modname)
889 $(TMP_TARGETS) : MODTYPE := %(modtype)
890 $(TMP_TARGETS) : $(TMP_DEPS)
891 @$(ECHO) "Generating include files"
892 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
895 #------------------------------------------------------------------------------
898 #------------------------------------------------------------------------------
899 # Common rules for all makefiles
901 # Delete generated makefiles
904 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
906 include $(SRCDIR)/config/make.tail
908 BDID := $(BDTARGETID)
910 #------------------------------------------------------------------------------
913 #############################################################################
914 #############################################################################
916 ## Here are the mmakefile build macros. These are macros that takes care ##
917 ## of everything to go from the sources to the generated target. Also all ##
918 ## intermediate files and directories that are needed are created by these ##
921 #############################################################################
922 #############################################################################
924 #------------------------------------------------------------------------------
926 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
927 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
928 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
929 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
930 compiler=target linker= srcdir=
934 BD_PROGNAME := %(progname)
935 BD_OBJDIR := %(objdir)
936 BD_TARGETDIR := %(targetdir)
937 BD_LINKER := %(linker)
939 # If not supplied, linker is equal to compiler
941 BD_LINKER := %(compiler)
945 BD_ASMFILES := %(asmfiles)
947 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
948 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
949 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
951 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
952 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
954 BD_CFLAGS := %(cflags)
955 BD_AFLAGS := %(aflags)
956 BD_DFLAGS := %(dflags)
957 BD_LDFLAGS := %(ldflags)
960 %(mmake)-quick : %(mmake)
962 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
963 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
965 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
966 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
967 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
968 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
969 aflags=$(BD_AFLAGS) compiler=%(compiler)
971 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
972 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
973 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
974 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
979 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
981 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
982 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
983 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
985 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
988 @$(ECHO) "Cleaning up for metatarget %(mmake)"
992 #------------------------------------------------------------------------------
995 #------------------------------------------------------------------------------
996 # Build programs, for every C file an executable will be built with the same
998 %define build_progs mmake=/A files=/A nix=no \
999 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1000 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1001 uselibs= usehostlibs= usestartup=yes detach=no
1005 BD_OBJDIR := %(objdir)
1006 BD_TARGETDIR := %(targetdir)
1008 BD_FILES := %(files)
1009 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1010 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1011 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1013 BD_CFLAGS := %(cflags)
1014 BD_DFLAGS := %(dflags)
1015 BD_LDFLAGS := %(ldflags)
1018 %(mmake)-quick : %(mmake)
1020 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1021 %(mmake) : $(BD_EXES)
1023 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1024 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1025 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1027 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1028 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1029 ldflags=$(BD_LDFLAGS) \
1030 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1031 usestartup="%(usestartup)" detach="%(detach)"
1035 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1037 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1038 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1039 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1041 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1044 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1048 #------------------------------------------------------------------------------
1051 #------------------------------------------------------------------------------
1053 # This is a bare version: It just compiles and links the given files. It is
1054 # assumed that all needed boiler plate code is in the files. This should only
1055 # be used for compiling external code. For AROS code use %build_module
1056 %define build_module_simple mmake=/A modname=/A modtype=/A \
1057 files="$(basename $(call WILDCARD, *.c))" \
1058 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1059 objdir=$(OBJDIR) moduledir= \
1060 uselibs= usehostlibs= compiler=target
1062 # Define metamake targets and their dependencies
1063 #MM %(mmake) : core-linklibs includes-generate-deps
1064 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1065 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1066 #MM %(mmake)-kobj-quick
1067 #MM %(mmake)-pkg-quick
1071 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1073 .PHONY : $(BD_ALLTARGETS)
1076 $(error using %build_module_simple: modname may not be empty)
1079 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1082 # Default values for variables and arguments
1083 BD_DEFLINKLIBNAME := %(modname)
1084 BD_DEFDFLAGS := %(cflags)
1085 OBJDIR ?= $(GENDIR)/$(CURDIR)
1086 BD_MODDIR := %(moduledir)
1087 ifeq ($(BD_MODDIR),)
1088 ifeq (%(modtype),library)
1089 BD_MODDIR := $(AROS_LIBS)
1091 ifeq (%(modtype),gadget)
1092 BD_MODDIR := $(AROS_GADGETS)
1094 ifeq (%(modtype),datatype)
1095 BD_MODDIR := $(AROS_DATATYPES)
1097 ifeq (%(modtype),handler)
1098 BD_MODDIR := $(AROS_FS)
1100 ifeq (%(modtype),device)
1101 BD_MODDIR := $(AROS_DEVS)
1103 ifeq (%(modtype),resource)
1104 BD_MODDIR := $(AROS_RESOURCES)
1106 ifeq (%(modtype),hook)
1107 BD_MODDIR := $(AROS_RESOURCES)
1109 ifeq (%(modtype),mui)
1110 BD_MODDIR := $(AROS_CLASSES)/Zune
1112 ifeq (%(modtype),mcc)
1113 BD_MODDIR := $(AROS_CLASSES)/Zune
1115 ifeq (%(modtype),mcp)
1116 BD_MODDIR := $(AROS_CLASSES)/Zune
1118 ifeq (%(modtype),usbclass)
1119 BD_MODDIR := $(AROS_CLASSES)/USB
1121 ifeq (%(modtype),hidd)
1122 BD_MODDIR := $(AROS_DRIVERS)
1125 ifeq ($(BD_MODDIR),)
1126 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1129 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1130 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1131 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1133 %rule_compile_multi \
1134 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1135 cflags="%(cflags)" dflags="%(dflags)" \
1136 compiler=%(compiler)
1138 # Handlers use dash instead of dot in their names
1139 ifeq (%(modtype),handler)
1140 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1141 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1143 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1144 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1146 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1148 %(mmake)-quick : %(mmake)
1149 %(mmake)-pkg-quick : $(BD_PKGMOD)
1150 %(mmake)-kobj-quick : $(BD_KOBJ)
1151 %(mmake) : $(BD_MODULE)
1152 %(mmake)-pkg : $(BD_PKGMOD)
1153 %(mmake)-kobj : $(BD_KOBJ)
1155 # The module is linked from all the compiled .o files
1156 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1158 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1159 # This breaks con-handler build. Here we work around this
1160 ifeq (%(modname),con)
1161 BD_ERR := $(notdir $(BD_MODULE)).err
1163 BD_ERR := %(modname).err
1166 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1167 endobj= err=$(BD_ERR) objdir=%(objdir) \
1168 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1170 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1171 endobj= err=$(BD_ERR) objdir=%(objdir) \
1172 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1174 # Link kernel object file
1175 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1177 # Make these symbols local
1178 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1179 UtilityBase ExpansionBase KeymapBase KernelBase
1181 BD_SYMBOLS := $(BD_KBASE)
1183 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1184 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1185 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1186 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1187 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1188 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1189 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1190 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1191 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1194 ## Dependency fine-tuning
1196 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1197 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1199 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1200 $(BD_MODULE) : | $(BD_MODDIR)
1201 $(BD_KOBJ) : | $(KOBJSDIR)
1202 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1204 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1206 @$(ECHO) "Cleaning up for module %(modname)"
1209 #------------------------------------------------------------------------------
1212 #------------------------------------------------------------------------------
1214 # Explanation of this macro is done in the developer's manual
1215 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1216 conffile= files="$(basename $(call WILDCARD, *.c))" \
1217 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1218 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1219 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1220 compiler=target nostartup=yes
1222 # Define metamake targets and their dependencies
1223 #MM- includes-all : %(mmake)-includes
1224 #MM- linklibs-%(modname): %(mmake)-linklib
1225 #MM- includes-%(modname): %(mmake)-includes
1226 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1227 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1228 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1229 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1230 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1231 #MM %(mmake)-linklib : %(mmake)-includes
1232 #MM %(mmake)-quick : %(mmake)-includes-quick
1233 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1234 #MM includes-generate-deps %(mmake)-fd
1235 #MM %(mmake)-includes-quick
1236 #MM %(mmake)-includes-dirs
1238 #MM %(mmake)-makefile
1241 # All MetaMake targets defined by this macro
1242 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1243 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1244 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1245 %(mmake)-linklib %(mmake)-fd
1247 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1250 $(error using %build_module: modname may not be empty)
1253 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1256 # Default values for variables and arguments
1257 BD_DEFLINKLIBNAME := %(modname)
1258 BD_DEFDFLAGS := %(cflags)
1259 OBJDIR ?= $(GENDIR)/$(CURDIR)
1261 ## Create genmodule include Makefile for the module
1263 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1265 %rule_genmodule_makefile \
1266 modname=%(modname) modtype=%(modtype) \
1267 modsuffix=%(modsuffix) targetdir=%(objdir) \
1268 conffile=%(conffile)
1270 %(objdir)/Makefile.%(modname) : | %(objdir)
1272 GLOB_MKDIRS += %(objdir)
1274 # Do not parse these statements if metatarget is not appropriate
1275 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1277 include %(objdir)/Makefile.%(modname)
1279 BD_DEFMODDIR := $(%(modname)_MODDIR)
1282 ## include files generation
1284 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1285 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1286 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1288 %(mmake)-includes-quick : %(mmake)-includes
1289 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1290 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1291 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1293 ifneq ($(%(modname)_INCLUDES),)
1294 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1295 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1296 conffile=%(conffile)
1298 %rule_copy_diff_multi \
1299 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1300 stampfile=%(objdir)/%(modname)_geninc
1302 %rule_copy_diff_multi \
1303 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1304 stampfile=%(objdir)/%(modname)_incs
1306 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1308 TMP%(modname)_INCDIRS := \
1309 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1310 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1311 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1312 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1316 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1317 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1318 conffile=%(conffile)
1320 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1321 $(BD_DEFLIBDEFSINC) :
1322 @$(ECHO) "generating $@"
1323 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1325 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1326 GLOB_MKDIRS += %(objdir)/include
1328 ## Extra genmodule src files generation
1330 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1331 modsuffix=%(modsuffix) targetdir=%(objdir) \
1332 conffile=%(conffile)
1336 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1337 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1339 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1340 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1342 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1344 GLOB_MKDIRS += $(BD_FDDIR)
1349 BD_FILES := %(files)
1350 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1351 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1352 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1354 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1355 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1356 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1358 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1359 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1361 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1362 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1363 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1366 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1368 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1370 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1371 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1372 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1375 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel.a
1377 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1379 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1380 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1381 $(BD_RELLINKLIBCFILES)
1383 %rule_compile_multi \
1384 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1385 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1386 compiler=%(compiler)
1387 %rule_compile_multi \
1388 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1389 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1390 compiler=%(compiler)
1392 ifneq ($(BD_LINKLIBAFILES),)
1393 %rule_assemble_multi \
1394 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1399 ifeq (%(modsuffix),)
1400 BD_SUFFIX := %(modtype)
1402 BD_SUFFIX := %(modsuffix)
1405 # Handlers use dash instead of dot in their names
1406 ifeq ($(BD_SUFFIX),handler)
1407 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1408 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1410 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1411 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1413 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1415 %(mmake)-quick : %(mmake)
1416 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1417 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1418 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1419 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1420 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1421 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1423 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1424 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1426 ifeq (%(nostartup),yes)
1427 # Handlers always have entry point
1428 ifneq (%(modtype),handler)
1429 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1433 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1434 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1437 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1440 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1441 # This breaks con-handler build. Here we work around this
1442 ifeq (%(modname),con)
1443 BD_ERR := $(notdir $(BD_MODULE)).err
1445 BD_ERR := %(modname).err
1448 # The module is linked from all the compiled .o files
1449 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1450 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1451 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1453 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1454 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1455 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1458 ifneq ($(BD_LINKLIB),)
1459 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1461 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1462 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1465 ifneq ($(BD_RELLINKLIB),)
1466 %rule_link_linklib libname=%(linklibname)_rel objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1468 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1469 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1472 # Link kernel object file
1473 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1475 # Make these symbols local
1476 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1477 UtilityBase ExpansionBase KeymapBase KernelBase
1479 BD_SYMBOLS := $(BD_KBASE)
1481 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1482 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1483 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1484 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1485 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1486 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1487 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1488 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1489 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1491 ## Dependency fine-tuning
1493 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1494 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1496 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1497 $(BD_MODULE) : | %(prefix)/%(moduledir)
1498 $(BD_PKGMOD) : | $(PKGDIR)
1499 $(BD_KOBJ) : | $(KOBJSDIR)
1500 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1502 # Some include files need to be generated before the .c can be parsed.
1503 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
1505 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1506 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1507 $(BD_DEPS) : $(BD_DFILE_DEPS)
1510 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1511 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1512 %(objdir)/Makefile.%(modname) \
1513 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1514 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1515 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1516 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1517 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1518 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1520 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1522 @$(ECHO) "Cleaning up for module %(modname)"
1525 endif # $(TARGET) in $(BD_ALLTARGETS)
1527 #------------------------------------------------------------------------------
1530 #------------------------------------------------------------------------------
1531 # Build a module skeleton
1532 # This is a stripped-down version of build_module, it only creates include files,
1533 # but no actual object. This is used when for plugins or classes with the same
1534 # API, but no actual implementation here.
1535 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1537 objdir=$(OBJDIR) prefix=$(AROSDIR)
1539 # Define metamake targets and their dependencies
1540 #MM- includes-all : %(mmake)-includes
1541 #MM %(mmake) : %(mmake)-includes core-linklibs
1542 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1543 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1544 #MM %(mmake)-linklib : %(mmake)-includes
1545 #MM %(mmake)-quick : %(mmake)-includes-quick
1546 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1547 #MM includes-generate-deps
1548 #MM %(mmake)-includes-quick
1549 #MM %(mmake)-includes-dirs
1550 #MM %(mmake)-makefile
1553 # All MetaMake targets defined by this macro
1554 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1555 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1556 %(mmake)-kobj %(mmake)-pkg
1558 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1561 $(error using %build_module_skeleton: modname may not be empty)
1564 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1567 # Default values for variables and arguments
1568 BD_DEFLINKLIBNAME := %(modname)
1569 BD_DEFDFLAGS := %(cflags)
1570 OBJDIR ?= $(GENDIR)/$(CURDIR)
1572 ## Create genmodule include Makefile for the module
1574 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1576 %rule_genmodule_makefile \
1577 modname=%(modname) modtype=%(modtype) \
1578 modsuffix=%(modsuffix) targetdir=%(objdir) \
1579 conffile=%(conffile)
1581 %(objdir)/Makefile.%(modname) : | %(objdir)
1583 GLOB_MKDIRS += %(objdir)
1585 # Do not parse these statements if metatarget is not appropriate
1586 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1588 include %(objdir)/Makefile.%(modname)
1590 BD_DEFMODDIR := $(%(modname)_MODDIR)
1593 ## include files generation
1595 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1596 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1597 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1599 %(mmake)-includes-quick : %(mmake)-includes
1600 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1601 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1602 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1604 ifneq ($(%(modname)_INCLUDES),)
1605 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1606 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1607 conffile=%(conffile)
1609 %rule_copy_diff_multi \
1610 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1611 stampfile=%(objdir)/%(modname)_geninc
1613 %rule_copy_diff_multi \
1614 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1615 stampfile=%(objdir)/%(modname)_incs
1617 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1619 TMP%(modname)_INCDIRS := \
1620 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1621 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1622 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1623 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1627 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1628 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1629 conffile=%(conffile)
1631 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1632 $(BD_DEFLIBDEFSINC) :
1633 @$(ECHO) "generating $@"
1634 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1636 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1637 GLOB_MKDIRS += %(objdir)/include
1639 ## Extra genmodule src files generation
1641 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1642 modsuffix=%(modsuffix) targetdir=%(objdir) \
1643 conffile=%(conffile)
1645 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1646 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1647 %(objdir)/Makefile.%(modname) \
1648 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1649 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1650 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1651 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1652 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1654 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1656 @$(ECHO) "Cleaning up for module %(modname)"
1659 endif # $(TARGET) in $(BD_ALLTARGETS)
1661 #------------------------------------------------------------------------------
1664 #------------------------------------------------------------------------------
1666 # - mmake is the mmaketarget
1667 # - libname is the baselibname e.g. lib%(libname).a will be created
1668 # - files are the C source files to include in the lib. The list of files
1669 # has to be given without the .c suffix
1670 # - asmfiles are the asm files to include in the lib. The list of files has to
1671 # be given without the .s suffix
1672 # - objs additional object to link into the linklib. The objects have to be
1673 # given with full absolute path and the .o suffix.
1674 # - cflags are the flags to compile the source (default $(CFLAGS))
1675 # - dflags are the flags use during makedepend (default equal to cflags)
1676 # - aflags are the flags use during assembling (default $(AFLAGS))
1677 # - objdir is where the .o are generated
1678 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1679 %define build_linklib mmake=/A libname=/A \
1680 files="$(basename $(call WILDCARD, *.c))" asmfiles= objs= compiler=target \
1681 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1683 # assign and generate the local variables used in this macro
1684 OBJDIR ?= $(GENDIR)/$(CURDIR)
1686 BD_FILES := %(files)
1687 BD_ASMFILES := %(asmfiles)
1689 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1690 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1691 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1693 BD_OBJS := $(BD_ARCHOBJS) \
1694 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1696 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1698 BD_CFLAGS := %(cflags)
1700 BD_DFLAGS := $(BD_CFLAGS)
1702 BD_DFLAGS := %(dflags)
1704 BD_AFLAGS := %(aflags)
1706 BD_LINKLIB := %(libdir)/lib%(libname).a
1708 .PHONY : %(mmake) %(mmake)-clean
1710 #MM %(mmake) : includes-generate-deps
1711 %(mmake) : $(BD_LINKLIB)
1715 @$(RM) $(BD_OBJS) $(BD_DEPS)
1717 ifeq ($(TARGET),%(mmake))
1718 ifneq ($(dir $(BD_FILES)),./)
1719 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1720 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1723 %rule_compile basename=% targetdir=%(objdir) compiler=%(compiler) \
1724 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1725 %rule_assemble basename=% targetdir=%(objdir) \
1728 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1731 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1733 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1734 $(BD_LINKLIB) : | %(libdir)
1735 GLOB_MKDIRS += %(objdir) %(libdir)
1738 #------------------------------------------------------------------------------
1741 #------------------------------------------------------------------------------
1743 # - mmake is the mmaketarget
1744 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1745 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1746 # - subdir is the destination subdirectory of the catalogs
1747 # - name is the name of the destination catalog, without the .catalog suffix
1748 # - source is the path to the generated source code file
1749 # - dir is the base destination directory (default $(AROS_CATALOGS))
1750 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1751 # - srcdir is the directory in which the *.cd and *.ct files are searched
1753 %define build_catalogs mmake=/A name=/A subdir=/A \
1754 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1755 sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1757 ifeq (%(description),)
1758 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1760 BD_DESC := %(description)
1764 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1766 BD_LNGS := %(catalogs)
1769 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1770 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1773 %(mmake) : $(BD_OBJS) %(source)
1775 $(BD_OBJS) : | $(BD_DIRS)
1776 GLOB_MKDIRS += $(BD_DIRS)
1778 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1779 @$(ECHO) "Creating %(name) catalog for language $*."
1780 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1783 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1784 %(source) : $(BD_DESC).cd | $(dir %(source))
1785 @$(ECHO) "Creating %(name) catalog source file %(source)"
1786 @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1791 $(RM) $(BD_OBJS) %(source)
1793 .PHONY: %(mmake) %(mmake)-clean
1796 #-----------------------------------------------------------------------------
1799 #-----------------------------------------------------------------------------
1801 # - mmake is the mmaketarget
1802 # - icons is a list of icon base names (ie. without the .info suffix)
1803 # - dir is the destination directory
1804 # - srcdir is where *.png and *.info.src are searched
1805 #-----------------------------------------------------------------------------
1807 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1809 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1812 %(mmake) : $(BD_OBJS)
1816 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1817 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
1818 @$(ILBMTOICON) $+ $@
1822 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1823 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
1824 @$(ILBMTOICON) $+ $@
1828 $(BD_OBJS) : | %(dir)
1829 GLOB_MKDIRS += %(dir)
1831 %(mmake)-clean : FILES := $(BD_OBJS)
1836 .PHONY: %(mmake) %(mmake)-clean
1839 #-----------------------------------------------------------------------------
1842 #------------------------------------------------------------------------------
1843 # Compile files for an arch-specific replacement of code for a module
1844 # - files: the basenames of the C files to compile.
1845 # - asmfiles: the basenames of the asm files to assemble.
1846 # - mainmmake: the mmake of the module in the main directory to compile these
1847 # arch specific files for.
1848 # - maindir: the object directory for the main module
1849 # - arch: the arch for which to compile these files. It can have the form
1850 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1851 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1852 # - dflags: the flags used during creation of dependency file. If not specified
1853 # the same value as cflags will be used
1854 # - aflags: the flags used during assembling
1855 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1856 # the target compiler is used
1857 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1858 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1860 ifeq (%(files) %(asmfiles),)
1861 $(error no files or asmfiles given)
1864 %buildid targets="%(mainmmake)-%(arch)"
1866 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1867 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1868 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1869 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1870 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1871 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1872 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1873 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1874 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1875 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1876 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1877 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1878 #MM- %(mainmmake)-pkg : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1879 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1880 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1881 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1882 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1883 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1884 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
1885 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
1886 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
1888 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1890 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
1891 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1892 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1893 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1894 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1896 ifneq (%(modulename),)
1897 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1900 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
1901 BD_TARGET := %(mainmmake)-%(arch)-quick
1903 BD_TARGET := %(mainmmake)-%(arch)
1907 ifeq ($(TARGET),$(BD_TARGET))
1908 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1909 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1910 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1911 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1914 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1915 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1918 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1921 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
1923 ifeq ($(findstring %(compiler),host kernel target),)
1924 $(error unknown compiler %(compiler))
1926 ifeq (%(compiler),target)
1927 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1928 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1929 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1931 ifeq (%(compiler),host)
1932 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1933 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1934 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1936 ifeq (%(compiler),kernel)
1937 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1938 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1939 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1941 ifneq (%(modulename),)
1942 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1944 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1946 ifeq ($(TARGET),$(BD_TARGET))
1947 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
1948 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1952 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1954 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1956 ifeq ($(TARGET),$(BD_TARGET))
1957 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
1958 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1961 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1963 ifeq ($(TARGET),$(BD_TARGET))
1964 $(BD_OBJDIR$(BDID))/%.o : %.s
1965 %assemble_q opt=$(AFLAGS)
1966 $(BD_OBJDIR$(BDID))/%.o : %.S
1967 %assemble_q opt=$(AFLAGS)
1970 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
1972 #------------------------------------------------------------------------------
1975 #------------------------------------------------------------------------------
1976 # generate asm files from c files (for debugging purposes)
1979 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1980 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1982 #------------------------------------------------------------------------------
1985 #------------------------------------------------------------------------------
1986 # Copy files from one directory to another.
1988 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1990 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1992 GLOB_MKDIRS += %(dst)
1998 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2001 #------------------------------------------------------------------------------
2004 #------------------------------------------------------------------------------
2005 # Copy a directory recursively to another place, preserving the original
2006 # hierarchical structure
2008 # src: the source directory whose content will be copied
2009 # dst: the directory where to copy src's content. If not existing, it will be made.
2011 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2013 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2014 %(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)
2015 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
2017 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2018 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2020 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2025 %(mmake): | $(GENDIR)/$(CURDIR)
2026 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2027 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
2028 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2029 for d in $(%(mmake)_DIRS); do \
2030 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
2032 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2033 for f in $(%(mmake)_FILES); do \
2034 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2036 for dst in %(dst); do \
2037 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2041 #------------------------------------------------------------------------------
2044 #------------------------------------------------------------------------------
2045 # Copy include files into the includes directories. There are currently
2046 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2047 # for building tools that need to run on the host system $(GENINCDIR). The
2048 # $(GENINCDIR) path must not contain any references to the C runtime
2049 # library header files.
2051 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2052 dir= compiler=target
2054 ifeq ($(findstring %(compiler),host kernel target),)
2055 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2059 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2060 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2061 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2063 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2064 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2067 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2071 ifeq (%(compiler),target)
2074 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2075 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2077 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2080 BD_INCL_FILES += $(BD_INCL_FILES2)
2082 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2087 %(mmake) : $(BD_INCL_FILES)
2091 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2092 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2094 #------------------------------------------------------------------------------
2097 #------------------------------------------------------------------------------
2098 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2099 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2100 STUBS_MEM := $(addsuffix .o,$(STUBS))
2101 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2102 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2103 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2105 #MM- linklibs : hidd-%(hidd)-stubs
2106 #MM- %(parenttarget): hidd-%(hidd)-stubs
2107 #MM hidd-%(hidd)-stubs : includes includes-copy
2108 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2110 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2113 $(STUBS_OBJ) : $(STUBS_SRC)
2114 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2116 $(STUBS_DEP) : $(STUBS_SRC)
2117 %mkdepend_q flags=%(dflags)
2120 %mkdirs_q $(OBJDIR) $(LIBDIR)
2124 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2126 DEPS := $(DEPS) $(STUBS_DEP)
2129 #------------------------------------------------------------------------------
2132 #------------------------------------------------------------------------------
2133 # Build an imported source tree which uses the configure script from the
2134 # autoconf package. This rule will try to "integrate" the produced files as
2135 # much as possible in the AROS build, for example by putting libraries in the
2136 # standard library directory, includes in the standard include directory, and
2137 # so on. You can however override this behaviour.
2139 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2140 # be %(bindir) (or its deduced value) when running "make install", and
2141 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2142 # configure script some more parameters whose value depends upon the PROGDIR
2143 # env var, so that the program gets all its stuff installed in the proper place
2144 # when building it, but when running it from inside AROS it can also find that
2145 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2146 # the configuration parameters set when running ./configure
2148 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2149 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2150 # to the name which has to follow it.
2153 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2154 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2155 install_target=install preconfigure= postconfigure= postinstall= \
2156 install_env= use_build_env=no
2159 %(mmake)-prefix := %(prefix)
2161 %(mmake)-prefix := $(AROS_CONTRIB)
2164 ifneq (%(aros_prefix),)
2165 %(mmake)-aros_prefix := %(aros_prefix)
2167 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2171 %(mmake)-nix := -nix
2172 %(mmake)-volpfx := /
2173 %(mmake)-volsfx := /
2175 ifeq (%(nix_dir_layout),)
2176 %(mmake)-nix_dir_layout := yes
2179 %(mmake)-volsfx := :
2181 ifeq (%(nix_dir_layout),)
2182 %(mmake)-nix_dir_layout := no
2186 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2188 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2189 exec_prefix=$(%(mmake)-prefix) %(install_env)
2191 # Check if chosen compiler is valid
2192 ifeq ($(findstring %(compiler),host target kernel),)
2193 $(error unknown compiler %(compiler))
2196 # Set legacy 'host' variable based on chosen compiler
2197 ifeq (%(compiler),host)
2200 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2202 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2207 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2209 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2213 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2214 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2216 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2217 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2218 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2221 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2222 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2224 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2227 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2229 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2230 sbindir=$(%(mmake)-prefix) \
2231 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2232 oldincludedir=$(AROS_INCLUDES) %(install_env)
2235 ifneq ($(DEBUG),yes)
2236 %(mmake)-s_flag = -s
2239 # Set up build environment, and options for configure script
2240 ifeq (%(compiler),host)
2242 CC="$(HOST_CC) $(HOST_CFLAGS)" \
2243 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2244 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2245 TARGET_RANLIB="$(RANLIB)"
2246 %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2248 ifeq (%(compiler),target)
2250 CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2251 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2252 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2253 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2254 TARGET_RANLIB="$(RANLIB)"
2255 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2256 --host=$(AROS_TARGET_CPU)-aros\
2257 --target=$(AROS_TARGET_CPU)-aros\
2259 --without-x --without-pic --disable-shared
2261 ifeq (%(compiler),kernel)
2263 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2264 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2265 TARGET_RANLIB="$(RANLIB)"
2266 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2267 --host=$(AROS_TARGET_CPU)-aros\
2268 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2269 --without-x --without-pic --disable-shared
2272 ifeq (%(use_build_env),yes)
2273 BUILD_ENV := $(CONFIG_ENV)
2277 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2279 #MM- %(mmake) : setup includes core-linklibs %(mmake)-quick
2281 # Using -j1 in install_command may result in a warning but finally
2282 # it does its job. make install for gcc does not work reliably for -jN
2284 ifneq (%(install_target),)
2285 %(mmake)-install_command = \
2286 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2287 -C $(%(mmake)-pkgdir) %(install_target) -j1
2289 %(mmake)-uninstall_command = \
2290 $(RM) $(%(mmake)-installflag) && \
2291 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2292 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2294 %(mmake)-install_command := true
2295 %(mmake)-uninstall_command := true
2298 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2301 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2303 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2304 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2305 $(RM) $(%(mmake)-installflag) && \
2306 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2307 -C $(%(mmake)-pkgdir) && \
2308 $(%(mmake)-install_command) && \
2309 $(TOUCH) $@ -r $^; \
2312 $(%(mmake)-pkgdir)/.files-touched:
2313 %mkdirs_q $(%(mmake)-pkgdir)
2314 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2318 %(mmake)-uninstall :
2319 $(%(mmake)-uninstall_command)
2322 %(mmake)-configure : $(%(mmake)-configflag)
2324 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2325 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2327 %mkdirs_q $(%(mmake)-pkgdir)
2328 cd $(%(mmake)-pkgdir) && \
2329 find . -name config.cache -exec $(RM) '{}' \; && \
2330 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2331 %(extraoptions) && \
2335 %(mmake)-clean : %(mmake)-uninstall
2336 @$(RM) $(%(mmake)-pkgdir)
2338 #------------------------------------------------------------------------------
2341 #------------------------------------------------------------------------------
2342 # Given an archive name, patches names and locations where to find them, fetch
2343 # the archive and the patches from any of those locations, unpack the archive
2344 # and then apply the patches.
2346 # Locations currently supported are http and ftp sites, plus local filesystem
2347 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2348 # the fetch.sh script needs to be modified, since this macro relies on that script.
2352 # - mmake = mmaketarget
2353 # - archive_origins = list of locations where to find the archive. They are tried
2354 # in sequence, until the archive is found and fetching it
2355 # succeeded. If not specified, the current directory is assumed.
2356 # - archive = the archive name. Mandatory.
2357 # - suffixes = a list of suffixes to append to the the package name plus the
2358 # version. Each one of them is tried until a matching archive is
2359 # found. They are appended to patches and these are tried the
2360 # same way as packages are.
2361 # - location = the local directory where to put the fetched archive and patches.
2362 # If not specified, the directory specified by destination is used.
2363 # - destination = the directory to unpack the archive to.
2364 # If not specified, the current directory is assumed.
2365 # - patches_origins = list of locations where to find the patches. They are tried
2366 # in sequence, until a patch is found and fetching it
2367 # succeeded. If not specified, the current directory is assumed.
2368 # - patches_specs = list of "patch specs". A patch spec is of the form
2369 # patch_name[:[patch_subdir][:patch_opt]].
2371 # - patch_name = the name of the patch file
2372 # - patch_subdir = the directory within \destination\ where to
2374 # - patch_opt = any options to pass to the `patch' command
2375 # when applying the patch.
2377 # The patch_subdir and patch_opt fields are optional.
2379 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2380 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2384 ifneq (%(location),)
2385 %(mmake)-location := %(location)
2387 %(mmake)-location := %(destination)
2392 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2393 -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2395 #------------------------------------------------------------------------------
2398 #------------------------------------------------------------------------------
2399 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2400 # unpatched source tree and runs diff against this and a previously fetched and possibly
2401 # patched tree. Depending on what happens after patching during a normal build it might
2402 # give best results if the new patch is created directly after fetch.
2406 # - mmake = mmaketarget
2407 # - archive = archive base name
2408 # - srcdir = directory the package is unpacked to, useful if archive unpacks to
2409 # a directory other than its name suggests.
2410 # - suffixes = a list of suffixes to append to the the package name plus the
2411 # version. Each one of them is tried until a matching archive is
2413 # - destination = the directory to unpack the archive to.
2414 # - excludes = diff patterns to exclude files or directories from the patch
2416 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2420 ifneq (%(excludes),)
2421 %(mmake)-exclude := -X ./exclude.patterns
2425 %(mmake)-srcdir := %(srcdir)
2427 %(mmake)-srcdir := %(archive)
2432 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2433 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2434 cd %(destination)/tmp ; \
2435 $(FOR) f in %(excludes) ; do \
2436 $(ECHO) $$f >> ./exclude.patterns ; \
2438 diff -ruN $(%(mmake)-exclude) \
2439 $(%(mmake)-srcdir) \
2440 $(%(mmake)-srcdir).aros \
2441 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2442 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2443 $(RM) %(destination)/tmp
2445 #------------------------------------------------------------------------------
2448 #------------------------------------------------------------------------------
2449 # Joins the features of %fetch and %build_with_configure, taking advantage of
2450 # the naming scheme of GNU packages. GNU packages names are in the form
2452 # <package name>-<version number>.<archive format suffix>
2454 # If a patch is provided, it *must* be named the following way:
2456 # <package name>-<version number>-aros.diff
2458 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2459 # CD'ing into the archive's extracted directory.
2461 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2462 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2463 # to make that patch fully comprehensive.
2465 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2469 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2471 # - package = the GNU package name, sans version and archive format suffixes.
2472 # - version = the package's version number, or otherwise any other version string.
2473 # It gets appended to the package name to form the basename of the archive.
2474 # - suffixes = a list of suffixes to apped to the the package name plus the
2475 # version. Each one of them is tried until a matching archive is found.
2476 # Defaults to "tar.bz2 tar.gz".
2477 # - destination = same meaning as the one for the %fetch macro
2478 # - location = same meaning as the one for the %fetch macro
2479 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2480 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2482 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2483 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2485 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2487 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2488 # - extracflags = same meaning as the one for the %build_with_configure macro.
2489 # - postinstall = same meaning as the one for the %build_with_configure macro.
2490 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2492 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2493 srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2494 preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2496 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2497 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2498 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2499 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2501 %(mmake)-archbase := %(package)-%(version)
2503 ifeq (%(compiler),host)
2504 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2506 %(mmake)-portdir := $(PORTSDIR)/%(package)
2510 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2512 %(mmake)-prefix := %(prefix)
2515 ifneq (%(subpackage),)
2516 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2518 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2522 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2524 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2528 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2530 %(mmake)-%(subpackage)-patches_specs := ::
2533 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2534 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2535 archive_origins=". %(package_repo)" \
2536 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2538 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2539 archive=$(%(mmake)-%(subpackage)-archbase) \
2540 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2541 suffixes="%(suffixes)" \
2542 destination=$(%(mmake)-portdir)
2544 #MM- %(mmake) : %(mmake)-%(subpackage)
2546 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2548 %(mmake)-%(subpackage)-package-basename := \
2549 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2551 ifneq (%(create_pkg),no)
2552 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2555 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2556 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2557 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2558 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2559 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2561 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2562 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2565 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2567 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2568 #that $^ and $@ have exactly the same mtime, and in that case make tries
2569 #to rebuild $@ again, which would fail because the directory where
2570 #the package got installed would not exist anymore.
2571 #We work this around by using an if statement to manually check the mtimes.
2572 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2573 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2575 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2576 mkdir -p "$(DISTDIR)/Packages" ; \
2577 mkdir -p "$(%(mmake)-prefix)" ; \
2578 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2579 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2580 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2583 #------------------------------------------------------------------------------
2586 #------------------------------------------------------------------------------
2587 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2588 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2589 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
2591 GNU_REPOSITORY := gnu://
2593 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2594 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2595 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2596 patch="%(patch)" patch_repo="%(patch_repo)" \
2597 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2598 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2601 #------------------------------------------------------------------------------
2604 #------------------------------------------------------------------------------
2605 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2606 # that the package is a "Development" package, and as such it needs to be placed
2607 # under the $(AROS_DEVELOPMENT) directory, as a default.
2609 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2610 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2611 # "mmake" argument, because the metatarget is implicitely defined as
2613 # #MM- development-%(package)
2615 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2616 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2617 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
2619 #MM- development : development-%(package)
2622 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2623 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2624 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2625 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2626 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2629 postinstall-%(package)-delete-la-files:
2630 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2633 #------------------------------------------------------------------------------
2635 # Builds a kickstart package in PKG format
2636 # mmake - target name
2637 # file - Destination file name with path
2638 # startup - The file which will be put first
2639 # Other arguments are self-explanatory
2641 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2643 PKG_CLASSES := $(addsuffix .class, %(classes))
2644 PKG_DEVICES := $(addsuffix .device, %(devs))
2645 PKG_HANDLERS := $(addsuffix -handler, %(handlers))
2646 PKG_HIDD := $(addsuffix .hidd, %(hidds))
2647 PKG_LIBS := $(addsuffix .library, %(libs))
2648 PKG_RESOURCES := $(addsuffix .resource, %(res))
2650 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2651 PKG_DIR := $(dir %(file))
2652 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2658 %(mmake)-quick : %(file)
2660 %(file): PKG_FILES := $(PKG_FILES)
2661 %(file): $(PKG_DEPS) | $(PKG_DIR)
2662 @$(ECHO) Packaging $@...
2663 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2665 %compress_file mmake=%(mmake) file=%(file)
2667 GLOB_MKDIRS += $(PKG_DIR)
2671 #------------------------------------------------------------------------------
2672 # Compresses %(file) with a gzip.
2673 # Good in conjunction with for example %build_prog
2675 %define compress_file mmake=/A file=/A
2677 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2680 %(mmake)-gz-quick : %(file).gz
2683 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2688 #------------------------------------------------------------------------------
2689 # Links a kickstart module in ELF format
2690 # Arguments are similar to make_package
2692 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2693 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2695 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2696 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2697 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2698 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2699 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2700 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2703 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2705 KOBJ_STARTUP := %(startup)
2708 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2710 TMP_LDFLAGS := %(ldflags)
2712 # Make a list of the lib files this program depends on.
2713 # In LDFLAGS remove white space between -L and directory
2714 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2715 # Filter out only the libdirs and remove -L
2716 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2718 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2719 # Add normal linklib path
2720 TMP_DIRS += $(LIBDIR)/
2721 # add lib and .a to static linklib names
2722 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2723 # search for the linklibs in the given path, ignore ones not found
2724 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2725 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2728 TMP_DIRS += $(dir %(file))
2730 TMP_LDFLAGS += $(GENMAP) %(map)
2731 TMP_DIRS += $(dir %(map))
2734 #MM %(mmake) : %(deps)
2740 %(mmake)-quick : %(file)
2742 %(file): KOBJS := $(KOBJS)
2743 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2744 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2745 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2746 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
2747 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
2750 %compress_file mmake=%(mmake) file=%(file)
2752 GLOB_MKDIRS += $(TMP_DIRS)
2756 #------------------------------------------------------------------------------
2757 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2758 # 'start' is an optional starting address
2759 # 'ldflags' is optional additional flags for the linker
2760 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2762 BD_OUTDIR := $(dir %(file))
2763 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2764 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2765 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2767 %(file) : %(objs) $(BD_OUTDIR)
2768 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
2769 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2770 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2772 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2773 GLOB_MKDIRS += $(BD_OUTDIR)