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_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26 @$(ECHO) "Compiling $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
35 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd=$(CC) 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) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,%(to))..."
67 @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
70 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
75 $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
76 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd=$(AROS_CC) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
90 @if %(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) \
91 $(GENMAP) %(objdir)/%(module).map \
92 %(objs) %(libs) %(endtag) \
93 -o $@ 2>&1 > %(objdir)/%(err); \
95 cat %(objdir)/%(err); \
97 echo "%(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(endtag) -o $@"; \
98 cat %(objdir)/%(err); \
102 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121 %mkdir_q dir="$(dir %(to))"
122 @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139 @$(FOR) dir in %(dirs) ; do \
140 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
149 ## Here are the mmakefile macros that are used to do certain tasks in a ##
150 ## mmakefile. They consist of one or more full makefile rules. ##
151 ## In general the files generated in these macros are also defined as ##
152 ## make targets so that they can be used as a dependency in other rules ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197 stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207 @for f in $(FILES); do \
208 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
220 # Restriction: at the moment when using a non-empty target dir %(from) may
222 %define rule_join to=/A from=/A text=
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean
238 %define include_deps deps=$(DEPS)/M depstargets=
240 ifneq (%(depstargets),)
241 ifneq ($(findstring $(TARGET),%(depstargets)),)
245 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default.
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 # the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 # it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
282 TMP_TARGETBASE := %(basename)
284 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
287 ifeq ($(findstring %(compiler),host kernel target),)
288 $(error unknown compiler %(compiler))
290 ifeq (%(compiler),target)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
298 ifeq (%(compiler),host)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
306 ifeq (%(compiler),kernel)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
315 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
321 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
323 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
327 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
329 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
332 $(TMP_TARGETBASE).d : %(basename).c
333 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile a C++ source file to an object file and generate
340 # the dependency file. Basename may contain a directory part, then the source
341 # file has to be in that directory. The generated file will be put in the
342 # object directory without the directory.
344 # - basename: the basename of the file to compile. Use % for a wildcard rule
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 # the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 # it is put in the same directory as the .c file
350 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
353 TMP_TARGETBASE := %(basename)
355 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
358 # Adjust compiler flags to suit C++
359 TMP_CXXFLAGS := %(cflags)
360 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
361 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
363 ifeq ($(findstring %(compiler),host kernel target),)
364 $(error unknown compiler %(compiler))
366 ifeq (%(compiler),target)
367 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
368 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
369 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
370 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
374 ifeq (%(compiler),host)
375 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
376 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
377 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
378 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
382 ifeq (%(compiler),kernel)
383 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
384 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
387 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
388 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
391 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
392 $(TMP_TARGETBASE).o : %(basename).cpp
393 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
397 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
399 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
403 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
405 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
408 $(TMP_TARGETBASE).d : %(basename).cpp
409 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
411 #------------------------------------------------------------------------------
414 #------------------------------------------------------------------------------
415 # Generate a rule to compile multiple C source files to an object file and
416 # generate the corresponding dependency files. The generated file will be put
417 # in the object directory without the directory part of the source file.
419 # - basenames: the basenames of the files to compile. The names may include
420 # relative or absolute path names. No wildcard is allowed
421 # - cflags (default $(CFLAGS)): the C flags to use for compilation
422 # - dflags: the flags used during creation of dependency file. If not specified
423 # the same value as cflags will be used
424 # - targetdir: the directory to put the .o file and the .d file. By default
425 # it is put in the same directory as the .c file. When targetdir is not
426 # empty, path names will be stripped from the file names so that all files
427 # are in that dir and not in subdirectories.
428 # - compiler (default target): compiler to use, target, kernel or host
429 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
433 TMP_TARGETS := $(addsuffix .o,%(basenames))
434 TMP_DTARGETS := $(addsuffix .d,%(basenames))
437 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
438 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
439 TMP_WILDCARD := %(targetdir)/%
441 # Be sure that all .c files are generated
442 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
444 # Be sure that all .c files are found
445 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
446 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
447 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
449 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
450 vpath %.c $(TMP_DIRS)
455 ifeq ($(findstring %(compiler),host kernel target),)
456 $(error unknown compiler %(compiler))
458 ifeq (%(compiler),target)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
460 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
463 ifeq (%(compiler),host)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
468 ifeq (%(compiler),kernel)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
471 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
474 $(TMP_TARGETS) : CFLAGS := %(cflags)
475 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
476 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
479 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
481 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
483 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
484 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
486 #------------------------------------------------------------------------------
489 #------------------------------------------------------------------------------
490 # Generate a rule to compile multiple C++ source files to an object file and
491 # generate the corresponding dependency files. The generated file will be put
492 # in the object directory without the directory part of the source file.
494 # - basenames: the basenames of the files to compile. The names may include
495 # relative or absolute path names. No wildcard is allowed
496 # - cflags (default $(CFLAGS)): the C flags to use for compilation
497 # - dflags: the flags used during creation of dependency file. If not specified
498 # the same value as cflags will be used
499 # - targetdir: the directory to put the .o file and the .d file. By default
500 # it is put in the same directory as the .c file. When targetdir is not
501 # empty, path names will be stripped from the file names so that all files
502 # are in that dir and not in subdirectories.
503 # - compiler (default target): compiler to use, target, kernel or host
504 # - suffix (default .cpp): suffix for source files to compile
505 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
506 targetdir= compiler=target suffix=.cpp
508 # Adjust compiler flags to suit C++
509 TMP_CXXFLAGS := %(cflags)
510 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
511 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
514 TMP_TARGETS := $(addsuffix .o,%(basenames))
515 TMP_DTARGETS := $(addsuffix .d,%(basenames))
518 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
519 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
520 TMP_WILDCARD := %(targetdir)/%
522 # Be sure that all source files are generated
523 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix %(suffix),%(basenames))
525 # Be sure that all source files are found
526 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
527 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
528 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
530 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
531 vpath %%(suffix) $(TMP_DIRS)
535 ifeq ($(findstring %(compiler),host kernel target),)
536 $(error unknown compiler %(compiler))
538 ifeq (%(compiler),target)
539 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
540 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
541 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
543 ifeq (%(compiler),host)
544 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
545 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
546 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
548 ifeq (%(compiler),kernel)
549 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
550 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
551 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
554 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
555 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
556 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
559 $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
561 ifeq (%(dflags),%(cflags))
562 $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
564 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
567 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %%(suffix)
568 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
570 #------------------------------------------------------------------------------
573 #------------------------------------------------------------------------------
574 # Generate a rule to compile an ObjC source file to an object file and generate
575 # the dependency file. Basename may contain a directory part, then the source
576 # file has to be in that directory. The generated file will be put in the
577 # object directory without the directory.
579 # - basename: the basename of the file to compile. Use % for a wildcard rule
580 # - cflags (default $(CFLAGS)): the C flags to use for compilation
581 # - dflags: the flags used during creation of dependency file. If not specified
582 # the same value as cflags will be used
583 # - targetdir: the directory to put the .o file and the .d file. By default
584 # it is put in the same directory as the .m file
585 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
588 TMP_TARGETBASE := %(basename)
590 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
593 # Adjust compiler flags to suit ObjC
594 TMP_OBJCFLAGS := %(cflags)
595 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
596 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
598 ifeq ($(findstring %(compiler),host kernel target),)
599 $(error unknown compiler %(compiler))
601 ifeq (%(compiler),target)
602 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
603 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
604 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
605 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
606 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
607 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
609 ifeq (%(compiler),host)
610 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
611 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
612 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
613 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
614 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
615 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
617 ifeq (%(compiler),kernel)
618 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
619 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
622 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
623 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
626 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
627 $(TMP_TARGETBASE).o : %(basename).m
628 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
632 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
634 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
638 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
640 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
643 $(TMP_TARGETBASE).d : %(basename).m
644 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
646 #------------------------------------------------------------------------------
648 #------------------------------------------------------------------------------
649 # Generate a rule to compile multiple ObjC source files to an object file and
650 # generate the corresponding dependency files. The generated file will be put
651 # in the object directory without the directory part of the source file.
653 # - basenames: the basenames of the files to compile. The names may include
654 # relative or absolute path names. No wildcard is allowed
655 # - cflags (default $(CFLAGS)): the C flags to use for compilation
656 # - dflags: the flags used during creation of dependency file. If not specified
657 # the same value as cflags will be used
658 # - targetdir: the directory to put the .o file and the .d file. By default
659 # it is put in the same directory as the .m file. When targetdir is not
660 # empty, path names will be stripped from the file names so that all files
661 # are in that dir and not in subdirectories.
662 # - compiler (default target): compiler to use, target, kernel or host
663 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
664 targetdir= compiler=target
666 # Adjust compiler flags to suit ObjC
667 TMP_OBJCFLAGS := %(cflags)
668 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
669 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
672 TMP_TARGETS := $(addsuffix .o,%(basenames))
673 TMP_DTARGETS := $(addsuffix .d,%(basenames))
676 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
677 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
678 TMP_WILDCARD := %(targetdir)/%
680 # Be sure that all .m files are generated
681 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
683 # Be sure that all .m files are found
684 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
685 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
686 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
688 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
689 vpath %.m $(TMP_DIRS)
693 # Define the use of cross compiler
694 ifeq ($(TARGET_OBJC),)
695 TMP_CC := $(TARGET_CC)
697 TMP_CC := $(TARGET_OBJC)
700 ifeq ($(findstring %(compiler),host kernel target),)
701 $(error unknown compiler %(compiler))
703 ifeq (%(compiler),target)
704 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
705 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
706 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
708 ifeq (%(compiler),host)
709 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
710 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
711 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
713 ifeq (%(compiler),kernel)
714 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
715 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
716 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
719 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
720 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
721 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
724 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
726 ifeq (%(dflags),%(cflags))
727 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
729 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
732 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
733 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
735 #------------------------------------------------------------------------------
738 #------------------------------------------------------------------------------
739 # Make an alias from one arch specific build to another arch.
741 # - mainmmake: the mmake of the module in the main tree
742 # - arch: the current arch
743 # - alias: the alias to which this should point
744 %define rule_archalias mainmmake=\A arch=\A alias=\A
746 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
748 #------------------------------------------------------------------------------
751 #------------------------------------------------------------------------------
752 # Generate a rule to assemble a source file to an object file. Basename may
753 # contain a directory part, then the source file has to be in that directory.
754 # The generated file will be put in the object directory without the directory.
756 # - basename: the basename of the file to compile. Use % for a wildcard rule
757 # - flags (default $(AFLAGS)): the asm flags to use for assembling
758 # - targetdir: the directory to put the .o file in. By default it is put in the
759 # same directory as the .s file
760 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
763 %(basename).o : AFLAGS := %(aflags)
764 %(basename).o : %(basename).s
766 %(basename).o : %(basename).S
770 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
771 %(targetdir)/$(notdir %(basename)).o : %(basename).s
773 %(targetdir)/$(notdir %(basename)).o : %(basename).S
778 #------------------------------------------------------------------------------
781 #------------------------------------------------------------------------------
782 # Generate a rule to assemble multiple source files to an object file. The
783 # generated file will be put in the object directory with the directory part
784 # of the source file stripped off.
786 # - basenames: the basenames of the files to compile. The names may include
787 # relative or absolute path names. No wildcard is allowed
788 # - aflags (default $(AFLAGS)): the flags to use for assembly
789 # - targetdir: the directory to put the .o file and the .d file. By default
790 # it is put in the same directory as the .c file. When targetdir is not
791 # empty, path names will be stripped from the file names so that all files
792 # are in that dir and not in subdirectories.
793 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
796 TMP_TARGETS := $(addsuffix .o,%(basenames))
799 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
800 TMP_WILDCARD := %(targetdir)/%
802 # Be sure that all .s files are generated
803 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
805 # Be sure that all .c files are found
806 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
807 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
808 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
810 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
811 vpath %%(suffix) $(TMP_DIRS)
816 ifeq ($(findstring %(compiler),host kernel target),)
817 $(error unknown compiler %(compiler))
819 ifeq (%(compiler),target)
820 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
822 ifeq (%(compiler),host)
823 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
825 ifeq (%(compiler),kernel)
826 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
829 $(TMP_TARGETS) : AFLAGS := %(aflags)
830 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
831 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
833 #------------------------------------------------------------------------------
836 #------------------------------------------------------------------------------
837 # Link %(objs) to %(prog) using the libraries in %(uselibs)
838 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
839 usehostlibs= usestartup=yes detach=no nix=no linker=target
844 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
846 ifeq (%(usestartup),no)
847 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
848 ifeq (%(linker),target)
849 TMP_EXTRA_LIBS += libinit autoinit
853 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
856 # Make a list of the lib files this program depends on.
857 # In LDFLAGS remove white space between -L and directory
858 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
859 # Filter out only the libdirs and remove -L
860 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
862 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
863 # Add normal linklib path
864 TMP_DIRS += $(LIBDIR)/
865 # add lib and .a to static linklib names
866 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
867 ifeq (%(usestartup),yes)
868 TMP_LIBS += startup.o
873 # search for the linklibs in the given path, ignore ones not found
874 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
875 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
878 ifeq (%(linker),target)
879 %(prog) : CMD:=$(TARGET_CC)
880 %(prog) : STRIPCMD:=$(TARGET_STRIP)
882 ifeq (%(linker),host)
883 %(prog) : CMD:=$(HOST_CC)
884 %(prog) : STRIPCMD:=$(HOST_STRIP)
886 ifeq (%(linker),kernel)
887 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
888 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
891 %(prog) : OBJS := %(objs)
892 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
893 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
894 %(prog) : %(objs) $(TMP_DEPLIBS)
895 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
897 #------------------------------------------------------------------------------
900 #------------------------------------------------------------------------------
901 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
902 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
903 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
904 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
905 usestartup=yes detach=no
910 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
912 ifeq (%(usestartup),no)
913 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
914 TMP_EXTRA_LIBS += libinit autoinit
917 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
920 # Make a list of the lib files the programs depend on.
921 # In LDFLAGS remove white space between -L and directory
922 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
923 # Filter out only the libdirs and remove -L
924 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
926 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
927 # Add normal linklib path
928 TMP_DIRS += $(LIBDIR)/
929 # add lib and .a to static linklib names
930 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
931 # search for the linklibs in the given path, ignore ones not found
932 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
933 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
935 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
937 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
938 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
939 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
940 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
942 #------------------------------------------------------------------------------
945 #------------------------------------------------------------------------------
946 # Link the %(objs) to the library %(libdir)/lib%(libname).a
947 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
949 ifeq (%(linker),target)
950 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
951 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
953 ifeq (%(linker),host)
954 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
955 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
957 ifeq (%(linker),kernel)
958 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
959 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
962 %(libdir)/lib%(libname).a : %(objs)
963 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
965 #------------------------------------------------------------------------------
967 #------------------------------------------------------------------------------
968 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
969 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
970 # The -nostdc flag is added so that modules are not linked with stdc.library,
971 # stdcio.library or posixc.library
972 # (see /config/specs.in file)
973 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
974 cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
976 TMP_LDFLAGS := %(ldflags)
977 # Make a list of the lib files the programs depend on.
978 # In LDFLAGS remove white space between -L and directory
979 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
980 # Filter out only the libdirs and remove -L
981 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
983 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
984 # Add normal linklib path
985 TMP_DIRS += $(LIBDIR)/
986 # add lib and .a to static linklib names
987 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
988 # search for the linklibs in the given path, ignore ones not found
989 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
990 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
993 %(module) : LIB_NAMES := %(uselibs)
994 %(module) : OBJS := %(objs)
995 %(module) : ENDTAG := %(endobj)
996 %(module) : ERR := %(err)
997 %(module) : OBJDIR := %(objdir)
998 %(module) : LDFLAGS := $(TMP_LDFLAGS)
999 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1000 -L/usr/lib $(addprefix -l,%(usehostlibs))
1001 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1002 %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1005 #------------------------------------------------------------------------------
1008 #------------------------------------------------------------------------------
1009 # Generate the libdefs.h include file for a module.
1010 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1012 TMP_TARGET := %(modname)_libdefs.h
1013 TMP_DEPS := $(GENMODULE)
1015 ifneq (%(conffile),)
1016 ifeq ($(dir %(conffile)),./)
1017 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1018 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1020 TMP_OPTS += -c %(conffile)
1021 TMP_DEPS += %(conffile)
1024 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1025 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1027 ifneq (%(modsuffix),)
1028 TMP_OPTS += -s %(modsuffix)
1030 ifneq (%(targetdir),)
1031 TMP_OPTS += -d %(targetdir)
1032 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1035 TMP_OPTS += -v %(version)
1038 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1039 $(TMP_TARGET) : MODNAME := %(modname)
1040 $(TMP_TARGET) : MODTYPE := %(modtype)
1041 $(TMP_TARGET) : $(TMP_DEPS)
1042 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1043 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1045 #------------------------------------------------------------------------------
1047 #------------------------------------------------------------------------------
1048 # Generate the _lib.fd file for a module.
1049 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1051 TMP_TARGET := %(modname)_lib.fd
1052 TMP_DEPS := $(GENMODULE)
1054 ifneq (%(conffile),)
1055 ifeq ($(dir %(conffile)),./)
1056 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1057 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1059 TMP_OPTS += -c %(conffile)
1060 TMP_DEPS += %(conffile)
1063 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1064 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1066 ifneq (%(modsuffix),)
1067 TMP_OPTS += -s %(modsuffix)
1069 ifneq (%(targetdir),)
1070 TMP_OPTS += -d %(targetdir)
1071 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1074 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1075 $(TMP_TARGET) : MODNAME := %(modname)
1076 $(TMP_TARGET) : MODTYPE := %(modtype)
1077 $(TMP_TARGET) : $(TMP_DEPS)
1078 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1079 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1081 #------------------------------------------------------------------------------
1083 #------------------------------------------------------------------------------
1084 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1085 # generated file in this Makefile
1086 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1089 TMP_TARGET := Makefile.%(modname)%(modtype)
1090 TMP_DEPS := $(GENMODULE)
1092 ifneq (%(conffile),)
1093 ifeq ($(dir %(conffile)),./)
1094 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1095 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1097 TMP_OPTS += -c %(conffile)
1098 TMP_DEPS += %(conffile)
1101 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1102 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1104 ifneq (%(modsuffix),)
1105 TMP_OPTS += -s %(modsuffix)
1107 ifneq (%(targetdir),)
1108 TMP_OPTS += -d %(targetdir)
1109 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1112 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1113 $(TMP_TARGET) : MODNAME := %(modname)
1114 $(TMP_TARGET) : MODTYPE := %(modtype)
1115 $(TMP_TARGET) : $(TMP_DEPS)
1116 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1118 #------------------------------------------------------------------------------
1121 #------------------------------------------------------------------------------
1122 # Generate the support files for compiling a module. This includes include
1123 # files and source files. This rule has to be preceeded by
1124 # %rule_genmodule_makefile
1125 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1128 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1129 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1130 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1131 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1133 TMP_DEPS := $(GENMODULE)
1136 ifneq (%(conffile),)
1137 ifeq ($(dir %(conffile)),./)
1138 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1139 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1141 TMP_OPTS += -c %(conffile)
1142 TMP_DEPS += %(conffile)
1145 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1146 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1148 ifneq (%(modsuffix),)
1149 TMP_OPTS += -s %(modsuffix)
1151 ifneq (%(targetdir),)
1152 TMP_OPTS += -d %(targetdir)
1153 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1154 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1157 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1158 $(TMP_TARGETS) : MODNAME := %(modname)
1159 $(TMP_TARGETS) : MODTYPE := %(modtype)
1160 $(TMP_TARGETS) : $(TMP_DEPS)
1161 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1162 ifneq (%(conffile),lib.conf)
1163 @$(IF) $(TEST) -f lib.conf; then \
1164 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1167 @$(IF) $(TEST) -f libdefs.h; then \
1168 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1170 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1172 #------------------------------------------------------------------------------
1175 #------------------------------------------------------------------------------
1176 # Generate the support files for compiling a module. This includes include
1177 # files and source files.
1178 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1179 targetdir= conffile=
1181 ifneq ($(%(modname)_INCLUDES),)
1182 TMP_TARGETS := $(%(modname)_INCLUDES)
1184 TMP_DEPS := $(GENMODULE)
1187 ifneq (%(conffile),)
1188 ifeq ($(dir %(conffile)),./)
1189 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1190 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1192 TMP_OPTS += -c %(conffile)
1193 TMP_DEPS += %(conffile)
1196 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1197 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1199 ifneq (%(modsuffix),)
1200 TMP_OPTS += -s %(modsuffix)
1202 ifneq (%(targetdir),)
1203 TMP_OPTS += -d %(targetdir)
1204 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1207 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1208 $(TMP_TARGETS) : MODNAME := %(modname)
1209 $(TMP_TARGETS) : MODTYPE := %(modtype)
1210 $(TMP_TARGETS) : $(TMP_DEPS)
1211 @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1212 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1215 #------------------------------------------------------------------------------
1217 #------------------------------------------------------------------------------
1218 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1219 # 'start' is an optional starting address
1220 # 'ldflags' is optional additional flags for the linker
1221 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1223 BD_OUTDIR := $(dir %(file))
1224 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1225 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1226 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1227 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1228 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1231 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1233 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1234 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
1235 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1236 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1238 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1239 GLOB_MKDIRS += $(BD_OUTDIR)
1244 #------------------------------------------------------------------------------
1245 # Common rules for all makefiles
1247 # Delete generated makefiles
1250 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1252 include $(SRCDIR)/config/make.tail
1254 BDID := $(BDTARGETID)
1256 #------------------------------------------------------------------------------
1259 #############################################################################
1260 #############################################################################
1262 ## Here are the mmakefile build macros. These are macros that takes care ##
1263 ## of everything to go from the sources to the generated target. Also all ##
1264 ## intermediate files and directories that are needed are created by these ##
1267 #############################################################################
1268 #############################################################################
1270 #------------------------------------------------------------------------------
1272 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1274 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1275 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1276 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1277 compiler=target linker=
1281 BD_PROGNAME := %(progname)
1282 BD_OBJDIR := %(objdir)
1283 BD_TARGETDIR := %(targetdir)
1284 BD_LINKER := %(linker)
1286 # If not supplied, linker is equal to compiler
1287 ifeq ($(BD_LINKER),)
1288 BD_LINKER := %(compiler)
1291 BD_FILES := %(files)
1292 BD_CXXFILES := %(cxxfiles)
1293 BD_OBJCFILES := %(objcfiles)
1294 BD_ASMFILES := %(asmfiles)
1296 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1297 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1298 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1300 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1301 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1302 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1304 BD_CFLAGS := %(cflags)
1305 BD_AFLAGS := %(aflags)
1306 BD_DFLAGS := %(dflags)
1307 BD_LDFLAGS := %(ldflags)
1310 %(mmake)-quick : %(mmake)
1312 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1313 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1315 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1316 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1317 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1318 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1319 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1320 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1321 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1322 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1323 aflags=$(BD_AFLAGS) compiler=%(compiler)
1325 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1326 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1327 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1328 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1333 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1335 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1336 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1337 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1339 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1342 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1346 #------------------------------------------------------------------------------
1349 #------------------------------------------------------------------------------
1350 # Build programs, for every C file an executable will be built with the same
1351 # name as the C file
1352 %define build_progs mmake=/A files=/A nix=no \
1353 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1354 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1355 uselibs= usehostlibs= usestartup=yes detach=no
1359 BD_OBJDIR := %(objdir)
1360 BD_TARGETDIR := %(targetdir)
1362 BD_FILES := %(files)
1363 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1364 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1365 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1367 BD_CFLAGS := %(cflags)
1368 BD_DFLAGS := %(dflags)
1369 BD_LDFLAGS := %(ldflags)
1372 %(mmake)-quick : %(mmake)
1374 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1375 %(mmake) : $(BD_EXES)
1377 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1378 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1379 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1381 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1382 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1383 ldflags=$(BD_LDFLAGS) \
1384 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1385 usestartup="%(usestartup)" detach="%(detach)"
1389 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1391 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1392 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1393 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1395 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1398 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1402 #------------------------------------------------------------------------------
1405 #------------------------------------------------------------------------------
1407 # This is a bare version: It just compiles and links the given files. It is
1408 # assumed that all needed boiler plate code is in the files. This should only
1409 # be used for compiling external code. For AROS code use %build_module
1410 %define build_module_simple mmake=/A modname=/A modtype=/A \
1411 files="$(basename $(call WILDCARD, *.c))" \
1412 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1413 objdir=$(OBJDIR) moduledir= \
1414 uselibs= usehostlibs= compiler=target
1416 # Define metamake targets and their dependencies
1417 #MM %(mmake) : core-linklibs includes-generate-deps
1418 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1419 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1420 #MM %(mmake)-kobj-quick
1421 #MM %(mmake)-pkg-quick
1425 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1427 .PHONY : $(BD_ALLTARGETS)
1430 $(error using %build_module_simple: modname may not be empty)
1433 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1436 # Default values for variables and arguments
1437 BD_DEFLINKLIBNAME := %(modname)
1438 BD_DEFDFLAGS := %(cflags)
1439 OBJDIR ?= $(GENDIR)/$(CURDIR)
1440 BD_MODDIR := %(moduledir)
1441 ifeq ($(BD_MODDIR),)
1442 ifeq (%(modtype),library)
1443 BD_MODDIR := $(AROS_LIBS)
1445 ifeq (%(modtype),gadget)
1446 BD_MODDIR := $(AROS_GADGETS)
1448 ifeq (%(modtype),datatype)
1449 BD_MODDIR := $(AROS_DATATYPES)
1451 ifeq (%(modtype),handler)
1452 BD_MODDIR := $(AROS_FS)
1454 ifeq (%(modtype),device)
1455 BD_MODDIR := $(AROS_DEVS)
1457 ifeq (%(modtype),resource)
1458 BD_MODDIR := $(AROS_RESOURCES)
1460 ifeq (%(modtype),hook)
1461 BD_MODDIR := $(AROS_RESOURCES)
1463 ifeq (%(modtype),mui)
1464 BD_MODDIR := $(AROS_CLASSES)/Zune
1466 ifeq (%(modtype),mcc)
1467 BD_MODDIR := $(AROS_CLASSES)/Zune
1469 ifeq (%(modtype),mcp)
1470 BD_MODDIR := $(AROS_CLASSES)/Zune
1472 ifeq (%(modtype),usbclass)
1473 BD_MODDIR := $(AROS_CLASSES)/USB
1475 ifeq (%(modtype),hidd)
1476 BD_MODDIR := $(AROS_DRIVERS)
1478 ifeq (%(modtype),printer)
1479 BD_MODDIR := $(AROS_PRINTERS)
1482 ifeq ($(BD_MODDIR),)
1483 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1486 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1487 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1488 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1490 %rule_compile_multi \
1491 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1492 cflags="%(cflags)" dflags="%(dflags)" \
1493 compiler=%(compiler)
1495 # Handlers use dash instead of dot in their names
1496 ifeq (%(modtype),handler)
1497 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1498 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1500 ifeq (%(modtype),printer)
1501 BD_MODULE := $(BD_MODDIR)/%(modname)
1502 BD_PKGMOD := $(PKGDIR)/%(modname)
1504 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1505 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1508 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1510 %(mmake)-quick : %(mmake)
1511 %(mmake)-pkg-quick : $(BD_PKGMOD)
1512 %(mmake)-kobj-quick : $(BD_KOBJ)
1513 %(mmake) : $(BD_MODULE)
1514 %(mmake)-pkg : $(BD_PKGMOD)
1515 %(mmake)-kobj : $(BD_KOBJ)
1517 # The module is linked from all the compiled .o files
1518 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1520 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1521 # This breaks con-handler build. Here we work around this
1522 ifeq (%(modname),con)
1523 BD_ERR := $(notdir $(BD_MODULE)).err
1525 BD_ERR := %(modname).err
1528 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1529 endobj= err=$(BD_ERR) objdir=%(objdir) \
1530 cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1531 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1533 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1534 endobj= err=$(BD_ERR) objdir=%(objdir) \
1535 cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1536 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1538 # Link kernel object file
1539 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1541 # Make these symbols local
1542 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1543 UtilityBase ExpansionBase KeymapBase KernelBase
1545 BD_SYMBOLS := $(BD_KBASE)
1547 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1548 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1549 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1550 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1551 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1552 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1553 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1554 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1555 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1558 ## Dependency fine-tuning
1560 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1561 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1563 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1564 $(BD_MODULE) : | $(BD_MODDIR)
1565 $(BD_KOBJ) : | $(KOBJSDIR)
1566 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1568 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1570 @$(ECHO) "Cleaning up for module %(modname)"
1573 #------------------------------------------------------------------------------
1576 #------------------------------------------------------------------------------
1578 # Explanation of this macro is done in the developer's manual
1579 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1580 files="$(basename $(call WILDCARD, *.c))" \
1581 cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1582 cxxxxfiles="$(basename $(call WILDCARD, *.cxx))" \
1583 cxxccfiles="$(basename $(call WILDCARD, *.cc))" \
1584 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1585 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1586 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1587 compiler=target nostartup=yes
1589 # Define metamake targets and their dependencies
1590 #MM- includes-all : %(mmake)-includes
1591 #MM- linklibs-%(modname): %(mmake)-linklib
1592 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1593 #MM- includes-%(modname): %(mmake)-includes
1594 #MM- includes-%(modname)_rel : %(mmake)-includes
1595 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1596 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1597 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1598 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1599 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1600 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1601 #MM %(mmake)-quick : %(mmake)-includes-quick
1602 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1603 #MM includes-generate-deps %(mmake)-fd
1604 #MM %(mmake)-includes-quick
1605 #MM %(mmake)-includes-dirs
1607 #MM %(mmake)-makefile
1610 # All MetaMake targets defined by this macro
1611 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1612 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1613 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1614 %(mmake)-linklib %(mmake)-fd
1616 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1619 $(error using %build_module: modname may not be empty)
1622 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1625 # Default values for variables and arguments
1626 BD_DEFLINKLIBNAME := %(modname)
1627 BD_DEFDFLAGS := %(cflags)
1628 OBJDIR ?= $(GENDIR)/$(CURDIR)
1630 ## Create genmodule include Makefile for the module
1632 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1634 %rule_genmodule_makefile \
1635 modname=%(modname) modtype=%(modtype) \
1636 modsuffix=%(modsuffix) targetdir=%(objdir) \
1637 conffile=%(conffile)
1639 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1641 GLOB_MKDIRS += %(objdir)
1643 # Do not parse these statements if metatarget is not appropriate
1644 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1646 include %(objdir)/Makefile.%(modname)%(modtype)
1648 BD_DEFMODDIR := $(%(modname)_MODDIR)
1651 ## include files generation
1653 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1654 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1655 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1657 %(mmake)-includes-quick : %(mmake)-includes
1658 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1659 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1660 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1662 ifneq ($(%(modname)_INCLUDES),)
1663 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1664 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1665 conffile=%(conffile)
1667 %rule_copy_diff_multi \
1668 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1669 stampfile=%(objdir)/%(modname)_geninc
1671 %rule_copy_diff_multi \
1672 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1673 stampfile=%(objdir)/%(modname)_incs
1675 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1677 TMP%(modname)_INCDIRS := \
1678 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1679 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1680 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1681 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1685 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1686 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1687 conffile=%(conffile) version=%(version)
1689 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1690 $(BD_DEFLIBDEFSINC) :
1691 @$(ECHO) "Generating $@"
1692 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1694 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1695 GLOB_MKDIRS += %(objdir)/include
1697 ## Extra genmodule src files generation
1699 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1700 modsuffix=%(modsuffix) targetdir=%(objdir) \
1701 conffile=%(conffile)
1705 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1706 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1708 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1709 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1711 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1713 GLOB_MKDIRS += $(BD_FDDIR)
1718 BD_FILES := %(files)
1719 BD_CXXFILES := %(cxxfiles)
1720 BD_CXXXXFILES := %(cxxxxfiles)
1721 BD_CXXCCFILES := %(cxxccfiles)
1723 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1725 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1726 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1728 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1729 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1730 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1732 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1733 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1735 ifeq (%(modtype),library)
1738 BD_LIBSUFFIX := .%(modtype)
1741 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1742 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1743 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1746 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1747 ifneq (%(modname),%(linklibname))
1748 BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1751 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1753 ifneq ($(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES),)
1754 BD_LINKCMD=$(AROS_CXX)
1756 BD_LINKCMD=$(AROS_CC)
1759 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1760 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1761 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1764 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1765 ifneq (%(modname),%(linklibname))
1766 BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1769 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1771 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1772 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1773 $(BD_RELLINKLIBCFILES)
1775 %rule_compile_multi \
1776 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1777 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1778 compiler=%(compiler)
1779 %rule_compile_multi \
1780 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1781 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1782 compiler=%(compiler)
1783 %rule_compile_cxx_multi \
1784 basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1785 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1786 compiler=%(compiler)
1787 %rule_compile_cxx_multi \
1788 basenames=$(BD_CXXXXFILES) targetdir=%(objdir) suffix=.cxx \
1789 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1790 compiler=%(compiler)
1791 %rule_compile_cxx_multi \
1792 basenames=$(BD_CXXCCFILES) targetdir=%(objdir) suffix=.cc \
1793 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1794 compiler=%(compiler)
1796 ifneq ($(BD_LINKLIBAFILES),)
1797 %rule_assemble_multi \
1798 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1803 ifeq (%(modsuffix),)
1804 BD_SUFFIX := %(modtype)
1806 BD_SUFFIX := %(modsuffix)
1809 # Handlers use dash instead of dot in their names
1810 ifeq ($(BD_SUFFIX),handler)
1811 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1812 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1814 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1815 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1817 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1819 %(mmake)-quick : %(mmake)
1820 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1821 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1822 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1823 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1824 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1825 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1827 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1828 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES)))) \
1829 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES))))
1831 ifeq (%(nostartup),yes)
1832 # Handlers always have entry point
1833 ifneq (%(modtype),handler)
1834 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1838 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1839 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1842 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1845 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1846 # This breaks con-handler build. Here we work around this
1847 ifeq (%(modname),con)
1848 BD_ERR := $(notdir $(BD_MODULE)).err
1850 BD_ERR := %(modname).err
1853 # The module is linked from all the compiled .o files
1854 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1855 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1856 cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1857 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1859 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1860 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1861 cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1862 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1865 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1866 BD_MODNAME := $(shell echo %(modname) | tr A-Z a-z)
1867 ifneq ($(BD_LINKLIB),)
1868 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1869 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1870 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1873 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1874 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1877 ifneq ($(BD_RELLINKLIB),)
1878 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1879 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1880 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1883 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1884 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1887 # Link kernel object file
1888 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1890 # Make these symbols local
1891 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1892 UtilityBase ExpansionBase KeymapBase KernelBase
1894 BD_SYMBOLS := $(BD_KBASE)
1896 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1897 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1898 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1899 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1900 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1901 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1902 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1903 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1904 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1906 ## Dependency fine-tuning
1908 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES)))) \
1909 $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES))))
1910 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1912 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1913 $(BD_MODULE) : | %(prefix)/%(moduledir)
1914 $(BD_PKGMOD) : | $(PKGDIR)
1915 $(BD_KOBJ) : | $(KOBJSDIR)
1916 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1918 # Some include files need to be generated before the .c can be parsed.
1919 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1921 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1922 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1923 $(BD_DEPS) : $(BD_DFILE_DEPS)
1926 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1927 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1928 %(objdir)/Makefile.%(modname)%(modtype) \
1929 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1930 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1931 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1932 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1933 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1934 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1936 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1938 @$(ECHO) "Cleaning up for module %(modname)"
1941 endif # $(TARGET) in $(BD_ALLTARGETS)
1943 #------------------------------------------------------------------------------
1946 #------------------------------------------------------------------------------
1947 # Build a module skeleton
1948 # This is a stripped-down version of build_module, it only creates include files,
1949 # but no actual object. This is used when for plugins or classes with the same
1950 # API, but no actual implementation here.
1951 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1953 objdir=$(OBJDIR) prefix=$(AROSDIR)
1955 # Define metamake targets and their dependencies
1956 #MM- includes-all : %(mmake)-includes
1957 #MM %(mmake) : %(mmake)-includes core-linklibs
1958 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1959 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1960 #MM %(mmake)-linklib : %(mmake)-includes
1961 #MM %(mmake)-quick : %(mmake)-includes-quick
1962 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1963 #MM includes-generate-deps
1964 #MM %(mmake)-includes-quick
1965 #MM %(mmake)-includes-dirs
1966 #MM %(mmake)-makefile
1969 # All MetaMake targets defined by this macro
1970 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1971 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1972 %(mmake)-kobj %(mmake)-pkg
1974 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1977 $(error using %build_module_skeleton: modname may not be empty)
1980 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1983 # Default values for variables and arguments
1984 BD_DEFLINKLIBNAME := %(modname)
1985 BD_DEFDFLAGS := %(cflags)
1986 OBJDIR ?= $(GENDIR)/$(CURDIR)
1988 ## Create genmodule include Makefile for the module
1990 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1992 %rule_genmodule_makefile \
1993 modname=%(modname) modtype=%(modtype) \
1994 modsuffix=%(modsuffix) targetdir=%(objdir) \
1995 conffile=%(conffile)
1997 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1999 GLOB_MKDIRS += %(objdir)
2001 # Do not parse these statements if metatarget is not appropriate
2002 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
2004 include %(objdir)/Makefile.%(modname)%(modtype)
2006 BD_DEFMODDIR := $(%(modname)_MODDIR)
2009 ## include files generation
2011 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
2012 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2013 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2015 %(mmake)-includes-quick : %(mmake)-includes
2016 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2017 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2018 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2020 ifneq ($(%(modname)_INCLUDES),)
2021 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2022 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2023 conffile=%(conffile)
2025 %rule_copy_diff_multi \
2026 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2027 stampfile=%(objdir)/%(modname)_geninc
2029 %rule_copy_diff_multi \
2030 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2031 stampfile=%(objdir)/%(modname)_incs
2033 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2035 TMP%(modname)_INCDIRS := \
2036 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2037 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2038 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2039 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2043 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2044 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2045 conffile=%(conffile)
2047 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2048 $(BD_DEFLIBDEFSINC) :
2049 @$(ECHO) "generating $@"
2050 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2052 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2053 GLOB_MKDIRS += %(objdir)/include
2055 ## Extra genmodule src files generation
2057 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2058 modsuffix=%(modsuffix) targetdir=%(objdir) \
2059 conffile=%(conffile)
2061 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2062 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2063 %(objdir)/Makefile.%(modname)%(modtype) \
2064 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2065 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2066 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2067 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2068 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2070 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2072 @$(ECHO) "Cleaning up for module %(modname)"
2075 endif # $(TARGET) in $(BD_ALLTARGETS)
2077 #------------------------------------------------------------------------------
2080 #------------------------------------------------------------------------------
2082 # - mmake is the mmaketarget
2083 # - libname is the baselibname e.g. lib%(libname).a will be created
2084 # - files are the C source files to include in the lib. The list of files
2085 # has to be given without the .c suffix
2086 # - asmfiles are the asm files to include in the lib. The list of files has to
2087 # be given without the .s suffix
2088 # - objs additional object to link into the linklib. The objects have to be
2089 # given with full absolute path and the .o suffix.
2090 # - cflags are the flags to compile the source (default $(CFLAGS))
2091 # - dflags are the flags use during makedepend (default equal to cflags)
2092 # - aflags are the flags use during assembling (default $(AFLAGS))
2093 # - objdir is where the .o are generated
2094 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
2095 %define build_linklib mmake=/A libname=/A \
2096 files="$(basename $(call WILDCARD, *.c))" \
2097 cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
2098 asmfiles= objs= compiler=target \
2099 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
2101 # assign and generate the local variables used in this macro
2102 OBJDIR ?= $(GENDIR)/$(CURDIR)
2104 BD_FILES := %(files)
2105 BD_CXXFILES := %(cxxfiles)
2106 BD_ASMFILES := %(asmfiles)
2108 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2109 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2110 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2112 BD_OBJS := $(BD_ARCHOBJS) \
2113 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
2115 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2117 BD_CFLAGS := %(cflags)
2119 BD_DFLAGS := $(BD_CFLAGS)
2121 BD_DFLAGS := %(dflags)
2123 BD_AFLAGS := %(aflags)
2125 BD_LINKLIB := %(libdir)/lib%(libname).a
2127 .PHONY : %(mmake) %(mmake)-clean
2129 #MM %(mmake) : includes-generate-deps
2130 %(mmake) : $(BD_LINKLIB)
2134 @$(RM) $(BD_OBJS) $(BD_DEPS)
2136 ifeq ($(TARGET),%(mmake))
2137 ifneq ($(dir $(BD_FILES)),./)
2138 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2139 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
2142 %rule_compile basename=% targetdir=%(objdir) \
2143 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2144 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2145 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2146 %rule_assemble basename=% targetdir=%(objdir) \
2149 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2152 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2154 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2155 $(BD_LINKLIB) : | %(libdir)
2156 GLOB_MKDIRS += %(objdir) %(libdir)
2159 #------------------------------------------------------------------------------
2162 #------------------------------------------------------------------------------
2164 # - mmake is the mmaketarget
2165 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2166 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2167 # - subdir is the destination subdirectory of the catalogs
2168 # - name is the name of the destination catalog, without the .catalog suffix
2169 # - source is the path to the generated source code file
2170 # - dir is the base destination directory (default $(AROS_CATALOGS))
2171 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2172 # - srcdir is the directory in which the *.cd and *.ct files are searched
2174 %define build_catalogs mmake=/A name=/A subdir=/A \
2175 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2176 sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2178 ifeq (%(description),)
2179 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2181 BD_DESC := %(description)
2184 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2187 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2189 BD_LNGS := %(catalogs)
2192 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2193 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2196 %(mmake) : $(BD_OBJS) %(source)
2198 $(BD_OBJS) : | $(BD_DIRS)
2199 GLOB_MKDIRS += $(BD_DIRS)
2201 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2202 @$(ECHO) "Creating %(name) catalog for language $*."
2203 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2206 %(source) : BD_DESC := $(BD_DESC)
2207 %(source) : BD_SRC := $(BD_SRC)
2208 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2209 @$(ECHO) "Creating %(name) catalog source file $@"
2210 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2215 $(RM) $(BD_OBJS) %(source)
2217 .PHONY: %(mmake) %(mmake)-clean
2220 #-----------------------------------------------------------------------------
2223 #-----------------------------------------------------------------------------
2225 # - mmake is the mmaketarget
2226 # - icons is a list of icon base names (ie. without the .info suffix)
2227 # - dir is the destination directory
2228 # - srcdir is where *.png and *.info.src are searched
2229 #-----------------------------------------------------------------------------
2231 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2233 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2236 %(mmake) : $(BD_OBJS)
2240 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2241 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2242 @$(ILBMTOICON) $+ $@
2246 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2247 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2248 @$(ILBMTOICON) $+ $@
2252 $(BD_OBJS) : | %(dir)
2253 GLOB_MKDIRS += %(dir)
2255 %(mmake)-clean : FILES := $(BD_OBJS)
2260 .PHONY: %(mmake) %(mmake)-clean
2263 #-----------------------------------------------------------------------------
2266 #------------------------------------------------------------------------------
2267 # Compile files for an arch-specific replacement of code for a module
2268 # - files: the basenames of the C files to compile.
2269 # - asmfiles: the basenames of the asm files to assemble.
2270 # - mainmmake: the mmake of the module in the main directory to compile these
2271 # arch specific files for.
2272 # - maindir: the object directory for the main module
2273 # - arch: the arch for which to compile these files. It can have the form
2274 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2275 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2276 # - dflags: the flags used during creation of dependency file. If not specified
2277 # the same value as cflags will be used
2278 # - aflags: the flags used during assembling
2279 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2280 # the target compiler is used
2281 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2282 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2284 ifeq (%(files) %(asmfiles),)
2285 $(error no files or asmfiles given)
2288 %buildid targets="%(mainmmake)-%(arch)"
2290 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2291 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2292 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2293 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2294 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2295 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2296 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2297 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2298 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2299 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2300 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2301 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2302 #MM- %(mainmmake)-pkg : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2303 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2304 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2305 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2306 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2307 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2308 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2309 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2310 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2312 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2314 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2315 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2316 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2317 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2318 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2320 ifneq (%(modulename),)
2321 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2324 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2325 BD_TARGET := %(mainmmake)-%(arch)-quick
2327 BD_TARGET := %(mainmmake)-%(arch)
2331 ifeq ($(TARGET),$(BD_TARGET))
2332 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2333 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2334 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2335 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2338 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2339 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2342 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2345 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2347 ifeq ($(findstring %(compiler),host kernel target),)
2348 $(error unknown compiler %(compiler))
2350 ifeq (%(compiler),target)
2351 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2352 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2353 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2355 ifeq (%(compiler),host)
2356 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2357 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2358 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2360 ifeq (%(compiler),kernel)
2361 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2362 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2363 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2365 ifneq (%(modulename),)
2366 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2368 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2370 ifeq ($(TARGET),$(BD_TARGET))
2371 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2372 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2376 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2378 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2380 ifeq ($(TARGET),$(BD_TARGET))
2381 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2382 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2385 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2387 ifeq ($(TARGET),$(BD_TARGET))
2388 $(BD_OBJDIR$(BDID))/%.o : %.s
2389 %assemble_q opt=$(AFLAGS)
2390 $(BD_OBJDIR$(BDID))/%.o : %.S
2391 %assemble_q opt=$(AFLAGS)
2394 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2396 #------------------------------------------------------------------------------
2399 #------------------------------------------------------------------------------
2400 # generate asm files from c files (for debugging purposes)
2403 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2404 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2406 #------------------------------------------------------------------------------
2409 #------------------------------------------------------------------------------
2410 # Copy files from one directory to another.
2412 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2414 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2416 GLOB_MKDIRS += %(dst)
2422 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2425 #------------------------------------------------------------------------------
2428 #------------------------------------------------------------------------------
2429 # Copy a directory recursively to another place, preserving the original
2430 # hierarchical structure
2432 # src: the source directory whose content will be copied
2433 # dst: the directory where to copy src's content. If not existing, it will be made.
2435 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2437 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2438 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
2439 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
2441 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2442 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2444 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2449 %(mmake): | $(GENDIR)/$(CURDIR)
2450 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2451 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
2452 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2453 for d in $(%(mmake)_DIRS); do \
2454 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
2456 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2457 for f in $(%(mmake)_FILES); do \
2458 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2460 for dst in %(dst); do \
2461 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2465 #------------------------------------------------------------------------------
2468 #------------------------------------------------------------------------------
2469 # Copy include files into the includes directories. There are currently
2470 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2471 # for building tools that need to run on the host system $(GENINCDIR). The
2472 # $(GENINCDIR) path must not contain any references to the C runtime
2473 # library header files.
2475 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2476 dir= compiler=target
2478 ifeq ($(findstring %(compiler),host kernel target),)
2479 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2483 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2484 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2485 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2487 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2488 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2491 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2495 ifeq (%(compiler),target)
2498 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2499 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2501 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2504 BD_INCL_FILES += $(BD_INCL_FILES2)
2506 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2511 %(mmake) : $(BD_INCL_FILES)
2515 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2516 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2518 #------------------------------------------------------------------------------
2521 #------------------------------------------------------------------------------
2522 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2523 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2524 STUBS_MEM := $(addsuffix .o,$(STUBS))
2525 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2526 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2527 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2529 #MM- linklibs : hidd-%(hidd)-stubs
2530 #MM- %(parenttarget): hidd-%(hidd)-stubs
2531 #MM hidd-%(hidd)-stubs : includes includes-copy
2532 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2534 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2537 $(STUBS_OBJ) : $(STUBS_SRC)
2538 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2540 $(STUBS_DEP) : $(STUBS_SRC)
2541 %mkdepend_q flags=%(dflags)
2544 %mkdirs_q $(OBJDIR) $(LIBDIR)
2548 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2550 DEPS := $(DEPS) $(STUBS_DEP)
2553 #------------------------------------------------------------------------------
2556 #------------------------------------------------------------------------------
2557 # Build an imported source tree which uses the configure script from the
2558 # autoconf package. This rule will try to "integrate" the produced files as
2559 # much as possible in the AROS build, for example by putting libraries in the
2560 # standard library directory, includes in the standard include directory, and
2561 # so on. You can however override this behaviour.
2563 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2564 # be %(bindir) (or its deduced value) when running "make install", and
2565 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2566 # configure script some more parameters whose value depends upon the PROGDIR
2567 # env var, so that the program gets all its stuff installed in the proper place
2568 # when building it, but when running it from inside AROS it can also find that
2569 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2570 # the configuration parameters set when running ./configure
2572 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2573 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2574 # to the name which has to follow it.
2578 # - mmake = the meta make target.
2579 # - package = name of the package to be built.
2580 # - srcdir = the location of the unpacked source code. Defaults
2581 # to $(SRCDIR)/$(CURDIR).
2582 # - prefix = the target directory. Must be an absolute path of the
2583 # host system. Defaults to $(AROS_CONTRIB).
2584 # - aros_prefix = set a path which is valid within the AROS filesystem.
2585 # Defaults to the value of the prefix option.
2586 # - extraoptions = additional options for the configure script.
2587 # - extracflags = additional flags which are used for both C and C++.
2588 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2589 # Defaults to the value of the nix argument.
2590 # - nix = enable u*nix path handling, i.e. a path like
2591 # /progdir//./file will be translated to
2592 # progdir:file during run-time. Defaults to no.
2593 # - compiler = target, host or kernel. Defaults to target.
2594 # - install_target = the command used for installing. Defaults to install. Leave
2595 # it empty if you want to suppress installing.
2596 # - preconfigure = a metatarget which is executed before configure is called.
2597 # - postconfigure = a metatarget which is executed after configure is called.
2598 # - postinstall = a metatarget which is executed after installing.
2599 # - install_env = set additional options for installing.
2600 # - use_build_env = if yes the configuration environment is used for
2601 # installing, too. Defaults to no.
2603 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2607 # --prefix = $(aros_prefix)
2608 # progdir = $(aros_prefix)/bin
2611 # --prefix = /PROGDIR
2612 # --bindir = /PROGDIR
2613 # --sbindir = /PROGDIR
2615 # --includedir = /INCLUDE
2616 # --oldincludedir = /INCLUDE
2618 # --prefix = $(aros_prefix)
2621 # progdir = $(aros_prefix)
2624 # bindir = $(prefix)
2625 # sbindir = $(prefix)
2626 # libdir = $(AROS_LIB)
2627 # includedir = $(AROS_INCLUDES)
2628 # oldincludedir = $(AROS_INCLUDES)
2632 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2633 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2634 install_target=install preconfigure= postconfigure= postinstall= \
2635 install_env= use_build_env=no
2638 %(mmake)-prefix := %(prefix)
2640 %(mmake)-prefix := $(AROS_CONTRIB)
2643 ifneq (%(aros_prefix),)
2644 %(mmake)-aros_prefix := %(aros_prefix)
2646 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2650 %(mmake)-nix := -nix
2651 %(mmake)-volpfx := /
2652 %(mmake)-volsfx := /
2654 ifeq (%(nix_dir_layout),)
2655 %(mmake)-nix_dir_layout := yes
2658 %(mmake)-volsfx := :
2660 ifeq (%(nix_dir_layout),)
2661 %(mmake)-nix_dir_layout := no
2665 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2667 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2668 exec_prefix=$(%(mmake)-prefix) %(install_env)
2670 # Check if chosen compiler is valid
2671 ifeq ($(findstring %(compiler),host target kernel),)
2672 $(error unknown compiler %(compiler))
2675 # Set legacy 'host' variable based on chosen compiler
2676 ifeq (%(compiler),host)
2679 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2681 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2686 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2688 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2693 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2695 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2699 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2700 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2702 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2703 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2704 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2707 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2708 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2710 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2713 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2715 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2716 sbindir=$(%(mmake)-prefix) \
2717 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2718 oldincludedir=$(AROS_INCLUDES) %(install_env)
2721 ifneq ($(DEBUG),yes)
2722 %(mmake)-s_flag = -s
2725 # Set up build environment, and options for configure script
2726 ifeq (%(compiler),host)
2729 CXXCPP="$(HOST_CPP)" \
2730 CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2731 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2732 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2733 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2734 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2735 TARGET_NM="$(NM_PLAIN)"
2737 ifeq (%(compiler),target)
2739 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2740 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2741 CPP="$(TARGET_CPP)" \
2742 CXXCPP="$(TARGET_CPP)" \
2743 CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2744 CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2745 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2746 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2747 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2748 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2749 TARGET_NM="$(NM_PLAIN)" \
2750 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2751 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2752 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2753 --host=$(AROS_TARGET_CPU)-aros\
2754 --target=$(AROS_TARGET_CPU)-aros\
2756 --without-x --without-pic --disable-shared
2758 ifeq (%(compiler),kernel)
2760 CPP="$(KERNEL_CPP)" \
2761 CXXCPP="$(KERNEL_CPP)" \
2762 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2763 CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2764 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2765 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2766 TARGET_NM="$(NM_PLAIN)"
2767 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2768 --host=$(AROS_TARGET_CPU)-aros\
2769 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2770 --without-x --without-pic --disable-shared
2773 ifeq (%(use_build_env),yes)
2774 BUILD_ENV := $(CONFIG_ENV)
2778 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2780 # When building for the host, we don't need to build the
2781 # linklibs - this is especially true when building the
2782 # crosstool toolchain on 'foreign' architectures (such as
2783 # building PPC on x86)
2785 #MM- %(mmake)-host : setup includes %(mmake)-quick
2786 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2787 #MM- %(mmake): %(mmake)-%(compiler)
2789 # Using -j1 in install_command may result in a warning but finally
2790 # it does its job. make install for gcc does not work reliably for -jN
2792 ifneq (%(install_target),)
2793 %(mmake)-install_command = \
2794 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2795 -C $(%(mmake)-pkgdir) %(install_target) -j1
2797 %(mmake)-uninstall_command = \
2798 $(RM) $(%(mmake)-installflag) && \
2799 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2800 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2802 %(mmake)-install_command := true
2803 %(mmake)-uninstall_command := true
2806 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2809 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2811 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2812 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2813 $(RM) $(%(mmake)-installflag) && \
2814 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2815 -C $(%(mmake)-pkgdir) && \
2816 $(%(mmake)-install_command) && \
2817 $(TOUCH) $@ -r $^; \
2820 $(%(mmake)-pkgdir)/.files-touched:
2821 %mkdirs_q $(%(mmake)-pkgdir)
2822 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2826 %(mmake)-uninstall :
2827 $(%(mmake)-uninstall_command)
2830 %(mmake)-configure : $(%(mmake)-configflag)
2832 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2833 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2835 %mkdirs_q $(%(mmake)-pkgdir)
2836 cd $(%(mmake)-pkgdir) && \
2837 find . -name config.cache -exec $(RM) '{}' \; && \
2838 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2839 %(extraoptions) && \
2843 %(mmake)-clean : %(mmake)-uninstall
2844 @$(RM) $(%(mmake)-pkgdir)
2846 #------------------------------------------------------------------------------
2849 #------------------------------------------------------------------------------
2850 # Given an archive name, patches names and locations where to find them, fetch
2851 # the archive and the patches from any of those locations, unpack the archive
2852 # and then apply the patches.
2854 # Locations currently supported are http and ftp sites, plus local filesystem
2855 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2856 # the fetch.sh script needs to be modified, since this macro relies on that script.
2860 # - mmake = mmaketarget
2861 # - archive_origins = list of locations where to find the archive. They are tried
2862 # in sequence, until the archive is found and fetching it
2863 # succeeded. If not specified, the current directory is assumed.
2864 # - archive = the archive name. Mandatory.
2865 # - suffixes = a list of suffixes to append to the the package name plus the
2866 # version. Each one of them is tried until a matching archive is
2867 # found. They are appended to patches and these are tried the
2868 # same way as packages are.
2869 # - location = the local directory where to put the fetched archive and patches.
2870 # If not specified, the directory specified by destination is used.
2871 # - destination = the directory to unpack the archive to.
2872 # If not specified, the current directory is assumed.
2873 # - patches_origins = list of locations where to find the patches. They are tried
2874 # in sequence, until a patch is found and fetching it
2875 # succeeded. If not specified, the current directory is assumed.
2876 # - patches_specs = list of "patch specs". A patch spec is of the form
2877 # patch_name[:[patch_subdir][:patch_opt]].
2879 # - patch_name = the name of the patch file
2880 # - patch_subdir = the directory within \destination\ where to
2882 # - patch_opt = any options to pass to the `patch' command
2883 # when applying the patch.
2885 # The patch_subdir and patch_opt fields are optional.
2887 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2888 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2892 ifneq (%(location),)
2893 %(mmake)-location := %(location)
2895 %(mmake)-location := %(destination)
2900 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2901 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2903 #------------------------------------------------------------------------------
2906 #------------------------------------------------------------------------------
2907 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2908 # unpatched source tree and runs diff against this and a previously fetched and possibly
2909 # patched tree. Depending on what happens after patching during a normal build it might
2910 # give best results if the new patch is created directly after fetch.
2914 # - mmake = mmaketarget
2915 # - archive = archive base name
2916 # - srcdir = the top level directory the package is unpacked to, useful if
2917 # an archive unpacks to a directory other than its name suggests.
2918 # this should not be deeper than a single path element.
2919 # - suffixes = a list of suffixes to append to the the package name plus the
2920 # version. Each one of them is tried until a matching archive is
2922 # - destination = the directory to unpack the archive to.
2923 # - excludes = diff patterns to exclude files or directories from the patch
2925 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2929 ifneq (%(excludes),)
2930 %(mmake)-exclude := -X ./exclude.patterns
2934 %(mmake)-srcdir := %(srcdir)
2936 %(mmake)-srcdir := %(archive)
2941 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2942 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2943 cd %(destination)/tmp ; \
2944 $(FOR) f in %(excludes) ; do \
2945 $(ECHO) $$f >> ./exclude.patterns ; \
2947 diff -ruN $(%(mmake)-exclude) \
2948 $(%(mmake)-srcdir) \
2949 $(%(mmake)-srcdir).aros \
2950 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2951 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2952 $(RM) %(destination)/tmp
2954 #------------------------------------------------------------------------------
2957 #------------------------------------------------------------------------------
2958 # Joins the features of %fetch and %build_with_configure.
2960 # If a patch is provided, it *must* be named the following way:
2962 # <package name>-<version number>-aros.diff
2964 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2965 # CD'ing into the archive's extracted directory.
2967 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2968 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2969 # to make that patch fully comprehensive.
2973 # - mmake = the meta make target.
2974 # - package = the GNU package name, sans version and archive format suffixes.
2975 # - subpackage = ???
2976 # - compiler = same meaning as the one for the %build_with_configure macro.
2977 # - install_target = same meaning as the one for the %build_with_configure macro.
2978 # - version = the package's version number, or otherwise any other version string.
2979 # It gets appended to the package name to form the basename of the archive.
2980 # - suffixes = a list of suffixes to apped to the the package name plus the
2981 # version. Each one of them is tried until a matching archive is found.
2982 # Defaults to "tar.bz2 tar.gz".
2983 # - srcdir = the top level directory the package is unpacked to (see create_patch).
2984 # - builddir = override the location we expect to run configure/make in.
2985 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2986 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2987 # fetched or not. Default to no.
2988 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2989 # - prefix = same meaning as the one for the %build_with_configure macro.
2990 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
2991 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2992 # - extracflags = same meaning as the one for the %build_with_configure macro.
2993 # - preconfigure = same meaning as the one for the %build_with_configure macro.
2994 # - postconfigure = same meaning as the one for the %build_with_configure macro.
2995 # - postinstall = same meaning as the one for the %build_with_configure macro.
2996 # - install_env = same meaning as the one for the %build_with_configure macro.
2997 # - use_build_env = same meaning as the one for the %build_with_configure macro.
2998 # - nix = same meaning as the one for the %build_with_configure macro.
2999 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
3000 # - create_pkg = create a distributable package of the compiled sources, defaults to no
3002 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3003 version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3004 prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
3005 install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3007 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3008 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3009 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3010 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3012 %(mmake)-archbase := %(package)-%(version)
3014 ifeq (%(compiler),host)
3015 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
3017 %(mmake)-portdir := $(PORTSDIR)/%(package)
3021 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3023 %(mmake)-prefix := %(prefix)
3026 ifneq (%(subpackage),)
3027 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
3029 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
3033 %(mmake)-%(subpackage)-srcdir := %(srcdir)
3035 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
3038 ifneq (%(builddir),)
3039 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3041 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)
3045 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3047 %(mmake)-%(subpackage)-patches_specs := ::
3050 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3051 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3052 archive_origins=". %(package_repo)" \
3053 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3055 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3056 archive=$(%(mmake)-%(subpackage)-archbase) \
3057 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3058 suffixes="%(suffixes)" \
3059 destination=$(%(mmake)-portdir)
3061 #MM- %(mmake) : %(mmake)-%(subpackage)
3063 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3065 %(mmake)-%(subpackage)-package-basename := \
3066 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3068 ifneq (%(create_pkg),no)
3069 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3072 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3073 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3074 install_env=%(install_env) use_build_env=%(use_build_env) \
3075 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3076 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3077 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3079 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3080 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3083 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3085 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3086 #that $^ and $@ have exactly the same mtime, and in that case make tries
3087 #to rebuild $@ again, which would fail because the directory where
3088 #the package got installed would not exist anymore.
3089 #We work this around by using an if statement to manually check the mtimes.
3090 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3091 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3093 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3094 mkdir -p "$(DISTDIR)/Packages" ; \
3095 mkdir -p "$(%(mmake)-prefix)" ; \
3096 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3097 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3098 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3101 #------------------------------------------------------------------------------
3104 #------------------------------------------------------------------------------
3105 # Joins the features of %fetch and %build_with_configure, taking advantage of
3106 # the naming scheme of GNU packages. GNU packages names are in the form
3108 # <package name>-<version number>.<archive format suffix>
3110 # If a patch is provided, it *must* be named the following way:
3112 # <package name>-<version number>-aros.diff
3114 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3115 # CD'ing into the archive's extracted directory.
3117 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3118 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3119 # to make that patch fully comprehensive.
3121 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3125 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3127 # - prefix = defaults to $(GNUDIR).
3128 # - aros_prefix = defaults to /GNU.
3130 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3131 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3132 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
3134 GNU_REPOSITORY := gnu://
3136 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3137 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3138 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3139 patch="%(patch)" patch_repo="%(patch_repo)" \
3140 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3141 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3144 #------------------------------------------------------------------------------
3147 #------------------------------------------------------------------------------
3148 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3149 # that the package is a "Development" package, and as such it needs to be placed
3150 # under the $(AROS_DEVELOPMENT) directory, as a default.
3152 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3153 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3154 # "mmake" argument, because the metatarget is implicitely defined as
3156 # #MM- development-%(package)
3158 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3159 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3160 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
3162 #MM- development : development-%(package)
3165 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3166 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
3167 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3168 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3169 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3172 postinstall-%(package)-delete-la-files:
3173 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3176 #------------------------------------------------------------------------------
3178 # Builds a kickstart package in PKG format
3182 # - mmake = target name
3183 # - file = destination file name with path
3184 # - startup = the file which will be put first
3186 # Other arguments are self-explanatory
3188 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
3190 PKG_CLASSES := $(addsuffix .class, %(classes))
3191 PKG_DEVICES := $(addsuffix .device, %(devs))
3192 PKG_HANDLERS := $(addsuffix -handler, %(handlers))
3193 PKG_HIDD := $(addsuffix .hidd, %(hidds))
3194 PKG_LIBS := $(addsuffix .library, %(libs))
3195 PKG_RESOURCES := $(addsuffix .resource, %(res))
3197 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
3198 PKG_DIR := $(dir %(file))
3199 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
3205 %(mmake)-quick : %(file)
3207 %(file): PKG_FILES := $(PKG_FILES)
3208 %(file): $(PKG_DEPS) | $(PKG_DIR)
3209 @$(ECHO) Packaging $@...
3210 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
3212 %compress_file mmake=%(mmake) file=%(file)
3214 GLOB_MKDIRS += $(PKG_DIR)
3218 #------------------------------------------------------------------------------
3219 # Compresses %(file) with a gzip.
3220 # Good in conjunction with for example %build_prog
3222 %define compress_file mmake=/A file=/A
3224 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3227 %(mmake)-gz-quick : %(file).gz
3230 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3235 #------------------------------------------------------------------------------
3236 # Links a kickstart module in ELF format
3237 # Arguments are similar to make_package
3239 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3240 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3242 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3243 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3244 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3245 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3246 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3247 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3250 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3252 KOBJ_STARTUP := %(startup)
3255 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3257 TMP_LDFLAGS := %(ldflags)
3259 # Make a list of the lib files this program depends on.
3260 # In LDFLAGS remove white space between -L and directory
3261 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3262 # Filter out only the libdirs and remove -L
3263 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3265 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3266 # Add normal linklib path
3267 TMP_DIRS += $(LIBDIR)/
3268 # add lib and .a to static linklib names
3269 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3270 # search for the linklibs in the given path, ignore ones not found
3271 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3272 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3275 TMP_DIRS += $(dir %(file))
3277 TMP_LDFLAGS += $(GENMAP) %(map)
3278 TMP_DIRS += $(dir %(map))
3281 #MM %(mmake) : %(deps)
3287 %(mmake)-quick : %(file)
3289 %(file): KOBJS := $(KOBJS)
3290 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3291 -nostdc -nosysbase -Wl,-Ur
3292 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3293 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3294 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3295 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3298 %compress_file mmake=%(mmake) file=%(file)
3300 GLOB_MKDIRS += $(TMP_DIRS)