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)" opt="$(TARGET_CFLAGS) $(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) objdir=$(GENDIR)/$(CURDIR)
66 @$(eval LINKTARGET=%(to))
67 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$(LINKTARGET))..."
68 @$(eval LINKTMPFILE=%(objdir)/$(notdir $(LINKTARGET)))
69 @$(IF) %(cmd) %(from) -o $(LINKTMPFILE) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
70 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
71 $(ECHO) "$(LINKTARGET): %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" >> $(GENDIR)/errors ; \
72 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
76 $(CP) $(LINKTMPFILE) $(LINKTARGET) ; \
78 $(ECHO) "Link failed: %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" 1>&2 ; \
79 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
82 %(strip) $(LINKTARGET)
84 #------------------------------------------------------------------------------
87 #-------------------------------------------------------------------------
88 # Link a module based upon a number of arguments and the standard $(LIBS)
89 # and $(DEPLIBS) make variables.
91 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
92 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
93 @$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
94 $(GENMAP) %(objdir)/%(module).map \
95 %(objs) %(libs) %(ldflags) %(endtag) \
96 -o $@ 2>&1 > %(objdir)/%(err); \
98 cat %(objdir)/%(err); \
100 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
101 cat %(objdir)/%(err); \
105 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
108 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
113 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
114 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
118 #------------------------------------------------------------------------------
121 #------------------------------------------------------------------------------
122 # Create the dependency file %(to) for %(from)
123 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
124 %mkdir_q dir="$(dir %(to))"
125 @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
126 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
128 #------------------------------------------------------------------------------
131 #------------------------------------------------------------------------------
132 # Create one directory without any output
133 %define mkdir_q dir=.
134 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
136 #------------------------------------------------------------------------------
139 #------------------------------------------------------------------------------
140 # Create several directories without any output
141 %define mkdirs_q dirs=/M
142 @$(FOR) dir in %(dirs) ; do \
143 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
146 #------------------------------------------------------------------------------
149 #############################################################################
150 #############################################################################
152 ## Here are the mmakefile macros that are used to do certain tasks in a ##
153 ## mmakefile. They consist of one or more full makefile rules. ##
154 ## In general the files generated in these macros are also defined as ##
155 ## make targets so that they can be used as a dependency in other rules ##
157 #############################################################################
158 #############################################################################
160 #------------------------------------------------------------------------------
161 # Generate a unique id for each of the %build... rules
162 %define buildid targets=/A
164 ifneq ($(filter $(TARGET),%(targets)),)
165 BDTARGETID := $(BDID)
168 #------------------------------------------------------------------------------
171 #------------------------------------------------------------------------------
172 # Copy file %(from) to %(to) in a makefile rule
173 %define rule_copy from=/A to=/A
177 #------------------------------------------------------------------------------
180 #------------------------------------------------------------------------------
181 # Copy the files %(files) to %(targetdir). For each file in %(files),
182 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
183 # appropriate subdirs are not generated by this rule so they have to be
185 %define rule_copy_multi files=/A targetdir=/A srcdir=.
187 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
190 #------------------------------------------------------------------------------
193 #------------------------------------------------------------------------------
194 # Copy the files %(files) to %(targetdir). For each file in %(files),
195 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
196 # %(stampfile) is used to keep track of when the last time the comparison has
197 # been done. The targetdir and the appropriate subdirs are not generated by
198 # this rule so they have to be present.
199 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
200 stampfile=$(TMP_SRCDIR)/.copy_stamp
202 TMP_SRCDIR := %(srcdir)
204 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
206 %(stampfile) : COPYSRCDIR := %(srcdir)
207 %(stampfile) : TGTDIR := %(targetdir)
208 %(stampfile) : FILES := %(files)
209 %(stampfile) : $(addprefix %(srcdir)/,%(files))
210 @for f in $(FILES); do \
211 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
212 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
217 #------------------------------------------------------------------------------
220 #------------------------------------------------------------------------------
221 # Will join all the files in %(from) to %(to). When text is specified it will
223 # Restriction: at the moment when using a non-empty target dir %(from) may
225 %define rule_join to=/A from=/A text=
233 #------------------------------------------------------------------------------
236 #------------------------------------------------------------------------------
237 # Include the dependency files and add some internal rules
238 # When depstargets is provided the depencies will only be included when one of
239 # these targets is the $(TARGET). Otherwise the dependencies will only be
240 # included when the $(TARGET) is not for setup or clean
241 %define include_deps deps=$(DEPS)/M depstargets=
243 ifneq (%(depstargets),)
244 ifneq ($(findstring $(TARGET),%(depstargets)),)
248 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
254 #------------------------------------------------------------------------------
257 #------------------------------------------------------------------------------
258 # Create the directories %(dirs). The creation will be done by adding rules to
259 # the %(setuptarget) make target with setup as the default.
260 %define rule_makedirs dirs=/A setuptarget=setup
262 %(setuptarget) :: %(dirs)
264 GLOB_MKDIRS += %(dirs)
267 #------------------------------------------------------------------------------
270 #------------------------------------------------------------------------------
271 # Generate a rule to compile a C source file to an object file and generate
272 # the dependency file. Basename may contain a directory part, then the source
273 # file has to be in that directory. The generated file will be put in the
274 # object directory without the directory.
276 # - basename: the basename of the file to compile. Use % for a wildcard rule
277 # - cflags (default $(CFLAGS)): the C flags to use for compilation
278 # - dflags: the flags used during creation of dependency file. If not specified
279 # the same value as cflags will be used
280 # - targetdir: the directory to put the .o file and the .d file. By default
281 # it is put in the same directory as the .c file
282 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
287 TMP_TARGETBASE := %(basename)
289 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
292 # Adjust compiler flags to suit C
293 TMP_CFLAGS := %(cflags)
294 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
296 TMP_DFLAGS := %(cflags)
298 TMP_DFLAGS := %(dflags)
301 ifeq ($(findstring %(compiler),host kernel target),)
302 $(error unknown compiler %(compiler))
304 ifeq (%(compiler),target)
305 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
306 BD_STRIP ?= $(TARGET_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
309 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
310 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
313 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
316 ifeq (%(compiler),host)
317 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
318 BD_STRIP ?= $(HOST_STRIP)
319 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
320 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
321 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
322 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
323 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
324 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
325 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
326 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
328 ifeq (%(compiler),kernel)
329 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
330 BD_STRIP ?= $(ECHO) >/dev/null
331 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
332 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
333 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
334 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
335 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
336 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
337 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
338 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
341 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
342 $(TMP_TARGETBASE).o : %(basename).c
343 %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
346 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
348 $(TMP_TARGETBASE).d : %(basename).c
349 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
351 #------------------------------------------------------------------------------
354 #------------------------------------------------------------------------------
355 # Generate a rule to compile a C++ source file to an object file and generate
356 # the dependency file. Basename may contain a directory part, then the source
357 # file has to be in that directory. The generated file will be put in the
358 # object directory without the directory.
360 # - basename: the basename of the file to compile. Use % for a wildcard rule
361 # - cflags (default $(CFLAGS)): the C flags to use for compilation
362 # - dflags: the flags used during creation of dependency file. If not specified
363 # the same value as cflags will be used
364 # - targetdir: the directory to put the .o file and the .d file. By default
365 # it is put in the same directory as the .c file
366 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
371 TMP_TARGETBASE := %(basename)
373 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
376 # Adjust compiler flags to suit C++
377 TMP_CXXFLAGS := %(cxxflags)
379 TMP_DXXFLAGS := %(cxxflags)
381 TMP_DXXFLAGS := %(dxxflags)
384 ifeq ($(findstring %(compiler),host kernel target),)
385 $(error unknown compiler %(compiler))
387 ifeq (%(compiler),target)
388 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
389 BD_STRIP ?= $(TARGET_STRIP)
390 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
391 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
392 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
393 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
394 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
395 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
396 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
397 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
399 ifeq (%(compiler),host)
400 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
401 BD_STRIP ?= $(HOST_STRIP)
402 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
403 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
404 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
405 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
406 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
407 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
408 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
409 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
411 ifeq (%(compiler),kernel)
412 KERNEL_CXX ?= $(KERNEL_CC)
413 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
414 BD_STRIP ?= $(ECHO) >/dev/null
415 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
416 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
417 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
418 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
419 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
420 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
421 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
422 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
425 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
426 $(TMP_TARGETBASE).o : %(basename).cpp
427 %compile_q cmd=$(TMP_CMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
430 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
432 $(TMP_TARGETBASE).d : %(basename).cpp
433 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DXXFLAGS)
438 #------------------------------------------------------------------------------
441 #------------------------------------------------------------------------------
442 # Generate a rule to compile an ObjC source file to an object file and generate
443 # the dependency file. Basename may contain a directory part, then the source
444 # file has to be in that directory. The generated file will be put in the
445 # object directory without the directory.
447 # - basename: the basename of the file to compile. Use % for a wildcard rule
448 # - cflags (default $(CFLAGS)): the C flags to use for compilation
449 # - dflags: the flags used during creation of dependency file. If not specified
450 # the same value as cflags will be used
451 # - targetdir: the directory to put the .o file and the .d file. By default
452 # it is put in the same directory as the .m file
453 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
458 TMP_TARGETBASE := %(basename)
460 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
463 # Adjust compiler flags to suit ObjC
464 TMP_OBJCFLAGS := %(cflags)
465 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
466 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
468 TMP_OBJCDFLAGS := %(cflags)
470 TMP_OBJCDFLAGS := %(dflags)
473 # Define the use of cross compiler
474 ifeq ($(TARGET_OBJC),)
475 TMP_CC := $(TARGET_CC)
477 TMP_CC := $(TARGET_OBJC)
480 ifeq ($(findstring %(compiler),host kernel target),)
481 $(error unknown compiler %(compiler))
483 ifeq (%(compiler),target)
484 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
485 BD_STRIP ?= $(TARGET_STRIP)
486 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
487 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
488 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
489 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
490 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
491 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
492 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
493 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
495 ifeq (%(compiler),host)
496 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
497 BD_STRIP ?= $(HOST_STRIP)
498 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
499 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
500 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
501 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
502 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
503 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
504 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
505 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
507 ifeq (%(compiler),kernel)
508 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
509 BD_STRIP ?= $(ECHO) >/dev/null
510 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
511 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
512 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
513 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
514 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
515 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
516 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
517 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
520 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
521 $(TMP_TARGETBASE).o : %(basename).m
522 %compile_q cmd=$(TMP_CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
525 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
527 $(TMP_TARGETBASE).d : %(basename).m
528 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_OBJCDFLAGS)
533 #------------------------------------------------------------------------------
536 #------------------------------------------------------------------------------
537 # Generate a rule to compile multiple C source files to an object file and
538 # generate the corresponding dependency files. The generated file will be put
539 # in the object directory without the directory part of the source file.
541 # - basenames: the basenames of the files to compile. The names may include
542 # relative or absolute path names. No wildcard is allowed
543 # - cflags (default $(CFLAGS)): the C flags to use for compilation
544 # - dflags: the flags used during creation of dependency file. If not specified
545 # the same value as cflags will be used
546 # - targetdir: the directory to put the .o file and the .d file. By default
547 # it is put in the same directory as the .c file. When targetdir is not
548 # empty, path names will be stripped from the file names so that all files
549 # are in that dir and not in subdirectories.
550 # - compiler (default target): compiler to use, target, kernel or host
551 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
555 TMP_TARGETS := $(addsuffix .o,%(basenames))
556 TMP_DTARGETS := $(addsuffix .d,%(basenames))
559 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
560 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
561 TMP_WILDCARD := %(targetdir)/%
563 # Be sure that all .c files are generated
564 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
566 # Be sure that all .c files are found
567 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
568 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
569 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
571 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
572 vpath %.c $(TMP_DIRS)
577 TMP_CFLAGS := %(cflags)
579 TMP_DFLAGS := %(cflags)
581 TMP_DFLAGS := %(dflags)
584 ifeq ($(findstring %(compiler),host kernel target),)
585 $(error unknown compiler %(compiler))
587 ifeq (%(compiler),target)
588 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
589 BD_STRIP ?= $(TARGET_STRIP)
590 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
591 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
592 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
593 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
594 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
595 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
597 ifeq (%(compiler),host)
598 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
599 BD_STRIP ?= $(HOST_STRIP)
600 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
601 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
602 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
603 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
604 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
605 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
607 ifeq (%(compiler),kernel)
608 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
609 BD_STRIP ?= $(ECHO) >/dev/null
610 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
611 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
612 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
613 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
614 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
615 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
618 $(TMP_TARGETS) : CFLAGS := %(TMP_CFLAGS)
619 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
620 %compile_q cmd=$(CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
622 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
623 %mkdepend_q cc=$(CMD) flags=$(TMP_DFLAGS)
625 #------------------------------------------------------------------------------
628 #------------------------------------------------------------------------------
629 # Generate a rule to compile multiple C++ source files to an object file and
630 # generate the corresponding dependency files. The generated file will be put
631 # in the object directory without the directory part of the source file.
633 # - basenames: the basenames of the files to compile. The names may include
634 # relative or absolute path names. No wildcard is allowed. basenames will be
635 # matched to supported AROS_CXXEXTS.
636 # - cflags (default $(CFLAGS)): the C flags to use for compilation
637 # - dflags: the flags used during creation of dependency file. If not specified
638 # the same value as cflags will be used
639 # - targetdir: the directory to put the .o file and the .d file. By default
640 # it is put in the same directory as the .c file. When targetdir is not
641 # empty, path names will be stripped from the file names so that all files
642 # are in that dir and not in subdirectories.
643 # - compiler (default target): compiler to use, target, kernel or host
644 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) dxxflags= \
645 targetdir= compiler=target
647 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
649 ifneq ($(TMP_CXXABSBASENAMES),)
651 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
653 # Identify the "real" c++ files from the passed in basenames
654 TMP_CXXFILES := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
657 TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
658 TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
661 TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
662 TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
663 TMP_WILDCARD := %(targetdir)/%
665 # Be sure that all source files are generated
666 $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
669 # Adjust compiler flags to suit C++
670 TMP_CXXFLAGS := %(cxxflags)
672 TMP_DXXFLAGS := %(cxxflags)
674 TMP_DXXFLAGS := %(dxxflags)
677 ifeq ($(findstring %(compiler),host kernel target),)
678 $(error unknown compiler %(compiler))
680 ifeq (%(compiler),host)
681 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
682 BD_STRIP ?= $(HOST_STRIP)
683 BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
684 TMP_CXXCMD:=$(HOST_CXX)
685 TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
686 TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
687 TMP_CXXIQUOTE:=$(HOST_IQUOTE)
688 TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
690 ifeq (%(compiler),target)
691 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
692 BD_STRIP ?= $(TARGET_STRIP)
693 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
694 TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
695 TMP_CXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
696 TMP_DXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
697 TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
698 TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
700 ifeq (%(compiler),kernel)
701 KERNEL_CXX ?= $(KERNEL_CC)
702 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
703 BD_STRIP ?= $(ECHO) >/dev/null
704 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
705 TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
706 TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
707 TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
708 TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
709 TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
712 define cxx_multi_recipe_template
714 %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
717 %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
720 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
722 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
728 #------------------------------------------------------------------------------
731 #------------------------------------------------------------------------------
732 # Generate a rule to compile multiple ObjC source files to an object file and
733 # generate the corresponding dependency files. The generated file will be put
734 # in the object directory without the directory part of the source file.
736 # - basenames: the basenames of the files to compile. The names may include
737 # relative or absolute path names. No wildcard is allowed
738 # - cflags (default $(CFLAGS)): the C flags to use for compilation
739 # - dflags: the flags used during creation of dependency file. If not specified
740 # the same value as cflags will be used
741 # - targetdir: the directory to put the .o file and the .d file. By default
742 # it is put in the same directory as the .m file. When targetdir is not
743 # empty, path names will be stripped from the file names so that all files
744 # are in that dir and not in subdirectories.
745 # - compiler (default target): compiler to use, target, kernel or host
746 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
747 targetdir= compiler=target
749 ifneq (%(basenames),)
752 TMP_TARGETS := $(addsuffix .o,%(basenames))
753 TMP_DTARGETS := $(addsuffix .d,%(basenames))
756 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
757 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
758 TMP_WILDCARD := %(targetdir)/%
760 # Be sure that all .m files are generated
761 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
763 # Be sure that all .m files are found
764 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
765 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
766 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
768 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
769 vpath %.m $(TMP_DIRS)
773 # Define the use of cross compiler
774 ifeq ($(TARGET_OBJC),)
775 TMP_CC := $(TARGET_CC)
777 TMP_CC := $(TARGET_OBJC)
780 # Adjust compiler flags to suit ObjC
781 TMP_OBJCFLAGS := %(cflags)
782 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
783 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
785 TMP_OBJCDFLAGS := %(cflags)
787 TMP_OBJCDFLAGS := %(dflags)
790 ifeq ($(findstring %(compiler),host kernel target),)
791 $(error unknown compiler %(compiler))
793 ifeq (%(compiler),target)
794 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
795 BD_STRIP ?= $(TARGET_STRIP)
796 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
797 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
798 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
799 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
800 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
801 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
803 ifeq (%(compiler),host)
804 BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
805 BD_STRIP ?= $(HOST_STRIP)
806 BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
807 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
808 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
809 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
810 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
811 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
813 ifeq (%(compiler),kernel)
814 KERNEL_OBJC ?= $(KERNEL_CC)
815 BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
816 BD_STRIP ?= $(ECHO) >/dev/null
817 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
818 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
819 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
820 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
821 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
822 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
825 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
826 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
827 %compile_q cmd=$(CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
829 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
830 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
835 #------------------------------------------------------------------------------
838 #------------------------------------------------------------------------------
839 # Make an alias from one arch specific build to another arch.
841 # - mainmmake: the mmake of the module in the main tree
842 # - arch: the current arch
843 # - alias: the alias to which this should point
844 %define rule_archalias mainmmake=\A arch=\A alias=\A
846 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
848 #------------------------------------------------------------------------------
851 #------------------------------------------------------------------------------
852 # Generate a rule to assemble a source file to an object file. Basename may
853 # contain a directory part, then the source file has to be in that directory.
854 # The generated file will be put in the object directory without the directory.
856 # - basename: the basename of the file to compile. Use % for a wildcard rule
857 # - flags (default $(AFLAGS)): the asm flags to use for assembling
858 # - targetdir: the directory to put the .o file in. By default it is put in the
859 # same directory as the .s file
860 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
863 %(basename).o : AFLAGS := %(aflags)
864 %(basename).o : %(basename).s
866 %(basename).o : %(basename).S
870 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
871 %(targetdir)/$(notdir %(basename)).o : %(basename).s
873 %(targetdir)/$(notdir %(basename)).o : %(basename).S
878 #------------------------------------------------------------------------------
881 #------------------------------------------------------------------------------
882 # Generate a rule to assemble multiple source files to an object file. The
883 # generated file will be put in the object directory with the directory part
884 # of the source file stripped off.
886 # - basenames: the basenames of the files to compile. The names may include
887 # relative or absolute path names. No wildcard is allowed
888 # - aflags (default $(AFLAGS)): the flags to use for assembly
889 # - targetdir: the directory to put the .o file and the .d file. By default
890 # it is put in the same directory as the .c file. When targetdir is not
891 # empty, path names will be stripped from the file names so that all files
892 # are in that dir and not in subdirectories.
893 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)" basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
896 TMP_TARGETS := $(addsuffix .o,%(basenames))
899 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
900 TMP_WILDCARD := %(targetdir)/%
902 # Be sure that all .s files are generated
903 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
905 # Be sure that all .c files are found
906 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
907 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
908 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
910 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
911 vpath %%(suffix) $(TMP_DIRS)
916 BD_ASSEMBLER ?= %(cmd)
918 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
920 $(TMP_TARGETS) : AFLAGS := %(aflags)
921 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
922 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
924 #------------------------------------------------------------------------------
927 #------------------------------------------------------------------------------
928 # Link %(objs) to %(prog) using the libraries in %(uselibs)
929 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
930 usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
935 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
937 ifeq (%(usestartup),no)
938 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
941 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
944 # Make a list of the lib files this program depends on.
945 # In LDFLAGS remove white space between -L and directory
946 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
947 # Filter out only the libdirs and remove -L
948 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
950 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
951 # Add normal linklib path
952 TMP_DIRS += $(AROS_LIB)/
953 # add lib and .a to static linklib names
954 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
955 ifeq (%(usestartup),yes)
956 TMP_LIBS += startup.o
961 # search for the linklibs in the given path, ignore ones not found
962 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
963 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
966 %(prog) : OBJDIR := %(objdir)
967 %(prog) : OBJS := %(objs)
968 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
969 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
970 %(prog) : %(objs) $(TMP_DEPLIBS)
971 %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
973 #------------------------------------------------------------------------------
976 #------------------------------------------------------------------------------
977 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
978 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
979 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
980 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
981 usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
986 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
988 ifeq (%(usestartup),no)
989 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
992 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
995 # Make a list of the lib files the programs depend on.
996 # In LDFLAGS remove white space between -L and directory
997 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
998 # Filter out only the libdirs and remove -L
999 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1001 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1002 # Add normal linklib path
1003 TMP_DIRS += $(AROS_LIB)/
1004 # add lib and .a to static linklib names
1005 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1006 # search for the linklibs in the given path, ignore ones not found
1007 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1008 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1010 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1012 $(TMP_PROGS) : OBJDIR := %(objdir)
1013 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1014 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1015 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1016 %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1018 #------------------------------------------------------------------------------
1021 #------------------------------------------------------------------------------
1022 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1023 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1025 ifeq (%(linker),target)
1026 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1027 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1029 ifeq (%(linker),host)
1030 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1031 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1033 ifeq (%(linker),kernel)
1034 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1035 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1038 %(libdir)/lib%(libname).a : %(objs)
1039 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1041 #------------------------------------------------------------------------------
1043 #------------------------------------------------------------------------------
1044 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1045 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1046 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1047 cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1049 TMP_LDFLAGS := %(ldflags)
1050 # Make a list of the lib files the programs depend on.
1051 # In LDFLAGS remove white space between -L and directory
1052 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1053 # Filter out only the libdirs and remove -L
1054 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1056 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1057 # Add normal linklib path
1058 TMP_DIRS += $(AROS_LIB)/
1059 # add lib and .a to static linklib names
1060 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1061 # search for the linklibs in the given path, ignore ones not found
1062 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1063 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1066 %(module) : LIB_NAMES := %(uselibs)
1067 %(module) : OBJS := %(objs)
1068 %(module) : ENDTAG := %(endobj)
1069 %(module) : ERR := %(err)
1070 %(module) : OBJDIR := %(objdir)
1071 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1072 ifeq (%(usehostlibs),)
1073 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1075 # Warning: the -L/usr/lib here can result in modules
1076 # linking against host libs instead of AROS libs (e.g stdc++) !!
1077 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1078 -L/usr/lib $(addprefix -l,%(usehostlibs))
1080 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1081 %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1084 #------------------------------------------------------------------------------
1087 #------------------------------------------------------------------------------
1088 # Generate the libdefs.h include file for a module.
1089 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1091 TMP_TARGET := %(modname)_libdefs.h
1092 TMP_DEPS := $(GENMODULE)
1094 ifneq (%(conffile),)
1095 ifeq ($(dir %(conffile)),./)
1096 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1097 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1099 TMP_OPTS += -c %(conffile)
1100 TMP_DEPS += %(conffile)
1103 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1104 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1106 ifneq (%(modsuffix),)
1107 TMP_OPTS += -s %(modsuffix)
1109 ifneq (%(targetdir),)
1110 TMP_OPTS += -d %(targetdir)
1111 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1114 TMP_OPTS += -v %(version)
1117 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1118 $(TMP_TARGET) : MODNAME := %(modname)
1119 $(TMP_TARGET) : MODTYPE := %(modtype)
1120 $(TMP_TARGET) : $(TMP_DEPS)
1121 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1122 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1124 #------------------------------------------------------------------------------
1126 #------------------------------------------------------------------------------
1127 # Generate the _lib.fd file for a module.
1128 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1130 TMP_TARGET := %(modname)_lib.fd
1131 TMP_DEPS := $(GENMODULE)
1133 ifneq (%(conffile),)
1134 ifeq ($(dir %(conffile)),./)
1135 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1136 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1138 TMP_OPTS += -c %(conffile)
1139 TMP_DEPS += %(conffile)
1142 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1143 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1145 ifneq (%(modsuffix),)
1146 TMP_OPTS += -s %(modsuffix)
1148 ifneq (%(targetdir),)
1149 TMP_OPTS += -d %(targetdir)
1150 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1153 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1154 $(TMP_TARGET) : MODNAME := %(modname)
1155 $(TMP_TARGET) : MODTYPE := %(modtype)
1156 $(TMP_TARGET) : $(TMP_DEPS)
1157 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1158 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1160 #------------------------------------------------------------------------------
1162 #------------------------------------------------------------------------------
1163 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1164 # generated file in this Makefile
1165 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1168 TMP_TARGET := Makefile.%(modname)%(modtype)
1169 TMP_DEPS := $(GENMODULE)
1171 ifneq (%(conffile),)
1172 ifeq ($(dir %(conffile)),./)
1173 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1174 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1176 TMP_OPTS += -c %(conffile)
1177 TMP_DEPS += %(conffile)
1180 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1181 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1183 ifneq (%(modsuffix),)
1184 TMP_OPTS += -s %(modsuffix)
1186 ifneq (%(targetdir),)
1187 TMP_OPTS += -d %(targetdir)
1188 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1191 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1192 $(TMP_TARGET) : MODNAME := %(modname)
1193 $(TMP_TARGET) : MODTYPE := %(modtype)
1194 $(TMP_TARGET) : $(TMP_DEPS)
1195 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1197 #------------------------------------------------------------------------------
1200 #------------------------------------------------------------------------------
1201 # Generate the support files for compiling a module. This includes include
1202 # files and source files. This rule has to be preceeded by
1203 # %rule_genmodule_makefile
1204 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1207 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1208 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1209 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1210 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1212 TMP_DEPS := $(GENMODULE)
1215 ifneq (%(conffile),)
1216 ifeq ($(dir %(conffile)),./)
1217 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1218 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1220 TMP_OPTS += -c %(conffile)
1221 TMP_DEPS += %(conffile)
1224 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1225 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1227 ifneq (%(modsuffix),)
1228 TMP_OPTS += -s %(modsuffix)
1230 ifneq (%(targetdir),)
1231 TMP_OPTS += -d %(targetdir)
1232 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1233 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1236 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1237 $(TMP_TARGETS) : MODNAME := %(modname)
1238 $(TMP_TARGETS) : MODTYPE := %(modtype)
1239 $(TMP_TARGETS) : $(TMP_DEPS)
1240 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1241 ifneq (%(conffile),lib.conf)
1242 @$(IF) $(TEST) -f lib.conf; then \
1243 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1246 @$(IF) $(TEST) -f libdefs.h; then \
1247 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1249 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1251 #------------------------------------------------------------------------------
1254 #------------------------------------------------------------------------------
1255 # Generate the support files for compiling a module. This includes include
1256 # files and source files.
1257 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1258 targetdir= conffile=
1260 ifneq ($(%(modname)_INCLUDES),)
1261 TMP_TARGETS := $(%(modname)_INCLUDES)
1263 TMP_DEPS := $(GENMODULE)
1266 ifneq (%(conffile),)
1267 ifeq ($(dir %(conffile)),./)
1268 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1269 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1271 TMP_OPTS += -c %(conffile)
1272 TMP_DEPS += %(conffile)
1275 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1276 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1278 ifneq (%(modsuffix),)
1279 TMP_OPTS += -s %(modsuffix)
1281 ifneq (%(targetdir),)
1282 TMP_OPTS += -d %(targetdir)
1283 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1286 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1287 $(TMP_TARGETS) : MODNAME := %(modname)
1288 $(TMP_TARGETS) : MODTYPE := %(modtype)
1289 $(TMP_TARGETS) : $(TMP_DEPS)
1290 @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1291 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1294 #------------------------------------------------------------------------------
1296 #------------------------------------------------------------------------------
1297 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1298 # 'start' is an optional starting address
1299 # 'ldflags' is optional additional flags for the linker
1300 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1302 BD_OUTDIR := $(dir %(file))
1303 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1304 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1305 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1306 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1307 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1310 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1312 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1313 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
1314 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1315 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1317 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1318 GLOB_MKDIRS += $(BD_OUTDIR)
1323 #------------------------------------------------------------------------------
1324 # Common rules for all makefiles
1326 # Delete generated makefiles
1329 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1331 include $(SRCDIR)/config/make.tail
1333 BDID := $(BDTARGETID)
1335 #------------------------------------------------------------------------------
1338 #############################################################################
1339 #############################################################################
1341 ## Here are the mmakefile build macros. These are macros that takes care ##
1342 ## of everything to go from the sources to the generated target. Also all ##
1343 ## intermediate files and directories that are needed are created by these ##
1346 #############################################################################
1347 #############################################################################
1349 #------------------------------------------------------------------------------
1351 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1353 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1354 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1355 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1356 includedir= libdir= \
1357 compiler=target linker= lto=$(TARGET_LTO)
1361 BD_PROGNAME := %(progname)
1362 BD_OBJDIR := %(objdir)
1363 BD_TARGETDIR := %(targetdir)
1364 BD_LINKER := %(linker)
1366 # If not supplied, linker is equal to compiler
1367 ifeq ($(BD_LINKER),)
1368 BD_LINKER := %(compiler)
1371 BD_FILES := %(files)
1372 BD_OBJCFILES := %(objcfiles)
1373 BD_ASMFILES := %(asmfiles)
1374 BD_CXXFILES := %(cxxfiles)
1376 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1377 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1378 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1380 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1381 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1382 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1384 BD_CFLAGS := %(cflags)
1385 BD_CXXFLAGS := %(cxxflags)
1387 ifeq (%(compiler),target)
1388 BD_CFLAGS := $(CFLAGS_LTO) $(BD_CFLAGS)
1389 BD_CXXFLAGS := $(CFLAGS_LTO) $(BD_CXXFLAGS)
1392 ifneq (%(includedir),)
1393 BD_CFLAGS += -I%(includedir)
1394 BD_CXXFLAGS += -I%(includedir)
1396 BD_AFLAGS := %(aflags)
1397 ifneq (%(includedir),)
1398 BD_AFLAGS += -I%(includedir)
1400 BD_DFLAGS := %(dflags)
1401 BD_DXXFLAGS := %(dxxflags)
1402 BD_LDFLAGS := %(ldflags)
1404 BD_LDFLAGS += -L%(libdir)
1408 %(mmake)-quick : %(mmake)
1410 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1411 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1413 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1414 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1415 cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1416 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1417 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1418 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1419 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1420 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1423 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1424 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1425 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1426 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1427 cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1431 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1433 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1434 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1435 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1437 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1440 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1444 #------------------------------------------------------------------------------
1447 #------------------------------------------------------------------------------
1448 # Build programs, for every C file an executable will be built with the same
1449 # name as the C file
1450 %define build_progs mmake=/A files=/A nix=no \
1451 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1452 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1453 includedir= libdir= \
1454 uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1458 BD_OBJDIR := %(objdir)
1459 BD_TARGETDIR := %(targetdir)
1461 BD_FILES := %(files)
1462 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1463 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1464 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1466 BD_CFLAGS := %(cflags)
1468 ifeq (%(compiler),target)
1469 BD_CFLAGS := $(CFLAGS_LTO) $(BD_CFLAGS)
1472 ifneq (%(includedir),)
1473 BD_CFLAGS += -I%(includedir)
1475 BD_DFLAGS := %(dflags)
1476 BD_LDFLAGS := %(ldflags)
1478 BD_LDFLAGS += -L%(libdir)
1482 %(mmake)-quick : %(mmake)
1484 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1485 %(mmake) : $(BD_EXES)
1487 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1488 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1489 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1491 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1492 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1493 ldflags=$(BD_LDFLAGS) \
1494 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1495 usestartup="%(usestartup)" detach="%(detach)" \
1496 cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1500 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1502 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1503 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1504 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1506 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1509 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1513 #------------------------------------------------------------------------------
1516 #------------------------------------------------------------------------------
1518 # This is a bare version: It just compiles and links the given files. It is
1519 # assumed that all needed boiler plate code is in the files. This should only
1520 # be used for compiling external code. For AROS code use %build_module
1521 %define build_module_simple mmake=/A modname=/A modtype=/A \
1522 files="$(basename $(call WILDCARD, *.c))" \
1523 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1524 objdir=$(OBJDIR) moduledir= \
1525 uselibs= usehostlibs= compiler=target
1527 # Define metamake targets and their dependencies
1528 #MM %(mmake) : core-linklibs includes-generate-deps
1529 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1530 #MM %(mmake)-kobj-quick
1534 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1536 .PHONY : $(BD_ALLTARGETS)
1539 $(error using %build_module_simple: modname may not be empty)
1542 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1545 # Default values for variables and arguments
1546 BD_DEFLINKLIBNAME := %(modname)
1547 BD_DEFDFLAGS := %(cflags)
1548 BD_DEFDXXFLAGS := %(dxxflags)
1549 OBJDIR ?= $(GENDIR)/$(CURDIR)
1550 BD_MODDIR := %(moduledir)
1551 ifeq ($(BD_MODDIR),)
1552 ifeq (%(modtype),library)
1553 BD_MODDIR := $(AROS_LIBRARIES)
1555 ifeq (%(modtype),gadget)
1556 BD_MODDIR := $(AROS_GADGETS)
1558 ifeq (%(modtype),datatype)
1559 BD_MODDIR := $(AROS_DATATYPES)
1561 ifeq (%(modtype),handler)
1562 BD_MODDIR := $(AROS_FS)
1564 ifeq (%(modtype),device)
1565 BD_MODDIR := $(AROS_DEVS)
1567 ifeq (%(modtype),resource)
1568 BD_MODDIR := $(AROS_RESOURCES)
1570 ifeq (%(modtype),hook)
1571 BD_MODDIR := $(AROS_RESOURCES)
1573 ifeq (%(modtype),mui)
1574 BD_MODDIR := $(AROS_CLASSES)/Zune
1576 ifeq (%(modtype),mcc)
1577 BD_MODDIR := $(AROS_CLASSES)/Zune
1579 ifeq (%(modtype),mcp)
1580 BD_MODDIR := $(AROS_CLASSES)/Zune
1582 ifeq (%(modtype),usbclass)
1583 BD_MODDIR := $(AROS_CLASSES)/USB
1585 ifeq (%(modtype),hidd)
1586 BD_MODDIR := $(AROS_DRIVERS)
1588 ifeq (%(modtype),printer)
1589 BD_MODDIR := $(AROS_PRINTERS)
1592 ifeq ($(BD_MODDIR),)
1593 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1596 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1597 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1598 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1600 %rule_compile_multi \
1601 basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1602 cflags="%(cflags)" dflags="%(dflags)" \
1603 compiler="%(compiler)"
1605 # Handlers use dash instead of dot in their names
1606 ifeq (%(modtype),handler)
1607 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1609 ifeq (%(modtype),printer)
1610 BD_MODULE := $(BD_MODDIR)/%(modname)
1612 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1615 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1617 %(mmake)-quick : %(mmake)
1618 %(mmake)-kobj-quick : $(BD_KOBJ)
1619 %(mmake) : $(BD_MODULE)
1620 %(mmake)-kobj : $(BD_KOBJ)
1622 # The module is linked from all the compiled .o files
1623 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1625 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1626 # This breaks con-handler build. Here we work around this
1627 ifeq (%(modname),con)
1628 BD_ERR := $(notdir $(BD_MODULE)).err
1630 BD_ERR := %(modname).err
1633 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1634 endobj= err=$(BD_ERR) objdir="%(objdir)" \
1635 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1636 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1638 # Link kernel object file
1639 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1641 # Make these symbols local
1642 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1643 UtilityBase ExpansionBase KeymapBase KernelBase
1645 BD_SYMBOLS := $(BD_KBASE)
1647 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1648 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1649 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1650 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1651 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1652 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1653 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1654 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1655 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1658 ## Dependency fine-tuning
1660 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1661 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1663 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1664 $(BD_MODULE) : | $(BD_MODDIR)
1665 $(BD_KOBJ) : | $(KOBJSDIR)
1666 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1668 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1670 @$(ECHO) "Cleaning up for module %(modname)"
1673 #------------------------------------------------------------------------------
1676 #------------------------------------------------------------------------------
1677 # Build a module - core routine
1678 # Explanation of this macro is done in the developer's manual
1679 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1680 files="$(basename $(call WILDCARD, *.c))" \
1681 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1682 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1683 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1684 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1685 compiler=target nostartup=yes archspecific=no \
1686 includedir= libdir= \
1687 build_abi= build_library=
1689 # We will employ a terrifying, but unavoidable, hack here.
1690 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1691 # ignores GNU Make ifeq() statements, but will process any #MM
1692 # headed lines in the file.
1694 # So, to make the following #MM lines conditional on whether we want
1695 # to build the ABI, Library, or both, we define build_abi= and
1696 # build_library as 'M' to enable, or '' to disable, which allows genmf
1697 # to do the following conversions:
1699 # #%(build_abi)M includes-foo: foo-include
1700 # becomes, when build_abi=M
1701 # #MM includes-foo: foo-include <= Processed by MetaMake
1702 # but, when build_abi= ...
1703 # #M includes-foo: foo-includes <= ignored by MetaMake! Yes!
1705 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1707 # Define metamake targets and their dependencies
1710 #MM %(mmake)-makefile
1714 #M%(build_abi)- includes-all : %(mmake)-includes
1715 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1716 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1717 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1718 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1719 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1720 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1721 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1722 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1723 #M%(build_abi) includes-generate-deps %(mmake)-fd
1724 #M%(build_abi) %(mmake)-includes-quick
1725 #M%(build_abi) %(mmake)-includes-dirs
1726 #M%(build_abi) %(mmake)-fd
1729 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1730 #%(build_library)M %(mmake)-kobj-quick :
1732 # Library with ABI targets:
1733 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1734 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1736 # All MetaMake targets defined by this macro
1737 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1739 ifeq (%(build_library),M)
1740 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1743 ifeq (%(build_abi),M)
1744 BD_ALLTARGETS += %(mmake)-includes \
1745 %(mmake)-includes-quick %(mmake)-includes-dirs \
1746 %(mmake)-linklib %(mmake)-fd
1749 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1752 $(error using %build_module: modname may not be empty)
1755 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1758 # Default values for variables and arguments
1759 BD_DEFLINKLIBNAME := %(modname)
1760 BD_DEFDFLAGS := %(cflags)
1761 BD_DEFDXXFLAGS := %(cxxflags)
1762 ifneq (%(includedir),)
1763 BD_DEFDFLAGS += -I%(includedir)
1764 BD_DEFDXXFLAGS += -I%(includedir)
1766 OBJDIR ?= $(GENDIR)/$(CURDIR)
1768 ## Create genmodule include Makefile for the module
1770 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1772 %rule_genmodule_makefile \
1773 modname="%(modname)" modtype="%(modtype)" \
1774 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1775 conffile="%(conffile)"
1777 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1779 GLOB_MKDIRS += %(objdir)
1781 # Do not parse these statements if metatarget is not appropriate
1782 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1784 include %(objdir)/Makefile.%(modname)%(modtype)
1786 BD_DEFMODDIR := $(%(modname)_MODDIR)
1787 ifeq (%(archspecific),yes)
1788 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1792 ## include files generation
1794 ifneq (%(includedir),)
1795 BD_INCDIR := %(includedir)
1797 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1799 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1800 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1802 ifeq (%(build_abi),M)
1803 %(mmake)-includes-quick : %(mmake)-includes
1804 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1805 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1806 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1808 ifneq ($(%(modname)_INCLUDES),)
1809 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1810 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1811 conffile="%(conffile)"
1813 %rule_copy_diff_multi \
1814 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1815 stampfile="%(objdir)/%(modname)_geninc"
1817 %rule_copy_diff_multi \
1818 files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1819 stampfile="%(objdir)/%(modname)_incs"
1821 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1823 TMP%(modname)_INCDIRS := \
1824 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1825 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1826 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1827 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1833 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1834 modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1835 conffile="%(conffile)" version="%(version)"
1837 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1838 $(BD_DEFLIBDEFSINC) :
1839 @$(ECHO) "Generating $@"
1840 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1842 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1843 GLOB_MKDIRS += %(objdir)/include
1845 ## Extra genmodule src files generation
1847 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1848 modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1849 conffile="%(conffile)"
1852 ifeq (%(build_abi),M)
1854 ifeq (%(includedir),)
1855 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1857 BD_FDDIR := %(includedir)/../fd
1859 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1861 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1862 modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1864 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1866 GLOB_MKDIRS += $(BD_FDDIR)
1871 BD_FILES := %(files)
1872 BD_CXXFILES := %(cxxfiles)
1874 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1876 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1877 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1879 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1880 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1881 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1883 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1884 BD_CXXFLAGS := %(cxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CXXFLAGS)
1885 # ifeq (%(compiler),target)
1886 # BD_CFLAGS := $(CFLAGS_LTO) $(BD_CFLAGS)
1887 # BD_CXXFLAGS := $(CFLAGS_LTO) $(BD_CXXFLAGS)
1889 ifneq (%(includedir),)
1890 BD_CFLAGS += -I%(includedir)
1891 BD_CXXFLAGS += -I%(includedir)
1893 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1894 BD_DXXFLAGS := %(dxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DXXFLAGS)
1896 ifeq (%(modtype),library)
1899 BD_LIBSUFFIX := .%(modtype)
1903 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1905 BD_LIBDIR := %(libdir)
1908 ifeq (%(build_abi),M)
1909 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1910 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1911 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1914 BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1915 ifneq (%(modname),%(linklibname))
1916 BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1919 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1921 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1922 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1923 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1926 BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1927 ifneq (%(modname),%(linklibname))
1928 BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1931 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1934 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1935 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1936 $(BD_RELLINKLIBCFILES)
1938 %rule_compile_cxx_multi \
1939 basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1940 cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
1941 compiler="%(compiler)"
1942 %rule_compile_multi \
1943 basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1944 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1945 compiler="%(compiler)"
1946 %rule_compile_multi \
1947 basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1948 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1949 compiler="%(compiler)"
1951 ifneq ($(BD_LINKLIBAFILES),)
1952 %rule_assemble_multi \
1953 cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1958 ifeq (%(modsuffix),)
1959 BD_SUFFIX := %(modtype)
1961 BD_SUFFIX := %(modsuffix)
1964 ifeq (%(build_library),M)
1965 # Handlers use dash instead of dot in their names
1966 ifeq ($(BD_SUFFIX),handler)
1967 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1969 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1971 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1977 %(mmake)-quick : %(mmake)
1978 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1979 ifeq (%(build_library),M)
1980 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1981 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1983 ifeq (%(build_abi),M)
1984 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1987 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1988 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1990 ifeq (%(nostartup),yes)
1991 # Handlers always have entry point
1992 ifneq (%(modtype),handler)
1993 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1997 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1998 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
2001 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
2004 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2005 # This breaks con-handler build. Here we work around this
2006 ifeq (%(modname),con)
2007 BD_ERR := $(notdir $(BD_MODULE)).err
2009 BD_ERR := %(modname).err
2012 ifeq (%(build_library),M)
2013 # The module is linked from all the compiled .o files
2014 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2015 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2016 cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2017 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2020 ifeq (%(build_abi),M)
2022 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2023 BD_MODNAME := $(shell echo %(modname) | tr A-Z a-z)
2024 ifneq ($(BD_LINKLIB),)
2025 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2026 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2027 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2030 $(BD_LINKLIB) : | $(BD_LIBDIR)
2031 GLOB_MKDIRS += $(BD_LIBDIR)
2034 ifneq ($(BD_RELLINKLIB),)
2035 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2036 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2037 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2040 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2041 GLOB_MKDIRS += $(BD_LIBDIR)
2045 ifeq (%(build_library),M)
2046 # Link kernel object file
2047 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2049 # Make these symbols local
2050 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2051 UtilityBase ExpansionBase KeymapBase KernelBase
2053 BD_SYMBOLS := $(BD_KBASE)
2055 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2056 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2057 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2058 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2059 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2060 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2061 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
2062 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2063 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2066 ## Dependency fine-tuning
2068 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
2070 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2072 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2073 $(BD_MODULE) : | %(prefix)/%(moduledir)
2074 $(BD_KOBJ) : | $(KOBJSDIR)
2075 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2077 # Some include files need to be generated before the .c can be parsed.
2078 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2080 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2081 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2082 $(BD_DEPS) : $(BD_DFILE_DEPS)
2085 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2086 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2087 %(objdir)/Makefile.%(modname)%(modtype) \
2088 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2089 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2090 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2091 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2092 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2093 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2095 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2097 @$(ECHO) "Cleaning up for module %(modname)"
2100 endif # $(TARGET) in $(BD_ALLTARGETS)
2102 #------------------------------------------------------------------------------
2104 #------------------------------------------------------------------------------
2105 # Build a module - ABI and library
2106 # Explanation of this macro is done in the developer's manual
2107 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2108 files="$(basename $(call WILDCARD, *.c))" \
2109 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2110 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2111 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2112 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2113 compiler=target nostartup=yes archspecific=no \
2116 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2117 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2118 files="%(files)" cxxfiles="%(cxxfiles)" \
2119 linklibname="%(linklibname)" \
2120 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2121 cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2122 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2123 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2124 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2125 includedir="%(includedir)" libdir="%(libdir)" \
2126 build_abi=M build_library=M
2129 #------------------------------------------------------------------------------
2132 #------------------------------------------------------------------------------
2133 # Build a module skeleton ABI
2134 # This is a stripped-down version of build_module, it only creates include
2135 # files and the linklibs.
2136 # This is used when for plugins or classes with the same API, but no actual
2137 # implementation here.
2138 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2139 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2140 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2141 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2142 compiler=target nostartup=yes archspecific=no \
2145 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2146 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2147 linklibname="%(linklibname)" \
2148 linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2149 cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2150 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2151 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2152 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2153 includedir="%(includedir)" libdir="%(libdir)" \
2154 build_abi=M build_library=
2157 #------------------------------------------------------------------------------
2159 #------------------------------------------------------------------------------
2160 # Build a module library - no includes nor linklibs
2161 # Explanation of this macro is done in the developer's manual
2162 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2163 files="$(basename $(call WILDCARD, *.c))" \
2164 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2165 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2166 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2167 uselibs= usehostlibs= \
2168 compiler=target nostartup=yes archspecific=no \
2171 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2172 modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2173 files="%(files)" cxxfiles="%(cxxfiles)" \
2174 cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2175 objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2176 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2177 nostartup="%(nostartup)" archspecific="%(archspecific)" \
2178 includedir="%(includedir)" libdir="%(libdir)" \
2179 build_abi= build_library=M
2182 #------------------------------------------------------------------------------
2186 #------------------------------------------------------------------------------
2188 # - mmake is the mmaketarget
2189 # - libname is the baselibname e.g. lib%(libname).a will be created
2190 # - files are the C source files to include in the lib. The list of files
2191 # has to be given without the .c suffix
2192 # - cxxfiles are C++ source files without suffix.
2193 # NB: files will be matched in the order .cpp > .cxx > .cc
2194 # - asmfiles are the asm files to include in the lib. The list of files has to
2195 # be given without the .s suffix
2196 # - objs additional object to link into the linklib. The objects have to be
2197 # given with full absolute path and the .o suffix.
2198 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2199 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2200 # - cflags are the flags to compile the source (default $(CFLAGS))
2201 # - dflags are the flags use during makedepend (default equal to cflags)
2202 # - aflags are the flags use during assembling (default $(AFLAGS))
2203 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2204 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2205 asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2207 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2208 aflags=$(AFLAGS) compiler=target
2210 # assign and generate the local variables used in this macro
2211 BD_LIBNAME := %(libname)
2212 BD_LINKLIB := %(libdir)/lib%(libname).a
2214 BD_FILES := %(files)
2215 BD_ASMFILES := %(asmfiles)
2216 BD_CXXFILES := %(cxxfiles)
2218 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2219 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2220 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2222 BD_OBJS := $(BD_ARCHOBJS) \
2223 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2225 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2227 BD_CFLAGS := %(cflags)
2228 BD_CXXFLAGS := %(cxxflags)
2229 ifneq (%(includedir),)
2230 BD_CFLAGS += -I%(includedir)
2231 BD_CXXFLAGS += -I%(includedir)
2233 BD_AFLAGS := %(aflags)
2234 BD_DFLAGS := %(dflags)
2235 BD_DXXFLAGS := %(dxxflags)
2237 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2240 %(mmake)-quick : %(mmake)
2242 #MM %(mmake) : includes-generate-deps
2243 %(mmake) : $(BD_LINKLIB)
2245 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2247 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2248 compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2249 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2250 compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2251 %rule_assemble basename=% targetdir="%(objdir)" \
2254 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2257 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2259 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2260 $(BD_LINKLIB) : | %(libdir)
2261 GLOB_MKDIRS += %(objdir) %(libdir)
2263 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2266 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2270 #------------------------------------------------------------------------------
2273 #------------------------------------------------------------------------------
2275 # - mmake is the mmaketarget
2276 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2277 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2278 # - subdir is the destination subdirectory of the catalogs
2279 # - name is the name of the destination catalog, without the .catalog suffix
2280 # - source is the path to the generated source code file
2281 # - dir is the base destination directory (default $(AROS_CATALOGS))
2282 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2283 # - srcdir is the directory in which the *.cd and *.ct files are searched
2285 %define build_catalogs mmake=/A name=/A subdir=/A \
2286 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2287 sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2289 ifeq (%(description),)
2290 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2292 BD_DESC := %(description)
2295 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2298 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2300 BD_LNGS := %(catalogs)
2303 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2304 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2307 %(mmake) : $(BD_OBJS) %(source)
2309 $(BD_OBJS) : | $(BD_DIRS)
2310 GLOB_MKDIRS += $(BD_DIRS)
2312 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2313 @$(ECHO) "Creating %(name) catalog for language $*."
2314 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2317 %(source) : BD_DESC := $(BD_DESC)
2318 %(source) : BD_SRC := $(BD_SRC)
2319 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2320 @$(ECHO) "Creating %(name) catalog source file $@"
2321 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2324 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2327 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2330 .PHONY: %(mmake) %(mmake)-clean
2333 #-----------------------------------------------------------------------------
2336 #-----------------------------------------------------------------------------
2338 # - mmake is the mmaketarget
2339 # - icons is a list of icon base names (ie. without the .info suffix)
2340 # - dir is the destination directory
2341 # - srcdir is where *.png and *.info.src are searched
2342 #-----------------------------------------------------------------------------
2344 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2346 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2349 %(mmake) : $(BD_OBJS)
2353 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2354 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2355 @$(ILBMTOICON) $+ $@
2359 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2360 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2361 @$(ILBMTOICON) $+ $@
2365 $(BD_OBJS) : | %(dir)
2366 GLOB_MKDIRS += %(dir)
2368 %(mmake)-clean : FILES := $(BD_OBJS)
2373 .PHONY: %(mmake) %(mmake)-clean
2376 #-----------------------------------------------------------------------------
2379 #------------------------------------------------------------------------------
2380 # Compile files for an arch-specific replacement of code for a module
2381 # - files: the basenames of the C files to compile.
2382 # - asmfiles: the basenames of the asm files to assemble.
2383 # - mainmmake: the mmake of the module in the main directory to compile these
2384 # arch specific files for.
2385 # - maindir: the object directory for the main module
2386 # - arch: the arch for which to compile these files. It can have the form
2387 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2388 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2389 # - dflags: the flags used during creation of dependency file. If not specified
2390 # the same value as cflags will be used
2391 # - aflags: the flags used during assembling
2392 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2393 # the target compiler is used
2394 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2395 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2397 ifeq (%(files) %(asmfiles),)
2398 $(error no files or asmfiles given)
2401 %buildid targets="%(mainmmake)-%(arch)"
2403 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2404 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2405 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2406 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2407 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2408 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2409 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2410 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2411 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2412 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2413 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2414 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2415 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2416 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2417 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2419 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2421 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2422 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2423 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2424 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2425 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2427 ifneq (%(modulename),)
2428 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2431 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2432 BD_TARGET := %(mainmmake)-%(arch)-quick
2434 BD_TARGET := %(mainmmake)-%(arch)
2438 ifeq ($(TARGET),$(BD_TARGET))
2439 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2440 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2441 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2442 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2445 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2446 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2449 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2452 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2454 ifeq ($(findstring %(compiler),host kernel target),)
2455 $(error unknown compiler %(compiler))
2457 ifeq (%(compiler),target)
2458 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2459 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2460 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2462 ifeq (%(compiler),host)
2463 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2464 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2465 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2467 ifeq (%(compiler),kernel)
2468 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2469 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2470 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2472 ifneq (%(modulename),)
2473 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2475 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2477 ifeq ($(TARGET),$(BD_TARGET))
2478 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2479 %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2483 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2485 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2487 ifeq ($(TARGET),$(BD_TARGET))
2488 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2489 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2492 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2494 ifeq ($(TARGET),$(BD_TARGET))
2495 $(BD_OBJDIR$(BDID))/%.o : %.s
2496 %assemble_q opt=$(AFLAGS)
2497 $(BD_OBJDIR$(BDID))/%.o : %.S
2498 %assemble_q opt=$(AFLAGS)
2501 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2503 #------------------------------------------------------------------------------
2506 #------------------------------------------------------------------------------
2507 # generate asm files from c files (for debugging purposes)
2510 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2511 @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2513 #------------------------------------------------------------------------------
2516 #------------------------------------------------------------------------------
2517 # Copy files from one directory to another.
2519 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2521 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2523 GLOB_MKDIRS += %(dst)
2529 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2532 #------------------------------------------------------------------------------
2535 #------------------------------------------------------------------------------
2536 # Copy a directory recursively to another place, preserving the original
2537 # hierarchical structure
2539 # src: the source directory whose content will be copied.
2540 # dst: the directories where to copy src's content. If not existing, they will be made.
2541 # excludefiles: files which must not be copied. Path must be relative to src.
2543 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2549 @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2552 #------------------------------------------------------------------------------
2555 #------------------------------------------------------------------------------
2556 # Copy include files into the includes directories. There are currently
2557 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2558 # for building tools that need to run on the host system $(GENINCDIR). The
2559 # $(GENINCDIR) path must not contain any references to the C runtime
2560 # library header files.
2562 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2563 dir= compiler=target includedir=$(AROS_INCLUDES)
2565 ifeq ($(findstring %(compiler),host kernel target),)
2566 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2571 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2572 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2573 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2574 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2575 ifeq ($(TMP_DIRFIRST),/)
2576 BD_INC_PATH := %(dir)/
2578 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2581 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2582 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2585 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2589 ifeq (%(compiler),target)
2592 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2593 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2595 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2598 BD_INCL_FILES += $(BD_INCL_FILES2)
2600 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2605 %(mmake) : $(BD_INCL_FILES)
2609 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2610 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2612 #------------------------------------------------------------------------------
2615 #------------------------------------------------------------------------------
2616 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2617 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2618 STUBS_MEM := $(addsuffix .o,$(STUBS))
2619 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2620 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2621 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2623 #MM- linklibs : hidd-%(hidd)-stubs
2624 #MM- %(parenttarget): hidd-%(hidd)-stubs
2625 #MM hidd-%(hidd)-stubs : includes includes-copy
2626 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2628 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2631 $(STUBS_OBJ) : $(STUBS_SRC)
2632 %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2634 $(STUBS_DEP) : $(STUBS_SRC)
2635 %mkdepend_q flags="%(dflags)"
2638 %mkdirs_q $(OBJDIR) $(AROS_LIB)
2642 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2644 DEPS := $(DEPS) $(STUBS_DEP)
2647 #------------------------------------------------------------------------------
2650 #------------------------------------------------------------------------------
2651 # Build an imported source tree which uses the configure script from the
2652 # autoconf package. This rule will try to "integrate" the produced files as
2653 # much as possible in the AROS build, for example by putting libraries in the
2654 # standard library directory, includes in the standard include directory, and
2655 # so on. You can however override this behaviour.
2657 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2658 # be %(bindir) (or its deduced value) when running "make install", and
2659 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2660 # configure script some more parameters whose value depends upon the PROGDIR
2661 # env var, so that the program gets all its stuff installed in the proper place
2662 # when building it, but when running it from inside AROS it can also find that
2663 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2664 # the configuration parameters set when running ./configure
2666 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2667 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2668 # to the name which has to follow it.
2672 # - mmake = the meta make target.
2673 # - package = name of the package to be built.
2674 # - srcdir = the location of the unpacked source code. Defaults
2675 # to $(SRCDIR)/$(CURDIR).
2676 # - prefix = the target directory. Must be an absolute path of the
2677 # host system. Defaults to $(AROS_CONTRIB).
2678 # - aros_prefix = set a path which is valid within the AROS filesystem.
2679 # Defaults to the value of the prefix option.
2680 # - extraoptions = additional options for the configure script.
2681 # - extracflags = additional flags to use with the C compiler.
2682 # - extracxxflags = additional flags to use with the C++ compiler.
2683 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2684 # Defaults to the value of the nix argument.
2685 # - nix = enable u*nix path handling, i.e. a path like
2686 # /progdir//./file will be translated to
2687 # progdir:file during run-time. Defaults to no.
2688 # - compiler = target, host or kernel. Defaults to target.
2689 # - install_target = the command used for installing. Defaults to install. Leave
2690 # it empty if you want to suppress installing.
2691 # - preconfigure = a metatarget which is executed before configure is called.
2692 # - postconfigure = a metatarget which is executed after configure is called.
2693 # - postinstall = a metatarget which is executed after installing.
2694 # - install_env = set additional options for installing.
2695 # - use_build_env = if yes the configuration environment is used for
2696 # installing, too. Defaults to no.
2698 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2702 # --prefix = $(aros_prefix)
2703 # progdir = $(aros_prefix)/bin
2706 # --prefix = /PROGDIR
2707 # --bindir = /PROGDIR
2708 # --sbindir = /PROGDIR
2710 # --includedir = /INCLUDE
2711 # --oldincludedir = /INCLUDE
2713 # --prefix = $(aros_prefix)
2716 # progdir = $(aros_prefix)
2719 # bindir = $(prefix)
2720 # sbindir = $(prefix)
2721 # libdir = $(AROS_LIB)
2722 # includedir = $(AROS_INCLUDES)
2723 # oldincludedir = $(AROS_INCLUDES)
2727 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2728 aros_prefix= extraoptions= extracflags= extracxxflags= nix_dir_layout= nix=no compiler=target \
2729 install_target=install preconfigure= postconfigure= postinstall= \
2730 config_env_extra= install_env= use_build_env=no gnuflags=yes
2733 %(mmake)-prefix := %(prefix)
2735 %(mmake)-prefix := $(AROS_CONTRIB)
2738 ifneq (%(aros_prefix),)
2739 %(mmake)-aros_prefix := %(aros_prefix)
2741 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2747 %(mmake)-nix := $(BD_NIXFLAG)
2748 %(mmake)-volpfx := /
2749 %(mmake)-volsfx := /
2751 ifeq (%(nix_dir_layout),)
2752 %(mmake)-nix_dir_layout := yes
2755 %(mmake)-volsfx := :
2757 ifeq (%(nix_dir_layout),)
2758 %(mmake)-nix_dir_layout := no
2762 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2764 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2765 exec_prefix=$(%(mmake)-prefix) %(install_env)
2767 # Check if chosen compiler is valid
2768 ifeq ($(findstring %(compiler),host target kernel),)
2769 $(error unknown compiler %(compiler))
2772 # Set legacy 'host' variable based on chosen compiler
2773 ifeq (%(compiler),host)
2776 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2778 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2783 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2785 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2790 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2792 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2796 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2797 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2799 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2800 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2801 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2804 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2805 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2807 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2810 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2812 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2813 sbindir=$(%(mmake)-prefix) \
2814 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2815 oldincludedir=$(AROS_INCLUDES) %(install_env)
2818 ifneq ($(DEBUG),yes)
2819 %(mmake)-s_flag = -s
2822 # Set up build environment, and options for configure script
2823 ifeq (%(compiler),host)
2824 # NB: We need to pass in our crosstoolsdir, but cannot set CLFAGS since it
2825 # confused configure scripts. We also cannot pass it via _FOR_BUILD
2826 # since that wont get picked up during configure.
2827 # We also cannot pass in the compiler including std flags so we need to use
2828 # the "plain" host compiler.
2829 CONFIG_ENV := %(config_env_extra) \
2831 CXXCPP="$(HOST_CPP)" \
2832 CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2833 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2834 LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2835 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2836 TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2837 TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2838 TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2839 TARGET_AS="$(TARGET_AS)" \
2840 OBJCOPY="$(OBJCOPY)" \
2841 TARGET_RANLIB="$(RANLIB)" \
2842 TARGET_STRIP="$(STRIP_PLAIN)" \
2843 TARGET_NM="$(NM_PLAIN)" \
2844 TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2846 ifeq (%(compiler),target)
2847 CONFIG_ENV := %(config_env_extra) \
2848 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2849 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2850 CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2851 CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2852 CC="$(TARGET_CC) $(TARGET_SYSROOT)" \
2853 CFLAGS=" $(TARGET_CFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2854 CXX="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2855 CXXFLAGS=" $(TARGET_CXXFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2856 LDFLAGS="-L$(AROS_DEVELOPMENT)/lib $(USER_LDFLAGS)" \
2858 CC_FOR_BUILD="$(HOST_DEF_CC)" \
2859 CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2860 CXX_FOR_BUILD="$(HOST_CXX)" \
2861 CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2862 RANLIB="$(RANLIB)" \
2864 STRIP="$(STRIP_PLAIN)" \
2865 TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2866 TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2867 TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2868 TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2869 TARGET_AS="$(TARGET_AS)" \
2870 OBJCOPY="$(OBJCOPY)" \
2871 TARGET_RANLIB="$(RANLIB)" \
2872 TARGET_STRIP="$(STRIP_PLAIN)" \
2873 TARGET_NM="$(NM_PLAIN)" \
2874 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_SYSROOT)" \
2875 CFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2876 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2877 CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2878 ifeq (%(gnuflags),yes)
2879 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2880 --host=$(AROS_TARGET_CPU)-aros\
2881 --target=$(AROS_TARGET_CPU)-aros\
2883 --without-x --without-pic --disable-shared
2886 ifeq (%(compiler),kernel)
2887 CONFIG_ENV := %(config_env_extra) \
2888 CPP="$(KERNEL_CPP)" \
2889 CXXCPP="$(KERNEL_CPP)" \
2890 CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2891 CFLAGS="$(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)" \
2892 CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2893 CXXFLAGS="$(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag)" \
2895 CC_FOR_BUILD="$(HOST_DEF_CC)" \
2896 CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2897 CXX_FOR_BUILD="$(HOST_CXX)" \
2898 CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2899 RANLIB="$(RANLIB)" \
2900 TARGET_RANLIB="$(RANLIB)" \
2901 TARGET_STRIP="$(STRIP_PLAIN)" \
2902 TARGET_NM="$(NM_PLAIN)"
2903 ifeq (%(gnuflags),yes)
2904 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2905 --host=$(AROS_TARGET_CPU)-aros\
2906 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2907 --without-x --without-pic --disable-shared
2911 ifeq (%(use_build_env),yes)
2912 BUILD_ENV := $(CONFIG_ENV)
2915 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2917 # When building for the host, we don't need to build the
2918 # linklibs - this is especially true when building the
2919 # crosstool toolchain on 'foreign' architectures (such as
2920 # building PPC on x86)
2922 #MM- %(mmake)-host : setup includes %(mmake)-quick
2923 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2924 #MM- %(mmake): %(mmake)-%(compiler)
2926 # Using -j1 in install_command may result in a warning but finally
2927 # it does its job. make install for gcc does not work reliably for -jN
2929 ifneq (%(install_target),)
2930 %(mmake)-install_command = \
2931 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2932 -C $(%(mmake)-pkgdir) %(install_target) -j1
2934 %(mmake)-uninstall_command = \
2935 $(RM) $(%(mmake)-installflag) && \
2936 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2937 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2939 %(mmake)-install_command := true
2940 %(mmake)-uninstall_command := true
2943 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2946 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2948 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2949 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2950 $(RM) $(%(mmake)-installflag) && \
2951 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2952 -C $(%(mmake)-pkgdir) && \
2953 $(%(mmake)-install_command) && \
2954 $(TOUCH) $@ -r $^; \
2957 $(%(mmake)-pkgdir)/.files-touched:
2958 %mkdirs_q $(%(mmake)-pkgdir)
2959 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2963 %(mmake)-uninstall :
2964 $(%(mmake)-uninstall_command)
2967 %(mmake)-configure : $(%(mmake)-configflag)
2969 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2970 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2972 %mkdirs_q $(%(mmake)-pkgdir)
2973 cd $(%(mmake)-pkgdir) && \
2974 find . -name config.cache -exec $(RM) '{}' \; && \
2975 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2976 %(extraoptions) && \
2980 %(mmake)-clean : %(mmake)-uninstall
2981 @$(RM) $(%(mmake)-pkgdir)
2983 #------------------------------------------------------------------------------
2986 #------------------------------------------------------------------------------
2987 # Build an imported source tree which uses cmake
2991 # - mmake = the meta make target.
2992 # - package = name of the package to be built.
2993 # - srcdir = the location of the unpacked source code. Defaults
2994 # to $(SRCDIR)/$(CURDIR).
2995 # - prefix = the target directory. Must be an absolute path of the
2996 # host system. Defaults to $(AROS_CONTRIB).
2997 # - aros_prefix = set a path which is valid within the AROS filesystem.
2998 # Defaults to the value of the prefix option.
2999 # - extraoptions = additional options for the cmake script.
3000 # - installoptions = additional options for the install step.
3003 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3004 aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3005 cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3008 %(mmake)-prefix := %(prefix)
3010 %(mmake)-prefix := $(AROS_CONTRIB)
3013 ifneq (%(aros_prefix),)
3014 %(mmake)-aros_prefix := %(aros_prefix)
3016 %(mmake)-aros_prefix := $(%(mmake)-prefix)
3019 ifeq (%(compiler),host)
3020 BD_LDFLAGS := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3021 BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3022 BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3023 %(mmake)-cmake_opts := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3025 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3027 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3030 BD_LDFLAGS := %(ldflags)
3031 BD_CFLAGS := %(cflags)
3032 BD_CXXFLAGS := %(cxxflags)
3033 %(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)" -DCMAKE_EXE_LINKER_FLAGS="$(BD_LDFLAGS)"
3035 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3037 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3042 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3044 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3048 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3049 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3051 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3053 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3055 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3058 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
3060 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3061 if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3062 $(RM) $(%(mmake)-installflag) && \
3063 $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3064 cd $(%(mmake)-pkgdir) && \
3065 cmake %(installoptions) -P cmake_install.cmake && \
3066 $(TOUCH) $@ -r $^; \
3069 $(%(mmake)-pkgdir)/.files-touched:
3070 %mkdirs_q $(%(mmake)-pkgdir)
3071 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3075 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3077 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3078 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3080 %mkdirs_q $(%(mmake)-pkgdir)
3081 cd $(%(mmake)-pkgdir) && \
3082 $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3083 cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3087 %(mmake)-clean : %(mmake)-uninstall
3088 @$(RM) $(%(mmake)-pkgdir)
3090 #------------------------------------------------------------------------------
3093 #------------------------------------------------------------------------------
3094 # Given an archive name, patches names and locations where to find them, fetch
3095 # the archive and the patches from any of those locations, unpack the archive
3096 # and then apply the patches.
3098 # Locations currently supported are http and ftp sites, plus local filesystem
3099 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3100 # the fetch.sh script needs to be modified, since this macro relies on that script.
3104 # - mmake = mmaketarget
3105 # - archive_origins = list of locations where to find the archive. They are tried
3106 # in sequence, until the archive is found and fetching it
3107 # succeeded. If not specified, the current directory is assumed.
3108 # - archive = the archive name. Mandatory.
3109 # - suffixes = a list of suffixes to append to the the package name plus the
3110 # version. Each one of them is tried until a matching archive is
3111 # found. They are appended to patches and these are tried the
3112 # same way as packages are.
3113 # - location = the local directory where to put the fetched archive and patches.
3114 # If not specified, the directory specified by destination is used.
3115 # - destination = the directory to unpack the archive to.
3116 # If not specified, the current directory is assumed.
3117 # - patches_origins = list of locations where to find the patches. They are tried
3118 # in sequence, until a patch is found and fetching it
3119 # succeeded. If not specified, the current directory is assumed.
3120 # - patches_specs = list of "patch specs". A patch spec is of the form
3121 # patch_name[:[patch_subdir][:patch_opt]].
3123 # - patch_name = the name of the patch file
3124 # - patch_subdir = the directory within \destination\ where to
3126 # - patch_opt = any options to pass to the `patch' command
3127 # when applying the patch.
3129 # The patch_subdir and patch_opt fields are optional.
3131 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3132 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3136 ifneq (%(location),)
3137 %(mmake)-location := %(location)
3139 %(mmake)-location := %(destination)
3144 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3145 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3147 #------------------------------------------------------------------------------
3150 #------------------------------------------------------------------------------
3151 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3152 # unpatched source tree and runs diff against this and a previously fetched and possibly
3153 # patched tree. Depending on what happens after patching during a normal build it might
3154 # give best results if the new patch is created directly after fetch.
3158 # - mmake = mmaketarget
3159 # - archive = archive base name
3160 # - srcdir = the top level directory the package is unpacked to, useful if
3161 # an archive unpacks to a directory other than its name suggests.
3162 # this should not be deeper than a single path element.
3163 # - suffixes = a list of suffixes to append to the the package name plus the
3164 # version. Each one of them is tried until a matching archive is
3166 # - destination = the directory to unpack the archive to.
3167 # - excludes = diff patterns to exclude files or directories from the patch
3169 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3173 ifneq (%(excludes),)
3174 %(mmake)-exclude := -X ./exclude.patterns
3178 %(mmake)-srcdir := %(srcdir)
3180 %(mmake)-srcdir := %(archive)
3183 #MM- %(mmake) : %(mmake)-diff
3184 #MM- %(mmake)-quick : %(mmake)-diff
3188 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3189 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3190 cd %(destination)/tmp ; \
3191 $(FOR) f in %(excludes) ; do \
3192 $(ECHO) $$f >> ./exclude.patterns ; \
3194 diff -ruN $(%(mmake)-exclude) \
3195 $(%(mmake)-srcdir) \
3196 $(%(mmake)-srcdir).aros \
3197 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3198 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3199 $(RM) %(destination)/tmp
3201 #------------------------------------------------------------------------------
3204 #------------------------------------------------------------------------------
3205 # Joins the features of %fetch and %build_with_configure.
3207 # If a patch is provided, it *must* be named the following way:
3209 # <package name>-<version number>-aros.diff
3211 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3212 # CD'ing into the archive's extracted directory.
3214 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3215 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3216 # to make that patch fully comprehensive.
3220 # - mmake = the meta make target.
3221 # - package = the GNU package name, sans version and archive format suffixes.
3222 # - subpackage = ???
3223 # - compiler = same meaning as the one for the %build_with_configure macro.
3224 # - install_target = same meaning as the one for the %build_with_configure macro.
3225 # - version = the package's version number, or otherwise any other version string.
3226 # It gets appended to the package name to form the basename of the archive.
3227 # - suffixes = a list of suffixes to apped to the the package name plus the
3228 # version. Each one of them is tried until a matching archive is found.
3229 # Defaults to "tar.bz2 tar.gz".
3230 # - srcdir = the top level directory the package is unpacked to (see create_patch).
3231 # - builddir = override the location we expect to run configure/make in.
3232 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
3233 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
3234 # fetched or not. Default to no.
3235 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
3236 # - prefix = same meaning as the one for the %build_with_configure macro.
3237 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
3238 # - extraoptions = same meaning as the one for the %build_with_configure macro.
3239 # - extracflags = same meaning as the one for the %build_with_configure macro.
3240 # - extracxxflags = same meaning as the one for the %build_with_configure macro.
3241 # - preconfigure = same meaning as the one for the %build_with_configure macro.
3242 # - postconfigure = same meaning as the one for the %build_with_configure macro.
3243 # - postinstall = same meaning as the one for the %build_with_configure macro.
3244 # - install_env = same meaning as the one for the %build_with_configure macro.
3245 # - use_build_env = same meaning as the one for the %build_with_configure macro.
3246 # - nix = same meaning as the one for the %build_with_configure macro.
3247 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
3248 # - create_pkg = create a distributable package of the compiled sources, defaults to no
3250 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3251 version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3252 prefix= aros_prefix= extraoptions= extracflags= extracxxflags= preconfigure= postconfigure= postinstall= \
3253 config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no gnuflags=yes
3255 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3256 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3257 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3258 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3260 %(mmake)-archbase := %(package)-%(version)
3262 ifeq (%(compiler),host)
3263 %(mmake)-portdir := $(HOSTDIR)/Ports/host/%(package)
3265 %(mmake)-portdir := $(PORTSDIR)/%(package)
3269 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3271 %(mmake)-prefix := %(prefix)
3274 ifneq (%(subpackage),)
3275 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
3277 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
3281 %(mmake)-%(subpackage)-srcdir := %(srcdir)
3283 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
3286 ifneq (%(builddir),)
3287 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3289 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)
3293 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3295 %(mmake)-%(subpackage)-patches_specs := ::
3298 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3299 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3300 archive_origins=". %(package_repo)" \
3301 patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3303 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3304 archive=$(%(mmake)-%(subpackage)-archbase) \
3305 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3306 suffixes="%(suffixes)" \
3307 destination=$(%(mmake)-portdir)
3309 #MM- %(mmake) : %(mmake)-%(subpackage)
3311 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3313 %(mmake)-%(subpackage)-package-basename := \
3314 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3316 ifneq (%(create_pkg),no)
3317 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3320 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3321 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3322 config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3323 nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3324 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3325 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" gnuflags=%(gnuflags)
3327 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3328 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3331 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3333 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3334 #that $^ and $@ have exactly the same mtime, and in that case make tries
3335 #to rebuild $@ again, which would fail because the directory where
3336 #the package got installed would not exist anymore.
3337 #We work this around by using an if statement to manually check the mtimes.
3338 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3339 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3341 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3342 mkdir -p "$(DISTDIR)/Packages" ; \
3343 mkdir -p "$(%(mmake)-prefix)" ; \
3344 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3345 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3346 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3349 #------------------------------------------------------------------------------
3352 #------------------------------------------------------------------------------
3353 # Joins the features of %fetch and %build_with_configure, taking advantage of
3354 # the naming scheme of GNU packages. GNU packages names are in the form
3356 # <package name>-<version number>.<archive format suffix>
3358 # If a patch is provided, it *must* be named the following way:
3360 # <package name>-<version number>-aros.diff
3362 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3363 # CD'ing into the archive's extracted directory.
3365 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3366 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3367 # to make that patch fully comprehensive.
3369 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3373 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3375 # - prefix = defaults to $(GNUDIR).
3376 # - aros_prefix = defaults to /GNU.
3378 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3379 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3380 aros_prefix=/GNU extraoptions= extracflags= extracxxflags= config_env_extra= preconfigure= postconfigure= postinstall=
3382 GNU_REPOSITORY := gnu://
3384 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3385 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3386 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3387 patch="%(patch)" patch_repo="%(patch_repo)" \
3388 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3389 config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3392 #------------------------------------------------------------------------------
3395 #------------------------------------------------------------------------------
3396 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3397 # that the package is a "Development" package, and as such it needs to be placed
3398 # under the $(AROS_DEVELOPMENT) directory, as a default.
3400 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3401 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3402 # "mmake" argument, because the metatarget is implicitely defined as
3404 # #MM- development-%(package)
3406 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3407 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3408 aros_prefix=/Development config_env_extra= preconfigure= postconfigure= postinstall= extraoptions= extracflags= extracxxflags=
3410 #MM- development : development-%(package)
3413 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3414 version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3415 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3416 aros_prefix="%(aros_prefix)" config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3417 extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3420 postinstall-%(package)-delete-la-files:
3421 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3424 #------------------------------------------------------------------------------
3426 # Builds a kickstart package in PKG format
3430 # - mmake = target name
3431 # - file = destination file name with path
3433 # Other arguments are self-explanatory
3435 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3436 arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3438 PKG_CLASSES := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3439 PKG_DEVICES := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3440 PKG_HANDLERS := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3441 PKG_HIDD := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3442 PKG_LIBS := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3443 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3445 PKG_CLASSES_ARCH := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3446 PKG_DEVICES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3447 PKG_HANDLERS_ARCH := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3448 PKG_HIDD_ARCH := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3449 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3450 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3452 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3453 $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3454 PKG_DIR := $(dir %(file))
3460 %(mmake)-quick : %(file)
3462 %(file): $(PKG_FILES) | $(PKG_DIR)
3463 @$(ECHO) Packaging $@...
3464 @$(SRCDIR)/tools/package/pkg c $@ $^
3466 %compress_file mmake="%(mmake)" file="%(file)"
3468 GLOB_MKDIRS += $(PKG_DIR)
3472 #------------------------------------------------------------------------------
3473 # Compresses %(file) with a gzip.
3474 # Good in conjunction with for example %build_prog
3476 %define compress_file mmake=/A file=/A
3478 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3481 %(mmake)-gz-quick : %(file).gz
3484 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3489 #------------------------------------------------------------------------------
3490 # Links a kickstart module in ELF format
3491 # Arguments are similar to make_package
3493 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3494 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3496 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3497 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3498 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3499 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3500 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3501 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3504 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3506 KOBJ_STARTUP := %(startup)
3509 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3511 TMP_LDFLAGS := %(ldflags)
3513 # Make a list of the lib files this program depends on.
3514 # In LDFLAGS remove white space between -L and directory
3515 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3516 # Filter out only the libdirs and remove -L
3517 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3519 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3520 # Add normal linklib path
3521 TMP_DIRS += $(AROS_LIB)/
3522 # add lib and .a to static linklib names
3523 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3524 # search for the linklibs in the given path, ignore ones not found
3525 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3526 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3529 TMP_DIRS += $(dir %(file))
3531 TMP_LDFLAGS += $(GENMAP) %(map)
3532 TMP_DIRS += $(dir %(map))
3535 #MM %(mmake) : %(deps)
3541 %(mmake)-quick : %(file)
3543 %(file): KOBJS := $(KOBJS)
3544 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3545 -static -nosysbase -Wl,-Ur
3546 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3547 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3548 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3549 @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3552 %compress_file mmake="%(mmake)" file="%(file)"
3554 GLOB_MKDIRS += $(TMP_DIRS)