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 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16 %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26 @$(ECHO) "Compiling $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
35 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd="$(CC) $(TARGET_SYSROOT)" opt=$(AFLAGS) from=$< to=$@
46 @$(ECHO) "Assembling $(notdir %(from))..."
47 @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
55 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,%(to))..."
67 @$(IF) %(cmd) %(from) -o %(to) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(opt) %(libs)" >> $(GENDIR)/errors ; \
70 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
75 $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(opt) %(libs)" 1>&2 ; \
76 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
90 @if %(cmd) $(NOSTARTUP_LDFLAGS) \
91 $(GENMAP) %(objdir)/%(module).map \
92 %(objs) %(libs) %(ldflags) %(endtag) \
93 -o $@ 2>&1 > %(objdir)/%(err); \
95 cat %(objdir)/%(err); \
97 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
98 cat %(objdir)/%(err); \
102 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
121 %mkdir_q dir="$(dir %(to))"
122 @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
133 #------------------------------------------------------------------------------
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 ; \
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
149 ## Here are the mmakefile macros that are used to do certain tasks in a ##
150 ## mmakefile. They consist of one or more full makefile rules. ##
151 ## In general the files generated in these macros are also defined as ##
152 ## make targets so that they can be used as a dependency in other rules ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197 stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207 @for f in $(FILES); do \
208 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
220 # Restriction: at the moment when using a non-empty target dir %(from) may
222 %define rule_join to=/A from=/A text=
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean
238 %define include_deps deps=$(DEPS)/M depstargets=
240 ifneq (%(depstargets),)
241 ifneq ($(findstring $(TARGET),%(depstargets)),)
245 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default.
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 # the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 # it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
282 TMP_TARGETBASE := %(basename)
284 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
287 # Adjust compiler flags to suit C
288 TMP_CFLAGS := %(cflags)
289 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
291 ifeq ($(findstring %(compiler),host kernel target),)
292 $(error unknown compiler %(compiler))
294 ifeq (%(compiler),target)
295 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
296 BD_STRIP ?= $(TARGET_STRIP)
297 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
298 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
304 ifeq (%(compiler),host)
305 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
306 BD_STRIP ?= $(HOST_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
314 ifeq (%(compiler),kernel)
315 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
316 BD_STRIP ?= $(ECHO) >/dev/null
317 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
318 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
319 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
320 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
321 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
322 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
325 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
326 $(TMP_TARGETBASE).o : %(basename).c
327 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
331 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
333 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
337 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
339 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
342 $(TMP_TARGETBASE).d : %(basename).c
343 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
345 #------------------------------------------------------------------------------
348 #------------------------------------------------------------------------------
349 # Generate a rule to compile a C++ source file to an object file and generate
350 # the dependency file. Basename may contain a directory part, then the source
351 # file has to be in that directory. The generated file will be put in the
352 # object directory without the directory.
354 # - basename: the basename of the file to compile. Use % for a wildcard rule
355 # - cflags (default $(CFLAGS)): the C flags to use for compilation
356 # - dflags: the flags used during creation of dependency file. If not specified
357 # the same value as cflags will be used
358 # - targetdir: the directory to put the .o file and the .d file. By default
359 # it is put in the same directory as the .c file
360 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
365 TMP_TARGETBASE := %(basename)
367 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
370 # Adjust compiler flags to suit C++
371 TMP_CXXFLAGS := %(cflags)
372 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include
373 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
375 ifeq ($(findstring %(compiler),host kernel target),)
376 $(error unknown compiler %(compiler))
378 ifeq (%(compiler),target)
379 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
380 BD_STRIP ?= $(TARGET_STRIP)
381 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
382 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
388 ifeq (%(compiler),host)
389 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
390 BD_STRIP ?= $(HOST_STRIP)
391 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
392 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
393 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
394 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
395 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
396 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
398 ifeq (%(compiler),kernel)
399 KERNEL_CXX ?= $(KERNEL_CC)
400 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
401 BD_STRIP ?= $(ECHO) >/dev/null
402 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
403 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
404 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
405 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
406 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
407 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
410 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
411 $(TMP_TARGETBASE).o : %(basename).cpp
412 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
416 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
418 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
422 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
424 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
427 $(TMP_TARGETBASE).d : %(basename).cpp
428 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
433 #------------------------------------------------------------------------------
436 #------------------------------------------------------------------------------
437 # Generate a rule to compile an ObjC source file to an object file and generate
438 # the dependency file. Basename may contain a directory part, then the source
439 # file has to be in that directory. The generated file will be put in the
440 # object directory without the directory.
442 # - basename: the basename of the file to compile. Use % for a wildcard rule
443 # - cflags (default $(CFLAGS)): the C flags to use for compilation
444 # - dflags: the flags used during creation of dependency file. If not specified
445 # the same value as cflags will be used
446 # - targetdir: the directory to put the .o file and the .d file. By default
447 # it is put in the same directory as the .m file
448 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
453 TMP_TARGETBASE := %(basename)
455 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
458 # Adjust compiler flags to suit ObjC
459 TMP_OBJCFLAGS := %(cflags)
460 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
461 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
463 # Define the use of cross compiler
464 ifeq ($(TARGET_OBJC),)
465 TMP_CC := $(TARGET_CC)
467 TMP_CC := $(TARGET_OBJC)
470 ifeq ($(findstring %(compiler),host kernel target),)
471 $(error unknown compiler %(compiler))
473 ifeq (%(compiler),target)
474 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
475 BD_STRIP ?= $(TARGET_STRIP)
476 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
477 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
478 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
479 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
480 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
481 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
483 ifeq (%(compiler),host)
484 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
485 BD_STRIP ?= $(HOST_STRIP)
486 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
487 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
488 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
489 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
490 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
491 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
493 ifeq (%(compiler),kernel)
494 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
495 BD_STRIP ?= $(ECHO) >/dev/null
496 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
497 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
498 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
499 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
500 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
501 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
504 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
505 $(TMP_TARGETBASE).o : %(basename).m
506 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
510 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
512 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
516 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
518 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
521 $(TMP_TARGETBASE).d : %(basename).m
522 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
527 #------------------------------------------------------------------------------
530 #------------------------------------------------------------------------------
531 # Generate a rule to compile multiple C source files to an object file and
532 # generate the corresponding dependency files. The generated file will be put
533 # in the object directory without the directory part of the source file.
535 # - basenames: the basenames of the files to compile. The names may include
536 # relative or absolute path names. No wildcard is allowed
537 # - cflags (default $(CFLAGS)): the C flags to use for compilation
538 # - dflags: the flags used during creation of dependency file. If not specified
539 # the same value as cflags will be used
540 # - targetdir: the directory to put the .o file and the .d file. By default
541 # it is put in the same directory as the .c file. When targetdir is not
542 # empty, path names will be stripped from the file names so that all files
543 # are in that dir and not in subdirectories.
544 # - compiler (default target): compiler to use, target, kernel or host
545 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
549 TMP_TARGETS := $(addsuffix .o,%(basenames))
550 TMP_DTARGETS := $(addsuffix .d,%(basenames))
553 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
554 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
555 TMP_WILDCARD := %(targetdir)/%
557 # Be sure that all .c files are generated
558 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
560 # Be sure that all .c files are found
561 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
562 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
563 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
565 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
566 vpath %.c $(TMP_DIRS)
571 ifeq ($(findstring %(compiler),host kernel target),)
572 $(error unknown compiler %(compiler))
574 ifeq (%(compiler),target)
575 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
576 BD_STRIP ?= $(TARGET_STRIP)
577 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
578 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
579 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
581 ifeq (%(compiler),host)
582 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
583 BD_STRIP ?= $(HOST_STRIP)
584 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
585 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
586 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
588 ifeq (%(compiler),kernel)
589 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
590 BD_STRIP ?= $(ECHO) >/dev/null
591 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
592 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
593 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
596 $(TMP_TARGETS) : CFLAGS := %(cflags)
597 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
598 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
601 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
603 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
605 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
606 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
608 #------------------------------------------------------------------------------
611 #------------------------------------------------------------------------------
612 # Generate a rule to compile multiple C++ source files to an object file and
613 # generate the corresponding dependency files. The generated file will be put
614 # in the object directory without the directory part of the source file.
616 # - basenames: the basenames of the files to compile. The names may include
617 # relative or absolute path names. No wildcard is allowed. basenames will be
618 # matched to supported AROS_CXXEXTS.
619 # - cflags (default $(CFLAGS)): the C flags to use for compilation
620 # - dflags: the flags used during creation of dependency file. If not specified
621 # the same value as cflags will be used
622 # - targetdir: the directory to put the .o file and the .d file. By default
623 # it is put in the same directory as the .c file. When targetdir is not
624 # empty, path names will be stripped from the file names so that all files
625 # are in that dir and not in subdirectories.
626 # - compiler (default target): compiler to use, target, kernel or host
627 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
628 targetdir= compiler=target
630 # Adjust compiler flags to suit C++
631 TMP_CXXFLAGS := %(cflags)
632 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
633 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include
635 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
637 ifneq ($(TMP_CXXABSBASENAMES),)
639 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
641 # Identify the "real" c++ files from the passed in basenames
642 TMP_CXXFILES := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
645 TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
646 TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
649 TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
650 TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
651 TMP_WILDCARD := %(targetdir)/%
653 # Be sure that all source files are generated
654 $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
657 ifeq ($(findstring %(compiler),host kernel target),)
658 $(error unknown compiler %(compiler))
660 ifeq (%(compiler),target)
661 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
662 BD_STRIP ?= $(TARGET_STRIP)
663 TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
664 TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
665 TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
667 ifeq (%(compiler),host)
668 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
669 BD_STRIP ?= $(HOST_STRIP)
670 TMP_CXXCMD:=$(HOST_CXX)
671 TMP_CXXIQUOTE:=$(HOST_IQUOTE)
672 TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
674 ifeq (%(compiler),kernel)
675 KERNEL_CXX ?= $(KERNEL_CC)
676 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
677 BD_STRIP ?= $(ECHO) >/dev/null
678 TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
679 TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
680 TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
684 TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
686 ifeq (%(dflags),%(cflags))
687 TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
689 TMP_CXXDFLAGS:=%(dflags)
693 define cxx_multi_recipe_template
695 %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
698 %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
701 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
703 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
709 #------------------------------------------------------------------------------
712 #------------------------------------------------------------------------------
713 # Generate a rule to compile multiple ObjC source files to an object file and
714 # generate the corresponding dependency files. The generated file will be put
715 # in the object directory without the directory part of the source file.
717 # - basenames: the basenames of the files to compile. The names may include
718 # relative or absolute path names. No wildcard is allowed
719 # - cflags (default $(CFLAGS)): the C flags to use for compilation
720 # - dflags: the flags used during creation of dependency file. If not specified
721 # the same value as cflags will be used
722 # - targetdir: the directory to put the .o file and the .d file. By default
723 # it is put in the same directory as the .m file. When targetdir is not
724 # empty, path names will be stripped from the file names so that all files
725 # are in that dir and not in subdirectories.
726 # - compiler (default target): compiler to use, target, kernel or host
727 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
728 targetdir= compiler=target
730 ifneq (%(basenames),)
732 # Adjust compiler flags to suit ObjC
733 TMP_OBJCFLAGS := %(cflags)
734 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
735 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
738 TMP_TARGETS := $(addsuffix .o,%(basenames))
739 TMP_DTARGETS := $(addsuffix .d,%(basenames))
742 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
743 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
744 TMP_WILDCARD := %(targetdir)/%
746 # Be sure that all .m files are generated
747 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
749 # Be sure that all .m files are found
750 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
751 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
752 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
754 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
755 vpath %.m $(TMP_DIRS)
759 # Define the use of cross compiler
760 ifeq ($(TARGET_OBJC),)
761 TMP_CC := $(TARGET_CC)
763 TMP_CC := $(TARGET_OBJC)
766 ifeq ($(findstring %(compiler),host kernel target),)
767 $(error unknown compiler %(compiler))
769 ifeq (%(compiler),target)
770 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
771 BD_STRIP ?= $(TARGET_STRIP)
772 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
773 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
774 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
776 ifeq (%(compiler),host)
777 BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
778 BD_STRIP ?= $(HOST_STRIP)
779 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
780 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
781 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
783 ifeq (%(compiler),kernel)
784 KERNEL_OBJC ?= $(KERNEL_CC)
785 BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
786 BD_STRIP ?= $(ECHO) >/dev/null
787 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
788 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
789 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
792 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
793 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
794 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
797 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
799 ifeq (%(dflags),%(cflags))
800 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
802 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
805 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
806 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
811 #------------------------------------------------------------------------------
814 #------------------------------------------------------------------------------
815 # Make an alias from one arch specific build to another arch.
817 # - mainmmake: the mmake of the module in the main tree
818 # - arch: the current arch
819 # - alias: the alias to which this should point
820 %define rule_archalias mainmmake=\A arch=\A alias=\A
822 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
824 #------------------------------------------------------------------------------
827 #------------------------------------------------------------------------------
828 # Generate a rule to assemble a source file to an object file. Basename may
829 # contain a directory part, then the source file has to be in that directory.
830 # The generated file will be put in the object directory without the directory.
832 # - basename: the basename of the file to compile. Use % for a wildcard rule
833 # - flags (default $(AFLAGS)): the asm flags to use for assembling
834 # - targetdir: the directory to put the .o file in. By default it is put in the
835 # same directory as the .s file
836 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
839 %(basename).o : AFLAGS := %(aflags)
840 %(basename).o : %(basename).s
842 %(basename).o : %(basename).S
846 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
847 %(targetdir)/$(notdir %(basename)).o : %(basename).s
849 %(targetdir)/$(notdir %(basename)).o : %(basename).S
854 #------------------------------------------------------------------------------
857 #------------------------------------------------------------------------------
858 # Generate a rule to assemble multiple source files to an object file. The
859 # generated file will be put in the object directory with the directory part
860 # of the source file stripped off.
862 # - basenames: the basenames of the files to compile. The names may include
863 # relative or absolute path names. No wildcard is allowed
864 # - aflags (default $(AFLAGS)): the flags to use for assembly
865 # - targetdir: the directory to put the .o file and the .d file. By default
866 # it is put in the same directory as the .c file. When targetdir is not
867 # empty, path names will be stripped from the file names so that all files
868 # are in that dir and not in subdirectories.
869 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
872 TMP_TARGETS := $(addsuffix .o,%(basenames))
875 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
876 TMP_WILDCARD := %(targetdir)/%
878 # Be sure that all .s files are generated
879 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
881 # Be sure that all .c files are found
882 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
883 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
884 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
886 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
887 vpath %%(suffix) $(TMP_DIRS)
892 ifeq ($(findstring %(compiler),host kernel target),)
893 $(error unknown compiler %(compiler))
895 ifeq (%(compiler),target)
896 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
898 ifeq (%(compiler),host)
899 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
901 ifeq (%(compiler),kernel)
902 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
905 $(TMP_TARGETS) : AFLAGS := %(aflags)
906 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
907 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
909 #------------------------------------------------------------------------------
912 #------------------------------------------------------------------------------
913 # Link %(objs) to %(prog) using the libraries in %(uselibs)
914 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
915 usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
920 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
922 ifeq (%(usestartup),no)
923 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
926 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
929 # Make a list of the lib files this program depends on.
930 # In LDFLAGS remove white space between -L and directory
931 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
932 # Filter out only the libdirs and remove -L
933 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
935 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
936 # Add normal linklib path
937 TMP_DIRS += $(AROS_LIB)/
938 # add lib and .a to static linklib names
939 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
940 ifeq (%(usestartup),yes)
941 TMP_LIBS += startup.o
946 # search for the linklibs in the given path, ignore ones not found
947 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
948 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
951 %(prog) : OBJS := %(objs)
952 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
953 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
954 %(prog) : %(objs) $(TMP_DEPLIBS)
955 %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
957 #------------------------------------------------------------------------------
960 #------------------------------------------------------------------------------
961 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
962 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
963 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
964 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
965 usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
970 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
972 ifeq (%(usestartup),no)
973 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
976 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
979 # Make a list of the lib files the programs depend on.
980 # In LDFLAGS remove white space between -L and directory
981 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
982 # Filter out only the libdirs and remove -L
983 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
985 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
986 # Add normal linklib path
987 TMP_DIRS += $(AROS_LIB)/
988 # add lib and .a to static linklib names
989 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
990 # search for the linklibs in the given path, ignore ones not found
991 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
992 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
994 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
996 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
997 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
998 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
999 %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS)
1001 #------------------------------------------------------------------------------
1004 #------------------------------------------------------------------------------
1005 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1006 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1008 ifeq (%(linker),target)
1009 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1010 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1012 ifeq (%(linker),host)
1013 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1014 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1016 ifeq (%(linker),kernel)
1017 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1018 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1021 %(libdir)/lib%(libname).a : %(objs)
1022 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1024 #------------------------------------------------------------------------------
1026 #------------------------------------------------------------------------------
1027 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1028 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1029 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1030 cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1032 TMP_LDFLAGS := %(ldflags)
1033 # Make a list of the lib files the programs depend on.
1034 # In LDFLAGS remove white space between -L and directory
1035 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1036 # Filter out only the libdirs and remove -L
1037 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1039 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1040 # Add normal linklib path
1041 TMP_DIRS += $(AROS_LIB)/
1042 # add lib and .a to static linklib names
1043 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1044 # search for the linklibs in the given path, ignore ones not found
1045 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1046 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1049 %(module) : LIB_NAMES := %(uselibs)
1050 %(module) : OBJS := %(objs)
1051 %(module) : ENDTAG := %(endobj)
1052 %(module) : ERR := %(err)
1053 %(module) : OBJDIR := %(objdir)
1054 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1055 ifeq (%(usehostlibs),)
1056 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1058 # Warning: the -L/usr/lib here can result in modules
1059 # linking against host libs instead of AROS libs (e.g stdc++) !!
1060 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1061 -L/usr/lib $(addprefix -l,%(usehostlibs))
1063 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1064 %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1067 #------------------------------------------------------------------------------
1070 #------------------------------------------------------------------------------
1071 # Generate the libdefs.h include file for a module.
1072 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1074 TMP_TARGET := %(modname)_libdefs.h
1075 TMP_DEPS := $(GENMODULE)
1077 ifneq (%(conffile),)
1078 ifeq ($(dir %(conffile)),./)
1079 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1080 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1082 TMP_OPTS += -c %(conffile)
1083 TMP_DEPS += %(conffile)
1086 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1087 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1089 ifneq (%(modsuffix),)
1090 TMP_OPTS += -s %(modsuffix)
1092 ifneq (%(targetdir),)
1093 TMP_OPTS += -d %(targetdir)
1094 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1097 TMP_OPTS += -v %(version)
1100 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1101 $(TMP_TARGET) : MODNAME := %(modname)
1102 $(TMP_TARGET) : MODTYPE := %(modtype)
1103 $(TMP_TARGET) : $(TMP_DEPS)
1104 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1105 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1107 #------------------------------------------------------------------------------
1109 #------------------------------------------------------------------------------
1110 # Generate the _lib.fd file for a module.
1111 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1113 TMP_TARGET := %(modname)_lib.fd
1114 TMP_DEPS := $(GENMODULE)
1116 ifneq (%(conffile),)
1117 ifeq ($(dir %(conffile)),./)
1118 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1119 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1121 TMP_OPTS += -c %(conffile)
1122 TMP_DEPS += %(conffile)
1125 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1126 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1128 ifneq (%(modsuffix),)
1129 TMP_OPTS += -s %(modsuffix)
1131 ifneq (%(targetdir),)
1132 TMP_OPTS += -d %(targetdir)
1133 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1136 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1137 $(TMP_TARGET) : MODNAME := %(modname)
1138 $(TMP_TARGET) : MODTYPE := %(modtype)
1139 $(TMP_TARGET) : $(TMP_DEPS)
1140 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1141 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1143 #------------------------------------------------------------------------------
1145 #------------------------------------------------------------------------------
1146 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1147 # generated file in this Makefile
1148 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1151 TMP_TARGET := Makefile.%(modname)%(modtype)
1152 TMP_DEPS := $(GENMODULE)
1154 ifneq (%(conffile),)
1155 ifeq ($(dir %(conffile)),./)
1156 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1157 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1159 TMP_OPTS += -c %(conffile)
1160 TMP_DEPS += %(conffile)
1163 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1164 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1166 ifneq (%(modsuffix),)
1167 TMP_OPTS += -s %(modsuffix)
1169 ifneq (%(targetdir),)
1170 TMP_OPTS += -d %(targetdir)
1171 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1174 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1175 $(TMP_TARGET) : MODNAME := %(modname)
1176 $(TMP_TARGET) : MODTYPE := %(modtype)
1177 $(TMP_TARGET) : $(TMP_DEPS)
1178 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1180 #------------------------------------------------------------------------------
1183 #------------------------------------------------------------------------------
1184 # Generate the support files for compiling a module. This includes include
1185 # files and source files. This rule has to be preceeded by
1186 # %rule_genmodule_makefile
1187 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1190 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1191 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1192 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1193 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1195 TMP_DEPS := $(GENMODULE)
1198 ifneq (%(conffile),)
1199 ifeq ($(dir %(conffile)),./)
1200 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1201 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1203 TMP_OPTS += -c %(conffile)
1204 TMP_DEPS += %(conffile)
1207 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1208 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1210 ifneq (%(modsuffix),)
1211 TMP_OPTS += -s %(modsuffix)
1213 ifneq (%(targetdir),)
1214 TMP_OPTS += -d %(targetdir)
1215 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1216 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1219 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1220 $(TMP_TARGETS) : MODNAME := %(modname)
1221 $(TMP_TARGETS) : MODTYPE := %(modtype)
1222 $(TMP_TARGETS) : $(TMP_DEPS)
1223 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1224 ifneq (%(conffile),lib.conf)
1225 @$(IF) $(TEST) -f lib.conf; then \
1226 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1229 @$(IF) $(TEST) -f libdefs.h; then \
1230 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1232 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1234 #------------------------------------------------------------------------------
1237 #------------------------------------------------------------------------------
1238 # Generate the support files for compiling a module. This includes include
1239 # files and source files.
1240 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1241 targetdir= conffile=
1243 ifneq ($(%(modname)_INCLUDES),)
1244 TMP_TARGETS := $(%(modname)_INCLUDES)
1246 TMP_DEPS := $(GENMODULE)
1249 ifneq (%(conffile),)
1250 ifeq ($(dir %(conffile)),./)
1251 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1252 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1254 TMP_OPTS += -c %(conffile)
1255 TMP_DEPS += %(conffile)
1258 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1259 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1261 ifneq (%(modsuffix),)
1262 TMP_OPTS += -s %(modsuffix)
1264 ifneq (%(targetdir),)
1265 TMP_OPTS += -d %(targetdir)
1266 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1269 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1270 $(TMP_TARGETS) : MODNAME := %(modname)
1271 $(TMP_TARGETS) : MODTYPE := %(modtype)
1272 $(TMP_TARGETS) : $(TMP_DEPS)
1273 @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1274 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1277 #------------------------------------------------------------------------------
1279 #------------------------------------------------------------------------------
1280 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1281 # 'start' is an optional starting address
1282 # 'ldflags' is optional additional flags for the linker
1283 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1285 BD_OUTDIR := $(dir %(file))
1286 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1287 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1288 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1289 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1290 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1293 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1295 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1296 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
1297 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1298 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1300 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1301 GLOB_MKDIRS += $(BD_OUTDIR)
1306 #------------------------------------------------------------------------------
1307 # Common rules for all makefiles
1309 # Delete generated makefiles
1312 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1314 include $(SRCDIR)/config/make.tail
1316 BDID := $(BDTARGETID)
1318 #------------------------------------------------------------------------------
1321 #############################################################################
1322 #############################################################################
1324 ## Here are the mmakefile build macros. These are macros that takes care ##
1325 ## of everything to go from the sources to the generated target. Also all ##
1326 ## intermediate files and directories that are needed are created by these ##
1329 #############################################################################
1330 #############################################################################
1332 #------------------------------------------------------------------------------
1334 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1336 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1337 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1338 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1339 compiler=target linker=
1343 BD_PROGNAME := %(progname)
1344 BD_OBJDIR := %(objdir)
1345 BD_TARGETDIR := %(targetdir)
1346 BD_LINKER := %(linker)
1348 # If not supplied, linker is equal to compiler
1349 ifeq ($(BD_LINKER),)
1350 BD_LINKER := %(compiler)
1353 BD_FILES := %(files)
1354 BD_OBJCFILES := %(objcfiles)
1355 BD_ASMFILES := %(asmfiles)
1356 BD_CXXFILES := %(cxxfiles)
1358 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1359 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1360 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1362 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1363 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1364 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1366 BD_CFLAGS := %(cflags)
1367 BD_AFLAGS := %(aflags)
1368 BD_DFLAGS := %(dflags)
1369 BD_LDFLAGS := %(ldflags)
1372 %(mmake)-quick : %(mmake)
1374 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1375 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1377 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1378 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1379 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1380 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1381 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1382 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1383 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1384 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1385 aflags=$(BD_AFLAGS) compiler="%(compiler)"
1387 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1388 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1389 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1390 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1391 cmd=$(BD_LINK) strip=$(BD_STRIP)
1395 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1397 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1398 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1399 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1401 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1404 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1408 #------------------------------------------------------------------------------
1411 #------------------------------------------------------------------------------
1412 # Build programs, for every C file an executable will be built with the same
1413 # name as the C file
1414 %define build_progs mmake=/A files=/A nix=no \
1415 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1416 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1417 uselibs= usehostlibs= usestartup=yes detach=no
1421 BD_OBJDIR := %(objdir)
1422 BD_TARGETDIR := %(targetdir)
1424 BD_FILES := %(files)
1425 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1426 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1427 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1429 BD_CFLAGS := %(cflags)
1430 BD_DFLAGS := %(dflags)
1431 BD_LDFLAGS := %(ldflags)
1434 %(mmake)-quick : %(mmake)
1436 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1437 %(mmake) : $(BD_EXES)
1439 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1440 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1441 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1443 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1444 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1445 ldflags=$(BD_LDFLAGS) \
1446 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1447 usestartup="%(usestartup)" detach="%(detach)" \
1448 cmd=$(BD_LINK) strip=$(BD_STRIP)
1452 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1454 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1455 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1456 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1458 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1461 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1465 #------------------------------------------------------------------------------
1468 #------------------------------------------------------------------------------
1470 # This is a bare version: It just compiles and links the given files. It is
1471 # assumed that all needed boiler plate code is in the files. This should only
1472 # be used for compiling external code. For AROS code use %build_module
1473 %define build_module_simple mmake=/A modname=/A modtype=/A \
1474 files="$(basename $(call WILDCARD, *.c))" \
1475 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1476 objdir=$(OBJDIR) moduledir= \
1477 uselibs= usehostlibs= compiler=target
1479 # Define metamake targets and their dependencies
1480 #MM %(mmake) : core-linklibs includes-generate-deps
1481 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1482 #MM %(mmake)-kobj-quick
1486 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1488 .PHONY : $(BD_ALLTARGETS)
1491 $(error using %build_module_simple: modname may not be empty)
1494 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1497 # Default values for variables and arguments
1498 BD_DEFLINKLIBNAME := %(modname)
1499 BD_DEFDFLAGS := %(cflags)
1500 OBJDIR ?= $(GENDIR)/$(CURDIR)
1501 BD_MODDIR := %(moduledir)
1502 ifeq ($(BD_MODDIR),)
1503 ifeq (%(modtype),library)
1504 BD_MODDIR := $(AROS_LIBRARIES)
1506 ifeq (%(modtype),gadget)
1507 BD_MODDIR := $(AROS_GADGETS)
1509 ifeq (%(modtype),datatype)
1510 BD_MODDIR := $(AROS_DATATYPES)
1512 ifeq (%(modtype),handler)
1513 BD_MODDIR := $(AROS_FS)
1515 ifeq (%(modtype),device)
1516 BD_MODDIR := $(AROS_DEVS)
1518 ifeq (%(modtype),resource)
1519 BD_MODDIR := $(AROS_RESOURCES)
1521 ifeq (%(modtype),hook)
1522 BD_MODDIR := $(AROS_RESOURCES)
1524 ifeq (%(modtype),mui)
1525 BD_MODDIR := $(AROS_CLASSES)/Zune
1527 ifeq (%(modtype),mcc)
1528 BD_MODDIR := $(AROS_CLASSES)/Zune
1530 ifeq (%(modtype),mcp)
1531 BD_MODDIR := $(AROS_CLASSES)/Zune
1533 ifeq (%(modtype),usbclass)
1534 BD_MODDIR := $(AROS_CLASSES)/USB
1536 ifeq (%(modtype),hidd)
1537 BD_MODDIR := $(AROS_DRIVERS)
1539 ifeq (%(modtype),printer)
1540 BD_MODDIR := $(AROS_PRINTERS)
1543 ifeq ($(BD_MODDIR),)
1544 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1547 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1548 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1549 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1551 %rule_compile_multi \
1552 basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1553 cflags="%(cflags)" dflags="%(dflags)" \
1554 compiler="%(compiler)"
1556 # Handlers use dash instead of dot in their names
1557 ifeq (%(modtype),handler)
1558 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1560 ifeq (%(modtype),printer)
1561 BD_MODULE := $(BD_MODDIR)/%(modname)
1563 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1566 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1568 %(mmake)-quick : %(mmake)
1569 %(mmake)-kobj-quick : $(BD_KOBJ)
1570 %(mmake) : $(BD_MODULE)
1571 %(mmake)-kobj : $(BD_KOBJ)
1573 # The module is linked from all the compiled .o files
1574 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1576 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1577 # This breaks con-handler build. Here we work around this
1578 ifeq (%(modname),con)
1579 BD_ERR := $(notdir $(BD_MODULE)).err
1581 BD_ERR := %(modname).err
1584 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1585 endobj= err=$(BD_ERR) objdir="%(objdir)" \
1586 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1587 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1589 # Link kernel object file
1590 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1592 # Make these symbols local
1593 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1594 UtilityBase ExpansionBase KeymapBase KernelBase
1596 BD_SYMBOLS := $(BD_KBASE)
1598 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1599 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1600 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1601 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1602 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1603 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1604 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1605 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1606 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1609 ## Dependency fine-tuning
1611 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1612 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1614 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1615 $(BD_MODULE) : | $(BD_MODDIR)
1616 $(BD_KOBJ) : | $(KOBJSDIR)
1617 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1619 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1621 @$(ECHO) "Cleaning up for module %(modname)"
1624 #------------------------------------------------------------------------------
1627 #------------------------------------------------------------------------------
1628 # Build a module - core routine
1629 # Explanation of this macro is done in the developer's manual
1630 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1631 files="$(basename $(call WILDCARD, *.c))" \
1632 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1633 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1634 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1635 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1636 compiler=target nostartup=yes archspecific=no \
1637 build_abi= build_library=
1639 # We will employ a terrifying, but unavoidable, hack here.
1640 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1641 # ignores GNU Make ifeq() statements, but will process any #MM
1642 # headed lines in the file.
1644 # So, to make the following #MM lines conditional on whether we want
1645 # to build the ABI, Library, or both, we define build_abi= and
1646 # build_library as 'M' to enable, or '' to disable, which allows genmf
1647 # to do the following conversions:
1649 # #%(build_abi)M includes-foo: foo-include
1650 # becomes, when build_abi=M
1651 # #MM includes-foo: foo-include <= Processed by MetaMake
1652 # but, when build_abi= ...
1653 # #M includes-foo: foo-includes <= ignored by MetaMake! Yes!
1655 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1657 # Define metamake targets and their dependencies
1660 #MM %(mmake)-makefile
1664 #M%(build_abi)- includes-all : %(mmake)-includes
1665 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1666 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1667 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1668 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1669 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1670 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1671 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1672 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1673 #M%(build_abi) includes-generate-deps %(mmake)-fd
1674 #M%(build_abi) %(mmake)-includes-quick
1675 #M%(build_abi) %(mmake)-includes-dirs
1676 #M%(build_abi) %(mmake)-fd
1679 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1680 #%(build_library)M %(mmake)-kobj-quick :
1682 # Library with ABI targets:
1683 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1684 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1686 # All MetaMake targets defined by this macro
1687 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1689 ifeq (%(build_library),M)
1690 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1693 ifeq (%(build_abi),M)
1694 BD_ALLTARGETS += %(mmake)-includes \
1695 %(mmake)-includes-quick %(mmake)-includes-dirs \
1696 %(mmake)-linklib %(mmake)-fd
1699 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1702 $(error using %build_module: modname may not be empty)
1705 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1708 # Default values for variables and arguments
1709 BD_DEFLINKLIBNAME := %(modname)
1710 BD_DEFDFLAGS := %(cflags)
1711 OBJDIR ?= $(GENDIR)/$(CURDIR)
1713 ## Create genmodule include Makefile for the module
1715 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1717 %rule_genmodule_makefile \
1718 modname="%(modname)" modtype="%(modtype)" \
1719 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1720 conffile="%(conffile)"
1722 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1724 GLOB_MKDIRS += %(objdir)
1726 # Do not parse these statements if metatarget is not appropriate
1727 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1729 include %(objdir)/Makefile.%(modname)%(modtype)
1731 BD_DEFMODDIR := $(%(modname)_MODDIR)
1732 ifeq (%(archspecific),yes)
1733 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1737 ## include files generation
1739 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1740 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1741 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1743 ifeq (%(build_abi),M)
1744 %(mmake)-includes-quick : %(mmake)-includes
1745 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1746 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1747 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1749 ifneq ($(%(modname)_INCLUDES),)
1750 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1751 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1752 conffile="%(conffile)"
1754 %rule_copy_diff_multi \
1755 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1756 stampfile="%(objdir)/%(modname)_geninc"
1758 %rule_copy_diff_multi \
1759 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1760 stampfile="%(objdir)/%(modname)_incs"
1762 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1764 TMP%(modname)_INCDIRS := \
1765 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1766 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1767 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1768 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1774 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1775 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1776 conffile="%(conffile)" version="%(version)"
1778 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1779 $(BD_DEFLIBDEFSINC) :
1780 @$(ECHO) "Generating $@"
1781 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1783 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1784 GLOB_MKDIRS += %(objdir)/include
1786 ## Extra genmodule src files generation
1788 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1789 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1790 conffile="%(conffile)"
1793 ifeq (%(build_abi),M)
1795 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1796 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1798 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1799 modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1801 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1803 GLOB_MKDIRS += $(BD_FDDIR)
1808 BD_FILES := %(files)
1809 BD_CXXFILES := %(cxxfiles)
1811 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1813 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1814 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1816 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1817 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1818 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1820 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1821 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1823 ifeq (%(modtype),library)
1826 BD_LIBSUFFIX := .%(modtype)
1829 ifeq (%(build_abi),M)
1830 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1831 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1832 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1835 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1836 ifneq (%(modname),%(linklibname))
1837 BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1840 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1842 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1843 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1844 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1847 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1848 ifneq (%(modname),%(linklibname))
1849 BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1852 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1855 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1856 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1857 $(BD_RELLINKLIBCFILES)
1859 %rule_compile_cxx_multi \
1860 basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1861 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1862 compiler="%(compiler)"
1863 %rule_compile_multi \
1864 basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1865 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1866 compiler="%(compiler)"
1867 %rule_compile_multi \
1868 basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1869 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1870 compiler="%(compiler)"
1872 ifneq ($(BD_LINKLIBAFILES),)
1873 %rule_assemble_multi \
1874 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1879 ifeq (%(modsuffix),)
1880 BD_SUFFIX := %(modtype)
1882 BD_SUFFIX := %(modsuffix)
1885 ifeq (%(build_library),M)
1886 # Handlers use dash instead of dot in their names
1887 ifeq ($(BD_SUFFIX),handler)
1888 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1890 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1892 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1898 %(mmake)-quick : %(mmake)
1899 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1900 ifeq (%(build_library),M)
1901 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1902 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1904 ifeq (%(build_abi),M)
1905 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1908 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1909 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1911 ifeq (%(nostartup),yes)
1912 # Handlers always have entry point
1913 ifneq (%(modtype),handler)
1914 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1918 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1919 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1922 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1925 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1926 # This breaks con-handler build. Here we work around this
1927 ifeq (%(modname),con)
1928 BD_ERR := $(notdir $(BD_MODULE)).err
1930 BD_ERR := %(modname).err
1933 ifeq (%(build_library),M)
1934 # The module is linked from all the compiled .o files
1935 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1936 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
1937 cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1938 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1941 ifeq (%(build_abi),M)
1943 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1944 BD_MODNAME := $(shell echo %(modname) | tr A-Z a-z)
1945 ifneq ($(BD_LINKLIB),)
1946 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="%(prefix)/$(AROS_DIR_LIB)"
1947 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1948 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="%(prefix)/$(AROS_DIR_LIB)"
1951 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1952 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1955 ifneq ($(BD_RELLINKLIB),)
1956 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="%(prefix)/$(AROS_DIR_LIB)"
1957 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1958 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="%(prefix)/$(AROS_DIR_LIB)"
1961 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1962 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1966 ifeq (%(build_library),M)
1967 # Link kernel object file
1968 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1970 # Make these symbols local
1971 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1972 UtilityBase ExpansionBase KeymapBase KernelBase
1974 BD_SYMBOLS := $(BD_KBASE)
1976 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1977 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1978 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1979 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1980 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1981 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1982 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1983 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1984 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1987 ## Dependency fine-tuning
1989 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1991 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1993 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1994 $(BD_MODULE) : | %(prefix)/%(moduledir)
1995 $(BD_KOBJ) : | $(KOBJSDIR)
1996 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1998 # Some include files need to be generated before the .c can be parsed.
1999 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2001 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2002 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2003 $(BD_DEPS) : $(BD_DFILE_DEPS)
2006 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2007 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2008 %(objdir)/Makefile.%(modname)%(modtype) \
2009 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2010 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2011 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2012 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2013 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2014 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2016 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2018 @$(ECHO) "Cleaning up for module %(modname)"
2021 endif # $(TARGET) in $(BD_ALLTARGETS)
2023 #------------------------------------------------------------------------------
2025 #------------------------------------------------------------------------------
2026 # Build a module - ABI and library
2027 # Explanation of this macro is done in the developer's manual
2028 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2029 files="$(basename $(call WILDCARD, *.c))" \
2030 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2031 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2032 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2033 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2034 compiler=target nostartup=yes archspecific=no
2036 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2037 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2038 files="%(files)" cxxfiles="%(cxxfiles)" \
2039 linklibname="%(linklibname)" \
2040 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2041 cflags="%(cflags)" dflags="%(dflags)" \
2042 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2043 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2044 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2045 build_abi=M build_library=M
2048 #------------------------------------------------------------------------------
2051 #------------------------------------------------------------------------------
2052 # Build a module skeleton ABI
2053 # This is a stripped-down version of build_module, it only creates include
2054 # files and the linklibs.
2055 # This is used when for plugins or classes with the same API, but no actual
2056 # implementation here.
2057 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2058 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2059 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2060 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2061 compiler=target nostartup=yes archspecific=no
2063 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2064 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2065 linklibname="%(linklibname)" \
2066 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2067 cflags="%(cflags)" dflags="%(dflags)" \
2068 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2069 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2070 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2071 build_abi=M build_library=
2074 #------------------------------------------------------------------------------
2076 #------------------------------------------------------------------------------
2077 # Build a module library - no includes nor linklibs
2078 # Explanation of this macro is done in the developer's manual
2079 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2080 files="$(basename $(call WILDCARD, *.c))" \
2081 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2082 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2083 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2084 uselibs= usehostlibs= \
2085 compiler=target nostartup=yes archspecific=no
2087 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2088 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2089 files="%(files)" cxxfiles="%(cxxfiles)" \
2090 cflags="%(cflags)" dflags="%(dflags)" \
2091 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2092 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2093 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2094 build_abi= build_library=M
2097 #------------------------------------------------------------------------------
2101 #------------------------------------------------------------------------------
2103 # - mmake is the mmaketarget
2104 # - libname is the baselibname e.g. lib%(libname).a will be created
2105 # - files are the C source files to include in the lib. The list of files
2106 # has to be given without the .c suffix
2107 # - cxxfiles are C++ source files without suffix.
2108 # NB: files will be matched in the order .cpp > .cxx > .cc
2109 # - asmfiles are the asm files to include in the lib. The list of files has to
2110 # be given without the .s suffix
2111 # - objs additional object to link into the linklib. The objects have to be
2112 # given with full absolute path and the .o suffix.
2113 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2114 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2115 # - cflags are the flags to compile the source (default $(CFLAGS))
2116 # - dflags are the flags use during makedepend (default equal to cflags)
2117 # - aflags are the flags use during assembling (default $(AFLAGS))
2118 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2119 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2120 asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2121 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2122 aflags=$(AFLAGS) compiler=target
2124 # assign and generate the local variables used in this macro
2125 BD_LIBNAME := %(libname)
2126 BD_LINKLIB := %(libdir)/lib%(libname).a
2128 BD_FILES := %(files)
2129 BD_ASMFILES := %(asmfiles)
2130 BD_CXXFILES := %(cxxfiles)
2132 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2133 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2134 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2136 BD_OBJS := $(BD_ARCHOBJS) \
2137 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2139 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2141 BD_CFLAGS := %(cflags)
2142 BD_AFLAGS := %(aflags)
2143 BD_DFLAGS := %(dflags)
2145 .PHONY : %(mmake) %(mmake)-clean
2147 #MM %(mmake) : includes-generate-deps
2148 %(mmake) : $(BD_LINKLIB)
2150 ifeq ($(TARGET),%(mmake))
2152 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2153 compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2154 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2155 compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2156 %rule_assemble basename=% targetdir="%(objdir)" \
2159 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2162 %include_deps depstargets="%(mmake)" deps=$(BD_DEPS)
2164 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2165 $(BD_LINKLIB) : | %(libdir)
2166 GLOB_MKDIRS += %(objdir) %(libdir)
2168 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2171 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2175 #------------------------------------------------------------------------------
2178 #------------------------------------------------------------------------------
2180 # - mmake is the mmaketarget
2181 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2182 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2183 # - subdir is the destination subdirectory of the catalogs
2184 # - name is the name of the destination catalog, without the .catalog suffix
2185 # - source is the path to the generated source code file
2186 # - dir is the base destination directory (default $(AROS_CATALOGS))
2187 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2188 # - srcdir is the directory in which the *.cd and *.ct files are searched
2190 %define build_catalogs mmake=/A name=/A subdir=/A \
2191 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2192 sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2194 ifeq (%(description),)
2195 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2197 BD_DESC := %(description)
2200 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2203 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2205 BD_LNGS := %(catalogs)
2208 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2209 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2212 %(mmake) : $(BD_OBJS) %(source)
2214 $(BD_OBJS) : | $(BD_DIRS)
2215 GLOB_MKDIRS += $(BD_DIRS)
2217 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2218 @$(ECHO) "Creating %(name) catalog for language $*."
2219 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2222 %(source) : BD_DESC := $(BD_DESC)
2223 %(source) : BD_SRC := $(BD_SRC)
2224 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2225 @$(ECHO) "Creating %(name) catalog source file $@"
2226 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2229 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2232 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2235 .PHONY: %(mmake) %(mmake)-clean
2238 #-----------------------------------------------------------------------------
2241 #-----------------------------------------------------------------------------
2243 # - mmake is the mmaketarget
2244 # - icons is a list of icon base names (ie. without the .info suffix)
2245 # - dir is the destination directory
2246 # - srcdir is where *.png and *.info.src are searched
2247 #-----------------------------------------------------------------------------
2249 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2251 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2254 %(mmake) : $(BD_OBJS)
2258 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2259 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2260 @$(ILBMTOICON) $+ $@
2264 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2265 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2266 @$(ILBMTOICON) $+ $@
2270 $(BD_OBJS) : | %(dir)
2271 GLOB_MKDIRS += %(dir)
2273 %(mmake)-clean : FILES := $(BD_OBJS)
2278 .PHONY: %(mmake) %(mmake)-clean
2281 #-----------------------------------------------------------------------------
2284 #------------------------------------------------------------------------------
2285 # Compile files for an arch-specific replacement of code for a module
2286 # - files: the basenames of the C files to compile.
2287 # - asmfiles: the basenames of the asm files to assemble.
2288 # - mainmmake: the mmake of the module in the main directory to compile these
2289 # arch specific files for.
2290 # - maindir: the object directory for the main module
2291 # - arch: the arch for which to compile these files. It can have the form
2292 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2293 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2294 # - dflags: the flags used during creation of dependency file. If not specified
2295 # the same value as cflags will be used
2296 # - aflags: the flags used during assembling
2297 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2298 # the target compiler is used
2299 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2300 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2302 ifeq (%(files) %(asmfiles),)
2303 $(error no files or asmfiles given)
2306 %buildid targets="%(mainmmake)-%(arch)"
2308 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2309 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2310 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2311 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2312 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2313 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2314 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2315 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2316 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2317 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2318 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2319 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2320 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2321 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2322 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2324 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2326 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2327 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2328 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2329 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2330 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2332 ifneq (%(modulename),)
2333 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2336 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2337 BD_TARGET := %(mainmmake)-%(arch)-quick
2339 BD_TARGET := %(mainmmake)-%(arch)
2343 ifeq ($(TARGET),$(BD_TARGET))
2344 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2345 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2346 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2347 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2350 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2351 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2354 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2357 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2359 ifeq ($(findstring %(compiler),host kernel target),)
2360 $(error unknown compiler %(compiler))
2362 ifeq (%(compiler),target)
2363 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2364 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2365 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2367 ifeq (%(compiler),host)
2368 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2369 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2370 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2372 ifeq (%(compiler),kernel)
2373 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2374 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2375 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2377 ifneq (%(modulename),)
2378 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2380 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2382 ifeq ($(TARGET),$(BD_TARGET))
2383 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2384 %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2388 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2390 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2392 ifeq ($(TARGET),$(BD_TARGET))
2393 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2394 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2397 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2399 ifeq ($(TARGET),$(BD_TARGET))
2400 $(BD_OBJDIR$(BDID))/%.o : %.s
2401 %assemble_q opt=$(AFLAGS)
2402 $(BD_OBJDIR$(BDID))/%.o : %.S
2403 %assemble_q opt=$(AFLAGS)
2406 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2408 #------------------------------------------------------------------------------
2411 #------------------------------------------------------------------------------
2412 # generate asm files from c files (for debugging purposes)
2415 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2416 @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2418 #------------------------------------------------------------------------------
2421 #------------------------------------------------------------------------------
2422 # Copy files from one directory to another.
2424 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2426 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2428 GLOB_MKDIRS += %(dst)
2434 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2437 #------------------------------------------------------------------------------
2440 #------------------------------------------------------------------------------
2441 # Copy a directory recursively to another place, preserving the original
2442 # hierarchical structure
2444 # src: the source directory whose content will be copied.
2445 # dst: the directories where to copy src's content. If not existing, they will be made.
2446 # excludefiles: files which must not be copied. Path must be relative to src.
2448 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2454 @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2457 #------------------------------------------------------------------------------
2460 #------------------------------------------------------------------------------
2461 # Copy include files into the includes directories. There are currently
2462 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2463 # for building tools that need to run on the host system $(GENINCDIR). The
2464 # $(GENINCDIR) path must not contain any references to the C runtime
2465 # library header files.
2467 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2468 dir= compiler=target
2470 ifeq ($(findstring %(compiler),host kernel target),)
2471 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2476 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2477 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2478 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2479 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2480 ifeq ($(TMP_DIRFIRST),/)
2481 BD_INC_PATH := %(dir)/
2483 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2486 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2487 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2490 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2494 ifeq (%(compiler),target)
2497 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2498 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2500 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2503 BD_INCL_FILES += $(BD_INCL_FILES2)
2505 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2510 %(mmake) : $(BD_INCL_FILES)
2514 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2515 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2517 #------------------------------------------------------------------------------
2520 #------------------------------------------------------------------------------
2521 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2522 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2523 STUBS_MEM := $(addsuffix .o,$(STUBS))
2524 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2525 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2526 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2528 #MM- linklibs : hidd-%(hidd)-stubs
2529 #MM- %(parenttarget): hidd-%(hidd)-stubs
2530 #MM hidd-%(hidd)-stubs : includes includes-copy
2531 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2533 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2536 $(STUBS_OBJ) : $(STUBS_SRC)
2537 %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2539 $(STUBS_DEP) : $(STUBS_SRC)
2540 %mkdepend_q flags="%(dflags)"
2543 %mkdirs_q $(OBJDIR) $(AROS_LIB)
2547 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2549 DEPS := $(DEPS) $(STUBS_DEP)
2552 #------------------------------------------------------------------------------
2555 #------------------------------------------------------------------------------
2556 # Build an imported source tree which uses the configure script from the
2557 # autoconf package. This rule will try to "integrate" the produced files as
2558 # much as possible in the AROS build, for example by putting libraries in the
2559 # standard library directory, includes in the standard include directory, and
2560 # so on. You can however override this behaviour.
2562 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2563 # be %(bindir) (or its deduced value) when running "make install", and
2564 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2565 # configure script some more parameters whose value depends upon the PROGDIR
2566 # env var, so that the program gets all its stuff installed in the proper place
2567 # when building it, but when running it from inside AROS it can also find that
2568 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2569 # the configuration parameters set when running ./configure
2571 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2572 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2573 # to the name which has to follow it.
2577 # - mmake = the meta make target.
2578 # - package = name of the package to be built.
2579 # - srcdir = the location of the unpacked source code. Defaults
2580 # to $(SRCDIR)/$(CURDIR).
2581 # - prefix = the target directory. Must be an absolute path of the
2582 # host system. Defaults to $(AROS_CONTRIB).
2583 # - aros_prefix = set a path which is valid within the AROS filesystem.
2584 # Defaults to the value of the prefix option.
2585 # - extraoptions = additional options for the configure script.
2586 # - extracflags = additional flags which are used for both C and C++.
2587 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2588 # Defaults to the value of the nix argument.
2589 # - nix = enable u*nix path handling, i.e. a path like
2590 # /progdir//./file will be translated to
2591 # progdir:file during run-time. Defaults to no.
2592 # - compiler = target, host or kernel. Defaults to target.
2593 # - install_target = the command used for installing. Defaults to install. Leave
2594 # it empty if you want to suppress installing.
2595 # - preconfigure = a metatarget which is executed before configure is called.
2596 # - postconfigure = a metatarget which is executed after configure is called.
2597 # - postinstall = a metatarget which is executed after installing.
2598 # - install_env = set additional options for installing.
2599 # - use_build_env = if yes the configuration environment is used for
2600 # installing, too. Defaults to no.
2602 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2606 # --prefix = $(aros_prefix)
2607 # progdir = $(aros_prefix)/bin
2610 # --prefix = /PROGDIR
2611 # --bindir = /PROGDIR
2612 # --sbindir = /PROGDIR
2614 # --includedir = /INCLUDE
2615 # --oldincludedir = /INCLUDE
2617 # --prefix = $(aros_prefix)
2620 # progdir = $(aros_prefix)
2623 # bindir = $(prefix)
2624 # sbindir = $(prefix)
2625 # libdir = $(AROS_LIB)
2626 # includedir = $(AROS_INCLUDES)
2627 # oldincludedir = $(AROS_INCLUDES)
2631 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2632 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2633 install_target=install preconfigure= postconfigure= postinstall= \
2634 install_env= use_build_env=no
2637 %(mmake)-prefix := %(prefix)
2639 %(mmake)-prefix := $(AROS_CONTRIB)
2642 ifneq (%(aros_prefix),)
2643 %(mmake)-aros_prefix := %(aros_prefix)
2645 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2649 %(mmake)-nix := -nix
2650 %(mmake)-volpfx := /
2651 %(mmake)-volsfx := /
2653 ifeq (%(nix_dir_layout),)
2654 %(mmake)-nix_dir_layout := yes
2657 %(mmake)-volsfx := :
2659 ifeq (%(nix_dir_layout),)
2660 %(mmake)-nix_dir_layout := no
2664 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2666 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2667 exec_prefix=$(%(mmake)-prefix) %(install_env)
2669 # Check if chosen compiler is valid
2670 ifeq ($(findstring %(compiler),host target kernel),)
2671 $(error unknown compiler %(compiler))
2674 # Set legacy 'host' variable based on chosen compiler
2675 ifeq (%(compiler),host)
2678 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2680 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2685 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2687 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2692 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2694 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2698 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2699 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2701 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2702 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2703 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2706 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2707 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2709 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2712 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2714 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2715 sbindir=$(%(mmake)-prefix) \
2716 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2717 oldincludedir=$(AROS_INCLUDES) %(install_env)
2720 ifneq ($(DEBUG),yes)
2721 %(mmake)-s_flag = -s
2724 # Set up build environment, and options for configure script
2725 ifeq (%(compiler),host)
2728 CXXCPP="$(HOST_CPP)" \
2729 CC="$(HOST_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2730 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2731 LDFLAGS="-L$(CROSSTOOLSDIR)/lib" \
2732 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2733 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2734 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2735 TARGET_NM="$(NM_PLAIN)"
2737 ifeq (%(compiler),target)
2739 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2740 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2741 CFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2742 CXXFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2743 CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2744 CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2745 CC="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2746 CXX="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2747 LDFLAGS="-L$(AROS_DEVELOPMENT)/lib" \
2748 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2749 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2750 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2751 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2752 TARGET_NM="$(NM_PLAIN)" \
2753 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2754 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2755 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2756 --host=$(AROS_TARGET_CPU)-aros\
2757 --target=$(AROS_TARGET_CPU)-aros\
2759 --without-x --without-pic --disable-shared
2761 ifeq (%(compiler),kernel)
2763 CPP="$(KERNEL_CPP)" \
2764 CXXCPP="$(KERNEL_CPP)" \
2765 CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2766 CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2767 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2768 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2769 TARGET_NM="$(NM_PLAIN)"
2770 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2771 --host=$(AROS_TARGET_CPU)-aros\
2772 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2773 --without-x --without-pic --disable-shared
2776 ifeq (%(use_build_env),yes)
2777 BUILD_ENV := $(CONFIG_ENV)
2780 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2782 # When building for the host, we don't need to build the
2783 # linklibs - this is especially true when building the
2784 # crosstool toolchain on 'foreign' architectures (such as
2785 # building PPC on x86)
2787 #MM- %(mmake)-host : setup includes %(mmake)-quick
2788 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2789 #MM- %(mmake): %(mmake)-%(compiler)
2791 # Using -j1 in install_command may result in a warning but finally
2792 # it does its job. make install for gcc does not work reliably for -jN
2794 ifneq (%(install_target),)
2795 %(mmake)-install_command = \
2796 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2797 -C $(%(mmake)-pkgdir) %(install_target) -j1
2799 %(mmake)-uninstall_command = \
2800 $(RM) $(%(mmake)-installflag) && \
2801 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2802 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2804 %(mmake)-install_command := true
2805 %(mmake)-uninstall_command := true
2808 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2811 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2813 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2814 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2815 $(RM) $(%(mmake)-installflag) && \
2816 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2817 -C $(%(mmake)-pkgdir) && \
2818 $(%(mmake)-install_command) && \
2819 $(TOUCH) $@ -r $^; \
2822 $(%(mmake)-pkgdir)/.files-touched:
2823 %mkdirs_q $(%(mmake)-pkgdir)
2824 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2828 %(mmake)-uninstall :
2829 $(%(mmake)-uninstall_command)
2832 %(mmake)-configure : $(%(mmake)-configflag)
2834 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2835 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2837 %mkdirs_q $(%(mmake)-pkgdir)
2838 cd $(%(mmake)-pkgdir) && \
2839 find . -name config.cache -exec $(RM) '{}' \; && \
2840 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2841 %(extraoptions) && \
2845 %(mmake)-clean : %(mmake)-uninstall
2846 @$(RM) $(%(mmake)-pkgdir)
2848 #------------------------------------------------------------------------------
2851 #------------------------------------------------------------------------------
2852 # Build an imported source tree which uses cmake
2856 # - mmake = the meta make target.
2857 # - package = name of the package to be built.
2858 # - srcdir = the location of the unpacked source code. Defaults
2859 # to $(SRCDIR)/$(CURDIR).
2860 # - prefix = the target directory. Must be an absolute path of the
2861 # host system. Defaults to $(AROS_CONTRIB).
2862 # - aros_prefix = set a path which is valid within the AROS filesystem.
2863 # Defaults to the value of the prefix option.
2864 # - extraoptions = additional options for the cmake script.
2865 # - installoptions = additional options for the install step.
2868 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2869 aros_prefix= extraoptions= installoptions= cflags=$(CFLAGS)
2872 %(mmake)-prefix := %(prefix)
2874 %(mmake)-prefix := $(AROS_CONTRIB)
2877 ifneq (%(aros_prefix),)
2878 %(mmake)-aros_prefix := %(aros_prefix)
2880 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2885 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2887 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2891 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2893 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2897 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
2898 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2900 BD_CFLAGS := %(cflags)
2901 BD_CXXFLAGS := $(subst -Wno-pointer-sign,,$(BD_CFLAGS))
2903 %(mmake)-cmake_opts := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
2905 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2907 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
2909 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
2912 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2914 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
2915 if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
2916 $(RM) $(%(mmake)-installflag) && \
2917 $(MAKE) -C $(%(mmake)-pkgdir) && \
2918 cd $(%(mmake)-pkgdir) && \
2919 cmake %(installoptions) -P cmake_install.cmake && \
2920 $(TOUCH) $@ -r $^; \
2923 $(%(mmake)-pkgdir)/.files-touched:
2924 %mkdirs_q $(%(mmake)-pkgdir)
2925 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
2929 %(mmake)-cmake : $(%(mmake)-cmakeflag)
2931 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2932 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2934 %mkdirs_q $(%(mmake)-pkgdir)
2935 cd $(%(mmake)-pkgdir) && \
2936 $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
2937 cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
2941 %(mmake)-clean : %(mmake)-uninstall
2942 @$(RM) $(%(mmake)-pkgdir)
2944 #------------------------------------------------------------------------------
2947 #------------------------------------------------------------------------------
2948 # Given an archive name, patches names and locations where to find them, fetch
2949 # the archive and the patches from any of those locations, unpack the archive
2950 # and then apply the patches.
2952 # Locations currently supported are http and ftp sites, plus local filesystem
2953 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2954 # the fetch.sh script needs to be modified, since this macro relies on that script.
2958 # - mmake = mmaketarget
2959 # - archive_origins = list of locations where to find the archive. They are tried
2960 # in sequence, until the archive is found and fetching it
2961 # succeeded. If not specified, the current directory is assumed.
2962 # - archive = the archive name. Mandatory.
2963 # - suffixes = a list of suffixes to append to the the package name plus the
2964 # version. Each one of them is tried until a matching archive is
2965 # found. They are appended to patches and these are tried the
2966 # same way as packages are.
2967 # - location = the local directory where to put the fetched archive and patches.
2968 # If not specified, the directory specified by destination is used.
2969 # - destination = the directory to unpack the archive to.
2970 # If not specified, the current directory is assumed.
2971 # - patches_origins = list of locations where to find the patches. They are tried
2972 # in sequence, until a patch is found and fetching it
2973 # succeeded. If not specified, the current directory is assumed.
2974 # - patches_specs = list of "patch specs". A patch spec is of the form
2975 # patch_name[:[patch_subdir][:patch_opt]].
2977 # - patch_name = the name of the patch file
2978 # - patch_subdir = the directory within \destination\ where to
2980 # - patch_opt = any options to pass to the `patch' command
2981 # when applying the patch.
2983 # The patch_subdir and patch_opt fields are optional.
2985 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2986 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2990 ifneq (%(location),)
2991 %(mmake)-location := %(location)
2993 %(mmake)-location := %(destination)
2998 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2999 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3001 #------------------------------------------------------------------------------
3004 #------------------------------------------------------------------------------
3005 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3006 # unpatched source tree and runs diff against this and a previously fetched and possibly
3007 # patched tree. Depending on what happens after patching during a normal build it might
3008 # give best results if the new patch is created directly after fetch.
3012 # - mmake = mmaketarget
3013 # - archive = archive base name
3014 # - srcdir = the top level directory the package is unpacked to, useful if
3015 # an archive unpacks to a directory other than its name suggests.
3016 # this should not be deeper than a single path element.
3017 # - suffixes = a list of suffixes to append to the the package name plus the
3018 # version. Each one of them is tried until a matching archive is
3020 # - destination = the directory to unpack the archive to.
3021 # - excludes = diff patterns to exclude files or directories from the patch
3023 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3027 ifneq (%(excludes),)
3028 %(mmake)-exclude := -X ./exclude.patterns
3032 %(mmake)-srcdir := %(srcdir)
3034 %(mmake)-srcdir := %(archive)
3039 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3040 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3041 cd %(destination)/tmp ; \
3042 $(FOR) f in %(excludes) ; do \
3043 $(ECHO) $$f >> ./exclude.patterns ; \
3045 diff -ruN $(%(mmake)-exclude) \
3046 $(%(mmake)-srcdir) \
3047 $(%(mmake)-srcdir).aros \
3048 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3049 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3050 $(RM) %(destination)/tmp
3052 #------------------------------------------------------------------------------
3055 #------------------------------------------------------------------------------
3056 # Joins the features of %fetch and %build_with_configure.
3058 # If a patch is provided, it *must* be named the following way:
3060 # <package name>-<version number>-aros.diff
3062 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3063 # CD'ing into the archive's extracted directory.
3065 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3066 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3067 # to make that patch fully comprehensive.
3071 # - mmake = the meta make target.
3072 # - package = the GNU package name, sans version and archive format suffixes.
3073 # - subpackage = ???
3074 # - compiler = same meaning as the one for the %build_with_configure macro.
3075 # - install_target = same meaning as the one for the %build_with_configure macro.
3076 # - version = the package's version number, or otherwise any other version string.
3077 # It gets appended to the package name to form the basename of the archive.
3078 # - suffixes = a list of suffixes to apped to the the package name plus the
3079 # version. Each one of them is tried until a matching archive is found.
3080 # Defaults to "tar.bz2 tar.gz".
3081 # - srcdir = the top level directory the package is unpacked to (see create_patch).
3082 # - builddir = override the location we expect to run configure/make in.
3083 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
3084 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
3085 # fetched or not. Default to no.
3086 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
3087 # - prefix = same meaning as the one for the %build_with_configure macro.
3088 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
3089 # - extraoptions = same meaning as the one for the %build_with_configure macro.
3090 # - extracflags = same meaning as the one for the %build_with_configure macro.
3091 # - preconfigure = same meaning as the one for the %build_with_configure macro.
3092 # - postconfigure = same meaning as the one for the %build_with_configure macro.
3093 # - postinstall = same meaning as the one for the %build_with_configure macro.
3094 # - install_env = same meaning as the one for the %build_with_configure macro.
3095 # - use_build_env = same meaning as the one for the %build_with_configure macro.
3096 # - nix = same meaning as the one for the %build_with_configure macro.
3097 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
3098 # - create_pkg = create a distributable package of the compiled sources, defaults to no
3100 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3101 version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3102 prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
3103 install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3105 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3106 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3107 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3108 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3110 %(mmake)-archbase := %(package)-%(version)
3112 ifeq (%(compiler),host)
3113 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
3115 %(mmake)-portdir := $(PORTSDIR)/%(package)
3119 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3121 %(mmake)-prefix := %(prefix)
3124 ifneq (%(subpackage),)
3125 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
3127 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
3131 %(mmake)-%(subpackage)-srcdir := %(srcdir)
3133 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
3136 ifneq (%(builddir),)
3137 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3139 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)
3143 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3145 %(mmake)-%(subpackage)-patches_specs := ::
3148 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3149 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3150 archive_origins=". %(package_repo)" \
3151 patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3153 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3154 archive=$(%(mmake)-%(subpackage)-archbase) \
3155 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3156 suffixes="%(suffixes)" \
3157 destination=$(%(mmake)-portdir)
3159 #MM- %(mmake) : %(mmake)-%(subpackage)
3161 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3163 %(mmake)-%(subpackage)-package-basename := \
3164 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3166 ifneq (%(create_pkg),no)
3167 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3170 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3171 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3172 install_env="%(install_env)" use_build_env="%(use_build_env)" \
3173 nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3174 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3175 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3177 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3178 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3181 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3183 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3184 #that $^ and $@ have exactly the same mtime, and in that case make tries
3185 #to rebuild $@ again, which would fail because the directory where
3186 #the package got installed would not exist anymore.
3187 #We work this around by using an if statement to manually check the mtimes.
3188 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3189 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3191 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3192 mkdir -p "$(DISTDIR)/Packages" ; \
3193 mkdir -p "$(%(mmake)-prefix)" ; \
3194 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3195 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3196 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3199 #------------------------------------------------------------------------------
3202 #------------------------------------------------------------------------------
3203 # Joins the features of %fetch and %build_with_configure, taking advantage of
3204 # the naming scheme of GNU packages. GNU packages names are in the form
3206 # <package name>-<version number>.<archive format suffix>
3208 # If a patch is provided, it *must* be named the following way:
3210 # <package name>-<version number>-aros.diff
3212 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3213 # CD'ing into the archive's extracted directory.
3215 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3216 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3217 # to make that patch fully comprehensive.
3219 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3223 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3225 # - prefix = defaults to $(GNUDIR).
3226 # - aros_prefix = defaults to /GNU.
3228 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3229 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3230 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
3232 GNU_REPOSITORY := gnu://
3234 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3235 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3236 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3237 patch="%(patch)" patch_repo="%(patch_repo)" \
3238 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3239 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3242 #------------------------------------------------------------------------------
3245 #------------------------------------------------------------------------------
3246 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3247 # that the package is a "Development" package, and as such it needs to be placed
3248 # under the $(AROS_DEVELOPMENT) directory, as a default.
3250 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3251 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3252 # "mmake" argument, because the metatarget is implicitely defined as
3254 # #MM- development-%(package)
3256 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3257 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3258 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
3260 #MM- development : development-%(package)
3263 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3264 version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3265 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3266 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3267 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3270 postinstall-%(package)-delete-la-files:
3271 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3274 #------------------------------------------------------------------------------
3276 # Builds a kickstart package in PKG format
3280 # - mmake = target name
3281 # - file = destination file name with path
3283 # Other arguments are self-explanatory
3285 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3286 arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3288 PKG_CLASSES := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3289 PKG_DEVICES := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3290 PKG_HANDLERS := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3291 PKG_HIDD := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3292 PKG_LIBS := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3293 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3295 PKG_CLASSES_ARCH := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3296 PKG_DEVICES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3297 PKG_HANDLERS_ARCH := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3298 PKG_HIDD_ARCH := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3299 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3300 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3302 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3303 $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3304 PKG_DIR := $(dir %(file))
3310 %(mmake)-quick : %(file)
3312 %(file): $(PKG_FILES) | $(PKG_DIR)
3313 @$(ECHO) Packaging $@...
3314 @$(SRCDIR)/tools/package/pkg c $@ $^
3316 %compress_file mmake="%(mmake)" file="%(file)"
3318 GLOB_MKDIRS += $(PKG_DIR)
3322 #------------------------------------------------------------------------------
3323 # Compresses %(file) with a gzip.
3324 # Good in conjunction with for example %build_prog
3326 %define compress_file mmake=/A file=/A
3328 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3331 %(mmake)-gz-quick : %(file).gz
3334 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3339 #------------------------------------------------------------------------------
3340 # Links a kickstart module in ELF format
3341 # Arguments are similar to make_package
3343 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3344 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3346 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3347 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3348 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3349 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3350 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3351 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3354 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3356 KOBJ_STARTUP := %(startup)
3359 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3361 TMP_LDFLAGS := %(ldflags)
3363 # Make a list of the lib files this program depends on.
3364 # In LDFLAGS remove white space between -L and directory
3365 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3366 # Filter out only the libdirs and remove -L
3367 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3369 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3370 # Add normal linklib path
3371 TMP_DIRS += $(AROS_LIB)/
3372 # add lib and .a to static linklib names
3373 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3374 # search for the linklibs in the given path, ignore ones not found
3375 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3376 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3379 TMP_DIRS += $(dir %(file))
3381 TMP_LDFLAGS += $(GENMAP) %(map)
3382 TMP_DIRS += $(dir %(map))
3385 #MM %(mmake) : %(deps)
3391 %(mmake)-quick : %(file)
3393 %(file): KOBJS := $(KOBJS)
3394 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3395 -static -nosysbase -Wl,-Ur
3396 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3397 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3398 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3399 @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3402 %compress_file mmake="%(mmake)" file="%(file)"
3404 GLOB_MKDIRS += $(TMP_DIRS)