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 includedir= libdir= \
1638 build_abi= build_library=
1640 # We will employ a terrifying, but unavoidable, hack here.
1641 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1642 # ignores GNU Make ifeq() statements, but will process any #MM
1643 # headed lines in the file.
1645 # So, to make the following #MM lines conditional on whether we want
1646 # to build the ABI, Library, or both, we define build_abi= and
1647 # build_library as 'M' to enable, or '' to disable, which allows genmf
1648 # to do the following conversions:
1650 # #%(build_abi)M includes-foo: foo-include
1651 # becomes, when build_abi=M
1652 # #MM includes-foo: foo-include <= Processed by MetaMake
1653 # but, when build_abi= ...
1654 # #M includes-foo: foo-includes <= ignored by MetaMake! Yes!
1656 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1658 # Define metamake targets and their dependencies
1661 #MM %(mmake)-makefile
1665 #M%(build_abi)- includes-all : %(mmake)-includes
1666 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1667 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1668 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1669 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1670 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1671 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1672 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1673 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1674 #M%(build_abi) includes-generate-deps %(mmake)-fd
1675 #M%(build_abi) %(mmake)-includes-quick
1676 #M%(build_abi) %(mmake)-includes-dirs
1677 #M%(build_abi) %(mmake)-fd
1680 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1681 #%(build_library)M %(mmake)-kobj-quick :
1683 # Library with ABI targets:
1684 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1685 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1687 # All MetaMake targets defined by this macro
1688 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1690 ifeq (%(build_library),M)
1691 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1694 ifeq (%(build_abi),M)
1695 BD_ALLTARGETS += %(mmake)-includes \
1696 %(mmake)-includes-quick %(mmake)-includes-dirs \
1697 %(mmake)-linklib %(mmake)-fd
1700 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1703 $(error using %build_module: modname may not be empty)
1706 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1709 # Default values for variables and arguments
1710 BD_DEFLINKLIBNAME := %(modname)
1711 BD_DEFDFLAGS := %(cflags)
1712 OBJDIR ?= $(GENDIR)/$(CURDIR)
1714 ## Create genmodule include Makefile for the module
1716 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1718 %rule_genmodule_makefile \
1719 modname="%(modname)" modtype="%(modtype)" \
1720 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1721 conffile="%(conffile)"
1723 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1725 GLOB_MKDIRS += %(objdir)
1727 # Do not parse these statements if metatarget is not appropriate
1728 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1730 include %(objdir)/Makefile.%(modname)%(modtype)
1732 BD_DEFMODDIR := $(%(modname)_MODDIR)
1733 ifeq (%(archspecific),yes)
1734 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1738 ## include files generation
1740 ifneq (%(includedir),)
1741 BD_INCDIR := %(includedir)
1743 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1745 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1746 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1748 ifeq (%(build_abi),M)
1749 %(mmake)-includes-quick : %(mmake)-includes
1750 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1751 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1752 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1754 ifneq ($(%(modname)_INCLUDES),)
1755 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1756 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1757 conffile="%(conffile)"
1759 %rule_copy_diff_multi \
1760 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1761 stampfile="%(objdir)/%(modname)_geninc"
1763 %rule_copy_diff_multi \
1764 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1765 stampfile="%(objdir)/%(modname)_incs"
1767 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1769 TMP%(modname)_INCDIRS := \
1770 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1771 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1772 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1773 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1779 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1780 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1781 conffile="%(conffile)" version="%(version)"
1783 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1784 $(BD_DEFLIBDEFSINC) :
1785 @$(ECHO) "Generating $@"
1786 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1788 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1789 GLOB_MKDIRS += %(objdir)/include
1791 ## Extra genmodule src files generation
1793 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1794 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1795 conffile="%(conffile)"
1798 ifeq (%(build_abi),M)
1800 ifeq (%(includedir),)
1801 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1803 BD_FDDIR := %(includedir)/../fd
1805 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1807 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1808 modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1810 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1812 GLOB_MKDIRS += $(BD_FDDIR)
1817 BD_FILES := %(files)
1818 BD_CXXFILES := %(cxxfiles)
1820 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1822 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1823 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1825 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1826 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1827 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1829 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1830 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1832 ifeq (%(modtype),library)
1835 BD_LIBSUFFIX := .%(modtype)
1839 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1841 BD_LIBDIR := %(libdir)
1844 ifeq (%(build_abi),M)
1845 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1846 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1847 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1850 BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1851 ifneq (%(modname),%(linklibname))
1852 BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1855 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1857 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1858 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1859 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1862 BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1863 ifneq (%(modname),%(linklibname))
1864 BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1867 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1870 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1871 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1872 $(BD_RELLINKLIBCFILES)
1874 %rule_compile_cxx_multi \
1875 basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1876 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1877 compiler="%(compiler)"
1878 %rule_compile_multi \
1879 basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1880 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1881 compiler="%(compiler)"
1882 %rule_compile_multi \
1883 basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1884 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1885 compiler="%(compiler)"
1887 ifneq ($(BD_LINKLIBAFILES),)
1888 %rule_assemble_multi \
1889 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1894 ifeq (%(modsuffix),)
1895 BD_SUFFIX := %(modtype)
1897 BD_SUFFIX := %(modsuffix)
1900 ifeq (%(build_library),M)
1901 # Handlers use dash instead of dot in their names
1902 ifeq ($(BD_SUFFIX),handler)
1903 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1905 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1907 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1913 %(mmake)-quick : %(mmake)
1914 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1915 ifeq (%(build_library),M)
1916 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1917 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1919 ifeq (%(build_abi),M)
1920 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1923 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1924 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1926 ifeq (%(nostartup),yes)
1927 # Handlers always have entry point
1928 ifneq (%(modtype),handler)
1929 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1933 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1934 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1937 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1940 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1941 # This breaks con-handler build. Here we work around this
1942 ifeq (%(modname),con)
1943 BD_ERR := $(notdir $(BD_MODULE)).err
1945 BD_ERR := %(modname).err
1948 ifeq (%(build_library),M)
1949 # The module is linked from all the compiled .o files
1950 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1951 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
1952 cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1953 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1956 ifeq (%(build_abi),M)
1958 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1959 BD_MODNAME := $(shell echo %(modname) | tr A-Z a-z)
1960 ifneq ($(BD_LINKLIB),)
1961 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1962 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1963 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1966 $(BD_LINKLIB) : | $(BD_LIBDIR)
1967 GLOB_MKDIRS += $(BD_LIBDIR)
1970 ifneq ($(BD_RELLINKLIB),)
1971 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
1972 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1973 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
1976 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
1977 GLOB_MKDIRS += $(BD_LIBDIR)
1981 ifeq (%(build_library),M)
1982 # Link kernel object file
1983 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1985 # Make these symbols local
1986 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1987 UtilityBase ExpansionBase KeymapBase KernelBase
1989 BD_SYMBOLS := $(BD_KBASE)
1991 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1992 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1993 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1994 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1995 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1996 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1997 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1998 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1999 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2002 ## Dependency fine-tuning
2004 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
2006 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2008 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2009 $(BD_MODULE) : | %(prefix)/%(moduledir)
2010 $(BD_KOBJ) : | $(KOBJSDIR)
2011 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2013 # Some include files need to be generated before the .c can be parsed.
2014 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2016 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2017 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2018 $(BD_DEPS) : $(BD_DFILE_DEPS)
2021 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2022 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2023 %(objdir)/Makefile.%(modname)%(modtype) \
2024 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2025 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2026 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2027 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2028 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2029 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2031 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2033 @$(ECHO) "Cleaning up for module %(modname)"
2036 endif # $(TARGET) in $(BD_ALLTARGETS)
2038 #------------------------------------------------------------------------------
2040 #------------------------------------------------------------------------------
2041 # Build a module - ABI and library
2042 # Explanation of this macro is done in the developer's manual
2043 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2044 files="$(basename $(call WILDCARD, *.c))" \
2045 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2046 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2047 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2048 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2049 compiler=target nostartup=yes archspecific=no \
2052 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2053 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2054 files="%(files)" cxxfiles="%(cxxfiles)" \
2055 linklibname="%(linklibname)" \
2056 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2057 cflags="%(cflags)" dflags="%(dflags)" \
2058 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2059 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2060 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2061 includedir="%(includedir)" libdir="%(libdir)" \
2062 build_abi=M build_library=M
2065 #------------------------------------------------------------------------------
2068 #------------------------------------------------------------------------------
2069 # Build a module skeleton ABI
2070 # This is a stripped-down version of build_module, it only creates include
2071 # files and the linklibs.
2072 # This is used when for plugins or classes with the same API, but no actual
2073 # implementation here.
2074 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2075 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2076 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2077 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2078 compiler=target nostartup=yes archspecific=no \
2081 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2082 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2083 linklibname="%(linklibname)" \
2084 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2085 cflags="%(cflags)" dflags="%(dflags)" \
2086 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2087 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2088 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2089 includedir="%(includedir)" libdir="%(libdir)" \
2090 build_abi=M build_library=
2093 #------------------------------------------------------------------------------
2095 #------------------------------------------------------------------------------
2096 # Build a module library - no includes nor linklibs
2097 # Explanation of this macro is done in the developer's manual
2098 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2099 files="$(basename $(call WILDCARD, *.c))" \
2100 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2101 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2102 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2103 uselibs= usehostlibs= \
2104 compiler=target nostartup=yes archspecific=no \
2107 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2108 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2109 files="%(files)" cxxfiles="%(cxxfiles)" \
2110 cflags="%(cflags)" dflags="%(dflags)" \
2111 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2112 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2113 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2114 includedir="%(includedir)" libdir="%(libdir)" \
2115 build_abi= build_library=M
2118 #------------------------------------------------------------------------------
2122 #------------------------------------------------------------------------------
2124 # - mmake is the mmaketarget
2125 # - libname is the baselibname e.g. lib%(libname).a will be created
2126 # - files are the C source files to include in the lib. The list of files
2127 # has to be given without the .c suffix
2128 # - cxxfiles are C++ source files without suffix.
2129 # NB: files will be matched in the order .cpp > .cxx > .cc
2130 # - asmfiles are the asm files to include in the lib. The list of files has to
2131 # be given without the .s suffix
2132 # - objs additional object to link into the linklib. The objects have to be
2133 # given with full absolute path and the .o suffix.
2134 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2135 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2136 # - cflags are the flags to compile the source (default $(CFLAGS))
2137 # - dflags are the flags use during makedepend (default equal to cflags)
2138 # - aflags are the flags use during assembling (default $(AFLAGS))
2139 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2140 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2141 asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2142 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2143 aflags=$(AFLAGS) compiler=target
2145 # assign and generate the local variables used in this macro
2146 BD_LIBNAME := %(libname)
2147 BD_LINKLIB := %(libdir)/lib%(libname).a
2149 BD_FILES := %(files)
2150 BD_ASMFILES := %(asmfiles)
2151 BD_CXXFILES := %(cxxfiles)
2153 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2154 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2155 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2157 BD_OBJS := $(BD_ARCHOBJS) \
2158 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2160 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2162 BD_CFLAGS := %(cflags)
2163 BD_AFLAGS := %(aflags)
2164 BD_DFLAGS := %(dflags)
2166 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2169 %(mmake)-quick : %(mmake)
2171 #MM %(mmake) : includes-generate-deps
2172 %(mmake) : $(BD_LINKLIB)
2174 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2176 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2177 compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2178 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2179 compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2180 %rule_assemble basename=% targetdir="%(objdir)" \
2183 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2186 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2188 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2189 $(BD_LINKLIB) : | %(libdir)
2190 GLOB_MKDIRS += %(objdir) %(libdir)
2192 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2195 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2199 #------------------------------------------------------------------------------
2202 #------------------------------------------------------------------------------
2204 # - mmake is the mmaketarget
2205 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2206 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2207 # - subdir is the destination subdirectory of the catalogs
2208 # - name is the name of the destination catalog, without the .catalog suffix
2209 # - source is the path to the generated source code file
2210 # - dir is the base destination directory (default $(AROS_CATALOGS))
2211 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2212 # - srcdir is the directory in which the *.cd and *.ct files are searched
2214 %define build_catalogs mmake=/A name=/A subdir=/A \
2215 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2216 sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2218 ifeq (%(description),)
2219 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2221 BD_DESC := %(description)
2224 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2227 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2229 BD_LNGS := %(catalogs)
2232 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2233 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2236 %(mmake) : $(BD_OBJS) %(source)
2238 $(BD_OBJS) : | $(BD_DIRS)
2239 GLOB_MKDIRS += $(BD_DIRS)
2241 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2242 @$(ECHO) "Creating %(name) catalog for language $*."
2243 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2246 %(source) : BD_DESC := $(BD_DESC)
2247 %(source) : BD_SRC := $(BD_SRC)
2248 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2249 @$(ECHO) "Creating %(name) catalog source file $@"
2250 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2253 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2256 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2259 .PHONY: %(mmake) %(mmake)-clean
2262 #-----------------------------------------------------------------------------
2265 #-----------------------------------------------------------------------------
2267 # - mmake is the mmaketarget
2268 # - icons is a list of icon base names (ie. without the .info suffix)
2269 # - dir is the destination directory
2270 # - srcdir is where *.png and *.info.src are searched
2271 #-----------------------------------------------------------------------------
2273 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2275 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2278 %(mmake) : $(BD_OBJS)
2282 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2283 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2284 @$(ILBMTOICON) $+ $@
2288 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2289 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2290 @$(ILBMTOICON) $+ $@
2294 $(BD_OBJS) : | %(dir)
2295 GLOB_MKDIRS += %(dir)
2297 %(mmake)-clean : FILES := $(BD_OBJS)
2302 .PHONY: %(mmake) %(mmake)-clean
2305 #-----------------------------------------------------------------------------
2308 #------------------------------------------------------------------------------
2309 # Compile files for an arch-specific replacement of code for a module
2310 # - files: the basenames of the C files to compile.
2311 # - asmfiles: the basenames of the asm files to assemble.
2312 # - mainmmake: the mmake of the module in the main directory to compile these
2313 # arch specific files for.
2314 # - maindir: the object directory for the main module
2315 # - arch: the arch for which to compile these files. It can have the form
2316 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2317 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2318 # - dflags: the flags used during creation of dependency file. If not specified
2319 # the same value as cflags will be used
2320 # - aflags: the flags used during assembling
2321 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2322 # the target compiler is used
2323 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2324 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2326 ifeq (%(files) %(asmfiles),)
2327 $(error no files or asmfiles given)
2330 %buildid targets="%(mainmmake)-%(arch)"
2332 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2333 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2334 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2335 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2336 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2337 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2338 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2339 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2340 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2341 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2342 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2343 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2344 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2345 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2346 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2348 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2350 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2351 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2352 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2353 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2354 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2356 ifneq (%(modulename),)
2357 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2360 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2361 BD_TARGET := %(mainmmake)-%(arch)-quick
2363 BD_TARGET := %(mainmmake)-%(arch)
2367 ifeq ($(TARGET),$(BD_TARGET))
2368 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2369 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2370 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2371 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2374 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2375 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2378 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2381 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2383 ifeq ($(findstring %(compiler),host kernel target),)
2384 $(error unknown compiler %(compiler))
2386 ifeq (%(compiler),target)
2387 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2388 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2389 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2391 ifeq (%(compiler),host)
2392 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2393 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2394 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2396 ifeq (%(compiler),kernel)
2397 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2398 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2399 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2401 ifneq (%(modulename),)
2402 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2404 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2406 ifeq ($(TARGET),$(BD_TARGET))
2407 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2408 %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2412 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2414 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2416 ifeq ($(TARGET),$(BD_TARGET))
2417 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2418 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2421 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2423 ifeq ($(TARGET),$(BD_TARGET))
2424 $(BD_OBJDIR$(BDID))/%.o : %.s
2425 %assemble_q opt=$(AFLAGS)
2426 $(BD_OBJDIR$(BDID))/%.o : %.S
2427 %assemble_q opt=$(AFLAGS)
2430 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2432 #------------------------------------------------------------------------------
2435 #------------------------------------------------------------------------------
2436 # generate asm files from c files (for debugging purposes)
2439 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2440 @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2442 #------------------------------------------------------------------------------
2445 #------------------------------------------------------------------------------
2446 # Copy files from one directory to another.
2448 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2450 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2452 GLOB_MKDIRS += %(dst)
2458 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2461 #------------------------------------------------------------------------------
2464 #------------------------------------------------------------------------------
2465 # Copy a directory recursively to another place, preserving the original
2466 # hierarchical structure
2468 # src: the source directory whose content will be copied.
2469 # dst: the directories where to copy src's content. If not existing, they will be made.
2470 # excludefiles: files which must not be copied. Path must be relative to src.
2472 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2478 @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2481 #------------------------------------------------------------------------------
2484 #------------------------------------------------------------------------------
2485 # Copy include files into the includes directories. There are currently
2486 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2487 # for building tools that need to run on the host system $(GENINCDIR). The
2488 # $(GENINCDIR) path must not contain any references to the C runtime
2489 # library header files.
2491 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2492 dir= compiler=target
2494 ifeq ($(findstring %(compiler),host kernel target),)
2495 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2500 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2501 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2502 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2503 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2504 ifeq ($(TMP_DIRFIRST),/)
2505 BD_INC_PATH := %(dir)/
2507 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2510 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2511 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2514 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2518 ifeq (%(compiler),target)
2521 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2522 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2524 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2527 BD_INCL_FILES += $(BD_INCL_FILES2)
2529 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2534 %(mmake) : $(BD_INCL_FILES)
2538 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2539 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2541 #------------------------------------------------------------------------------
2544 #------------------------------------------------------------------------------
2545 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2546 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2547 STUBS_MEM := $(addsuffix .o,$(STUBS))
2548 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2549 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2550 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2552 #MM- linklibs : hidd-%(hidd)-stubs
2553 #MM- %(parenttarget): hidd-%(hidd)-stubs
2554 #MM hidd-%(hidd)-stubs : includes includes-copy
2555 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2557 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2560 $(STUBS_OBJ) : $(STUBS_SRC)
2561 %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2563 $(STUBS_DEP) : $(STUBS_SRC)
2564 %mkdepend_q flags="%(dflags)"
2567 %mkdirs_q $(OBJDIR) $(AROS_LIB)
2571 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2573 DEPS := $(DEPS) $(STUBS_DEP)
2576 #------------------------------------------------------------------------------
2579 #------------------------------------------------------------------------------
2580 # Build an imported source tree which uses the configure script from the
2581 # autoconf package. This rule will try to "integrate" the produced files as
2582 # much as possible in the AROS build, for example by putting libraries in the
2583 # standard library directory, includes in the standard include directory, and
2584 # so on. You can however override this behaviour.
2586 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2587 # be %(bindir) (or its deduced value) when running "make install", and
2588 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2589 # configure script some more parameters whose value depends upon the PROGDIR
2590 # env var, so that the program gets all its stuff installed in the proper place
2591 # when building it, but when running it from inside AROS it can also find that
2592 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2593 # the configuration parameters set when running ./configure
2595 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2596 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2597 # to the name which has to follow it.
2601 # - mmake = the meta make target.
2602 # - package = name of the package to be built.
2603 # - srcdir = the location of the unpacked source code. Defaults
2604 # to $(SRCDIR)/$(CURDIR).
2605 # - prefix = the target directory. Must be an absolute path of the
2606 # host system. Defaults to $(AROS_CONTRIB).
2607 # - aros_prefix = set a path which is valid within the AROS filesystem.
2608 # Defaults to the value of the prefix option.
2609 # - extraoptions = additional options for the configure script.
2610 # - extracflags = additional flags which are used for both C and C++.
2611 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2612 # Defaults to the value of the nix argument.
2613 # - nix = enable u*nix path handling, i.e. a path like
2614 # /progdir//./file will be translated to
2615 # progdir:file during run-time. Defaults to no.
2616 # - compiler = target, host or kernel. Defaults to target.
2617 # - install_target = the command used for installing. Defaults to install. Leave
2618 # it empty if you want to suppress installing.
2619 # - preconfigure = a metatarget which is executed before configure is called.
2620 # - postconfigure = a metatarget which is executed after configure is called.
2621 # - postinstall = a metatarget which is executed after installing.
2622 # - install_env = set additional options for installing.
2623 # - use_build_env = if yes the configuration environment is used for
2624 # installing, too. Defaults to no.
2626 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2630 # --prefix = $(aros_prefix)
2631 # progdir = $(aros_prefix)/bin
2634 # --prefix = /PROGDIR
2635 # --bindir = /PROGDIR
2636 # --sbindir = /PROGDIR
2638 # --includedir = /INCLUDE
2639 # --oldincludedir = /INCLUDE
2641 # --prefix = $(aros_prefix)
2644 # progdir = $(aros_prefix)
2647 # bindir = $(prefix)
2648 # sbindir = $(prefix)
2649 # libdir = $(AROS_LIB)
2650 # includedir = $(AROS_INCLUDES)
2651 # oldincludedir = $(AROS_INCLUDES)
2655 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2656 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2657 install_target=install preconfigure= postconfigure= postinstall= \
2658 install_env= use_build_env=no
2661 %(mmake)-prefix := %(prefix)
2663 %(mmake)-prefix := $(AROS_CONTRIB)
2666 ifneq (%(aros_prefix),)
2667 %(mmake)-aros_prefix := %(aros_prefix)
2669 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2673 %(mmake)-nix := -nix
2674 %(mmake)-volpfx := /
2675 %(mmake)-volsfx := /
2677 ifeq (%(nix_dir_layout),)
2678 %(mmake)-nix_dir_layout := yes
2681 %(mmake)-volsfx := :
2683 ifeq (%(nix_dir_layout),)
2684 %(mmake)-nix_dir_layout := no
2688 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2690 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2691 exec_prefix=$(%(mmake)-prefix) %(install_env)
2693 # Check if chosen compiler is valid
2694 ifeq ($(findstring %(compiler),host target kernel),)
2695 $(error unknown compiler %(compiler))
2698 # Set legacy 'host' variable based on chosen compiler
2699 ifeq (%(compiler),host)
2702 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2704 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2709 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2711 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2716 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2718 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2722 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2723 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2725 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2726 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2727 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2730 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2731 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2733 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2736 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2738 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2739 sbindir=$(%(mmake)-prefix) \
2740 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2741 oldincludedir=$(AROS_INCLUDES) %(install_env)
2744 ifneq ($(DEBUG),yes)
2745 %(mmake)-s_flag = -s
2748 # Set up build environment, and options for configure script
2749 ifeq (%(compiler),host)
2752 CXXCPP="$(HOST_CPP)" \
2753 CC="$(HOST_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2754 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2755 LDFLAGS="-L$(CROSSTOOLSDIR)/lib" \
2756 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2757 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2758 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2759 TARGET_NM="$(NM_PLAIN)" TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2761 ifeq (%(compiler),target)
2763 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2764 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2765 CFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2766 CXXFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2767 CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2768 CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2769 CC="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2770 CXX="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2771 LDFLAGS="-L$(AROS_DEVELOPMENT)/lib" \
2772 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2773 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2774 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2775 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2776 TARGET_NM="$(NM_PLAIN)" \
2777 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)"\
2778 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)"
2779 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2780 --host=$(AROS_TARGET_CPU)-aros\
2781 --target=$(AROS_TARGET_CPU)-aros\
2783 --without-x --without-pic --disable-shared
2785 ifeq (%(compiler),kernel)
2787 CPP="$(KERNEL_CPP)" \
2788 CXXCPP="$(KERNEL_CPP)" \
2789 CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2790 CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2791 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2792 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2793 TARGET_NM="$(NM_PLAIN)"
2794 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2795 --host=$(AROS_TARGET_CPU)-aros\
2796 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2797 --without-x --without-pic --disable-shared
2800 ifeq (%(use_build_env),yes)
2801 BUILD_ENV := $(CONFIG_ENV)
2804 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2806 # When building for the host, we don't need to build the
2807 # linklibs - this is especially true when building the
2808 # crosstool toolchain on 'foreign' architectures (such as
2809 # building PPC on x86)
2811 #MM- %(mmake)-host : setup includes %(mmake)-quick
2812 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2813 #MM- %(mmake): %(mmake)-%(compiler)
2815 # Using -j1 in install_command may result in a warning but finally
2816 # it does its job. make install for gcc does not work reliably for -jN
2818 ifneq (%(install_target),)
2819 %(mmake)-install_command = \
2820 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2821 -C $(%(mmake)-pkgdir) %(install_target) -j1
2823 %(mmake)-uninstall_command = \
2824 $(RM) $(%(mmake)-installflag) && \
2825 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2826 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2828 %(mmake)-install_command := true
2829 %(mmake)-uninstall_command := true
2832 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2835 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2837 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2838 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2839 $(RM) $(%(mmake)-installflag) && \
2840 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2841 -C $(%(mmake)-pkgdir) && \
2842 $(%(mmake)-install_command) && \
2843 $(TOUCH) $@ -r $^; \
2846 $(%(mmake)-pkgdir)/.files-touched:
2847 %mkdirs_q $(%(mmake)-pkgdir)
2848 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2852 %(mmake)-uninstall :
2853 $(%(mmake)-uninstall_command)
2856 %(mmake)-configure : $(%(mmake)-configflag)
2858 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2859 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2861 %mkdirs_q $(%(mmake)-pkgdir)
2862 cd $(%(mmake)-pkgdir) && \
2863 find . -name config.cache -exec $(RM) '{}' \; && \
2864 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2865 %(extraoptions) && \
2869 %(mmake)-clean : %(mmake)-uninstall
2870 @$(RM) $(%(mmake)-pkgdir)
2872 #------------------------------------------------------------------------------
2875 #------------------------------------------------------------------------------
2876 # Build an imported source tree which uses cmake
2880 # - mmake = the meta make target.
2881 # - package = name of the package to be built.
2882 # - srcdir = the location of the unpacked source code. Defaults
2883 # to $(SRCDIR)/$(CURDIR).
2884 # - prefix = the target directory. Must be an absolute path of the
2885 # host system. Defaults to $(AROS_CONTRIB).
2886 # - aros_prefix = set a path which is valid within the AROS filesystem.
2887 # Defaults to the value of the prefix option.
2888 # - extraoptions = additional options for the cmake script.
2889 # - installoptions = additional options for the install step.
2892 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2893 aros_prefix= extraoptions= installoptions= cflags=$(CFLAGS)
2896 %(mmake)-prefix := %(prefix)
2898 %(mmake)-prefix := $(AROS_CONTRIB)
2901 ifneq (%(aros_prefix),)
2902 %(mmake)-aros_prefix := %(aros_prefix)
2904 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2909 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2911 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2915 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2917 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2921 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
2922 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2924 BD_CFLAGS := %(cflags)
2925 BD_CXXFLAGS := $(subst -Wno-pointer-sign,,$(BD_CFLAGS))
2927 %(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)"
2929 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2931 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
2933 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
2936 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2938 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
2939 if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
2940 $(RM) $(%(mmake)-installflag) && \
2941 $(MAKE) -C $(%(mmake)-pkgdir) && \
2942 cd $(%(mmake)-pkgdir) && \
2943 cmake %(installoptions) -P cmake_install.cmake && \
2944 $(TOUCH) $@ -r $^; \
2947 $(%(mmake)-pkgdir)/.files-touched:
2948 %mkdirs_q $(%(mmake)-pkgdir)
2949 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
2953 %(mmake)-cmake : $(%(mmake)-cmakeflag)
2955 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2956 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2958 %mkdirs_q $(%(mmake)-pkgdir)
2959 cd $(%(mmake)-pkgdir) && \
2960 $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
2961 cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
2965 %(mmake)-clean : %(mmake)-uninstall
2966 @$(RM) $(%(mmake)-pkgdir)
2968 #------------------------------------------------------------------------------
2971 #------------------------------------------------------------------------------
2972 # Given an archive name, patches names and locations where to find them, fetch
2973 # the archive and the patches from any of those locations, unpack the archive
2974 # and then apply the patches.
2976 # Locations currently supported are http and ftp sites, plus local filesystem
2977 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2978 # the fetch.sh script needs to be modified, since this macro relies on that script.
2982 # - mmake = mmaketarget
2983 # - archive_origins = list of locations where to find the archive. They are tried
2984 # in sequence, until the archive is found and fetching it
2985 # succeeded. If not specified, the current directory is assumed.
2986 # - archive = the archive name. Mandatory.
2987 # - suffixes = a list of suffixes to append to the the package name plus the
2988 # version. Each one of them is tried until a matching archive is
2989 # found. They are appended to patches and these are tried the
2990 # same way as packages are.
2991 # - location = the local directory where to put the fetched archive and patches.
2992 # If not specified, the directory specified by destination is used.
2993 # - destination = the directory to unpack the archive to.
2994 # If not specified, the current directory is assumed.
2995 # - patches_origins = list of locations where to find the patches. They are tried
2996 # in sequence, until a patch is found and fetching it
2997 # succeeded. If not specified, the current directory is assumed.
2998 # - patches_specs = list of "patch specs". A patch spec is of the form
2999 # patch_name[:[patch_subdir][:patch_opt]].
3001 # - patch_name = the name of the patch file
3002 # - patch_subdir = the directory within \destination\ where to
3004 # - patch_opt = any options to pass to the `patch' command
3005 # when applying the patch.
3007 # The patch_subdir and patch_opt fields are optional.
3009 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3010 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3014 ifneq (%(location),)
3015 %(mmake)-location := %(location)
3017 %(mmake)-location := %(destination)
3022 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3023 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3025 #------------------------------------------------------------------------------
3028 #------------------------------------------------------------------------------
3029 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3030 # unpatched source tree and runs diff against this and a previously fetched and possibly
3031 # patched tree. Depending on what happens after patching during a normal build it might
3032 # give best results if the new patch is created directly after fetch.
3036 # - mmake = mmaketarget
3037 # - archive = archive base name
3038 # - srcdir = the top level directory the package is unpacked to, useful if
3039 # an archive unpacks to a directory other than its name suggests.
3040 # this should not be deeper than a single path element.
3041 # - suffixes = a list of suffixes to append to the the package name plus the
3042 # version. Each one of them is tried until a matching archive is
3044 # - destination = the directory to unpack the archive to.
3045 # - excludes = diff patterns to exclude files or directories from the patch
3047 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3051 ifneq (%(excludes),)
3052 %(mmake)-exclude := -X ./exclude.patterns
3056 %(mmake)-srcdir := %(srcdir)
3058 %(mmake)-srcdir := %(archive)
3063 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3064 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3065 cd %(destination)/tmp ; \
3066 $(FOR) f in %(excludes) ; do \
3067 $(ECHO) $$f >> ./exclude.patterns ; \
3069 diff -ruN $(%(mmake)-exclude) \
3070 $(%(mmake)-srcdir) \
3071 $(%(mmake)-srcdir).aros \
3072 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3073 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3074 $(RM) %(destination)/tmp
3076 #------------------------------------------------------------------------------
3079 #------------------------------------------------------------------------------
3080 # Joins the features of %fetch and %build_with_configure.
3082 # If a patch is provided, it *must* be named the following way:
3084 # <package name>-<version number>-aros.diff
3086 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3087 # CD'ing into the archive's extracted directory.
3089 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3090 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3091 # to make that patch fully comprehensive.
3095 # - mmake = the meta make target.
3096 # - package = the GNU package name, sans version and archive format suffixes.
3097 # - subpackage = ???
3098 # - compiler = same meaning as the one for the %build_with_configure macro.
3099 # - install_target = same meaning as the one for the %build_with_configure macro.
3100 # - version = the package's version number, or otherwise any other version string.
3101 # It gets appended to the package name to form the basename of the archive.
3102 # - suffixes = a list of suffixes to apped to the the package name plus the
3103 # version. Each one of them is tried until a matching archive is found.
3104 # Defaults to "tar.bz2 tar.gz".
3105 # - srcdir = the top level directory the package is unpacked to (see create_patch).
3106 # - builddir = override the location we expect to run configure/make in.
3107 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
3108 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
3109 # fetched or not. Default to no.
3110 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
3111 # - prefix = same meaning as the one for the %build_with_configure macro.
3112 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
3113 # - extraoptions = same meaning as the one for the %build_with_configure macro.
3114 # - extracflags = same meaning as the one for the %build_with_configure macro.
3115 # - preconfigure = same meaning as the one for the %build_with_configure macro.
3116 # - postconfigure = same meaning as the one for the %build_with_configure macro.
3117 # - postinstall = same meaning as the one for the %build_with_configure macro.
3118 # - install_env = same meaning as the one for the %build_with_configure macro.
3119 # - use_build_env = same meaning as the one for the %build_with_configure macro.
3120 # - nix = same meaning as the one for the %build_with_configure macro.
3121 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
3122 # - create_pkg = create a distributable package of the compiled sources, defaults to no
3124 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3125 version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3126 prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
3127 install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3129 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3130 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3131 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3132 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3134 %(mmake)-archbase := %(package)-%(version)
3136 ifeq (%(compiler),host)
3137 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
3139 %(mmake)-portdir := $(PORTSDIR)/%(package)
3143 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3145 %(mmake)-prefix := %(prefix)
3148 ifneq (%(subpackage),)
3149 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
3151 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
3155 %(mmake)-%(subpackage)-srcdir := %(srcdir)
3157 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
3160 ifneq (%(builddir),)
3161 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3163 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)
3167 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3169 %(mmake)-%(subpackage)-patches_specs := ::
3172 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3173 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3174 archive_origins=". %(package_repo)" \
3175 patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3177 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3178 archive=$(%(mmake)-%(subpackage)-archbase) \
3179 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3180 suffixes="%(suffixes)" \
3181 destination=$(%(mmake)-portdir)
3183 #MM- %(mmake) : %(mmake)-%(subpackage)
3185 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3187 %(mmake)-%(subpackage)-package-basename := \
3188 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3190 ifneq (%(create_pkg),no)
3191 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3194 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3195 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3196 install_env="%(install_env)" use_build_env="%(use_build_env)" \
3197 nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3198 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3199 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3201 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3202 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3205 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3207 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3208 #that $^ and $@ have exactly the same mtime, and in that case make tries
3209 #to rebuild $@ again, which would fail because the directory where
3210 #the package got installed would not exist anymore.
3211 #We work this around by using an if statement to manually check the mtimes.
3212 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3213 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3215 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3216 mkdir -p "$(DISTDIR)/Packages" ; \
3217 mkdir -p "$(%(mmake)-prefix)" ; \
3218 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3219 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3220 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3223 #------------------------------------------------------------------------------
3226 #------------------------------------------------------------------------------
3227 # Joins the features of %fetch and %build_with_configure, taking advantage of
3228 # the naming scheme of GNU packages. GNU packages names are in the form
3230 # <package name>-<version number>.<archive format suffix>
3232 # If a patch is provided, it *must* be named the following way:
3234 # <package name>-<version number>-aros.diff
3236 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3237 # CD'ing into the archive's extracted directory.
3239 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3240 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3241 # to make that patch fully comprehensive.
3243 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3247 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3249 # - prefix = defaults to $(GNUDIR).
3250 # - aros_prefix = defaults to /GNU.
3252 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3253 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3254 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
3256 GNU_REPOSITORY := gnu://
3258 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3259 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3260 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3261 patch="%(patch)" patch_repo="%(patch_repo)" \
3262 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3263 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3266 #------------------------------------------------------------------------------
3269 #------------------------------------------------------------------------------
3270 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3271 # that the package is a "Development" package, and as such it needs to be placed
3272 # under the $(AROS_DEVELOPMENT) directory, as a default.
3274 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3275 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3276 # "mmake" argument, because the metatarget is implicitely defined as
3278 # #MM- development-%(package)
3280 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3281 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3282 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
3284 #MM- development : development-%(package)
3287 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3288 version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3289 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3290 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3291 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3294 postinstall-%(package)-delete-la-files:
3295 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3298 #------------------------------------------------------------------------------
3300 # Builds a kickstart package in PKG format
3304 # - mmake = target name
3305 # - file = destination file name with path
3307 # Other arguments are self-explanatory
3309 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3310 arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3312 PKG_CLASSES := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3313 PKG_DEVICES := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3314 PKG_HANDLERS := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3315 PKG_HIDD := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3316 PKG_LIBS := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3317 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3319 PKG_CLASSES_ARCH := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3320 PKG_DEVICES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3321 PKG_HANDLERS_ARCH := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3322 PKG_HIDD_ARCH := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3323 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3324 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3326 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3327 $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3328 PKG_DIR := $(dir %(file))
3334 %(mmake)-quick : %(file)
3336 %(file): $(PKG_FILES) | $(PKG_DIR)
3337 @$(ECHO) Packaging $@...
3338 @$(SRCDIR)/tools/package/pkg c $@ $^
3340 %compress_file mmake="%(mmake)" file="%(file)"
3342 GLOB_MKDIRS += $(PKG_DIR)
3346 #------------------------------------------------------------------------------
3347 # Compresses %(file) with a gzip.
3348 # Good in conjunction with for example %build_prog
3350 %define compress_file mmake=/A file=/A
3352 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3355 %(mmake)-gz-quick : %(file).gz
3358 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3363 #------------------------------------------------------------------------------
3364 # Links a kickstart module in ELF format
3365 # Arguments are similar to make_package
3367 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3368 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3370 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3371 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3372 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3373 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3374 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3375 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3378 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3380 KOBJ_STARTUP := %(startup)
3383 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3385 TMP_LDFLAGS := %(ldflags)
3387 # Make a list of the lib files this program depends on.
3388 # In LDFLAGS remove white space between -L and directory
3389 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3390 # Filter out only the libdirs and remove -L
3391 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3393 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3394 # Add normal linklib path
3395 TMP_DIRS += $(AROS_LIB)/
3396 # add lib and .a to static linklib names
3397 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3398 # search for the linklibs in the given path, ignore ones not found
3399 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3400 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3403 TMP_DIRS += $(dir %(file))
3405 TMP_LDFLAGS += $(GENMAP) %(map)
3406 TMP_DIRS += $(dir %(map))
3409 #MM %(mmake) : %(deps)
3415 %(mmake)-quick : %(file)
3417 %(file): KOBJS := $(KOBJS)
3418 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3419 -static -nosysbase -Wl,-Ur
3420 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3421 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3422 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3423 @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3426 %compress_file mmake="%(mmake)" file="%(file)"
3428 GLOB_MKDIRS += $(TMP_DIRS)