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 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
652 uselibs= usehostlibs=
654 %(module) : OBJS := %(objs)
655 %(module) : ENDTAG := %(endobj)
656 %(module) : ERR := %(err)
657 %(module) : OBJDIR := %(objdir)
658 %(module) : LIBS := $(addprefix -l,%(uselibs)) -larosc -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
659 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
660 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR)
663 #------------------------------------------------------------------------------
666 #------------------------------------------------------------------------------
667 # Generate a rule to generate a function reference file from a C source file.
668 # Basename may contain a directory part, then the source file has to be in that
669 # directory. The generated file will be put in the object directory without the
672 # - basename: the basename of the file to compile. Use % for a wildcard rule
673 # - cflags (default $(CFLAGS)): the C flags to use for compilation
674 # - targetdir: the directory to put the generated .ref file. By default the
675 # .ref file will be put in the same directory as the .c file.
676 # - includefile: This file will be included at the head of the source file
677 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
680 GENFILE_TMP := %(basename).ref
682 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
685 ifeq ($(filter %(compiler),target kernel host),)
686 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
689 ifeq (%(compiler),target)
690 $(GENFILE_TMP) : CC:=$(TARGET_CC)
692 ifeq (%(compiler),host)
693 $(GENFILE_TMP) : CC:=$(HOST_CC)
695 ifeq(%(compiler),kernel)
696 $(GENFILE_TMP) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
699 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
700 ifeq (%(includefile),)
701 %mkref_q cc=$(CC) cflags="%(cflags)"
703 %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
707 #------------------------------------------------------------------------------
710 #------------------------------------------------------------------------------
711 # Generate a rule to generate a function reference file from a C source file.
712 # Basename may contain a directory part, then the source file has to be in that
713 # directory. The generated file will be put in the object directory without the
716 # - basenames: the basenames of the files to compile. No wildcard is allowed
717 # - cflags (default $(CFLAGS)): the C flags to use for compilation
718 # - targetdir: the directory to put the generated .ref file. By default the
719 # .ref file will be put in the same directory as the .c file. When targetdir
720 # is not empty all files will be put there and path parts in the basenames
721 # will be stripped off.
722 # - includefile: This file will be included at the head of the source file
723 %define rule_ref_multi basenames=/A cflags=$(CFLAGS) targetdir= includefile= \
727 TMP_TARGETS := $(addsuffix .ref,%(basenames))
728 TMP_WILDCARD := %.ref
730 TMP_TARGETS := $(addprefix %(targetdir)/,$(addsuffix .ref,$(notdir %(basenames))))
731 TMP_WILDCARD := %(targetdir)/%.ref
733 # Be sure that all .c files are generated
734 $(TMP_TARGETS) : | $(addsuffix .c,%(basenames))
736 # Be sure that all .c files are found
737 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
738 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
739 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
741 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
742 vpath %.c $(TMP_DIRS)
747 ifeq ($(filter %(compiler),target kernel host),)
748 $(error use of %rule_ref: compiler has to be 'host', 'kernel' or 'target')
751 ifeq (%(compiler),target)
752 $(TMP_TARGETS) : CC:=$(TARGET_CC)
754 ifeq (%(compiler),host)
755 $(TMP_TARGETS) : CC:=$(HOST_CC)
757 ifeq (%(compiler),kernel)
758 $(TMP_TARGETS) : CC:=$(KERNEL_CC) $(KERNEL_CFLAGS)
760 ifeq (%(includefile),)
761 $(TMP_TARGETS) : CFLAGS:=%(cflags)
763 $(TMP_TARGETS) : CFLAGS:="%(cflags) -include %(includefile)"
764 $(TMP_TARGETS) : %(includefile)
766 $(TMP_TARGETS) : $(CXREF)
767 $(TMP_TARGETS) : $(TMP_WILDCARD) : %.c
770 #------------------------------------------------------------------------------
773 #------------------------------------------------------------------------------
774 # Generate the libdefs.h include file for a module.
775 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
777 TMP_TARGET := %(modname)_libdefs.h
778 TMP_DEPS := $(GENMODULE)
781 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
782 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
784 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
785 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
787 ifneq (%(modsuffix),)
788 TMP_OPTS += -s %(modsuffix)
790 ifneq (%(targetdir),)
791 TMP_OPTS += -d %(targetdir)
792 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
795 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
796 $(TMP_TARGET) : MODNAME := %(modname)
797 $(TMP_TARGET) : MODTYPE := %(modtype)
798 $(TMP_TARGET) : $(TMP_DEPS)
799 @$(ECHO) "Generating $(notdir $@)"
800 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
802 #------------------------------------------------------------------------------
805 #------------------------------------------------------------------------------
806 # Generate the libdefs.h include file for a module.
807 %define rule_genmodule_funclist \
808 modname=/A modtype=/A modsuffix= conffile= targetdir= reffile=
810 TMP_TARGET := %(modname).funclist
811 TMP_DEPS := $(GENMODULE)
814 $(error reffile needed in rule_genmodule_funclist but none specified)
816 TMP_OPTS := -r %(reffile)
817 TMP_DEPS += %(reffile)
819 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
820 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
822 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
823 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
825 ifneq (%(modsuffix),)
826 TMP_OPTS += -s %(modsuffix)
828 ifneq (%(targetdir),)
829 TMP_OPTS += -d %(targetdir)
830 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
833 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
834 $(TMP_TARGET) : MODNAME := %(modname)
835 $(TMP_TARGET) : MODTYPE := %(modtype)
836 $(TMP_TARGET) : $(TMP_DEPS)
837 @$(ECHO) "Generating $(notdir $@)"
838 @$(GENMODULE) $(OPTS) writefunclist $(MODNAME) $(MODTYPE)
840 #------------------------------------------------------------------------------
843 #------------------------------------------------------------------------------
844 # Generate a Makefile.%(modname) with the genmodule program and include this
845 # generated file in this Makefile
846 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
849 TMP_TARGET := Makefile.%(modname)
850 TMP_DEPS := $(GENMODULE)
853 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
854 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
856 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
857 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
859 ifneq (%(modsuffix),)
860 TMP_OPTS += -s %(modsuffix)
862 ifneq (%(targetdir),)
863 TMP_OPTS += -d %(targetdir)
864 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
867 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
868 $(TMP_TARGET) : MODNAME := %(modname)
869 $(TMP_TARGET) : MODTYPE := %(modtype)
870 $(TMP_TARGET) : $(TMP_DEPS)
871 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
873 #------------------------------------------------------------------------------
875 #------------------------------------------------------------------------------
876 # Generate dummy support files so cxref when used on the a module source file
877 # will find something to include. This rule has to be preceeded by
878 # %rule_genmodule_makefile
879 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile= targetdir=
881 ifneq ($(%(modname)_INCLUDES),)
882 TMP_TARGETS := $(%(modname)_INCLUDES)
884 TMP_DEPS := $(GENMODULE)
887 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
888 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
890 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
891 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
893 ifneq (%(modsuffix),)
894 TMP_OPTS += -s %(modsuffix)
896 ifneq (%(targetdir),)
897 TMP_OPTS += -d %(targetdir)
898 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
901 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
902 $(TMP_TARGETS) : MODNAME := %(modname)
903 $(TMP_TARGETS) : MODTYPE := %(modtype)
904 $(TMP_TARGETS) : $(TMP_DEPS)
905 @$(ECHO) "Generating dummy include files"
906 @$(GENMODULE) $(OPTS) writedummy $(MODNAME) $(MODTYPE)
909 #------------------------------------------------------------------------------
912 #------------------------------------------------------------------------------
913 # Generate the support files for compiling a module. This includes include
914 # files and source files. This rule has to be preceeded by
915 # %rule_genmodule_makefile
916 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
919 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
920 $(%(modname)_LINKLIBFILES)
921 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
923 TMP_DEPS := $(GENMODULE)
924 ifeq ($(%(modname)_NEEDREF), yes)
926 $(error reffile needed in rule_genmodule_files but none specified)
928 TMP_OPTS := -r %(reffile)
929 TMP_DEPS += %(reffile)
934 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
935 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
937 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
938 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
940 ifneq (%(modsuffix),)
941 TMP_OPTS += -s %(modsuffix)
943 ifneq (%(targetdir),)
944 TMP_OPTS += -d %(targetdir)
945 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
946 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
949 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
950 $(TMP_TARGETS) : MODNAME := %(modname)
951 $(TMP_TARGETS) : MODTYPE := %(modtype)
952 $(TMP_TARGETS) : $(TMP_DEPS)
953 @$(ECHO) "Generating functable and support files for module $(MODNAME$(BDID))"
954 ifneq (%(conffile),lib.conf)
955 @$(IF) $(TEST) -f lib.conf; then \
956 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
959 @$(IF) $(TEST) -f libdefs.h; then \
960 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
962 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
964 #------------------------------------------------------------------------------
966 #------------------------------------------------------------------------------
967 # Generate the support files for compiling a module. This includes include
968 # files and source files.
969 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
970 targetdir= conffile= reffile=
973 ifneq ($(%(modname)_INCLUDES),)
974 TMP_TARGETS := $(%(modname)_INCLUDES)
976 TMP_DEPS := $(GENMODULE)
977 ifeq ($(%(modname)_NEEDREF), yes)
979 $(error reffile needed in rule_genmodule_files but none specified)
981 TMP_OPTS := -r %(reffile)
982 TMP_DEPS += %(reffile)
987 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
988 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
990 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
991 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
993 ifneq (%(modsuffix),)
994 TMP_OPTS += -s %(modsuffix)
996 ifneq (%(targetdir),)
997 TMP_OPTS += -d %(targetdir)
998 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1001 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1002 $(TMP_TARGETS) : MODNAME := %(modname)
1003 $(TMP_TARGETS) : MODTYPE := %(modtype)
1004 $(TMP_TARGETS) : $(TMP_DEPS)
1005 @$(ECHO) "Generating include files"
1006 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1009 #------------------------------------------------------------------------------
1011 #------------------------------------------------------------------------------
1012 # Common rules for all makefiles
1014 # Delete generated makefiles
1017 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1019 include $(SRCDIR)/config/make.tail
1021 BDID := $(BDTARGETID)
1023 #------------------------------------------------------------------------------
1026 #############################################################################
1027 #############################################################################
1029 ## Here are the mmakefile build macro's. These are macro's that takes care ##
1030 ## of everything to go from the sources to the generated target. Also all ##
1031 ## intermediate files and directories that are needed are created by these ##
1034 #############################################################################
1035 #############################################################################
1037 #------------------------------------------------------------------------------
1039 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
1040 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1041 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1042 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1047 BD_PROGNAME := %(progname)
1048 BD_OBJDIR := %(objdir)
1049 BD_TARGETDIR := %(targetdir)
1051 BD_FILES := %(files)
1052 BD_ASMFILES := %(asmfiles)
1053 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES) $(BD_ASMFILES)))
1054 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1056 BD_CFLAGS := %(cflags)
1057 BD_AFLAGS := %(aflags)
1058 BD_DFLAGS := %(dflags)
1059 BD_LDFLAGS := %(ldflags)
1062 %(mmake)-quick : %(mmake)
1064 #MM %(mmake) : includes-generate-deps
1065 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1067 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1068 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1069 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1070 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1073 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1074 objs=$(BD_OBJS) ldflags=$(BD_LDFLAGS) \
1075 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1076 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
1080 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1082 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1083 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1084 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1086 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1089 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1093 #------------------------------------------------------------------------------
1096 #------------------------------------------------------------------------------
1097 # Build programs, for every C file an executable will be built with the same
1099 %define build_progs mmake=/A files=/A nix=no \
1100 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1101 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1102 uselibs= usehostlibs= usestartup=yes detach=no
1106 BD_OBJDIR := %(objdir)
1107 BD_TARGETDIR := %(targetdir)
1109 BD_FILES := %(files)
1110 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1111 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1112 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1114 BD_CFLAGS := %(cflags)
1115 BD_DFLAGS := %(dflags)
1116 BD_LDFLAGS := %(ldflags)
1119 %(mmake)-quick : %(mmake)
1121 #MM %(mmake) : includes-generate-deps
1122 %(mmake) : $(BD_EXES)
1124 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1125 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1126 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1128 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1129 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1130 ldflags=$(BD_LDFLAGS) \
1131 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1132 usestartup="%(usestartup)" detach="%(detach)"
1136 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1138 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1139 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1140 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1142 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1145 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1149 #------------------------------------------------------------------------------
1152 #------------------------------------------------------------------------------
1154 # This is a bare version: It just compiles and links the given files. It is
1155 # assumed that all needed boiler plate code is in the files. This should only
1156 # be used for compiling external code. For AROS code use %build_module
1157 %define build_module_simple mmake=/A modname=/A modtype=/A \
1158 files="$(basename $(call WILDCARD, *.c))" \
1159 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1160 objdir=$(OBJDIR) moduledir= \
1161 uselibs= usehostlibs= compiler=target
1163 # Define metamake targets and their dependencies
1164 #MM %(mmake) : core-linklibs includes-generate-deps
1165 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1169 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1171 .PHONY : $(BD_ALLTARGETS)
1174 $(error using %build_module_simple: modname may not be empty)
1177 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1180 # Default values for variables and arguments
1181 BD_DEFLINKLIBNAME := %(modname)
1182 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1183 BD_DEFDFLAGS := %(cflags)
1184 OBJDIR ?= $(GENDIR)/$(CURDIR)
1185 BD_MODDIR := %(moduledir)
1186 ifeq ($(BD_MODDIR),)
1187 ifeq (%(modtype),library)
1188 BD_MODDIR := $(AROS_LIBS)
1190 ifeq (%(modtype),gadget)
1191 BD_MODDIR := $(AROS_GADGETS)
1193 ifeq (%(modtype),datatype)
1194 BD_MODDIR := $(AROS_DATATYPES)
1196 ifeq (%(modtype),handler)
1197 BD_MODDIR := $(AROS_FS)
1199 ifeq (%(modtype),device)
1200 BD_MODDIR := $(AROS_DEVS)
1202 ifeq (%(modtype),resource)
1203 BD_MODDIR := $(AROS_RESOURCES)
1205 ifeq (%(modtype),mui)
1206 BD_MODDIR := $(AROS_CLASSES)/Zune
1208 ifeq (%(modtype),mcc)
1209 BD_MODDIR := $(AROS_CLASSES)/Zune
1211 ifeq (%(modtype),mcp)
1212 BD_MODDIR := $(AROS_CLASSES)/Zune
1214 ifeq (%(modtype),usbclass)
1215 BD_MODDIR := $(AROS_CLASSES)/USB
1217 ifeq (%(modtype),hidd)
1218 BD_MODDIR := $(AROS_DRIVERS)
1221 ifeq ($(BD_MODDIR),)
1222 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1225 %rule_compile_multi \
1226 basenames="%(files)" targetdir="%(objdir)" \
1227 cflags="%(cflags)" dflags="%(dflags)" \
1228 compiler=%(compiler)
1230 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1231 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1233 %(mmake)-quick : %(mmake)
1234 %(mmake) : $(BD_MODULE)
1235 %(mmake)-kobj : $(BD_KOBJ)
1237 # The module is linked from all the compiled .o files
1238 BD_OBJS := $(addprefix %(objdir)/, $(addsuffix .o,%(files)))
1239 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1240 endobj= err=%(modname).err objdir=%(objdir) \
1241 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1243 # Link kernel object file
1244 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1246 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1247 GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1248 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1249 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1250 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1251 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1252 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1253 @$(ECHO) "Linking $@"
1254 @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1255 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1258 ## Dependency fine-tuning
1260 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1261 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1263 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1264 $(BD_MODULE) : | $(BD_MODDIR)
1265 $(BD_KOBJ) : | $(KOBJSDIR)
1266 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1268 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1270 @$(ECHO) "Cleaning up for module %(modname)"
1275 #------------------------------------------------------------------------------
1277 # Explanation of this macro is done in the developer's manual
1278 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1279 conffile= files="$(basename $(call WILDCARD, *.c))" \
1280 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1281 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1282 reffile=$(BD_DEFREFFILE) noref= \
1283 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1286 # Define metamake targets and their dependencies
1287 #MM- includes-all : %(mmake)-includes
1288 #MM %(mmake) : %(mmake)-includes core-linklibs
1289 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1290 #MM %(mmake)-linklib : %(mmake)-includes
1291 #MM %(mmake)-quick : %(mmake)-includes-quick
1292 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1293 #MM includes-generate-deps
1294 #MM %(mmake)-includes-quick
1295 #MM %(mmake)-includes-dirs
1296 #MM %(mmake)-makefile
1297 #MM %(mmake)-funclist
1300 # All MetaMake targets defined by this macro
1301 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1302 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1303 %(mmake)-kobj %(mmake)-funclist %(mmake)-linklib
1305 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1308 $(error using %build_module: modname may not be empty)
1311 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1314 # Default values for variables and arguments
1315 BD_DEFLINKLIBNAME := %(modname)
1316 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
1317 BD_DEFDFLAGS := %(cflags)
1318 OBJDIR ?= $(GENDIR)/$(CURDIR)
1320 ## Create genmodule include Makefile for the module
1322 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1324 %rule_genmodule_makefile \
1325 modname=%(modname) modtype=%(modtype) \
1326 modsuffix=%(modsuffix) targetdir=%(objdir) \
1327 conffile=%(conffile)
1329 %(objdir)/Makefile.%(modname) : | %(objdir)
1331 GLOB_MKDIRS += %(objdir)
1333 # Do not parse these statements if metatarget is not appropriate
1334 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1336 include %(objdir)/Makefile.%(modname)
1338 BD_DEFMODDIR := $(%(modname)_MODDIR)
1341 ## include files generation
1343 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1344 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1345 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1347 %(mmake)-includes-quick : %(mmake)-includes
1348 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1349 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1350 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1352 ifneq ($(%(modname)_INCLUDES),)
1353 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1354 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1355 conffile=%(conffile) reffile=%(reffile)
1357 %rule_copy_diff_multi \
1358 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1359 stampfile=%(objdir)/%(modname)_geninc
1361 %rule_copy_diff_multi \
1362 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1363 stampfile=%(objdir)/%(modname)_incs
1365 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
1366 modsuffix=%(modsuffix) \
1367 targetdir=%(objdir)/dummyinc conffile=%(conffile)
1369 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1371 TMP%(modname)_INCDIRS := \
1372 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1373 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1374 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1375 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1377 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1378 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
1382 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1383 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1384 conffile=%(conffile)
1386 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1387 $(BD_DEFLIBDEFSINC) :
1388 @$(ECHO) "generating $@"
1389 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1391 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1392 GLOB_MKDIRS += %(objdir)/include
1394 ## Generation of the funclist file
1396 %(mmake)-funclist : %(modname).funclist
1398 %rule_genmodule_funclist \
1399 modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
1400 conffile=%(conffile) reffile=%(reffile)
1403 ## Extra genmodule src files generation
1405 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1406 modsuffix=%(modsuffix) targetdir=%(objdir) \
1407 conffile=%(conffile) reffile=%(reffile)
1411 BD_FILES := %(files)
1412 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1413 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1414 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1416 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1417 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1418 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1420 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1421 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1423 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1424 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1425 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1428 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1430 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1432 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1433 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES)
1435 %rule_compile_multi \
1436 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1437 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1438 compiler=%(compiler)
1439 %rule_compile_multi \
1440 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1441 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1442 compiler=%(compiler)
1444 ifneq ($(BD_LINKLIBAFILES),)
1445 %rule_assemble_multi \
1446 basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1449 ## function reference files generation
1451 BD_CFLAGS_REF := -I$(dir $(GENMODULE))/genmod_inc -I%(objdir)/dummyinc $(strip %(cflags)) -I$(TOP)/$(CURDIR) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1453 basenames=$(BD_FILES) targetdir=%(objdir) \
1454 cflags=$(BD_CFLAGS_REF) \
1455 compiler=%(compiler)
1458 BD_REFS := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(BD_FILES))))
1460 BD_REFS := $(addprefix %(objdir)/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES)))))
1463 %rule_join from=$(BD_REFS) to=%(reffile) \
1464 text="Collecting function references for module %(modname)"
1469 ifeq (%(modsuffix),)
1470 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modtype)
1471 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1473 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1474 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1477 %(mmake)-quick : %(mmake)
1478 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1479 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1480 %(mmake)-linklib : $(BD_LINKLIB)
1482 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1483 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1484 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1485 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1488 # The module is linked from all the compiled .o files
1489 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1490 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1491 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1494 ifneq ($(BD_LINKLIB),)
1495 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1497 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1498 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1501 # Link kernel object file
1502 BD_KAUTOLIB := workbench dos cybergraphics intuition layers graphics oop utility \
1504 BD_KBASE := WorkbenchBase DOSBase CyberGfxBase IntuitionBase LayersBase \
1505 GfxBase OOPBase UtilityBase ExpansionBase KeymapBase
1506 BD_KLIB := hiddgraphicsstubs hiddstubs amiga arossupport rom arosm autoinit libinit
1507 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1508 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1509 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_KBASE))
1510 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1511 @$(ECHO) "Linking $@"
1512 @$(AROS_LD) -Ur -o $@ $^ -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1513 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1515 ## Dependency fine-tuning
1517 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1518 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1520 $(BD_OBJS) $(BD_DEPS) $(BD_REFS) : | %(objdir)
1521 $(BD_MODULE) : | %(prefix)/%(moduledir)
1522 $(BD_KOBJ) : | $(KOBJSDIR)
1523 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1525 # Some include files need to be generated before the .c can be parsed.
1526 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
1527 BD_REFFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1528 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES))
1529 $(BD_REFS) : $(BD_REFFILE_DEPS) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
1531 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1532 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1533 $(BD_DEPS) : $(BD_DFILE_DEPS)
1536 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
1537 $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1538 %(objdir)/Makefile.%(modname) \
1539 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1540 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1541 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1542 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1543 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1544 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1546 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1548 @$(ECHO) "Cleaning up for module %(modname)"
1551 endif # $(TARGET) in $(BD_ALLTARGETS)
1553 #------------------------------------------------------------------------------
1556 #------------------------------------------------------------------------------
1558 # - mmake is the mmaketarget
1559 # - libname is the baselibname e.g. lib%(libname).a will be created
1560 # - files are the C source files to include in the lib. The list of files
1561 # has to be given without the .c suffix
1562 # - asmfiles are the asm files to include in the lib. The list of files has to
1563 # be given without the .s suffix
1564 # - objs additional object to link into the linklib. The objects have to be
1565 # given with full absolute path and the .o suffix.
1566 # - cflags are the flags to compile the source (default $(CFLAGS))
1567 # - dflags are the flags use during makedepend (default equal to cflags)
1568 # - aflags are the flags use during assembling (default $(AFLAGS))
1569 # - objdir is where the .o are generated
1570 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1571 %define build_linklib mmake=/A libname=/A \
1572 files="$(basename $(call WILDCARD, *.c))" asmfiles= objs= \
1573 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1575 # assign and generate the local variables used in this macro
1576 OBJDIR ?= $(GENDIR)/$(CURDIR)
1578 BD_FILES := %(files)
1579 BD_ASMFILES := %(asmfiles)
1581 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1582 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1583 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1585 BD_OBJS := $(BD_ARCHOBJS) \
1586 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1588 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1590 BD_CFLAGS := %(cflags)
1592 BD_DFLAGS := $(BD_CFLAGS)
1594 BD_DFLAGS := %(dflags)
1596 BD_AFLAGS := %(aflags)
1598 BD_LINKLIB := %(libdir)/lib%(libname).a
1600 .PHONY : %(mmake) %(mmake)-clean
1602 #MM %(mmake) : includes-generate-deps
1603 %(mmake) : $(BD_LINKLIB)
1607 @$(RM) $(BD_OBJS) $(BD_DEPS)
1609 ifeq ($(TARGET),%(mmake))
1610 ifneq ($(dir $(BD_FILES)),./)
1611 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1612 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1615 %rule_compile basename=% targetdir=%(objdir) \
1616 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1617 %rule_assemble basename=% targetdir=%(objdir) \
1621 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1623 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1625 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1626 $(BD_LINKLIB) : | %(libdir)
1627 GLOB_MKDIRS += %(objdir) %(libdir)
1630 #------------------------------------------------------------------------------
1633 #------------------------------------------------------------------------------
1635 # - mmake is the mmaketarget
1636 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1637 # - description is the catalog description file (.cd) (default *.cd)
1638 # - subdir is the destination subdir of the catalogs
1639 # - name is the name of the destination catalog, without the .catalog suffix
1640 # - source is the path to the generated source code file
1641 # - dir is the base destination directory (default $(AROS_CATALOGS))
1642 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1644 %define build_catalogs mmake=/A name=/A subdir=/A \
1645 catalogs="$(basename $(call WILDCARD, *.ct))" source="../strings.h" \
1646 description="$(basename $(call WILDCARD, *.cd))" dir=$(AROS_CATALOGS) \
1647 sourcedescription="$(TOOLDIR)/C_h_orig"
1649 BD_SRCS := $(addsuffix .ct, %(catalogs))
1650 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, %(catalogs)))
1651 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, %(catalogs)))
1654 %(mmake) : $(BD_OBJS) %(source)
1656 $(BD_OBJS) : | $(BD_DIRS)
1657 GLOB_MKDIRS += $(BD_DIRS)
1659 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1660 @$(ECHO) "Creating %(name) catalog for language $*."
1661 @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1664 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1665 %(source) : %(description).cd
1666 @$(ECHO) "Creating %(name) catalog source file %(source)"
1667 @$(FLEXCAT) $(SRCDIR)/$(CURDIR)/%(description).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1670 %(mmake)-clean : FILES := $(BD_OJS) %(source)
1675 .PHONY: %(mmake) %(mmake)-clean
1679 #-----------------------------------------------------------------------------
1681 #-----------------------------------------------------------------------------
1683 # - mmake is the mmaketarget
1684 # - icons is a list of icon base names (ie. without the .info suffix)
1685 # - dir is the destination directory
1686 #-----------------------------------------------------------------------------
1688 %define build_icons mmake=/A icons=/A dir=/A
1690 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1693 %(mmake) : $(BD_OBJS)
1695 %(dir)/%.info : %.info.src %.png
1696 @$(ECHO) Creating $(notdir $@)...
1697 @$(ILBMTOICON) $+ $@
1699 $(BD_OBJS) : | %(dir)
1700 GLOB_MKDIRS += %(dir)
1702 %(mmake)-clean : FILES := $(BD_OBJS)
1707 .PHONY: %(mmake) %(mmake)-clean
1711 #-----------------------------------------------------------------------------
1713 #------------------------------------------------------------------------------
1714 # Compile files for an arch-specific replacement of code for a module
1715 # - files: the basenames of the C files to compile.
1716 # - asmfiles: the basenames of the asm files to assemble.
1717 # - mainmmake: the mmake of the module in the main directory to compile these
1718 # arch specific files for.
1719 # - maindir: the object directory for the main module
1720 # - arch: the arch for which to compile these files. It can have the form
1721 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1722 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1723 # - dflags: the flags used during creation of dependency file. If not specified
1724 # the same value as cflags will be used
1725 # - aflags: the flags used during assembling
1726 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1727 # the target compiler is used
1728 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1729 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1731 ifeq (%(files) %(asmfiles),)
1732 $(error no files or asmfiles given)
1735 %buildid targets="%(mainmmake)-%(arch)"
1737 ifeq ($(AROS_TARGET_VARIANT),)
1738 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1739 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1740 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1742 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1743 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1744 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1747 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1750 $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1753 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
1754 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1755 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1756 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1757 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1759 ifeq ($(TARGET),%(mainmmake)-%(arch))
1760 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1761 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1762 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1763 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1766 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1767 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1770 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1772 ifeq ($(findstring %(compiler),host kernel target),)
1773 $(error unknown compiler %(compiler))
1775 ifeq (%(compiler),target)
1776 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1777 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1778 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1780 ifeq (%(compiler),host)
1781 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1782 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1783 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1785 ifeq (%(compiler),kernel)
1786 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1787 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1788 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1790 ifneq (%(modulename),)
1791 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1792 -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1794 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1796 ifeq ($(TARGET),%(mainmmake)-%(arch))
1797 $(BD_OBJDIR$(BDID))/%.o : %.c
1798 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1802 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1804 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1806 ifeq ($(TARGET),%(mainmmake)-%(arch))
1807 $(BD_OBJDIR$(BDID))/%.d : %.c
1808 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1811 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1813 ifeq ($(TARGET),%(mainmmake)-%(arch))
1814 $(BD_OBJDIR$(BDID))/%.o : %.s
1815 %assemble_q opt=$(AFLAGS)
1816 $(BD_OBJDIR$(BDID))/%.o : %.S
1817 %assemble_q opt=$(AFLAGS)
1820 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1822 #------------------------------------------------------------------------------
1830 # ======================
1831 # Old stuff, will probably be removed in the future
1836 # GNU Make automatic variables
1838 # $< First dependency
1839 # $? All newer dependencies
1840 # $^ All dependencies
1841 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1842 # a.%.b, then the stem is dir/foo)
1844 #------------------------------------------------------------------------------
1845 # rule to generate libdefs.h with archtool (options may go away!)
1846 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1847 %(dest) : %(conffile) %(genlibdefstool)
1848 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1849 @%(genlibdefstool) -c -o $@ %(conffile)
1853 #------------------------------------------------------------------------------
1854 # generate asm files from c files (for debugging purposes)
1857 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1858 @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1861 #------------------------------------------------------------------------------
1862 # Convert two png images to an Amiga icon file based on the description
1863 # file %(from), with outputfile going to %(to).
1864 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1865 @$(ECHO) "Creating icon %(to)..."
1866 @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1867 @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1868 @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1871 #------------------------------------------------------------------------------
1872 # NOTE: The following are all part of Iain's build changes, please don't use
1873 # or change anything below this line until you know what you are doing. This
1874 # is so that I don't conflict with the semantics of any of the above macros.
1875 #------------------------------------------------------------------------------
1877 #------------------------------------------------------------------------------
1878 # Copy files from one directory to another.
1880 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1882 %(maketarget)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1884 %(maketarget) : setup
1885 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(maketarget)_SRC)),$(%(maketarget)_SRC),$(SRCDIR)/$(CURDIR)/$(%(maketarget)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1892 #----------------------------------------------------------------------------------
1893 # Copy a directory recursively to another place, preserving the original
1894 # hierarchical structure
1896 # src: the source directory whose content will be copied
1897 # dst: the directory where to copy src's content. If not existing, it will be made.
1899 %define copy_dir_recursive mmake=/A src=. dst=/A
1901 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1902 %(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)
1903 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
1905 define %(mmake)_mkdir
1910 define %(mmake)_copy
1911 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1918 %(mmake): | $(GENDIR)/$(CURDIR)
1919 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1920 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
1921 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1922 for d in $(%(mmake)_DIRS); do \
1923 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
1925 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1926 for f in $(%(mmake)_FILES); do \
1927 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1929 for dst in %(dst); do \
1930 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1933 $(GENDIR)/$(CURDIR):
1938 #------------------------------------------------------------------------------
1939 # Copy include files into the includes directories. There are currently
1940 # two include directories. One for building AROS $(AROS_INCLUDES) and one
1941 # for building tools that need to run on the host system $(GENINCDIR). The
1942 # $(GENINCDIR) path must not contain any references to the C runtime
1943 # library header files.
1945 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1946 dir= compiler=target
1948 ifeq ($(findstring %(compiler),host kernel target),)
1949 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1953 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1954 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1956 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1957 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1960 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1964 ifeq (%(compiler),target)
1967 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1969 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1972 BD_INCL_FILES += $(BD_INCL_FILES2)
1974 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1979 %(mmake) : $(BD_INCL_FILES)
1983 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1984 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1988 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1989 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1990 STUBS_MEM := $(addsuffix .o,$(STUBS))
1991 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1992 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1993 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1995 #MM- linklibs : hidd-%(hidd)-stubs
1996 #MM- %(parenttarget): hidd-%(hidd)-stubs
1997 #MM hidd-%(hidd)-stubs : includes includes-copy
1998 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2000 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2003 $(STUBS_OBJ) : $(STUBS_SRC)
2004 %compile_q cmd=$(TARGET_CC) opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2006 $(STUBS_DEP) : $(STUBS_SRC)
2007 %mkdepend_q flags=%(dflags)
2010 %mkdirs_q $(OBJDIR) $(LIBDIR)
2014 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2016 DEPS := $(DEPS) $(STUBS_DEP)
2020 #------------------------------------------------------------------------------
2021 # Build an imported source tree which uses the configure script from the
2022 # autoconf package. This rule will try to "integrate" the produced files as
2023 # much as possible in the AROS build, for example by putting libraries in the
2024 # standard library directory, includes in the standard include directory, and
2025 # so on. You can however override this behaviour.
2027 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2028 # be %(bindir) (or its deduced value) when running "make install", and
2029 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2030 # configure script some more parameters whose value depends upon the PROGDIR
2031 # env var, so that the program gets all its stuff installed in the proper place
2032 # when building it, but when running it from inside AROS it can also find that
2033 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2034 # the configuration parameters set when running ./configure
2036 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2037 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2038 # to the name which has to follow it.
2041 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2042 aros_prefix= extraoptions= nix_dir_layout= nix=no compiler=target \
2043 install_target=install preconfigure= postconfigure= postinstall= \
2047 %(mmake)-prefix := %(prefix)
2049 %(mmake)-prefix := $(AROS_CONTRIB)
2052 ifneq (%(aros_prefix),)
2053 %(mmake)-aros_prefix := %(aros_prefix)
2055 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2059 %(mmake)-nix := -nix
2060 %(mmake)-volpfx := /
2061 %(mmake)-volsfx := /
2063 ifeq (%(nix_dir_layout),)
2064 %(mmake)-nix_dir_layout := yes
2067 %(mmake)-volsfx := :
2069 ifeq (%(nix_dir_layout),)
2070 %(mmake)-nix_dir_layout := no
2074 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2076 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2077 exec_prefix=$(%(mmake)-prefix) %(install_env)
2079 # Check if chosen compiler is valid
2080 ifeq ($(findstring %(compiler),host target kernel),)
2081 $(error unknown compiler %(compiler))
2084 # Set legacy 'host' variable based on chosen compiler
2085 ifeq (%(compiler),host)
2088 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2090 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2095 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2097 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2101 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2102 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2104 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2105 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2106 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2109 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2110 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2112 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2115 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2117 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2118 sbindir=$(%(mmake)-prefix) \
2119 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2120 oldincludedir=$(AROS_INCLUDES) %(install_env)
2124 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2126 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2128 # Using -j1 in install_command may result in a warning but finally
2129 # it does its job. make install for gcc does not work reliable for -jN
2131 ifneq (%(install_target),)
2132 %(mmake)-install_command = \
2133 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2134 -C $(%(mmake)-pkgdir) %(install_target) -j1 && \
2135 $(TOUCH) $(%(mmake)-installflag)
2137 %(mmake)-uninstall_command = \
2138 $(RM) $(%(mmake)-installflag) && \
2139 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2140 -C $(%(mmake)-pkgdir) uninstall
2142 %(mmake)-install_command := true
2143 %(mmake)-uninstall_command := true
2146 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2149 %(mmake)-build_and_install-quick : $(%(mmake)-configflag)
2150 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2151 $(RM) $(%(mmake)-installflag) && \
2152 $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(%(mmake)-pkgdir) && \
2153 $(%(mmake)-install_command); \
2156 %(srcdir)/.files-touched:
2157 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2161 %(mmake)-uninstall :
2162 $(%(mmake)-uninstall_command)
2164 ifneq ($(DEBUG),yes)
2165 %(mmake)-s_flag = -s
2169 %(mmake)-configure : $(%(mmake)-configflag)
2171 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2172 ifeq (%(compiler),host)
2173 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2175 %mkdirs_q $(%(mmake)-pkgdir)
2176 cd $(%(mmake)-pkgdir) && \
2177 find . -name config.cache -exec $(RM) '{}' \; && \
2179 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2180 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2181 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2182 --target=$(AROS_TARGET_CPU)-aros && \
2185 ifeq (%(compiler),target)
2186 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2188 %mkdirs_q $(%(mmake)-pkgdir)
2189 cd $(%(mmake)-pkgdir) && \
2190 find . -name config.cache -exec $(RM) '{}' \; && \
2191 CC="$(TARGET_CC) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2192 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2193 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2194 --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2195 --host=$(AROS_TARGET_CPU)-aros \
2196 --target=$(AROS_TARGET_CPU)-aros \
2198 --without-x --without-pic --disable-shared && \
2201 ifeq (%(compiler),kernel)
2202 $(%(mmake)-configflag) : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2204 %mkdirs_q $(%(mmake)-pkgdir)
2205 cd $(%(mmake)-pkgdir) && \
2206 find . -name config.cache -exec $(RM) '{}' \; && \
2207 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2208 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" \
2209 $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) \
2210 --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH) \
2211 --host=$(AROS_TARGET_CPU)-aros \
2212 --target=$(AROS_TARGET_CPU)-aros --disable-nls \
2213 --without-x --without-pic --disable-shared && \
2218 %(mmake)-clean : %(mmake)-uninstall
2219 @$(RM) $(%(mmake)-pkgdir)
2222 #############################################################################
2223 #############################################################################
2225 ## Miscellaneous macros. Everything that doesn't fit above should be put ##
2228 #############################################################################
2229 #############################################################################
2231 #----------------------------------------------------------------------------------
2232 # Given an archive name, patches names and locations where to find them, fetch
2233 # the archive and the patches from any of those locations, unpack the archive
2234 # and then apply the patches.
2236 # Locations currently supported are http and ftp sites, plus local filesystem
2237 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2238 # the fetch.sh script needs to be modified, since this macro relies on that script.
2242 # - archive_origins = list of locations where to find the archive. They are tried
2243 # in sequence, until the archive is found and fetching it
2244 # succeeded. If not specified, the current directory is assumed.
2245 # - archive = the archive name. Mandatory.
2246 # - suffixes = a list of suffixes to append to the the package name plus the
2247 # version. Each one of them is tried until a matching archive is
2248 # found. They are appended to patches and these are tried the
2249 # same way as packages are.
2250 # - destination = the local directory where to put the archive and patches.
2251 # If not specified, the current directory is assumed.
2252 # - patches_origins = list of locations where to find the patches. They are tried
2253 # in sequence, until a patch is found and fetching it
2254 # succeeded. If not specified, the current directory is assumed.
2255 # - patches_specs = list of "patch specs". A patch spec is of the form
2256 # patch_name[:[patch_subdir][:patch_opt]].
2258 # - patch_name = the name of the patch file
2259 # - patch_subdir = the directory within \destination\ where to
2261 # - patch_opt = any options to pass to the `patch' command
2262 # when applying the patch.
2264 # The patch_subdir and patch_opt fields are optional.
2266 %define fetch archive_origins=. archive=/A suffixes= location=%destination destination=. patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2267 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l %(location) -d %(destination) \
2268 -po "%(patches_origins)" -p %(patches_specs)
2271 #-----------------------------------------------------------------------------------------
2272 # Joins the features of %fetch and %build_with_configure, taking advantage of
2273 # the naming scheme of GNU packages. GNU packages names are in the form
2275 # <package name>-<version number>.<archive format suffix>
2277 # If a patch is provided, it *must* be named the following way:
2279 # <package name>-<version number>-aros.diff
2281 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2282 # CD'ing into the archive's extracted directory.
2284 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2285 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2286 # to make that patch fully comprehensive.
2288 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2292 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2294 # - package = the GNU package name, sans version and archive format suffixes.
2295 # - version = the package's version number, or otherwise any other version string.
2296 # It gets appended to the package name to form the basename of the archive.
2297 # - suffixes = a list of suffixes to apped to the the package name plus the
2298 # version. Each one of them is tried until a matching archive is found.
2299 # Defaults to "tar.bz2 tar.gz".
2300 # - destination = same meaning as the one for the %fetch macro
2301 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2302 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2304 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2305 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2307 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2309 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2310 # - postinstall = same meaning as the one for the %build_with_configure macro.
2312 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2313 srcdir= package_repo= patch=no patch_repo= prefix= \
2314 aros_prefix= extraoptions= preconfigure= postconfigure= postinstall= nix=no nix_dir_layout=
2316 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2317 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2318 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2320 %(mmake)-archbase := %(package)-%(version)
2322 ifeq (%(compiler),host)
2323 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2325 %(mmake)-portdir := $(PORTSDIR)/%(package)
2329 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2331 %(mmake)-prefix := %(prefix)
2334 ifneq (%(subpackage),)
2335 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2337 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2341 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2343 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2347 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2349 %(mmake)-%(subpackage)-patches_specs := ::
2352 .PHONY : %(mmake)-%(subpackage)-fetch
2354 %(mmake)-%(subpackage)-fetch :
2355 %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2356 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2357 archive_origins=". %(package_repo)" \
2358 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2360 #MM- %(mmake) : %(mmake)-%(subpackage)
2362 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2364 %(mmake)-%(subpackage)-package-basename := \
2365 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2367 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2368 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2369 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2370 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2371 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)"
2373 .PHONY : %(mmake)-%(subpackage)-make-package
2374 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2377 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2379 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2380 #that $^ and $@ have exactly the same mtime, and in that case make tries
2381 #to rebuild $@ again, which would fail because the directory where
2382 #the package got installed would not exist anymore.
2383 #We work this around by using an if statement to manually check the mtimes.
2384 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2385 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2387 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2388 mkdir -p "$(DISTDIR)/Packages" ; \
2389 mkdir -p "$(%(mmake)-prefix)" ; \
2390 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2391 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2392 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2396 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2397 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2398 aros_prefix=/GNU extraoptions= preconfigure= postconfigure= postinstall=
2400 GNU_REPOSITORY := gnu://
2402 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2403 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2404 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2405 patch="%(patch)" patch_repo="%(patch_repo)" \
2406 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2407 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2411 #-----------------------------------------------------------------------------------------
2412 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2413 # that the package is a "Development" package, and as such it needs to be placed
2414 # under the $(AROS_DEVELOPMENT) directory, as a default.
2416 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2417 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2418 # "mmake" argument, because the metatarget is implicitely defined as
2420 # #MM- development-%(package)
2422 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2423 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2424 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions=
2426 #MM- development : development-%(package)
2429 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2430 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2431 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2432 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2433 extraoptions="%(extraoptions)"
2438 #------------------------------------------------------------------------------
2439 # NOTE: The following are all part of platon42's build changes, please don't use
2440 # or change anything below this line until you know what you are doing.
2441 #------------------------------------------------------------------------------
2444 #------------------------------------------------------------------------------
2445 # Build a module skeleton
2446 # This is a stripped-down version of build_module, it only creates include files,
2447 # but no actual object. This is used when for plugins or classes with the same
2448 # API, but no actual implementation here.
2449 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
2451 objdir=$(OBJDIR) prefix=$(AROSDIR) \
2452 reffile=$(BD_DEFREFFILE)
2454 # Define metamake targets and their dependencies
2455 #MM- includes-all : %(mmake)-includes
2456 #MM %(mmake) : %(mmake)-includes core-linklibs
2457 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
2458 #MM %(mmake)-linklib : %(mmake)-includes
2459 #MM %(mmake)-quick : %(mmake)-includes-quick
2460 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
2461 #MM includes-generate-deps
2462 #MM %(mmake)-includes-quick
2463 #MM %(mmake)-includes-dirs
2464 #MM %(mmake)-makefile
2465 #MM %(mmake)-funclist
2468 # All MetaMake targets defined by this macro
2469 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
2470 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
2471 %(mmake)-kobj %(mmake)-funclist
2473 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
2476 $(error using %build_module_skeleton: modname may not be empty)
2479 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
2482 # Default values for variables and arguments
2483 BD_DEFLINKLIBNAME := %(modname)
2484 BD_DEFREFFILE := %(objdir)/%(modname)_ALL.ref
2485 BD_DEFDFLAGS := %(cflags)
2486 OBJDIR ?= $(GENDIR)/$(CURDIR)
2488 ## Create genmodule include Makefile for the module
2490 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
2492 %rule_genmodule_makefile \
2493 modname=%(modname) modtype=%(modtype) \
2494 modsuffix=%(modsuffix) targetdir=%(objdir) \
2495 conffile=%(conffile)
2497 %(objdir)/Makefile.%(modname) : | %(objdir)
2499 GLOB_MKDIRS += %(objdir)
2501 # Do not parse these statements if metatarget is not appropriate
2502 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
2504 include %(objdir)/Makefile.%(modname)
2506 BD_DEFMODDIR := $(%(modname)_MODDIR)
2509 ## include files generation
2511 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
2512 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2513 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2515 %(mmake)-includes-quick : %(mmake)-includes
2516 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2517 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2518 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2520 ifneq ($(%(modname)_INCLUDES),)
2521 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2522 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2523 conffile=%(conffile) reffile=%(reffile)
2525 %rule_copy_diff_multi \
2526 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2527 stampfile=%(objdir)/%(modname)_geninc
2529 %rule_copy_diff_multi \
2530 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2531 stampfile=%(objdir)/%(modname)_incs
2533 %rule_genmodule_dummy modname=%(modname) modtype=%(modtype) \
2534 modsuffix=%(modsuffix) \
2535 targetdir=%(objdir)/dummyinc conffile=%(conffile)
2537 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2539 TMP%(modname)_INCDIRS := \
2540 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2541 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2542 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2543 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2545 $(addprefix %(objdir)/dummyinc/,$(%(modname)_INCLUDES)) : | %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2546 GLOB_MKDIRS += %(objdir)/dummyinc $(addprefix %(objdir)/dummyinc/,$(BD_INCDIRS))
2550 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2551 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2552 conffile=%(conffile)
2554 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2555 $(BD_DEFLIBDEFSINC) :
2556 @$(ECHO) "generating $@"
2557 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2559 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2560 GLOB_MKDIRS += %(objdir)/include
2562 ## Generation of the funclist file
2564 %(mmake)-funclist : %(modname).funclist
2566 %rule_genmodule_funclist \
2567 modname=%(modname) modtype=%(modtype) modsuffix=%(modsuffix) \
2568 conffile=%(conffile) reffile=%(reffile)
2571 ## Extra genmodule src files generation
2573 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2574 modsuffix=%(modsuffix) targetdir=%(objdir) \
2575 conffile=%(conffile) reffile=%(reffile)
2577 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) %(reffile) \
2578 $(BD_REFS) $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2579 %(objdir)/Makefile.%(modname) \
2580 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2581 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2582 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2583 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2584 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2586 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2588 @$(ECHO) "Cleaning up for module %(modname)"
2591 endif # $(TARGET) in $(BD_ALLTARGETS)
2593 #------------------------------------------------------------------------------