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) opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16 @$(ECHO) "Compiling %(from)"
17 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
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)
56 @$(ECHO) "Linking %(to)..."
57 @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
65 $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
72 #-------------------------------------------------------------------------
73 # Link a module based upon a number of arguments and the standard $(LIBS)
74 # and $(DEPLIBS) make variables.
76 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
77 @$(ECHO) "Building $(notdir $@) ..."
78 @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
79 $(GENMAP) %(objdir)/%(module).map \
80 %(objs) %(libs) %(endtag) \
81 -o $@ 2>&1 > %(objdir)/%(err); \
83 cat %(objdir)/%(err); \
85 cat %(objdir)/%(err); \
89 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92 #------------------------------------------------------------------------------
94 #------------------------------------------------------------------------------
96 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
97 @$(ECHO) "Creating library %(to)..."
102 #------------------------------------------------------------------------------
103 # Create the dependency file %(to) for %(from)
104 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
105 %mkdir_q dir="$(dir %(to))"
106 @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
107 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the function reference file %(to) to %(from)
113 %define mkref_q cc=$(AROS_CC) cppflags="-E -C -dD -D__CXREF__" cflags=$(CFLAGS) from=$< to=$@
114 @$(ECHO) "Generating ref for $(notdir %(from))..."
115 @$(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to) 2>$(GENDIR)/cerrors
116 @$(IF) $(TEST) -s %(to) ; \
118 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
119 $(ECHO) "%(from): $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" >> $(GENDIR)/errors ; \
120 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
123 $(ECHO) "Reference generation failed: $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" 1>&2 ; \
124 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
130 #------------------------------------------------------------------------------
131 # Create one directory without any output
132 %define mkdir_q dir=.
133 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139 @$(FOR) dir in %(dirs) ; do \
140 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
144 #############################################################################
145 #############################################################################
147 ## Here are the mmakefile macro's that are used to do certain tasks in a ##
148 ## mmakefile. They consist of one or more full makefile rules. ##
149 ## In general the files generated in these macro's are also defined as ##
150 ## make targets so that they can be used as a dependency in other rules ##
152 #############################################################################
153 #############################################################################
155 #------------------------------------------------------------------------------
156 # Generate a unique id for each of the %build... rules
157 %define buildid targets=/A
159 ifneq ($(filter $(TARGET),%(targets)),)
160 BDTARGETID := $(BDID)
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy file %(from) to %(to) in a makefile rule
168 %define rule_copy from=/A to=/A
172 #------------------------------------------------------------------------------
175 #------------------------------------------------------------------------------
176 # Copy the files %(files) to %(targetdir). For each file in %(files),
177 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
178 # appropriate subdirs are not generated by this rule so they have to be
180 %define rule_copy_multi files=/A targetdir=/A srcdir=.
182 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185 #------------------------------------------------------------------------------
187 #------------------------------------------------------------------------------
188 # Copy the files %(files) to %(targetdir). For each file in %(files),
189 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
190 # %(stampfile) is used to keep track of when the last time the comparison has
191 # been done. The targetdir and the appropriate subdirs are not generated by
192 # this rule so they have to be present.
193 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
194 stampfile=$(TMP_SRCDIR)/.copy_stamp
196 TMP_SRCDIR := %(srcdir)
198 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
200 %(stampfile) : COPYSRCDIR := %(srcdir)
201 %(stampfile) : TGTDIR := %(targetdir)
202 %(stampfile) : FILES := %(files)
203 %(stampfile) : $(addprefix %(srcdir)/,%(files))
204 @for f in $(FILES); do \
205 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
206 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
211 #------------------------------------------------------------------------------
213 #------------------------------------------------------------------------------
214 # Will join all the files in %(from) to %(to). When text is specified it will
216 # Restriction: at the moment when using a non-empty target dir %(from) may
218 %define rule_join to=/A from=/A text=
226 #------------------------------------------------------------------------------
229 #------------------------------------------------------------------------------
230 # Include the dependency files and add some internal rules
231 # When depstargets is provided the depencies will only be included when one of
232 # these targets is the $(TARGET). Otherwise the dependencies will only be
233 # include when the $(TARGET) is not for setup or clean
234 %define include_deps deps=$(DEPS)/M depstargets=
236 ifneq (%(depstargets),)
237 ifneq ($(findstring $(TARGET),%(depstargets)),)
241 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
247 #------------------------------------------------------------------------------
250 #------------------------------------------------------------------------------
251 # Create the directories %(dirs). The creation will be done by adding rules to
252 # the %(setuptarget) make target with setup as the default.
253 %define rule_makedirs dirs=/A setuptarget=setup
255 %(setuptarget) :: %(dirs)
257 GLOB_MKDIRS += %(dirs)
260 #------------------------------------------------------------------------------
263 #------------------------------------------------------------------------------
264 # Generate a rule to compile a C source file to an object file and generate
265 # the dependency file. Basename may contain a directory part, then the source
266 # file has to be in that directory. The generated file will be put in the
267 # object directory without the directory.
269 # - basename: the basename of the file to compile. Use % for a wildcard rule
270 # - cflags (default $(CFLAGS)): the C flags to use for compilation
271 # - dflags: the flags used during creation of dependency file. If not specified
272 # the same value as cflags will be used
273 # - targetdir: the directory to put the .o file and the .d file. By default
274 # it is put in the same directory as the .c file
275 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
278 TMP_TARGETBASE := %(basename)
280 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
283 ifeq ($(findstring %(compiler),host kernel target),)
284 $(error unknown compiler %(compiler))
286 ifeq (%(compiler),target)
287 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC)
288 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC)
289 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
290 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
291 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
292 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
294 ifeq (%(compiler),host)
295 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
296 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
297 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
298 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
302 ifeq (%(compiler),kernel)
303 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
304 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
305 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
306 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
307 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
308 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
314 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
321 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
323 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
327 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
329 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
332 $(TMP_TARGETBASE).d : %(basename).c
333 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile multiple C source files to an object file and
340 # generate the corresponding dependency files. The generated file will be put
341 # in the object directory without the directory part of the source file.
343 # - basenames: the basenames of the files to compile. The names may include
344 # relative or absolute path names. No wildcard is allowed
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 # the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 # it is put in the same directory as the .c file. When targetdir is not
350 # empty, path names will be stripped from the file names so that all files
351 # are in that dir and not in subdirectories.
352 # - compiler (default target): compiler to use, target, kernel or host
353 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
357 TMP_TARGETS := $(addsuffix .o,%(basenames))
358 TMP_DTARGETS := $(addsuffix .d,%(basenames))
361 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
362 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
363 TMP_WILDCARD := %(targetdir)/%
365 # Be sure that all .c files are generated
366 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
368 # Be sure that all .c files are found
369 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
370 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
371 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
373 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
374 vpath %.c $(TMP_DIRS)
379 ifeq ($(findstring %(compiler),host kernel target),)
380 $(error unknown compiler %(compiler))
382 ifeq (%(compiler),target)
383 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC)
384 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
385 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
387 ifeq (%(compiler),host)
388 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
389 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
390 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
392 ifeq (%(compiler),kernel)
393 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
394 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
395 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
398 $(TMP_TARGETS) : CFLAGS := %(cflags)
399 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
400 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
403 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
405 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
407 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
408 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
410 #------------------------------------------------------------------------------
413 #------------------------------------------------------------------------------
414 # Make an alias from one arch specific build to another arch.
416 # - mainmmake: the mmake of the module in the main tree
417 # - arch: the current arch
418 # - alias: the alias to which this should point
419 %define rule_archalias mainmmake=\A arch=\A alias=\A
421 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
423 #------------------------------------------------------------------------------
426 #------------------------------------------------------------------------------
427 # Generate a rule to compile a C source file to a shared object file with a
428 # .so suffix. Basename may contain a directory part, then the source
429 # file has to be in that directory. The generated file will be put in the
430 # object directory without the directory.
432 # - basename: the basename of the file to compile. Use % for a wildcard rule
433 # - cflags (default $(CFLAGS)): the C flags to use for compilation
434 # - targetdir: the directory to put the .o file and the .d file. By default
435 # it is put in the same directory as the .c file
436 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
439 TMP_TARGETBASE := %(basename)
441 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
444 ifeq ($(findstring %(compiler),host kernel target),)
445 $(error unknown compiler %(compiler))
447 ifeq (%(compiler),target)
448 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
449 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
450 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
452 ifeq (%(compiler),host)
453 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
454 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
455 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
457 ifeq (%(compiler),kernel)
458 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
459 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
460 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
463 $(TMP_TARGETBASE).so : %(basename).c
464 %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
466 #------------------------------------------------------------------------------
469 #------------------------------------------------------------------------------
470 # Generate a rule to assemble a source file to an object file. Basename may
471 # contain a directory part, then the source file has to be in that directory.
472 # The generated file will be put in the object directory without the directory.
474 # - basename: the basename of the file to compile. Use % for a wildcard rule
475 # - flags (default $(AFLAGS)): the asm flags to use for assembling
476 # - targetdir: the directory to put the .o file in. By default it is put in the
477 # same directory as the .s file
478 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
481 %(basename).o : AFLAGS := %(aflags)
482 %(basename).o : %(basename).s
486 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
487 %(targetdir)/$(notdir %(basename)).o : %(basename).s
492 #------------------------------------------------------------------------------
495 #------------------------------------------------------------------------------
496 # Generate a rule to assemble multiple source files to an object file. The
497 # generated file will be put in the object directory with the directory part
498 # of the source file stripped off.
500 # - basenames: the basenames of the files to compile. The names may include
501 # relative or absolute path names. No wildcard is allowed
502 # - aflags (default $(AFLAGS)): the flags to use for assembly
503 # - targetdir: the directory to put the .o file and the .d file. By default
504 # it is put in the same directory as the .c file. When targetdir is not
505 # empty, path names will be stripped from the file names so that all files
506 # are in that dir and not in subdirectories.
507 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
510 TMP_TARGETS := $(addsuffix .o,%(basenames))
513 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
514 TMP_WILDCARD := %(targetdir)/%
516 # Be sure that all .s files are generated
517 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
519 # Be sure that all .c files are found
520 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
521 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
522 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
524 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
525 vpath %%(suffix) $(TMP_DIRS)
530 $(TMP_TARGETS) : AFLAGS := %(aflags)
531 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
532 %assemble_q opt=$(AFLAGS)
534 #------------------------------------------------------------------------------
537 #------------------------------------------------------------------------------
538 # Link %(objs) to %(prog) using the libraries in %(uselibs)
539 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
540 usehostlibs= usestartup=yes detach=no nix=no
544 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
546 ifeq (%(usestartup),no)
547 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
550 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
553 # Make a list of the lib files this program depends on.
555 # In LDFLAGS remove white space between -L and directory
556 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
557 # Filter out only the libdirs and remove -L
558 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
560 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
561 # Add normal linklib path
562 TMP_DIRS += $(LIBDIR)/
563 # add lib and .a to static linklib names
564 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
565 # search for the linklibs in the given path, ignore ones not found
566 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
567 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
573 %(prog) : OBJS := %(objs)
574 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
575 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
576 %(prog) : %(objs) $(TMP_DEPLIBS)
577 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
579 #------------------------------------------------------------------------------
582 #------------------------------------------------------------------------------
583 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
584 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
585 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
586 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
587 usestartup=yes detach=no
591 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
593 ifeq (%(usestartup),no)
594 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
597 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
600 # Make a list of the lib files the programs depend on.
602 # In LDFLAGS remove white space between -L and directory
603 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
604 # Filter out only the libdirs and remove -L
605 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
607 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
608 # Add normal linklib path
609 TMP_DIRS += $(LIBDIR)/lib/
610 # add lib and .a to static linklib names
611 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
612 # search for the linklibs in the given path, ignore ones not found
613 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
614 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
620 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
621 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
622 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
623 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
625 #------------------------------------------------------------------------------
628 #------------------------------------------------------------------------------
629 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
630 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
632 %(libdir)/lib%(libname).a : %(objs)
635 #------------------------------------------------------------------------------
638 #------------------------------------------------------------------------------
639 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
640 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
642 %(libdir)/lib%(libname).so : %(objs)
643 @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
645 #------------------------------------------------------------------------------
648 #------------------------------------------------------------------------------
649 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
650 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
651 # The -noarosc flag is added so that modules are not linked with arosc.library
652 # (see /config/specs.in file)
653 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
654 uselibs= usehostlibs=
656 %(module) : OBJS := %(objs)
657 %(module) : ENDTAG := %(endobj)
658 %(module) : ERR := %(err)
659 %(module) : OBJDIR := %(objdir)
660 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
661 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
662 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
665 #------------------------------------------------------------------------------
668 #------------------------------------------------------------------------------
669 # Generate a rule to generate a function reference file from a C source file.
670 # Basename may contain a directory part, then the source file has to be in that
671 # directory. The generated file will be put in the object directory without the
674 # - basename: the basename of the file to compile. Use % for a wildcard rule
675 # - cflags (default $(CFLAGS)): the C flags to use for compilation
676 # - targetdir: the directory to put the generated .ref file. By default the
677 # .ref file will be put in the same directory as the .c file.
678 # - includefile: This file will be included at the head of the source file
679 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
682 GENFILE_TMP := %(basename).ref
684 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
687 ifeq ($(filter %(compiler),target kernel host),)
688 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
691 ifeq (%(compiler),target)
692 $(GENFILE_TMP) : CC:=$(TARGET_CC)
694 ifeq (%(compiler),host)
695 $(GENFILE_TMP) : CC:=$(HOST_CC)
697 ifeq(%(compiler),kernel)
698 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
701 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
702 ifeq (%(includefile),)
703 %mkref_q cc=$(CC) cflags="%(cflags)"
705 %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
709 #------------------------------------------------------------------------------
712 #------------------------------------------------------------------------------
713 # Generate a rule to generate a function reference file from a C source file.
714 # Basename may contain a directory part, then the source file has to be in that
715 # directory. The generated file will be put in the object directory without the
718 # - basenames: the basenames of the files to compile. No wildcard is allowed
719 # - cflags (default $(CFLAGS)): the C flags to use for compilation
720 # - targetdir: the directory to put the generated .ref file. By default the
721 # .ref file will be put in the same directory as the .c file. When targetdir
722 # is not empty all files will be put there and path parts in the basenames
723 # will be stripped off.
724 # - includefile: This file will be included at the head of the source file
725 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
729 TMP_TARGETS := $(addsuffix .ref,%(basenames))
730 TMP_WILDCARD := %.ref
732 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
733 TMP_WILDCARD := %(targetdir)/%.ref
735 # Be sure that all .c files are generated
736 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
738 # Be sure that all .c files are found
739 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
740 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
741 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
743 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
744 vpath %.c $(TMP_DIRS)
749 ifeq ($(filter %(compiler),target kernel host),)
750 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
753 ifeq (%(compiler),target)
754 $(TMP_TARGETS) : CC:=$(TARGET_CC)
756 ifeq (%(compiler),host)
757 $(TMP_TARGETS) : CC:=$(HOST_CC)
759 ifeq (%(compiler),kernel)
760 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
762 ifeq (%(includefile),)
763 $(TMP_TARGETS) : CFLAGS:=%(cflags)
765 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
766 $(TMP_TARGETS) : %(includefile)
768 $(TMP_TARGETS) : $(CXREF)
769 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
772 #------------------------------------------------------------------------------
775 #------------------------------------------------------------------------------
776 # Generate the libdefs.h include file for a module.
777 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
779 TMP_TARGET := %(modname)_libdefs.h
780 TMP_DEPS := $(GENMODULE)
783 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
784 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
786 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
787 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
789 ifneq (%(modsuffix),)
790 TMP_OPTS += -s %(modsuffix)
792 ifneq (%(targetdir),)
793 TMP_OPTS += -d %(targetdir)
794 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
797 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
798 $(TMP_TARGET) : MODNAME := %(modname)
799 $(TMP_TARGET) : MODTYPE := %(modtype)
800 $(TMP_TARGET) : $(TMP_DEPS)
801 @$(ECHO) "Generating $(notdir $@)"
802 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
804 #------------------------------------------------------------------------------
807 #------------------------------------------------------------------------------
808 # Generate the libdefs.h include file for a module.
809 %define rule_genmodule_funclist \
810 modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
812 TMP_TARGET := %(modname).funclist
813 TMP_DEPS := $(GENMODULE)
816 $(error reffile needed in rule_genmodule_funclist but none specified)
818 TMP_OPTS := -r %(reffile)
819 TMP_DEPS += %(reffile)
821 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
822 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
824 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
825 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
827 ifneq (%(modsuffix),)
828 TMP_OPTS += -s %(modsuffix)
830 ifneq (%(targetdir),)
831 TMP_OPTS += -d %(targetdir)
832 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
835 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
836 $(TMP_TARGET) : MODNAME := %(modname)
837 $(TMP_TARGET) : MODTYPE := %(modtype)
838 $(TMP_TARGET) : $(TMP_DEPS)
839 @$(ECHO) "Generating $(notdir $@)"
840 @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
842 #------------------------------------------------------------------------------
845 #------------------------------------------------------------------------------
846 # Generate a Makefile.%(modname) with the genmodule program and include this
847 # generated file in this Makefile
848 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
851 TMP_TARGET := Makefile.%(modname)
852 TMP_DEPS := $(GENMODULE)
855 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
856 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
858 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
859 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
861 ifneq (%(modsuffix),)
862 TMP_OPTS += -s %(modsuffix)
864 ifneq (%(targetdir),)
865 TMP_OPTS += -d %(targetdir)
866 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
869 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
870 $(TMP_TARGET) : MODNAME := %(modname)
871 $(TMP_TARGET) : MODTYPE := %(modtype)
872 $(TMP_TARGET) : $(TMP_DEPS)
873 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
875 #------------------------------------------------------------------------------
877 #------------------------------------------------------------------------------
878 # Generate dummy support files so cxref when used on the a module source file
879 # will find something to include. This rule has to be preceeded by
880 # %rule_genmodule_makefile
881 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
883 ifneq ($(%(modname)_INCLUDES),)
884 TMP_TARGETS := $(%(modname)_INCLUDES)
886 TMP_DEPS := $(GENMODULE)
889 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
890 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
892 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
893 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
895 ifneq (%(modsuffix),)
896 TMP_OPTS += -s %(modsuffix)
898 ifneq (%(targetdir),)
899 TMP_OPTS += -d %(targetdir)
900 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
903 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
904 $(TMP_TARGETS) : MODNAME := %(modname)
905 $(TMP_TARGETS) : MODTYPE := %(modtype)
906 $(TMP_TARGETS) : $(TMP_DEPS)
907 @$(ECHO) "Generating dummy include files"
908 @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
911 #------------------------------------------------------------------------------
914 #------------------------------------------------------------------------------
915 # Generate the support files for compiling a module. This includes include
916 # files and source files. This rule has to be preceeded by
917 # %rule_genmodule_makefile
918 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
921 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
922 $(%(modname)_LINKLIBFILES)
923 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
925 TMP_DEPS := $(GENMODULE)
926 ifeq ($(%(modname)_NEEDREF), yes)
928 $(error reffile needed in rule_genmodule_files but none specified)
930 TMP_OPTS := -r %(reffile)
931 TMP_DEPS += %(reffile)
936 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
937 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
939 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
940 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
942 ifneq (%(modsuffix),)
943 TMP_OPTS += -s %(modsuffix)
945 ifneq (%(targetdir),)
946 TMP_OPTS += -d %(targetdir)
947 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
948 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
951 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
952 $(TMP_TARGETS) : MODNAME := %(modname)
953 $(TMP_TARGETS) : MODTYPE := %(modtype)
954 $(TMP_TARGETS) : $(TMP_DEPS)
955 @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
956 ifneq (%(conffile),lib.conf)
957 @$(IF) $(TEST) -f lib.conf; then \
958 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
961 @$(IF) $(TEST) -f libdefs.h; then \
962 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
964 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
966 #------------------------------------------------------------------------------
968 #------------------------------------------------------------------------------
969 # Generate the support files for compiling a module. This includes include
970 # files and source files.
971 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
972 targetdir= conffile= reffile=
975 ifneq ($(%(modname)_INCLUDES),)
976 TMP_TARGETS := $(%(modname)_INCLUDES)
978 TMP_DEPS := $(GENMODULE)
979 ifeq ($(%(modname)_NEEDREF), yes)
981 $(error reffile needed in rule_genmodule_files but none specified)
983 TMP_OPTS := -r %(reffile)
984 TMP_DEPS += %(reffile)
989 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
990 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
992 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
993 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
995 ifneq (%(modsuffix),)
996 TMP_OPTS += -s %(modsuffix)
998 ifneq (%(targetdir),)
999 TMP_OPTS += -d %(targetdir)
1000 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1003 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1004 $(TMP_TARGETS) : MODNAME := %(modname)
1005 $(TMP_TARGETS) : MODTYPE := %(modtype)
1006 $(TMP_TARGETS) : $(TMP_DEPS)
1007 @$(ECHO) "Generating include files"
1008 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1011 #------------------------------------------------------------------------------
1013 #------------------------------------------------------------------------------
1014 # Common rules for all makefiles
1016 # Delete generated makefiles
1019 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1021 include $(SRCDIR)/config/make.tail
1023 BDID := $(BDTARGETID)
1025 #------------------------------------------------------------------------------
1028 #############################################################################
1029 #############################################################################
1031 ## Here are the mmakefile build macro's. These are macro's that takes care ##
1032 ## of everything to go from the sources to the generated target. Also all ##
1033 ## intermediate files and directories that are needed are created by these ##
1036 #############################################################################
1037 #############################################################################
1039 #------------------------------------------------------------------------------
1041 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1042 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1043 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1044 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1049 BD_PROGNAME := %(progname)
1050 BD_OBJDIR := %(objdir)
1051 BD_TARGETDIR := %(targetdir)
1053 BD_FILES := %(files)
1054 BD_ASMFILES := %(asmfiles)
1055 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES) $(BD_ASMFILES)))
1056 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1058 BD_CFLAGS := %(cflags)
1059 BD_AFLAGS := %(aflags)
1060 BD_DFLAGS := %(dflags)
1061 BD_LDFLAGS := %(ldflags)
1064 %(mmake)-quick : %(mmake)
1066 #MM %(mmake) : includes-generate-deps
1067 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1069 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1070 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1071 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1072 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1075 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1076 objs=$(BD_OBJS) ldflags=$(BD_LDFLAGS) \
1077 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1078 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
1082 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1084 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1085 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1086 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1088 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1091 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1095 #------------------------------------------------------------------------------
1098 #------------------------------------------------------------------------------
1099 # Build programs, for every C file an executable will be built with the same
1101 %define build_progs mmake=/A files=/A nix=no \
1102 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1103 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1104 uselibs= usehostlibs= usestartup=yes detach=no
1108 BD_OBJDIR := %(objdir)
1109 BD_TARGETDIR := %(targetdir)
1111 BD_FILES := %(files)
1112 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1113 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1114 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1116 BD_CFLAGS := %(cflags)
1117 BD_DFLAGS := %(dflags)
1118 BD_LDFLAGS := %(ldflags)
1121 %(mmake)-quick : %(mmake)
1123 #MM %(mmake) : includes-generate-deps
1124 %(mmake) : $(BD_EXES)
1126 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1127 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1128 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1130 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1131 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1132 ldflags=$(BD_LDFLAGS) \
1133 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1134 usestartup="%(usestartup)" detach="%(detach)"
1138 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1140 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1141 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1142 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1144 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1147 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1151 #------------------------------------------------------------------------------
1154 #------------------------------------------------------------------------------
1156 # This is a bare version: It just compiles and links the given files. It is
1157 # assumed that all needed boiler plate code is in the files. This should only
1158 # be used for compiling external code. For AROS code use %build_module
1159 %define build_module_simple mmake=/A modname=/A modtype=/A \
1160 files="$(basename $(call WILDCARD, *.c))" \
1161 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1162 objdir=$(OBJDIR) moduledir= \
1163 uselibs= usehostlibs= compiler=target
1165 # Define metamake targets and their dependencies
1166 #MM %(mmake) : core-linklibs includes-generate-deps
1167 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1171 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1173 .PHONY : $(BD_ALLTARGETS)
1176 $(error using %build_module_simple: modname may not be empty)
1179 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1182 # Default values for variables and arguments
1183 BD_DEFLINKLIBNAME := %(modname)
1184 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1185 BD_DEFDFLAGS := %(cflags)
1186 OBJDIR ?= $(GENDIR)/$(CURDIR)
1187 BD_MODDIR := %(moduledir)
1188 ifeq ($(BD_MODDIR),)
1189 ifeq (%(modtype),library)
1190 BD_MODDIR := $(AROS_LIBS)
1192 ifeq (%(modtype),gadget)
1193 BD_MODDIR := $(AROS_GADGETS)
1195 ifeq (%(modtype),datatype)
1196 BD_MODDIR := $(AROS_DATATYPES)
1198 ifeq (%(modtype),handler)
1199 BD_MODDIR := $(AROS_FS)
1201 ifeq (%(modtype),device)
1202 BD_MODDIR := $(AROS_DEVS)
1204 ifeq (%(modtype),resource)
1205 BD_MODDIR := $(AROS_RESOURCES)
1207 ifeq (%(modtype),mui)
1208 BD_MODDIR := $(AROS_CLASSES)/Zune
1210 ifeq (%(modtype),mcc)
1211 BD_MODDIR := $(AROS_CLASSES)/Zune
1213 ifeq (%(modtype),mcp)
1214 BD_MODDIR := $(AROS_CLASSES)/Zune
1216 ifeq (%(modtype),usbclass)
1217 BD_MODDIR := $(AROS_CLASSES)/USB
1219 ifeq (%(modtype),hidd)
1220 BD_MODDIR := $(AROS_DRIVERS)
1223 ifeq ($(BD_MODDIR),)
1224 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1227 %rule_compile_multi \
1228 basenames="%(files)" targetdir="%(objdir)" \
1229 cflags="%(cflags)" dflags="%(dflags)" \
1230 compiler=%(compiler)
1232 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1233 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1235 %(mmake)-quick : %(mmake)
1236 %(mmake) : $(BD_MODULE)
1237 %(mmake)-kobj : $(BD_KOBJ)
1239 # The module is linked from all the compiled .o files
1240 BD_OBJS := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1241 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1242 endobj= err=%(modname).err objdir=%(objdir) \
1243 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1245 # Link kernel object file
1246 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1248 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1249 GfxBase OOPBase UtilityBase ExpansionBase KeymapBase KernelBase
1250 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1251 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1252 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1253 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1254 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1255 @$(ECHO) "Linking $@"
1256 @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1257 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1260 ## Dependency fine-tuning
1262 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1263 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1265 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1266 $(BD_MODULE) : | $(BD_MODDIR)
1267 $(BD_KOBJ) : | $(KOBJSDIR)
1268 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1270 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1272 @$(ECHO) "Cleaning up for module %(modname)"
1277 #------------------------------------------------------------------------------
1279 # Explanation of this macro is done in the developer's manual
1280 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1281 conffile= files="$(basename $(call WILDCARD, *.c))" \
1282 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1283 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1284 reffile=$(BD_DEFREFFILE) noref= \
1285 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1288 # Define metamake targets and their dependencies
1289 #MM- includes-all : %(mmake)-includes
1290 #MM %(mmake) : %(mmake)-includes core-linklibs
1291 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1292 #MM %(mmake)-linklib : %(mmake)-includes
1293 #MM %(mmake)-quick : %(mmake)-includes-quick
1294 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1295 #MM includes-generate-deps
1296 #MM %(mmake)-includes-quick
1297 #MM %(mmake)-includes-dirs
1298 #MM %(mmake)-makefile
1299 #MM %(mmake)-funclist
1302 # All MetaMake targets defined by this macro
1303 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1304 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1305 %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1307 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1310 $(error using %build_module: modname may not be empty)
1313 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1316 # Default values for variables and arguments
1317 BD_DEFLINKLIBNAME := %(modname)
1318 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1319 BD_DEFDFLAGS := %(cflags)
1320 OBJDIR ?= $(GENDIR)/$(CURDIR)
1322 ## Create genmodule include Makefile for the module
1324 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1326 %rule_genmodule_makefile \
1327 modname=%(modname) modtype=%(modtype) \
1328 modsuffix=%(modsuffix) targetdir=%(objdir) \
1329 conffile=%(conffile)
1331 %(objdir)/Makefile.%(modname) : | %(objdir)
1333 GLOB_MKDIRS += %(objdir)
1335 # Do not parse these statements if metatarget is not appropriate
1336 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1338 include %(objdir)/Makefile.%(modname)
1340 BD_DEFMODDIR := $(%(modname)_MODDIR)
1343 ## include files generation
1345 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1346 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1347 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1349 %(mmake)-includes-quick : %(mmake)-includes
1350 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1351 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1352 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1354 ifneq ($(%(modname)_INCLUDES),)
1355 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1356 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1357 conffile=%(conffile) reffile=%(reffile)
1359 %rule_copy_diff_multi \
1360 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1361 stampfile=%(objdir)/%(modname)_geninc
1363 %rule_copy_diff_multi \
1364 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1365 stampfile=%(objdir)/%(modname)_incs
1367 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1368 modsuffix=%(modsuffix) \
1369 targetdir=%(objdir)/dummyinc conffile=%(conffile)
1371 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1373 TMP%(modname)_INCDIRS := \
1374 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1375 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1376 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1377 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1379 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1380 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1384 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1385 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1386 conffile=%(conffile)
1388 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1389 $(BD_DEFLIBDEFSINC) :
1390 @$(ECHO) "generating $@"
1391 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1393 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1394 GLOB_MKDIRS += %(objdir)/include
1396 ## Generation of the funclist file
1398 %(mmake)-funclist : %(modname).funclist
1400 %rule_genmodule_funclist \
1401 modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1402 conffile=%(conffile) reffile=%(reffile)
1405 ## Extra genmodule src files generation
1407 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1408 modsuffix=%(modsuffix) targetdir=%(objdir) \
1409 conffile=%(conffile) reffile=%(reffile)
1413 BD_FILES := %(files)
1414 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1415 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1416 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1418 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1419 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1420 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1422 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1423 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1425 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1426 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1427 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1430 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1432 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1434 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1435 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES)
1437 %rule_compile_multi \
1438 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1439 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1440 compiler=%(compiler)
1441 %rule_compile_multi \
1442 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1443 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1444 compiler=%(compiler)
1446 ifneq ($(BD_LINKLIBAFILES),)
1447 %rule_assemble_multi \
1448 basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1451 ## function reference files generation
1453 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1455 basenames=$(BD_FILES) targetdir=%(objdir) \
1456 cflags=$(BD_CFLAGS_REF) \
1457 compiler=%(compiler)
1460 BD_REFS := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1462 BD_REFS := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1465 %rule_join from=$(BD_REFS) to=%(reffile) \
1466 text="Collecting function references for module %(modname)"
1471 ifeq (%(modsuffix),)
1472 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modtype)
1473 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1475 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1476 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1479 %(mmake)-quick : %(mmake)
1480 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1481 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1482 %(mmake)-linklib : $(BD_LINKLIB)
1484 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1485 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1486 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1487 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1490 # The module is linked from all the compiled .o files
1491 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1492 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1493 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1496 ifneq ($(BD_LINKLIB),)
1497 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1499 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1500 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1503 # Link kernel object file
1504 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1506 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1507 GfxBase OOPBase UtilityBase ExpansionBase KeymapBase KernelBase
1508 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1509 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1510 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1511 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1512 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1513 @$(ECHO) "Linking $@"
1514 @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1515 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1517 ## Dependency fine-tuning
1519 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1520 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1522 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1523 $(BD_MODULE) : | %(prefix)/%(moduledir)
1524 $(BD_KOBJ) : | $(KOBJSDIR)
1525 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1527 # Some include files need to be generated before the .c can be parsed.
1528 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1529 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1530 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1531 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1533 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1534 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1535 $(BD_DEPS) : $(BD_DFILE_DEPS)
1538 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1539 $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1540 %(objdir)/Makefile.%(modname) \
1541 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1542 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1543 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1544 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1545 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1546 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1548 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1550 @$(ECHO) "Cleaning up for module %(modname)"
1553 endif # $(TARGET) in $(BD_ALLTARGETS)
1555 #------------------------------------------------------------------------------
1558 #------------------------------------------------------------------------------
1560 # - mmake is the mmaketarget
1561 # - libname is the baselibname e.g. lib%(libname).a will be created
1562 # - files are the C source files to include in the lib. The list of files
1563 # has to be given without the .c suffix
1564 # - asmfiles are the asm files to include in the lib. The list of files has to
1565 # be given without the .s suffix
1566 # - objs additional object to link into the linklib. The objects have to be
1567 # given with full absolute path and the .o suffix.
1568 # - cflags are the flags to compile the source (default $(CFLAGS))
1569 # - dflags are the flags use during makedepend (default equal to cflags)
1570 # - aflags are the flags use during assembling (default $(AFLAGS))
1571 # - objdir is where the .o are generated
1572 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1573 %define build_linklib mmake=/A libname=/A \
1574 files="$(basename $(call WILDCARD, *.c))" asmfiles= objs= \
1575 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1577 # assign and generate the local variables used in this macro
1578 OBJDIR ?= $(GENDIR)/$(CURDIR)
1580 BD_FILES := %(files)
1581 BD_ASMFILES := %(asmfiles)
1583 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1584 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1585 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1587 BD_OBJS := $(BD_ARCHOBJS) \
1588 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1590 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1592 BD_CFLAGS := %(cflags)
1594 BD_DFLAGS := $(BD_CFLAGS)
1596 BD_DFLAGS := %(dflags)
1598 BD_AFLAGS := %(aflags)
1600 BD_LINKLIB := %(libdir)/lib%(libname).a
1602 .PHONY : %(mmake) %(mmake)-clean
1604 #MM %(mmake) : includes-generate-deps
1605 %(mmake) : $(BD_LINKLIB)
1609 @$(RM) $(BD_OBJS) $(BD_DEPS)
1611 ifeq ($(TARGET),%(mmake))
1612 ifneq ($(dir $(BD_FILES)),./)
1613 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1614 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1617 %rule_compile basename=% targetdir=%(objdir) \
1618 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1619 %rule_assemble basename=% targetdir=%(objdir) \
1623 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1625 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1627 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1628 $(BD_LINKLIB) : | %(libdir)
1629 GLOB_MKDIRS += %(objdir) %(libdir)
1632 #------------------------------------------------------------------------------
1635 #------------------------------------------------------------------------------
1637 # - mmake is the mmaketarget
1638 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1639 # - description is the catalog description file (.cd) (default *.cd)
1640 # - subdir is the destination subdir of the catalogs
1641 # - name is the name of the destination catalog, without the .catalog suffix
1642 # - source is the path to the generated source code file
1643 # - dir is the base destination directory (default $(AROS_CATALOGS))
1644 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1646 %define build_catalogs mmake=/A name=/A subdir=/A \
1647 catalogs="$(basename $(call WILDCARD, *.ct))" source="../strings.h" \
1648 description="$(basename $(call WILDCARD, *.cd))" dir=$(AROS_CATALOGS) \
1649 sourcedescription="$(TOOLDIR)/C_h_orig"
1651 BD_SRCS := $(addsuffix .ct, %(catalogs))
1652 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1653 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1656 %(mmake) : $(BD_OBJS) %(source)
1658 $(BD_OBJS) : | $(BD_DIRS)
1659 GLOB_MKDIRS += $(BD_DIRS)
1661 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1662 @$(ECHO) "Creating %(name) catalog for language $*."
1663 @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1666 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1667 %(source) : %(description).cd
1668 @$(ECHO) "Creating %(name) catalog source file %(source)"
1669 @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1672 %(mmake)-clean : FILES := $(BD_OJS) %(source)
1677 .PHONY: %(mmake) %(mmake)-clean
1681 #-----------------------------------------------------------------------------
1683 #-----------------------------------------------------------------------------
1685 # - mmake is the mmaketarget
1686 # - icons is a list of icon base names (ie. without the .info suffix)
1687 # - dir is the destination directory
1688 #-----------------------------------------------------------------------------
1690 %define build_icons mmake=/A icons=/A dir=/A
1692 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1695 %(mmake) : $(BD_OBJS)
1697 %(dir)/%.info : %.info.src %.png
1698 @$(ECHO) Creating $(notdir $@)...
1699 @$(ILBMTOICON) $+ $@
1701 $(BD_OBJS) : | %(dir)
1702 GLOB_MKDIRS += %(dir)
1704 %(mmake)-clean : FILES := $(BD_OBJS)
1709 .PHONY: %(mmake) %(mmake)-clean
1713 #-----------------------------------------------------------------------------
1715 #------------------------------------------------------------------------------
1716 # Compile files for an arch-specific replacement of code for a module
1717 # - files: the basenames of the C files to compile.
1718 # - asmfiles: the basenames of the asm files to assemble.
1719 # - mainmmake: the mmake of the module in the main directory to compile these
1720 # arch specific files for.
1721 # - maindir: the object directory for the main module
1722 # - arch: the arch for which to compile these files. It can have the form
1723 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1724 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1725 # - dflags: the flags used during creation of dependency file. If not specified
1726 # the same value as cflags will be used
1727 # - aflags: the flags used during assembling
1728 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1729 # the target compiler is used
1730 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1731 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1733 ifeq (%(files) %(asmfiles),)
1734 $(error no files or asmfiles given)
1737 %buildid targets="%(mainmmake)-%(arch)"
1739 ifeq ($(AROS_TARGET_VARIANT),)
1740 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1741 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1742 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1744 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1745 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1746 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1749 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1752 $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1755 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
1756 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1757 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1758 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1759 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1761 ifeq ($(TARGET),%(mainmmake)-%(arch))
1762 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1763 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1764 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1765 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1768 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1769 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1772 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1774 ifeq ($(findstring %(compiler),host kernel target),)
1775 $(error unknown compiler %(compiler))
1777 ifeq (%(compiler),target)
1778 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1779 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1780 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1782 ifeq (%(compiler),host)
1783 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1784 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1785 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1787 ifeq (%(compiler),kernel)
1788 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1789 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1790 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1792 ifneq (%(modulename),)
1793 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1794 -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1796 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1798 ifeq ($(TARGET),%(mainmmake)-%(arch))
1799 $(BD_OBJDIR$(BDID))/%.o : %.c
1800 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1804 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1806 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1808 ifeq ($(TARGET),%(mainmmake)-%(arch))
1809 $(BD_OBJDIR$(BDID))/%.d : %.c
1810 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1813 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1815 ifeq ($(TARGET),%(mainmmake)-%(arch))
1816 $(BD_OBJDIR$(BDID))/%.o : %.s
1817 %assemble_q opt=$(AFLAGS)
1818 $(BD_OBJDIR$(BDID))/%.o : %.S
1819 %assemble_q opt=$(AFLAGS)
1822 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1824 #------------------------------------------------------------------------------
1832 # ======================
1833 # Old stuff, will probably be removed in the future
1838 # GNU Make automatic variables
1840 # $< First dependency
1841 # $? All newer dependencies
1842 # $^ All dependencies
1843 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1844 # a.%.b, then the stem is dir/foo)
1846 #------------------------------------------------------------------------------
1847 # rule to generate libdefs.h with archtool (options may go away!)
1848 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1849 %(dest) : %(conffile) %(genlibdefstool)
1850 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1851 @%(genlibdefstool) -c -o $@ %(conffile)
1855 #------------------------------------------------------------------------------
1856 # generate asm files from c files (for debugging purposes)
1859 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1860 @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1863 #------------------------------------------------------------------------------
1864 # Convert two png images to an Amiga icon file based on the description
1865 # file %(from), with outputfile going to %(to).
1866 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1867 @$(ECHO) "Creating icon %(to)..."
1868 @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1869 @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1870 @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1873 #------------------------------------------------------------------------------
1874 # NOTE: The following are all part of Iain's build changes, please don't use
1875 # or change anything below this line until you know what you are doing. This
1876 # is so that I don't conflict with the semantics of any of the above macros.
1877 #------------------------------------------------------------------------------
1879 #------------------------------------------------------------------------------
1880 # Copy files from one directory to another.
1882 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1884 %(maketarget)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1886 %(maketarget) : setup
1887 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(maketarget)_SRC)),$(%(maketarget)_SRC),$(SRCDIR)/$(CURDIR)/$(%(maketarget)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1894 #----------------------------------------------------------------------------------
1895 # Copy a directory recursively to another place, preserving the original
1896 # hierarchical structure
1898 # src: the source directory whose content will be copied
1899 # dst: the directory where to copy src's content. If not existing, it will be made.
1901 %define copy_dir_recursive mmake=/A src=. dst=/A
1903 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1904 %(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 -o -type f -print)
1905 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
1907 define %(mmake)_mkdir
1912 define %(mmake)_copy
1913 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1920 %(mmake): | $(GENDIR)/$(CURDIR)
1921 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1922 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
1923 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1924 for d in $(%(mmake)_DIRS); do \
1925 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
1927 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1928 for f in $(%(mmake)_FILES); do \
1929 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1931 for dst in %(dst); do \
1932 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1935 $(GENDIR)/$(CURDIR):
1940 #------------------------------------------------------------------------------
1941 # Copy include files into the includes directories. There are currently
1942 # two include directories. One for building AROS $(AROS_INCLUDES) and one
1943 # for building tools that need to run on the host system $(GENINCDIR). The
1944 # $(GENINCDIR) path must not contain any references to the C runtime
1945 # library header files.
1947 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1948 dir= compiler=target
1950 ifeq ($(findstring %(compiler),host kernel target),)
1951 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1955 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1956 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1958 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1959 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1962 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1966 ifeq (%(compiler),target)
1969 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1971 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1974 BD_INCL_FILES += $(BD_INCL_FILES2)
1976 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1981 %(mmake) : $(BD_INCL_FILES)
1985 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1986 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1990 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1991 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1992 STUBS_MEM := $(addsuffix .o,$(STUBS))
1993 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1994 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1995 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1997 #MM- linklibs : hidd-%(hidd)-stubs
1998 #MM- %(parenttarget): hidd-%(hidd)-stubs
1999 #MM hidd-%(hidd)-stubs : includes includes-copy
2000 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2002 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2005 $(STUBS_OBJ) : $(STUBS_SRC)
2006 %compile_q cmd=$(TARGET_CC) opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2008 $(STUBS_DEP) : $(STUBS_SRC)
2009 %mkdepend_q flags=%(dflags)
2012 %mkdirs_q $(OBJDIR) $(LIBDIR)
2016 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2018 DEPS := $(DEPS) $(STUBS_DEP)
2022 #------------------------------------------------------------------------------
2023 # Build an imported source tree which uses the configure script from the
2024 # autoconf package. This rule will try to "integrate" the produced files as
2025 # much as possible in the AROS build, for example by putting libraries in the
2026 # standard library directory, includes in the standard include directory, and
2027 # so on. You can however override this behaviour.
2029 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2030 # be %(bindir) (or its deduced value) when running "make install", and
2031 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2032 # configure script some more parameters whose value depends upon the PROGDIR
2033 # env var, so that the program gets all its stuff installed in the proper place
2034 # when building it, but when running it from inside AROS it can also find that
2035 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2036 # the configuration parameters set when running ./configure
2038 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2039 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2040 # to the name which has to follow it.
2043 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2044 aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
2045 install_target=install preconfigure= postconfigure= postinstall= \
2049 %(mmake)-prefix := %(prefix)
2051 %(mmake)-prefix := $(AROS_CONTRIB)
2054 ifneq (%(aros_prefix),)
2055 %(mmake)-aros_prefix := %(aros_prefix)
2057 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2061 %(mmake)-nix := -nix
2062 %(mmake)-volpfx := /
2063 %(mmake)-volsfx := /
2065 ifeq (%(nix_dir_layout),)
2066 %(mmake)-nix_dir_layout := yes
2069 %(mmake)-volsfx := :
2071 ifeq (%(nix_dir_layout),)
2072 %(mmake)-nix_dir_layout := no
2076 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2078 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2079 exec_prefix=$(%(mmake)-prefix) %(install_env)
2081 # Check if chosen compiler is valid
2082 ifeq ($(findstring %(compiler),host target kernel),)
2083 $(error unknown compiler %(compiler))
2086 # Set legacy 'host' variable based on chosen compiler
2087 ifeq (%(compiler),host)
2090 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2092 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2097 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2099 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2103 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2104 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2106 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2107 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2108 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2111 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2112 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2114 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2117 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2119 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2120 sbindir=$(%(mmake)-prefix) \
2121 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2122 oldincludedir=$(AROS_INCLUDES) %(install_env)
2126 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2128 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2130 # Using -j1 in install_command may result in a warning but finally
2131 # it does its job. make install for gcc does not work reliable for -jN
2133 ifneq (%(install_target),)
2134 %(mmake)-install_command = \
2135 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2136 -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2137 $(TOUCH) $(%(mmake)-installflag)
2139 %(mmake)-uninstall_command = \
2140 $(RM) $(%(mmake)-installflag) && \
2141 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2142 -C $(%(mmake)-pkgdir) uninstall
2144 %(mmake)-install_command := true
2145 %(mmake)-uninstall_command := true
2148 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2151 %(mmake)-build_and_install-quick : $(%(mmake)-configflag)
2152 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2153 $(RM) $(%(mmake)-installflag) && \
2154 $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2155 $(%(mmake)-install_command); \
2158 %(srcdir)/.files-touched:
2159 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2163 %(mmake)-uninstall :
2164 $(%(mmake)-uninstall_command)
2166 ifneq ($(DEBUG),yes)
2167 %(mmake)-s_flag = -s
2171 %(mmake)-configure : $(%(mmake)-configflag)
2173 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2174 ifeq (%(compiler),host)
2175 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2177 %mkdirs_q $(%(mmake)-pkgdir)
2178 cd $(%(mmake)-pkgdir) && \
2179 find . -name config.cache -exec $(RM) '{}' \; && \
2181 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2182 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2183 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2184 --target=$(AROS_TARGET_CPU)-aros && \
2187 ifeq (%(compiler),target)
2188 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2190 %mkdirs_q $(%(mmake)-pkgdir)
2191 cd $(%(mmake)-pkgdir) && \
2192 find . -name config.cache -exec $(RM) '{}' \; && \
2193 CC="$(TARGET_CC) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2194 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2195 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2196 --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2197 --host=$(AROS_TARGET_CPU)-aros \
2198 --target=$(AROS_TARGET_CPU)-aros \
2200 --without-x --without-pic --disable-shared && \
2203 ifeq (%(compiler),kernel)
2204 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2206 %mkdirs_q $(%(mmake)-pkgdir)
2207 cd $(%(mmake)-pkgdir) && \
2208 find . -name config.cache -exec $(RM) '{}' \; && \
2209 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2210 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2211 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2212 --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2213 --host=$(AROS_TARGET_CPU)-aros \
2214 --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2215 --without-x --without-pic --disable-shared && \
2220 %(mmake)-clean : %(mmake)-uninstall
2221 @$(RM) $(%(mmake)-pkgdir)
2224 #############################################################################
2225 #############################################################################
2227 ## Miscellaneous macros. Everything that doesn't fit above should be put ##
2230 #############################################################################
2231 #############################################################################
2233 #----------------------------------------------------------------------------------
2234 # Given an archive name, patches names and locations where to find them, fetch
2235 # the archive and the patches from any of those locations, unpack the archive
2236 # and then apply the patches.
2238 # Locations currently supported are http and ftp sites, plus local filesystem
2239 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2240 # the fetch.sh script needs to be modified, since this macro relies on that script.
2244 # - archive_origins = list of locations where to find the archive. They are tried
2245 # in sequence, until the archive is found and fetching it
2246 # succeeded. If not specified, the current directory is assumed.
2247 # - archive = the archive name. Mandatory.
2248 # - suffixes = a list of suffixes to append to the the package name plus the
2249 # version. Each one of them is tried until a matching archive is
2250 # found. They are appended to patches and these are tried the
2251 # same way as packages are.
2252 # - destination = the local directory where to put the archive and patches.
2253 # If not specified, the current directory is assumed.
2254 # - patches_origins = list of locations where to find the patches. They are tried
2255 # in sequence, until a patch is found and fetching it
2256 # succeeded. If not specified, the current directory is assumed.
2257 # - patches_specs = list of "patch specs". A patch spec is of the form
2258 # patch_name[:[patch_subdir][:patch_opt]].
2260 # - patch_name = the name of the patch file
2261 # - patch_subdir = the directory within \destination\ where to
2263 # - patch_opt = any options to pass to the `patch' command
2264 # when applying the patch.
2266 # The patch_subdir and patch_opt fields are optional.
2268 %define fetch archive_origins=. archive=/A suffixes= location=%destination destination=. patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2269 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l %(location) -d %(destination) \
2270 -po "%(patches_origins)" -p %(patches_specs)
2273 #-----------------------------------------------------------------------------------------
2274 # Joins the features of %fetch and %build_with_configure, taking advantage of
2275 # the naming scheme of GNU packages. GNU packages names are in the form
2277 # <package name>-<version number>.<archive format suffix>
2279 # If a patch is provided, it *must* be named the following way:
2281 # <package name>-<version number>-aros.diff
2283 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2284 # CD'ing into the archive's extracted directory.
2286 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2287 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2288 # to make that patch fully comprehensive.
2290 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2294 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2296 # - package = the GNU package name, sans version and archive format suffixes.
2297 # - version = the package's version number, or otherwise any other version string.
2298 # It gets appended to the package name to form the basename of the archive.
2299 # - suffixes = a list of suffixes to apped to the the package name plus the
2300 # version. Each one of them is tried until a matching archive is found.
2301 # Defaults to "tar.bz2 tar.gz".
2302 # - destination = same meaning as the one for the %fetch macro
2303 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2304 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2306 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2307 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2309 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2311 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2312 # - postinstall = same meaning as the one for the %build_with_configure macro.
2314 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2315 srcdir= package_repo= patch=no patch_repo= prefix= \
2316 aros_prefix= extraoptions= preconfigure= postconfigure= postinstall= nix=no nix_dir_layout=
2318 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2319 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2320 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2322 %(mmake)-archbase := %(package)-%(version)
2324 ifeq (%(compiler),host)
2325 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2327 %(mmake)-portdir := $(PORTSDIR)/%(package)
2331 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2333 %(mmake)-prefix := %(prefix)
2336 ifneq (%(subpackage),)
2337 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2339 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2343 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2345 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2349 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2351 %(mmake)-%(subpackage)-patches_specs := ::
2354 .PHONY : %(mmake)-%(subpackage)-fetch
2356 %(mmake)-%(subpackage)-fetch :
2357 %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2358 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2359 archive_origins=". %(package_repo)" \
2360 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2362 #MM- %(mmake) : %(mmake)-%(subpackage)
2364 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2366 %(mmake)-%(subpackage)-package-basename := \
2367 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2369 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2370 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2371 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2372 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2373 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)"
2375 .PHONY : %(mmake)-%(subpackage)-make-package
2376 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2379 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2381 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2382 #that $^ and $@ have exactly the same mtime, and in that case make tries
2383 #to rebuild $@ again, which would fail because the directory where
2384 #the package got installed would not exist anymore.
2385 #We work this around by using an if statement to manually check the mtimes.
2386 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2387 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2389 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2390 mkdir -p "$(DISTDIR)/Packages" ; \
2391 mkdir -p "$(%(mmake)-prefix)" ; \
2392 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2393 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2394 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2398 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2399 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2400 aros_prefix=/GNU extraoptions= preconfigure= postconfigure= postinstall=
2402 GNU_REPOSITORY := gnu://
2404 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2405 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2406 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2407 patch="%(patch)" patch_repo="%(patch_repo)" \
2408 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2409 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2413 #-----------------------------------------------------------------------------------------
2414 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2415 # that the package is a "Development" package, and as such it needs to be placed
2416 # under the $(AROS_DEVELOPMENT) directory, as a default.
2418 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2419 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2420 # "mmake" argument, because the metatarget is implicitely defined as
2422 # #MM- development-%(package)
2424 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2425 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2426 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions=
2428 #MM- development : development-%(package)
2431 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2432 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2433 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2434 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2435 extraoptions="%(extraoptions)"
2440 #------------------------------------------------------------------------------
2441 # NOTE: The following are all part of platon42's build changes, please don't use
2442 # or change anything below this line until you know what you are doing.
2443 #------------------------------------------------------------------------------
2446 #------------------------------------------------------------------------------
2447 # Build a module skeleton
2448 # This is a stripped-down version of build_module, it only creates include files,
2449 # but no actual object. This is used when for plugins or classes with the same
2450 # API, but no actual implementation here.
2451 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
2453 objdir=$(OBJDIR) prefix=$(AROSDIR) \
2454 reffile=$(BD_DEFREFFILE)
2456 # Define metamake targets and their dependencies
2457 #MM- includes-all : %(mmake)-includes
2458 #MM %(mmake) : %(mmake)-includes core-linklibs
2459 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
2460 #MM %(mmake)-linklib : %(mmake)-includes
2461 #MM %(mmake)-quick : %(mmake)-includes-quick
2462 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
2463 #MM includes-generate-deps
2464 #MM %(mmake)-includes-quick
2465 #MM %(mmake)-includes-dirs
2466 #MM %(mmake)-makefile
2467 #MM %(mmake)-funclist
2470 # All MetaMake targets defined by this macro
2471 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
2472 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
2473 %(mmake)-kobj %(mmake)-funclist
2475 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
2478 $(error using %build_module_skeleton: modname may not be empty)
2481 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
2484 # Default values for variables and arguments
2485 BD_DEFLINKLIBNAME := %(modname)
2486 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
2487 BD_DEFDFLAGS := %(cflags)
2488 OBJDIR ?= $(GENDIR)/$(CURDIR)
2490 ## Create genmodule include Makefile for the module
2492 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
2494 %rule_genmodule_makefile \
2495 modname=%(modname) modtype=%(modtype) \
2496 modsuffix=%(modsuffix) targetdir=%(objdir) \
2497 conffile=%(conffile)
2499 %(objdir)/Makefile.%(modname) : | %(objdir)
2501 GLOB_MKDIRS += %(objdir)
2503 # Do not parse these statements if metatarget is not appropriate
2504 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
2506 include %(objdir)/Makefile.%(modname)
2508 BD_DEFMODDIR := $(%(modname)_MODDIR)
2511 ## include files generation
2513 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
2514 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2515 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2517 %(mmake)-includes-quick : %(mmake)-includes
2518 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2519 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2520 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2522 ifneq ($(%(modname)_INCLUDES),)
2523 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2524 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2525 conffile=%(conffile) reffile=%(reffile)
2527 %rule_copy_diff_multi \
2528 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2529 stampfile=%(objdir)/%(modname)_geninc
2531 %rule_copy_diff_multi \
2532 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2533 stampfile=%(objdir)/%(modname)_incs
2535 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
2536 modsuffix=%(modsuffix) \
2537 targetdir=%(objdir)/dummyinc conffile=%(conffile)
2539 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2541 TMP%(modname)_INCDIRS := \
2542 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2543 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2544 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2545 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2547 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2548 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2552 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2553 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2554 conffile=%(conffile)
2556 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2557 $(BD_DEFLIBDEFSINC) :
2558 @$(ECHO) "generating $@"
2559 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2561 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2562 GLOB_MKDIRS += %(objdir)/include
2564 ## Generation of the funclist file
2566 %(mmake)-funclist : %(modname).funclist
2568 %rule_genmodule_funclist \
2569 modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
2570 conffile=%(conffile) reffile=%(reffile)
2573 ## Extra genmodule src files generation
2575 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2576 modsuffix=%(modsuffix) targetdir=%(objdir) \
2577 conffile=%(conffile) reffile=%(reffile)
2579 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
2580 $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2581 %(objdir)/Makefile.%(modname) \
2582 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2583 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2584 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2585 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2586 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2588 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2590 @$(ECHO) "Cleaning up for module %(modname)"
2593 endif # $(TARGET) in $(BD_ALLTARGETS)
2595 #------------------------------------------------------------------------------