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 $(CURDIR)/$(notdir %(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 err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
90 @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
91 $(GENMAP) %(objdir)/%(module).map \
92 %(objs) %(libs) %(endtag) \
93 -o $@ 2>&1 > %(objdir)/%(err); \
95 cat %(objdir)/%(err); \
97 echo "$(AROS_CC) $(NOSTARTUP_LDFLAGS) %(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 $(CURDIR)/$(notdir %(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 nix=no
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)
316 $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
318 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
320 $(TMP_TARGETBASE).o : %(basename).c
321 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
325 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
327 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
331 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
333 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
336 $(TMP_TARGETBASE).d : %(basename).c
337 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
339 #------------------------------------------------------------------------------
342 #------------------------------------------------------------------------------
343 # Generate a rule to compile a C++ source file to an object file and generate
344 # the dependency file. Basename may contain a directory part, then the source
345 # file has to be in that directory. The generated file will be put in the
346 # object directory without the directory.
348 # - basename: the basename of the file to compile. Use % for a wildcard rule
349 # - cflags (default $(CFLAGS)): the C flags to use for compilation
350 # - dflags: the flags used during creation of dependency file. If not specified
351 # the same value as cflags will be used
352 # - targetdir: the directory to put the .o file and the .d file. By default
353 # it is put in the same directory as the .c file
354 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
357 TMP_TARGETBASE := %(basename)
359 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
362 # Adjust compiler flags to suit C++
363 TMP_CXXFLAGS := %(cflags)
364 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
365 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
367 ifeq ($(findstring %(compiler),host kernel target),)
368 $(error unknown compiler %(compiler))
370 ifeq (%(compiler),target)
371 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
372 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
373 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
374 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
375 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
376 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
378 ifeq (%(compiler),host)
379 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
380 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
386 ifeq (%(compiler),kernel)
387 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
388 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
389 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
390 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
391 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
392 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
396 $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_CXXFLAGS)
398 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
400 $(TMP_TARGETBASE).o : %(basename).cpp
401 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
405 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
407 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
411 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
413 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
416 $(TMP_TARGETBASE).d : %(basename).cpp
417 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
419 #------------------------------------------------------------------------------
422 #------------------------------------------------------------------------------
423 # Generate a rule to compile multiple C source files to an object file and
424 # generate the corresponding dependency files. The generated file will be put
425 # in the object directory without the directory part of the source file.
427 # - basenames: the basenames of the files to compile. The names may include
428 # relative or absolute path names. No wildcard is allowed
429 # - cflags (default $(CFLAGS)): the C flags to use for compilation
430 # - dflags: the flags used during creation of dependency file. If not specified
431 # the same value as cflags will be used
432 # - targetdir: the directory to put the .o file and the .d file. By default
433 # it is put in the same directory as the .c file. When targetdir is not
434 # empty, path names will be stripped from the file names so that all files
435 # are in that dir and not in subdirectories.
436 # - compiler (default target): compiler to use, target, kernel or host
437 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
441 TMP_TARGETS := $(addsuffix .o,%(basenames))
442 TMP_DTARGETS := $(addsuffix .d,%(basenames))
445 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
446 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
447 TMP_WILDCARD := %(targetdir)/%
449 # Be sure that all .c files are generated
450 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
452 # Be sure that all .c files are found
453 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
454 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
455 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
457 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
458 vpath %.c $(TMP_DIRS)
463 ifeq ($(findstring %(compiler),host kernel target),)
464 $(error unknown compiler %(compiler))
466 ifeq (%(compiler),target)
467 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
471 ifeq (%(compiler),host)
472 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
473 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
474 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
476 ifeq (%(compiler),kernel)
477 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
478 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
479 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
482 $(TMP_TARGETS) : CFLAGS := %(cflags)
483 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
484 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
487 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
489 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
491 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
492 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
494 #------------------------------------------------------------------------------
497 #------------------------------------------------------------------------------
498 # Generate a rule to compile multiple C++ source files to an object file and
499 # generate the corresponding dependency files. The generated file will be put
500 # in the object directory without the directory part of the source file.
502 # - basenames: the basenames of the files to compile. The names may include
503 # relative or absolute path names. No wildcard is allowed
504 # - cflags (default $(CFLAGS)): the C flags to use for compilation
505 # - dflags: the flags used during creation of dependency file. If not specified
506 # the same value as cflags will be used
507 # - targetdir: the directory to put the .o file and the .d file. By default
508 # it is put in the same directory as the .c file. When targetdir is not
509 # empty, path names will be stripped from the file names so that all files
510 # are in that dir and not in subdirectories.
511 # - compiler (default target): compiler to use, target, kernel or host
512 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
513 targetdir= compiler=target
515 # Adjust compiler flags to suit C++
516 TMP_CXXFLAGS := %(cflags)
517 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
518 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
521 TMP_TARGETS := $(addsuffix .o,%(basenames))
522 TMP_DTARGETS := $(addsuffix .d,%(basenames))
525 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
526 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
527 TMP_WILDCARD := %(targetdir)/%
529 # Be sure that all .cpp files are generated
530 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .cpp,%(basenames))
532 # Be sure that all .cpp files are found
533 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
534 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
535 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
537 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
538 vpath %.cpp $(TMP_DIRS)
542 # Define the use of cross compiler
543 ifeq ($(TARGET_CXX),)
544 TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-g++
546 TMP_CC := $(TARGET_CXX)
549 ifeq ($(findstring %(compiler),host kernel target),)
550 $(error unknown compiler %(compiler))
552 ifeq (%(compiler),target)
553 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
554 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
555 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
557 ifeq (%(compiler),host)
558 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
559 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
560 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
562 ifeq (%(compiler),kernel)
563 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
564 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
565 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
568 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
569 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
570 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
573 $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
575 ifeq (%(dflags),%(cflags))
576 $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
578 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
581 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
582 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
584 #------------------------------------------------------------------------------
587 #------------------------------------------------------------------------------
588 # Generate a rule to compile an ObjC source file to an object file and generate
589 # the dependency file. Basename may contain a directory part, then the source
590 # file has to be in that directory. The generated file will be put in the
591 # object directory without the directory.
593 # - basename: the basename of the file to compile. Use % for a wildcard rule
594 # - cflags (default $(CFLAGS)): the C flags to use for compilation
595 # - dflags: the flags used during creation of dependency file. If not specified
596 # the same value as cflags will be used
597 # - targetdir: the directory to put the .o file and the .d file. By default
598 # it is put in the same directory as the .m file
599 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
602 TMP_TARGETBASE := %(basename)
604 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
607 # Adjust compiler flags to suit ObjC
608 TMP_OBJCFLAGS := %(cflags)
609 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
610 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
612 ifeq ($(findstring %(compiler),host kernel target),)
613 $(error unknown compiler %(compiler))
615 ifeq (%(compiler),target)
616 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
617 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
618 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
619 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
623 ifeq (%(compiler),host)
624 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
625 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
626 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
627 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
628 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
629 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
631 ifeq (%(compiler),kernel)
632 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
633 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
634 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
635 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
636 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
637 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
641 $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_OBJCFLAGS)
643 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
645 $(TMP_TARGETBASE).o : %(basename).m
646 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
650 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
652 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
656 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
658 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
661 $(TMP_TARGETBASE).d : %(basename).m
662 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
664 #------------------------------------------------------------------------------
666 #------------------------------------------------------------------------------
667 # Generate a rule to compile multiple ObjC source files to an object file and
668 # generate the corresponding dependency files. The generated file will be put
669 # in the object directory without the directory part of the source file.
671 # - basenames: the basenames of the files to compile. The names may include
672 # relative or absolute path names. No wildcard is allowed
673 # - cflags (default $(CFLAGS)): the C flags to use for compilation
674 # - dflags: the flags used during creation of dependency file. If not specified
675 # the same value as cflags will be used
676 # - targetdir: the directory to put the .o file and the .d file. By default
677 # it is put in the same directory as the .m file. When targetdir is not
678 # empty, path names will be stripped from the file names so that all files
679 # are in that dir and not in subdirectories.
680 # - compiler (default target): compiler to use, target, kernel or host
681 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
682 targetdir= compiler=target
684 # Adjust compiler flags to suit ObjC
685 TMP_OBJCFLAGS := %(cflags)
686 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
687 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
690 TMP_TARGETS := $(addsuffix .o,%(basenames))
691 TMP_DTARGETS := $(addsuffix .d,%(basenames))
694 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
695 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
696 TMP_WILDCARD := %(targetdir)/%
698 # Be sure that all .m files are generated
699 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
701 # Be sure that all .m files are found
702 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
703 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
704 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
706 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
707 vpath %.m $(TMP_DIRS)
711 # Define the use of cross compiler
712 ifeq ($(TARGET_OBJC),)
713 TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-gcc
715 TMP_CC := $(TARGET_OBJC)
718 ifeq ($(findstring %(compiler),host kernel target),)
719 $(error unknown compiler %(compiler))
721 ifeq (%(compiler),target)
722 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
723 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
724 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
726 ifeq (%(compiler),host)
727 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
728 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
729 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
731 ifeq (%(compiler),kernel)
732 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
733 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
734 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
737 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
738 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
739 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
742 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
744 ifeq (%(dflags),%(cflags))
745 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
747 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
750 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
751 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
753 #------------------------------------------------------------------------------
756 #------------------------------------------------------------------------------
757 # Make an alias from one arch specific build to another arch.
759 # - mainmmake: the mmake of the module in the main tree
760 # - arch: the current arch
761 # - alias: the alias to which this should point
762 %define rule_archalias mainmmake=\A arch=\A alias=\A
764 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
766 #------------------------------------------------------------------------------
769 #------------------------------------------------------------------------------
770 # Generate a rule to assemble a source file to an object file. Basename may
771 # contain a directory part, then the source file has to be in that directory.
772 # The generated file will be put in the object directory without the directory.
774 # - basename: the basename of the file to compile. Use % for a wildcard rule
775 # - flags (default $(AFLAGS)): the asm flags to use for assembling
776 # - targetdir: the directory to put the .o file in. By default it is put in the
777 # same directory as the .s file
778 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
781 %(basename).o : AFLAGS := %(aflags)
782 %(basename).o : %(basename).s
784 %(basename).o : %(basename).S
788 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
789 %(targetdir)/$(notdir %(basename)).o : %(basename).s
791 %(targetdir)/$(notdir %(basename)).o : %(basename).S
796 #------------------------------------------------------------------------------
799 #------------------------------------------------------------------------------
800 # Generate a rule to assemble multiple source files to an object file. The
801 # generated file will be put in the object directory with the directory part
802 # of the source file stripped off.
804 # - basenames: the basenames of the files to compile. The names may include
805 # relative or absolute path names. No wildcard is allowed
806 # - aflags (default $(AFLAGS)): the flags to use for assembly
807 # - targetdir: the directory to put the .o file and the .d file. By default
808 # it is put in the same directory as the .c file. When targetdir is not
809 # empty, path names will be stripped from the file names so that all files
810 # are in that dir and not in subdirectories.
811 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
814 TMP_TARGETS := $(addsuffix .o,%(basenames))
817 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
818 TMP_WILDCARD := %(targetdir)/%
820 # Be sure that all .s files are generated
821 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
823 # Be sure that all .c files are found
824 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
825 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
826 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
828 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
829 vpath %%(suffix) $(TMP_DIRS)
834 ifeq ($(findstring %(compiler),host kernel target),)
835 $(error unknown compiler %(compiler))
837 ifeq (%(compiler),target)
838 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
840 ifeq (%(compiler),host)
841 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
843 ifeq (%(compiler),kernel)
844 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
847 $(TMP_TARGETS) : AFLAGS := %(aflags)
848 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
849 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
851 #------------------------------------------------------------------------------
854 #------------------------------------------------------------------------------
855 # Link %(objs) to %(prog) using the libraries in %(uselibs)
856 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
857 usehostlibs= usestartup=yes detach=no nix=no linker=target
862 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
864 ifeq (%(usestartup),no)
865 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
866 TMP_EXTRA_LIBS += arosc.static
867 ifeq (%(linker),target)
868 TMP_EXTRA_LIBS += libinit autoinit
872 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
875 # Make a list of the lib files this program depends on.
876 # In LDFLAGS remove white space between -L and directory
877 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
878 # Filter out only the libdirs and remove -L
879 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
881 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
882 # Add normal linklib path
883 TMP_DIRS += $(LIBDIR)/
884 # add lib and .a to static linklib names
885 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
886 ifeq (%(usestartup),yes)
887 TMP_LIBS += startup.o
892 # search for the linklibs in the given path, ignore ones not found
893 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
894 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
897 ifeq (%(linker),target)
898 %(prog) : CMD:=$(TARGET_CC)
899 %(prog) : STRIPCMD:=$(TARGET_STRIP)
901 ifeq (%(linker),host)
902 %(prog) : CMD:=$(HOST_CC)
903 %(prog) : STRIPCMD:=$(HOST_STRIP)
905 ifeq (%(linker),kernel)
906 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
907 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
910 %(prog) : OBJS := %(objs)
911 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
912 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
913 %(prog) : %(objs) $(TMP_DEPLIBS)
914 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
916 #------------------------------------------------------------------------------
919 #------------------------------------------------------------------------------
920 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
921 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
922 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
923 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
924 usestartup=yes detach=no
929 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
931 ifeq (%(usestartup),no)
932 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
933 TMP_EXTRA_LIBS += arosc.static libinit autoinit
936 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
939 # Make a list of the lib files the programs depend on.
940 # In LDFLAGS remove white space between -L and directory
941 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
942 # Filter out only the libdirs and remove -L
943 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
945 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
946 # Add normal linklib path
947 TMP_DIRS += $(LIBDIR)/
948 # add lib and .a to static linklib names
949 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
950 # search for the linklibs in the given path, ignore ones not found
951 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
952 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
955 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
956 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
957 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
958 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
960 #------------------------------------------------------------------------------
963 #------------------------------------------------------------------------------
964 # Link the %(objs) to the library %(libdir)/lib%(libname).a
965 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
967 ifeq (%(linker),target)
968 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
969 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
971 ifeq (%(linker),host)
972 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
973 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
975 ifeq (%(linker),kernel)
976 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
977 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
980 %(libdir)/lib%(libname).a : %(objs)
981 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
983 #------------------------------------------------------------------------------
985 #------------------------------------------------------------------------------
986 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
987 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
988 # The -noarosc flag is added so that modules are not linked with arosc.library
989 # (see /config/specs.in file)
990 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
991 ldflags=$(LDFLAGS) uselibs= usehostlibs=
993 TMP_LDFLAGS := %(ldflags)
994 # Make a list of the lib files the programs depend on.
995 # In LDFLAGS remove white space between -L and directory
996 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
997 # Filter out only the libdirs and remove -L
998 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1000 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1001 # Add normal linklib path
1002 TMP_DIRS += $(LIBDIR)/
1003 # add lib and .a to static linklib names
1004 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
1005 # search for the linklibs in the given path, ignore ones not found
1006 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1007 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1010 %(module) : LIB_NAMES := %(uselibs)
1011 %(module) : OBJS := %(objs)
1012 %(module) : ENDTAG := %(endobj)
1013 %(module) : ERR := %(err)
1014 %(module) : OBJDIR := %(objdir)
1015 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1016 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1017 -L/usr/lib $(addprefix -l,%(usehostlibs))
1018 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1019 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
1022 #------------------------------------------------------------------------------
1025 #------------------------------------------------------------------------------
1026 # Generate the libdefs.h include file for a module.
1027 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1029 TMP_TARGET := %(modname)_libdefs.h
1030 TMP_DEPS := $(GENMODULE)
1032 ifneq (%(conffile),)
1033 ifeq ($(dir %(conffile)),./)
1034 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1035 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1037 TMP_OPTS += -c %(conffile)
1038 TMP_DEPS += %(conffile)
1041 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1042 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1044 ifneq (%(modsuffix),)
1045 TMP_OPTS += -s %(modsuffix)
1047 ifneq (%(targetdir),)
1048 TMP_OPTS += -d %(targetdir)
1049 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1052 TMP_OPTS += -v %(version)
1055 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1056 $(TMP_TARGET) : MODNAME := %(modname)
1057 $(TMP_TARGET) : MODTYPE := %(modtype)
1058 $(TMP_TARGET) : $(TMP_DEPS)
1059 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1060 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1062 #------------------------------------------------------------------------------
1064 #------------------------------------------------------------------------------
1065 # Generate the _lib.fd file for a module.
1066 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1068 TMP_TARGET := %(modname)_lib.fd
1069 TMP_DEPS := $(GENMODULE)
1071 ifneq (%(conffile),)
1072 ifeq ($(dir %(conffile)),./)
1073 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1074 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1076 TMP_OPTS += -c %(conffile)
1077 TMP_DEPS += %(conffile)
1080 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1081 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1083 ifneq (%(modsuffix),)
1084 TMP_OPTS += -s %(modsuffix)
1086 ifneq (%(targetdir),)
1087 TMP_OPTS += -d %(targetdir)
1088 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1091 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1092 $(TMP_TARGET) : MODNAME := %(modname)
1093 $(TMP_TARGET) : MODTYPE := %(modtype)
1094 $(TMP_TARGET) : $(TMP_DEPS)
1095 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1096 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1098 #------------------------------------------------------------------------------
1100 #------------------------------------------------------------------------------
1101 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1102 # generated file in this Makefile
1103 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1106 TMP_TARGET := Makefile.%(modname)%(modtype)
1107 TMP_DEPS := $(GENMODULE)
1109 ifneq (%(conffile),)
1110 ifeq ($(dir %(conffile)),./)
1111 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1112 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1114 TMP_OPTS += -c %(conffile)
1115 TMP_DEPS += %(conffile)
1118 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1119 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1121 ifneq (%(modsuffix),)
1122 TMP_OPTS += -s %(modsuffix)
1124 ifneq (%(targetdir),)
1125 TMP_OPTS += -d %(targetdir)
1126 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1129 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1130 $(TMP_TARGET) : MODNAME := %(modname)
1131 $(TMP_TARGET) : MODTYPE := %(modtype)
1132 $(TMP_TARGET) : $(TMP_DEPS)
1133 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1135 #------------------------------------------------------------------------------
1138 #------------------------------------------------------------------------------
1139 # Generate the support files for compiling a module. This includes include
1140 # files and source files. This rule has to be preceeded by
1141 # %rule_genmodule_makefile
1142 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1145 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1146 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1147 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1148 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1150 TMP_DEPS := $(GENMODULE)
1153 ifneq (%(conffile),)
1154 ifeq ($(dir %(conffile)),./)
1155 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1156 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1158 TMP_OPTS += -c %(conffile)
1159 TMP_DEPS += %(conffile)
1162 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1163 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1165 ifneq (%(modsuffix),)
1166 TMP_OPTS += -s %(modsuffix)
1168 ifneq (%(targetdir),)
1169 TMP_OPTS += -d %(targetdir)
1170 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1171 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1174 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1175 $(TMP_TARGETS) : MODNAME := %(modname)
1176 $(TMP_TARGETS) : MODTYPE := %(modtype)
1177 $(TMP_TARGETS) : $(TMP_DEPS)
1178 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1179 ifneq (%(conffile),lib.conf)
1180 @$(IF) $(TEST) -f lib.conf; then \
1181 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1184 @$(IF) $(TEST) -f libdefs.h; then \
1185 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1187 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1189 #------------------------------------------------------------------------------
1192 #------------------------------------------------------------------------------
1193 # Generate the support files for compiling a module. This includes include
1194 # files and source files.
1195 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1196 targetdir= conffile=
1198 ifneq ($(%(modname)_INCLUDES),)
1199 TMP_TARGETS := $(%(modname)_INCLUDES)
1201 TMP_DEPS := $(GENMODULE)
1204 ifneq (%(conffile),)
1205 ifeq ($(dir %(conffile)),./)
1206 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1207 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1209 TMP_OPTS += -c %(conffile)
1210 TMP_DEPS += %(conffile)
1213 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1214 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1216 ifneq (%(modsuffix),)
1217 TMP_OPTS += -s %(modsuffix)
1219 ifneq (%(targetdir),)
1220 TMP_OPTS += -d %(targetdir)
1221 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1224 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1225 $(TMP_TARGETS) : MODNAME := %(modname)
1226 $(TMP_TARGETS) : MODTYPE := %(modtype)
1227 $(TMP_TARGETS) : $(TMP_DEPS)
1228 @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1229 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1232 #------------------------------------------------------------------------------
1234 #------------------------------------------------------------------------------
1235 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1236 # 'start' is an optional starting address
1237 # 'ldflags' is optional additional flags for the linker
1238 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1240 BD_OUTDIR := $(dir %(file))
1241 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1242 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1243 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1244 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1245 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1248 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1250 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1251 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
1252 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1253 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1255 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1256 GLOB_MKDIRS += $(BD_OUTDIR)
1261 #------------------------------------------------------------------------------
1262 # Common rules for all makefiles
1264 # Delete generated makefiles
1267 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1269 include $(SRCDIR)/config/make.tail
1271 BDID := $(BDTARGETID)
1273 #------------------------------------------------------------------------------
1276 #############################################################################
1277 #############################################################################
1279 ## Here are the mmakefile build macros. These are macros that takes care ##
1280 ## of everything to go from the sources to the generated target. Also all ##
1281 ## intermediate files and directories that are needed are created by these ##
1284 #############################################################################
1285 #############################################################################
1287 #------------------------------------------------------------------------------
1289 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1291 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1292 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1293 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1294 compiler=target linker=
1298 BD_PROGNAME := %(progname)
1299 BD_OBJDIR := %(objdir)
1300 BD_TARGETDIR := %(targetdir)
1301 BD_LINKER := %(linker)
1303 # If not supplied, linker is equal to compiler
1304 ifeq ($(BD_LINKER),)
1305 BD_LINKER := %(compiler)
1308 BD_FILES := %(files)
1309 BD_CXXFILES := %(cxxfiles)
1310 BD_OBJCFILES := %(objcfiles)
1311 BD_ASMFILES := %(asmfiles)
1313 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1314 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1315 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1317 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1318 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1319 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1321 BD_CFLAGS := %(cflags)
1322 BD_AFLAGS := %(aflags)
1323 BD_DFLAGS := %(dflags)
1324 BD_LDFLAGS := %(ldflags)
1327 %(mmake)-quick : %(mmake)
1329 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1330 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1332 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1333 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1334 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1335 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1336 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1337 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1338 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1339 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1340 aflags=$(BD_AFLAGS) compiler=%(compiler)
1342 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1343 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1344 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1345 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1350 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1352 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1353 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1354 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1356 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1359 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1363 #------------------------------------------------------------------------------
1366 #------------------------------------------------------------------------------
1367 # Build programs, for every C file an executable will be built with the same
1368 # name as the C file
1369 %define build_progs mmake=/A files=/A nix=no \
1370 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1371 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1372 uselibs= usehostlibs= usestartup=yes detach=no
1376 BD_OBJDIR := %(objdir)
1377 BD_TARGETDIR := %(targetdir)
1379 BD_FILES := %(files)
1380 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1381 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1382 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1384 BD_CFLAGS := %(cflags)
1385 BD_DFLAGS := %(dflags)
1386 BD_LDFLAGS := %(ldflags)
1389 %(mmake)-quick : %(mmake)
1391 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1392 %(mmake) : $(BD_EXES)
1394 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1395 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1396 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1398 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1399 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1400 ldflags=$(BD_LDFLAGS) \
1401 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1402 usestartup="%(usestartup)" detach="%(detach)"
1406 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1408 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1409 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1410 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1412 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1415 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1419 #------------------------------------------------------------------------------
1422 #------------------------------------------------------------------------------
1424 # This is a bare version: It just compiles and links the given files. It is
1425 # assumed that all needed boiler plate code is in the files. This should only
1426 # be used for compiling external code. For AROS code use %build_module
1427 %define build_module_simple mmake=/A modname=/A modtype=/A \
1428 files="$(basename $(call WILDCARD, *.c))" \
1429 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1430 objdir=$(OBJDIR) moduledir= \
1431 uselibs= usehostlibs= compiler=target
1433 # Define metamake targets and their dependencies
1434 #MM %(mmake) : core-linklibs includes-generate-deps
1435 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1436 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1437 #MM %(mmake)-kobj-quick
1438 #MM %(mmake)-pkg-quick
1442 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1444 .PHONY : $(BD_ALLTARGETS)
1447 $(error using %build_module_simple: modname may not be empty)
1450 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1453 # Default values for variables and arguments
1454 BD_DEFLINKLIBNAME := %(modname)
1455 BD_DEFDFLAGS := %(cflags)
1456 OBJDIR ?= $(GENDIR)/$(CURDIR)
1457 BD_MODDIR := %(moduledir)
1458 ifeq ($(BD_MODDIR),)
1459 ifeq (%(modtype),library)
1460 BD_MODDIR := $(AROS_LIBS)
1462 ifeq (%(modtype),gadget)
1463 BD_MODDIR := $(AROS_GADGETS)
1465 ifeq (%(modtype),datatype)
1466 BD_MODDIR := $(AROS_DATATYPES)
1468 ifeq (%(modtype),handler)
1469 BD_MODDIR := $(AROS_FS)
1471 ifeq (%(modtype),device)
1472 BD_MODDIR := $(AROS_DEVS)
1474 ifeq (%(modtype),resource)
1475 BD_MODDIR := $(AROS_RESOURCES)
1477 ifeq (%(modtype),hook)
1478 BD_MODDIR := $(AROS_RESOURCES)
1480 ifeq (%(modtype),mui)
1481 BD_MODDIR := $(AROS_CLASSES)/Zune
1483 ifeq (%(modtype),mcc)
1484 BD_MODDIR := $(AROS_CLASSES)/Zune
1486 ifeq (%(modtype),mcp)
1487 BD_MODDIR := $(AROS_CLASSES)/Zune
1489 ifeq (%(modtype),usbclass)
1490 BD_MODDIR := $(AROS_CLASSES)/USB
1492 ifeq (%(modtype),hidd)
1493 BD_MODDIR := $(AROS_DRIVERS)
1495 ifeq (%(modtype),printer)
1496 BD_MODDIR := $(AROS_PRINTERS)
1499 ifeq ($(BD_MODDIR),)
1500 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1503 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1504 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1505 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1507 %rule_compile_multi \
1508 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1509 cflags="%(cflags)" dflags="%(dflags)" \
1510 compiler=%(compiler)
1512 # Handlers use dash instead of dot in their names
1513 ifeq (%(modtype),handler)
1514 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1515 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1517 ifeq (%(modtype),printer)
1518 BD_MODULE := $(BD_MODDIR)/%(modname)
1519 BD_PKGMOD := $(PKGDIR)/%(modname)
1521 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1522 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1525 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1527 %(mmake)-quick : %(mmake)
1528 %(mmake)-pkg-quick : $(BD_PKGMOD)
1529 %(mmake)-kobj-quick : $(BD_KOBJ)
1530 %(mmake) : $(BD_MODULE)
1531 %(mmake)-pkg : $(BD_PKGMOD)
1532 %(mmake)-kobj : $(BD_KOBJ)
1534 # The module is linked from all the compiled .o files
1535 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1537 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1538 # This breaks con-handler build. Here we work around this
1539 ifeq (%(modname),con)
1540 BD_ERR := $(notdir $(BD_MODULE)).err
1542 BD_ERR := %(modname).err
1545 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1546 endobj= err=$(BD_ERR) objdir=%(objdir) \
1547 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1548 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1550 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1551 endobj= err=$(BD_ERR) objdir=%(objdir) \
1552 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1553 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1555 # Link kernel object file
1556 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1558 # Make these symbols local
1559 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1560 UtilityBase ExpansionBase KeymapBase KernelBase
1562 BD_SYMBOLS := $(BD_KBASE)
1564 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1565 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1566 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1567 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1568 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1569 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1570 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1571 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1572 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1575 ## Dependency fine-tuning
1577 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1578 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1580 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1581 $(BD_MODULE) : | $(BD_MODDIR)
1582 $(BD_KOBJ) : | $(KOBJSDIR)
1583 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1585 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1587 @$(ECHO) "Cleaning up for module %(modname)"
1590 #------------------------------------------------------------------------------
1593 #------------------------------------------------------------------------------
1595 # Explanation of this macro is done in the developer's manual
1596 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1597 conffile= files="$(basename $(call WILDCARD, *.c))" \
1598 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1599 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1600 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1601 compiler=target nostartup=yes
1603 # Define metamake targets and their dependencies
1604 #MM- includes-all : %(mmake)-includes
1605 #MM- linklibs-%(modname): %(mmake)-linklib
1606 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1607 #MM- includes-%(modname): %(mmake)-includes
1608 #MM- includes-%(modname)_rel : %(mmake)-includes
1609 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1610 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1611 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1612 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1613 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1614 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1615 #MM %(mmake)-quick : %(mmake)-includes-quick
1616 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1617 #MM includes-generate-deps %(mmake)-fd
1618 #MM %(mmake)-includes-quick
1619 #MM %(mmake)-includes-dirs
1621 #MM %(mmake)-makefile
1624 # All MetaMake targets defined by this macro
1625 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1626 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1627 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1628 %(mmake)-linklib %(mmake)-fd
1630 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1633 $(error using %build_module: modname may not be empty)
1636 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1639 # Default values for variables and arguments
1640 BD_DEFLINKLIBNAME := %(modname)
1641 BD_DEFDFLAGS := %(cflags)
1642 OBJDIR ?= $(GENDIR)/$(CURDIR)
1644 ## Create genmodule include Makefile for the module
1646 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1648 %rule_genmodule_makefile \
1649 modname=%(modname) modtype=%(modtype) \
1650 modsuffix=%(modsuffix) targetdir=%(objdir) \
1651 conffile=%(conffile)
1653 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1655 GLOB_MKDIRS += %(objdir)
1657 # Do not parse these statements if metatarget is not appropriate
1658 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1660 include %(objdir)/Makefile.%(modname)%(modtype)
1662 BD_DEFMODDIR := $(%(modname)_MODDIR)
1665 ## include files generation
1667 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1668 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1669 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1671 %(mmake)-includes-quick : %(mmake)-includes
1672 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1673 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1674 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1676 ifneq ($(%(modname)_INCLUDES),)
1677 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1678 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1679 conffile=%(conffile)
1681 %rule_copy_diff_multi \
1682 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1683 stampfile=%(objdir)/%(modname)_geninc
1685 %rule_copy_diff_multi \
1686 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1687 stampfile=%(objdir)/%(modname)_incs
1689 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1691 TMP%(modname)_INCDIRS := \
1692 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1693 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1694 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1695 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1699 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1700 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1701 conffile=%(conffile) version=%(version)
1703 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1704 $(BD_DEFLIBDEFSINC) :
1705 @$(ECHO) "generating $@"
1706 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1708 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1709 GLOB_MKDIRS += %(objdir)/include
1711 ## Extra genmodule src files generation
1713 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1714 modsuffix=%(modsuffix) targetdir=%(objdir) \
1715 conffile=%(conffile)
1719 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1720 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1722 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1723 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1725 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1727 GLOB_MKDIRS += $(BD_FDDIR)
1732 BD_FILES := %(files)
1733 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1734 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1735 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1737 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1738 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1739 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1741 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1742 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1744 ifeq (%(modtype),library)
1747 BD_LIBSUFFIX := .%(modtype)
1750 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1751 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1752 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1755 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1756 ifneq (%(modname),%(linklibname))
1757 BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1760 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1762 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1763 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1764 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1767 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1768 ifneq (%(modname),%(linklibname))
1769 BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1772 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1774 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1775 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1776 $(BD_RELLINKLIBCFILES)
1778 %rule_compile_multi \
1779 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1780 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1781 compiler=%(compiler)
1782 %rule_compile_multi \
1783 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1784 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1785 compiler=%(compiler)
1787 ifneq ($(BD_LINKLIBAFILES),)
1788 %rule_assemble_multi \
1789 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1794 ifeq (%(modsuffix),)
1795 BD_SUFFIX := %(modtype)
1797 BD_SUFFIX := %(modsuffix)
1800 # Handlers use dash instead of dot in their names
1801 ifeq ($(BD_SUFFIX),handler)
1802 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1803 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1805 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1806 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1808 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1810 %(mmake)-quick : %(mmake)
1811 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1812 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1813 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1814 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1815 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1816 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1818 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1819 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1821 ifeq (%(nostartup),yes)
1822 # Handlers always have entry point
1823 ifneq (%(modtype),handler)
1824 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1828 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1829 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1832 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1835 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1836 # This breaks con-handler build. Here we work around this
1837 ifeq (%(modname),con)
1838 BD_ERR := $(notdir $(BD_MODULE)).err
1840 BD_ERR := %(modname).err
1843 # The module is linked from all the compiled .o files
1844 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1845 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1846 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1847 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1849 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1850 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1851 ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1852 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1855 ifneq ($(BD_LINKLIB),)
1856 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1858 ifneq (%(modname),%(linklibname))
1859 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1862 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1863 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1866 ifneq ($(BD_RELLINKLIB),)
1867 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1868 ifneq (%(modname),%(linklibname))
1869 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1872 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1873 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1876 # Link kernel object file
1877 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1879 # Make these symbols local
1880 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1881 UtilityBase ExpansionBase KeymapBase KernelBase
1883 BD_SYMBOLS := $(BD_KBASE)
1885 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1886 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1887 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1888 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1889 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1890 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1891 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1892 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1893 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1895 ## Dependency fine-tuning
1897 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1898 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1900 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1901 $(BD_MODULE) : | %(prefix)/%(moduledir)
1902 $(BD_PKGMOD) : | $(PKGDIR)
1903 $(BD_KOBJ) : | $(KOBJSDIR)
1904 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1906 # Some include files need to be generated before the .c can be parsed.
1907 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
1909 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1910 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1911 $(BD_DEPS) : $(BD_DFILE_DEPS)
1914 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1915 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1916 %(objdir)/Makefile.%(modname)%(modtype) \
1917 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1918 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1919 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1920 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1921 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1922 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1924 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1926 @$(ECHO) "Cleaning up for module %(modname)"
1929 endif # $(TARGET) in $(BD_ALLTARGETS)
1931 #------------------------------------------------------------------------------
1934 #------------------------------------------------------------------------------
1935 # Build a module skeleton
1936 # This is a stripped-down version of build_module, it only creates include files,
1937 # but no actual object. This is used when for plugins or classes with the same
1938 # API, but no actual implementation here.
1939 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1941 objdir=$(OBJDIR) prefix=$(AROSDIR)
1943 # Define metamake targets and their dependencies
1944 #MM- includes-all : %(mmake)-includes
1945 #MM %(mmake) : %(mmake)-includes core-linklibs
1946 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1947 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1948 #MM %(mmake)-linklib : %(mmake)-includes
1949 #MM %(mmake)-quick : %(mmake)-includes-quick
1950 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1951 #MM includes-generate-deps
1952 #MM %(mmake)-includes-quick
1953 #MM %(mmake)-includes-dirs
1954 #MM %(mmake)-makefile
1957 # All MetaMake targets defined by this macro
1958 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1959 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1960 %(mmake)-kobj %(mmake)-pkg
1962 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1965 $(error using %build_module_skeleton: modname may not be empty)
1968 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1971 # Default values for variables and arguments
1972 BD_DEFLINKLIBNAME := %(modname)
1973 BD_DEFDFLAGS := %(cflags)
1974 OBJDIR ?= $(GENDIR)/$(CURDIR)
1976 ## Create genmodule include Makefile for the module
1978 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1980 %rule_genmodule_makefile \
1981 modname=%(modname) modtype=%(modtype) \
1982 modsuffix=%(modsuffix) targetdir=%(objdir) \
1983 conffile=%(conffile)
1985 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1987 GLOB_MKDIRS += %(objdir)
1989 # Do not parse these statements if metatarget is not appropriate
1990 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1992 include %(objdir)/Makefile.%(modname)%(modtype)
1994 BD_DEFMODDIR := $(%(modname)_MODDIR)
1997 ## include files generation
1999 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
2000 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2001 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2003 %(mmake)-includes-quick : %(mmake)-includes
2004 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2005 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2006 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2008 ifneq ($(%(modname)_INCLUDES),)
2009 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2010 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2011 conffile=%(conffile)
2013 %rule_copy_diff_multi \
2014 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2015 stampfile=%(objdir)/%(modname)_geninc
2017 %rule_copy_diff_multi \
2018 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2019 stampfile=%(objdir)/%(modname)_incs
2021 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2023 TMP%(modname)_INCDIRS := \
2024 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2025 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2026 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2027 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2031 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2032 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2033 conffile=%(conffile)
2035 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2036 $(BD_DEFLIBDEFSINC) :
2037 @$(ECHO) "generating $@"
2038 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2040 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2041 GLOB_MKDIRS += %(objdir)/include
2043 ## Extra genmodule src files generation
2045 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2046 modsuffix=%(modsuffix) targetdir=%(objdir) \
2047 conffile=%(conffile)
2049 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2050 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2051 %(objdir)/Makefile.%(modname)%(modtype) \
2052 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2053 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2054 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2055 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2056 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2058 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2060 @$(ECHO) "Cleaning up for module %(modname)"
2063 endif # $(TARGET) in $(BD_ALLTARGETS)
2065 #------------------------------------------------------------------------------
2068 #------------------------------------------------------------------------------
2070 # - mmake is the mmaketarget
2071 # - libname is the baselibname e.g. lib%(libname).a will be created
2072 # - files are the C source files to include in the lib. The list of files
2073 # has to be given without the .c suffix
2074 # - asmfiles are the asm files to include in the lib. The list of files has to
2075 # be given without the .s suffix
2076 # - objs additional object to link into the linklib. The objects have to be
2077 # given with full absolute path and the .o suffix.
2078 # - cflags are the flags to compile the source (default $(CFLAGS))
2079 # - dflags are the flags use during makedepend (default equal to cflags)
2080 # - aflags are the flags use during assembling (default $(AFLAGS))
2081 # - objdir is where the .o are generated
2082 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
2083 %define build_linklib mmake=/A libname=/A \
2084 files="$(basename $(call WILDCARD, *.c))" \
2085 cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
2086 asmfiles= objs= compiler=target \
2087 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
2089 # assign and generate the local variables used in this macro
2090 OBJDIR ?= $(GENDIR)/$(CURDIR)
2092 BD_FILES := %(files)
2093 BD_CXXFILES := %(cxxfiles)
2094 BD_ASMFILES := %(asmfiles)
2096 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2097 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2098 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2100 BD_OBJS := $(BD_ARCHOBJS) \
2101 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
2103 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2105 BD_CFLAGS := %(cflags)
2107 BD_DFLAGS := $(BD_CFLAGS)
2109 BD_DFLAGS := %(dflags)
2111 BD_AFLAGS := %(aflags)
2113 BD_LINKLIB := %(libdir)/lib%(libname).a
2115 .PHONY : %(mmake) %(mmake)-clean
2117 #MM %(mmake) : includes-generate-deps
2118 %(mmake) : $(BD_LINKLIB)
2122 @$(RM) $(BD_OBJS) $(BD_DEPS)
2124 ifeq ($(TARGET),%(mmake))
2125 ifneq ($(dir $(BD_FILES)),./)
2126 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2127 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
2130 %rule_compile basename=% targetdir=%(objdir) \
2131 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2132 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2133 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2134 %rule_assemble basename=% targetdir=%(objdir) \
2137 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2140 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2142 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2143 $(BD_LINKLIB) : | %(libdir)
2144 GLOB_MKDIRS += %(objdir) %(libdir)
2147 #------------------------------------------------------------------------------
2150 #------------------------------------------------------------------------------
2152 # - mmake is the mmaketarget
2153 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2154 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2155 # - subdir is the destination subdirectory of the catalogs
2156 # - name is the name of the destination catalog, without the .catalog suffix
2157 # - source is the path to the generated source code file
2158 # - dir is the base destination directory (default $(AROS_CATALOGS))
2159 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2160 # - srcdir is the directory in which the *.cd and *.ct files are searched
2162 %define build_catalogs mmake=/A name=/A subdir=/A \
2163 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2164 sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2166 ifeq (%(description),)
2167 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2169 BD_DESC := %(description)
2172 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2175 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2177 BD_LNGS := %(catalogs)
2180 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2181 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2184 %(mmake) : $(BD_OBJS) %(source)
2186 $(BD_OBJS) : | $(BD_DIRS)
2187 GLOB_MKDIRS += $(BD_DIRS)
2189 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2190 @$(ECHO) "Creating %(name) catalog for language $*."
2191 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2194 %(source) : BD_DESC := $(BD_DESC)
2195 %(source) : BD_SRC := $(BD_SRC)
2196 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2197 @$(ECHO) "Creating %(name) catalog source file $@"
2198 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2203 $(RM) $(BD_OBJS) %(source)
2205 .PHONY: %(mmake) %(mmake)-clean
2208 #-----------------------------------------------------------------------------
2211 #-----------------------------------------------------------------------------
2213 # - mmake is the mmaketarget
2214 # - icons is a list of icon base names (ie. without the .info suffix)
2215 # - dir is the destination directory
2216 # - srcdir is where *.png and *.info.src are searched
2217 #-----------------------------------------------------------------------------
2219 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2221 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2224 %(mmake) : $(BD_OBJS)
2228 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2229 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2230 @$(ILBMTOICON) $+ $@
2234 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2235 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2236 @$(ILBMTOICON) $+ $@
2240 $(BD_OBJS) : | %(dir)
2241 GLOB_MKDIRS += %(dir)
2243 %(mmake)-clean : FILES := $(BD_OBJS)
2248 .PHONY: %(mmake) %(mmake)-clean
2251 #-----------------------------------------------------------------------------
2254 #------------------------------------------------------------------------------
2255 # Compile files for an arch-specific replacement of code for a module
2256 # - files: the basenames of the C files to compile.
2257 # - asmfiles: the basenames of the asm files to assemble.
2258 # - mainmmake: the mmake of the module in the main directory to compile these
2259 # arch specific files for.
2260 # - maindir: the object directory for the main module
2261 # - arch: the arch for which to compile these files. It can have the form
2262 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2264 # - dflags: the flags used during creation of dependency file. If not specified
2265 # the same value as cflags will be used
2266 # - aflags: the flags used during assembling
2267 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2268 # the target compiler is used
2269 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2270 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2272 ifeq (%(files) %(asmfiles),)
2273 $(error no files or asmfiles given)
2276 %buildid targets="%(mainmmake)-%(arch)"
2278 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2279 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2280 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2281 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2282 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2283 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2284 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2285 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2286 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2287 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2288 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2289 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2290 #MM- %(mainmmake)-pkg : %(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)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2294 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2295 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2296 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2297 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2298 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2300 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2302 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2303 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2304 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2305 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2306 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2308 ifneq (%(modulename),)
2309 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2312 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2313 BD_TARGET := %(mainmmake)-%(arch)-quick
2315 BD_TARGET := %(mainmmake)-%(arch)
2319 ifeq ($(TARGET),$(BD_TARGET))
2320 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2321 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2322 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2323 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2326 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2327 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2330 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2333 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2335 ifeq ($(findstring %(compiler),host kernel target),)
2336 $(error unknown compiler %(compiler))
2338 ifeq (%(compiler),target)
2339 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2340 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2341 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2343 ifeq (%(compiler),host)
2344 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2345 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2346 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2348 ifeq (%(compiler),kernel)
2349 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2350 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2351 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2353 ifneq (%(modulename),)
2354 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2356 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2358 ifeq ($(TARGET),$(BD_TARGET))
2359 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2360 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2364 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2366 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2368 ifeq ($(TARGET),$(BD_TARGET))
2369 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2370 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2373 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2375 ifeq ($(TARGET),$(BD_TARGET))
2376 $(BD_OBJDIR$(BDID))/%.o : %.s
2377 %assemble_q opt=$(AFLAGS)
2378 $(BD_OBJDIR$(BDID))/%.o : %.S
2379 %assemble_q opt=$(AFLAGS)
2382 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2384 #------------------------------------------------------------------------------
2387 #------------------------------------------------------------------------------
2388 # generate asm files from c files (for debugging purposes)
2391 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2392 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2394 #------------------------------------------------------------------------------
2397 #------------------------------------------------------------------------------
2398 # Copy files from one directory to another.
2400 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2402 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2404 GLOB_MKDIRS += %(dst)
2410 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2413 #------------------------------------------------------------------------------
2416 #------------------------------------------------------------------------------
2417 # Copy a directory recursively to another place, preserving the original
2418 # hierarchical structure
2420 # src: the source directory whose content will be copied
2421 # dst: the directory where to copy src's content. If not existing, it will be made.
2423 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2425 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2426 %(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)
2427 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
2429 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2430 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2432 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2437 %(mmake): | $(GENDIR)/$(CURDIR)
2438 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2439 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
2440 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2441 for d in $(%(mmake)_DIRS); do \
2442 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
2444 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2445 for f in $(%(mmake)_FILES); do \
2446 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2448 for dst in %(dst); do \
2449 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2453 #------------------------------------------------------------------------------
2456 #------------------------------------------------------------------------------
2457 # Copy include files into the includes directories. There are currently
2458 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2459 # for building tools that need to run on the host system $(GENINCDIR). The
2460 # $(GENINCDIR) path must not contain any references to the C runtime
2461 # library header files.
2463 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2464 dir= compiler=target
2466 ifeq ($(findstring %(compiler),host kernel target),)
2467 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2471 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2472 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2473 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2475 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2476 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2479 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2483 ifeq (%(compiler),target)
2486 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2487 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2489 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2492 BD_INCL_FILES += $(BD_INCL_FILES2)
2494 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2499 %(mmake) : $(BD_INCL_FILES)
2503 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2504 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2506 #------------------------------------------------------------------------------
2509 #------------------------------------------------------------------------------
2510 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2511 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2512 STUBS_MEM := $(addsuffix .o,$(STUBS))
2513 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2514 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2515 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2517 #MM- linklibs : hidd-%(hidd)-stubs
2518 #MM- %(parenttarget): hidd-%(hidd)-stubs
2519 #MM hidd-%(hidd)-stubs : includes includes-copy
2520 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2522 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2525 $(STUBS_OBJ) : $(STUBS_SRC)
2526 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2528 $(STUBS_DEP) : $(STUBS_SRC)
2529 %mkdepend_q flags=%(dflags)
2532 %mkdirs_q $(OBJDIR) $(LIBDIR)
2536 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2538 DEPS := $(DEPS) $(STUBS_DEP)
2541 #------------------------------------------------------------------------------
2544 #------------------------------------------------------------------------------
2545 # Build an imported source tree which uses the configure script from the
2546 # autoconf package. This rule will try to "integrate" the produced files as
2547 # much as possible in the AROS build, for example by putting libraries in the
2548 # standard library directory, includes in the standard include directory, and
2549 # so on. You can however override this behaviour.
2551 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2552 # be %(bindir) (or its deduced value) when running "make install", and
2553 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2554 # configure script some more parameters whose value depends upon the PROGDIR
2555 # env var, so that the program gets all its stuff installed in the proper place
2556 # when building it, but when running it from inside AROS it can also find that
2557 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2558 # the configuration parameters set when running ./configure
2560 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2561 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2562 # to the name which has to follow it.
2566 # - mmake = the meta make target.
2567 # - package = name of the package to be built.
2568 # - srcdir = the location of the unpacked source code. Defaults
2569 # to $(SRCDIR)/$(CURDIR).
2570 # - prefix = the target directory. Must be an absolute path of the
2571 # host system. Defaults to $(AROS_CONTRIB).
2572 # - aros_prefix = set a path which is valid within the AROS filesystem.
2573 # Defaults to the value of the prefix option.
2574 # - extraoptions = additional options for the configure script.
2575 # - extracflags = additional flags which are used for both C and C++.
2576 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2577 # Defaults to the value of the nix argument.
2578 # - nix = enable u*nix path handling, i.e. a path like
2579 # /progdir//./file will be translated to
2580 # progdir:file during run-time. Defaults to no.
2581 # - compiler = target, host or kernel. Defaults to target.
2582 # - install_target = the command used for installing. Defaults to install. Leave
2583 # it empty if you want to suppress installing.
2584 # - preconfigure = a metatarget which is executed before configure is called.
2585 # - postconfigure = a metatarget which is executed after configure is called.
2586 # - postinstall = a metatarget which is executed after installing.
2587 # - install_env = set additional options for installing.
2588 # - use_build_env = if yes the configuration environment is used for
2589 # installing, too. Defaults to no.
2591 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2595 # --prefix = $(aros_prefix)
2596 # progdir = $(aros_prefix)/bin
2599 # --prefix = /PROGDIR
2600 # --bindir = /PROGDIR
2601 # --sbindir = /PROGDIR
2603 # --includedir = /INCLUDE
2604 # --oldincludedir = /INCLUDE
2606 # --prefix = $(aros_prefix)
2609 # progdir = $(aros_prefix)
2612 # bindir = $(prefix)
2613 # sbindir = $(prefix)
2614 # libdir = $(AROS_LIB)
2615 # includedir = $(AROS_INCLUDES)
2616 # oldincludedir = $(AROS_INCLUDES)
2620 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2621 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2622 install_target=install preconfigure= postconfigure= postinstall= \
2623 install_env= use_build_env=no
2626 %(mmake)-prefix := %(prefix)
2628 %(mmake)-prefix := $(AROS_CONTRIB)
2631 ifneq (%(aros_prefix),)
2632 %(mmake)-aros_prefix := %(aros_prefix)
2634 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2638 %(mmake)-nix := -nix
2639 %(mmake)-volpfx := /
2640 %(mmake)-volsfx := /
2642 ifeq (%(nix_dir_layout),)
2643 %(mmake)-nix_dir_layout := yes
2646 %(mmake)-volsfx := :
2648 ifeq (%(nix_dir_layout),)
2649 %(mmake)-nix_dir_layout := no
2653 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2655 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2656 exec_prefix=$(%(mmake)-prefix) %(install_env)
2658 # Check if chosen compiler is valid
2659 ifeq ($(findstring %(compiler),host target kernel),)
2660 $(error unknown compiler %(compiler))
2663 # Set legacy 'host' variable based on chosen compiler
2664 ifeq (%(compiler),host)
2667 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2669 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2674 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2676 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2680 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2681 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2683 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2684 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2685 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2688 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2689 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2691 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2694 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2696 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2697 sbindir=$(%(mmake)-prefix) \
2698 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2699 oldincludedir=$(AROS_INCLUDES) %(install_env)
2702 ifneq ($(DEBUG),yes)
2703 %(mmake)-s_flag = -s
2706 # Set up build environment, and options for configure script
2707 ifeq (%(compiler),host)
2710 CXXCPP="$(HOST_CPP)" \
2711 CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2712 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2713 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2714 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2715 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2716 TARGET_NM="$(NM_PLAIN)"
2718 ifeq (%(compiler),target)
2720 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2721 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2722 CPP="$(TARGET_CPP)" \
2723 CXXCPP="$(TARGET_CPP)" \
2724 CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2725 CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2726 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2727 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2728 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2729 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2730 TARGET_NM="$(NM_PLAIN)" \
2731 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2732 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2733 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2734 --host=$(AROS_TARGET_CPU)-aros\
2735 --target=$(AROS_TARGET_CPU)-aros\
2737 --without-x --without-pic --disable-shared
2739 ifeq (%(compiler),kernel)
2741 CPP="$(KERNEL_CPP)" \
2742 CXXCPP="$(KERNEL_CPP)" \
2743 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2744 CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2745 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2746 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2747 TARGET_NM="$(NM_PLAIN)"
2748 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2749 --host=$(AROS_TARGET_CPU)-aros\
2750 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2751 --without-x --without-pic --disable-shared
2754 ifeq (%(use_build_env),yes)
2755 BUILD_ENV := $(CONFIG_ENV)
2759 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2761 # When building for the host, we don't need to build the
2762 # linklibs - this is especially true when building the
2763 # crosstool toolchain on 'foreign' architectures (such as
2764 # building PPC on x86)
2766 #MM- %(mmake)-host : setup includes %(mmake)-quick
2767 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2768 #MM- %(mmake): %(mmake)-%(compiler)
2770 # Using -j1 in install_command may result in a warning but finally
2771 # it does its job. make install for gcc does not work reliably for -jN
2773 ifneq (%(install_target),)
2774 %(mmake)-install_command = \
2775 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2776 -C $(%(mmake)-pkgdir) %(install_target) -j1
2778 %(mmake)-uninstall_command = \
2779 $(RM) $(%(mmake)-installflag) && \
2780 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2781 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2783 %(mmake)-install_command := true
2784 %(mmake)-uninstall_command := true
2787 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2790 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2792 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2793 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2794 $(RM) $(%(mmake)-installflag) && \
2795 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2796 -C $(%(mmake)-pkgdir) && \
2797 $(%(mmake)-install_command) && \
2798 $(TOUCH) $@ -r $^; \
2801 $(%(mmake)-pkgdir)/.files-touched:
2802 %mkdirs_q $(%(mmake)-pkgdir)
2803 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2807 %(mmake)-uninstall :
2808 $(%(mmake)-uninstall_command)
2811 %(mmake)-configure : $(%(mmake)-configflag)
2813 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2814 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2816 %mkdirs_q $(%(mmake)-pkgdir)
2817 cd $(%(mmake)-pkgdir) && \
2818 find . -name config.cache -exec $(RM) '{}' \; && \
2819 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2820 %(extraoptions) && \
2824 %(mmake)-clean : %(mmake)-uninstall
2825 @$(RM) $(%(mmake)-pkgdir)
2827 #------------------------------------------------------------------------------
2830 #------------------------------------------------------------------------------
2831 # Given an archive name, patches names and locations where to find them, fetch
2832 # the archive and the patches from any of those locations, unpack the archive
2833 # and then apply the patches.
2835 # Locations currently supported are http and ftp sites, plus local filesystem
2836 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2837 # the fetch.sh script needs to be modified, since this macro relies on that script.
2841 # - mmake = mmaketarget
2842 # - archive_origins = list of locations where to find the archive. They are tried
2843 # in sequence, until the archive is found and fetching it
2844 # succeeded. If not specified, the current directory is assumed.
2845 # - archive = the archive name. Mandatory.
2846 # - suffixes = a list of suffixes to append to the the package name plus the
2847 # version. Each one of them is tried until a matching archive is
2848 # found. They are appended to patches and these are tried the
2849 # same way as packages are.
2850 # - location = the local directory where to put the fetched archive and patches.
2851 # If not specified, the directory specified by destination is used.
2852 # - destination = the directory to unpack the archive to.
2853 # If not specified, the current directory is assumed.
2854 # - patches_origins = list of locations where to find the patches. They are tried
2855 # in sequence, until a patch is found and fetching it
2856 # succeeded. If not specified, the current directory is assumed.
2857 # - patches_specs = list of "patch specs". A patch spec is of the form
2858 # patch_name[:[patch_subdir][:patch_opt]].
2860 # - patch_name = the name of the patch file
2861 # - patch_subdir = the directory within \destination\ where to
2863 # - patch_opt = any options to pass to the `patch' command
2864 # when applying the patch.
2866 # The patch_subdir and patch_opt fields are optional.
2868 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2869 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2873 ifneq (%(location),)
2874 %(mmake)-location := %(location)
2876 %(mmake)-location := %(destination)
2881 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2882 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2884 #------------------------------------------------------------------------------
2887 #------------------------------------------------------------------------------
2888 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2889 # unpatched source tree and runs diff against this and a previously fetched and possibly
2890 # patched tree. Depending on what happens after patching during a normal build it might
2891 # give best results if the new patch is created directly after fetch.
2895 # - mmake = mmaketarget
2896 # - archive = archive base name
2897 # - srcdir = directory the package is unpacked to, useful if archive unpacks to
2898 # a directory other than its name suggests.
2899 # - suffixes = a list of suffixes to append to the the package name plus the
2900 # version. Each one of them is tried until a matching archive is
2902 # - destination = the directory to unpack the archive to.
2903 # - excludes = diff patterns to exclude files or directories from the patch
2905 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2909 ifneq (%(excludes),)
2910 %(mmake)-exclude := -X ./exclude.patterns
2914 %(mmake)-srcdir := %(srcdir)
2916 %(mmake)-srcdir := %(archive)
2921 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2922 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2923 cd %(destination)/tmp ; \
2924 $(FOR) f in %(excludes) ; do \
2925 $(ECHO) $$f >> ./exclude.patterns ; \
2927 diff -ruN $(%(mmake)-exclude) \
2928 $(%(mmake)-srcdir) \
2929 $(%(mmake)-srcdir).aros \
2930 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2931 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2932 $(RM) %(destination)/tmp
2934 #------------------------------------------------------------------------------
2937 #------------------------------------------------------------------------------
2938 # Joins the features of %fetch and %build_with_configure.
2940 # If a patch is provided, it *must* be named the following way:
2942 # <package name>-<version number>-aros.diff
2944 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2945 # CD'ing into the archive's extracted directory.
2947 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2948 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2949 # to make that patch fully comprehensive.
2953 # - mmake = the meta make target.
2954 # - package = the GNU package name, sans version and archive format suffixes.
2955 # - subpackage = ???
2956 # - compiler = same meaning as the one for the %build_with_configure macro.
2957 # - install_target = same meaning as the one for the %build_with_configure macro.
2958 # - version = the package's version number, or otherwise any other version string.
2959 # It gets appended to the package name to form the basename of the archive.
2960 # - suffixes = a list of suffixes to apped to the the package name plus the
2961 # version. Each one of them is tried until a matching archive is found.
2962 # Defaults to "tar.bz2 tar.gz".
2964 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2965 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2966 # fetched or not. Default to no.
2967 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2968 # - prefix = same meaning as the one for the %build_with_configure macro.
2969 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
2970 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2971 # - extracflags = same meaning as the one for the %build_with_configure macro.
2972 # - preconfigure = same meaning as the one for the %build_with_configure macro.
2973 # - postconfigure = same meaning as the one for the %build_with_configure macro.
2974 # - postinstall = same meaning as the one for the %build_with_configure macro.
2975 # - install_env = same meaning as the one for the %build_with_configure macro.
2976 # - use_build_env = same meaning as the one for the %build_with_configure macro.
2977 # - nix = same meaning as the one for the %build_with_configure macro.
2978 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
2979 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2981 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2982 version=/A suffixes="tar.bz2 tar.gz" srcdir= package_repo= patch=no patch_repo= \
2983 prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2984 install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2986 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2987 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2988 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2989 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2991 %(mmake)-archbase := %(package)-%(version)
2993 ifeq (%(compiler),host)
2994 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2996 %(mmake)-portdir := $(PORTSDIR)/%(package)
3000 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3002 %(mmake)-prefix := %(prefix)
3005 ifneq (%(subpackage),)
3006 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
3008 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
3012 %(mmake)-%(subpackage)-srcdir := %(srcdir)
3014 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
3018 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3020 %(mmake)-%(subpackage)-patches_specs := ::
3023 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3024 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3025 archive_origins=". %(package_repo)" \
3026 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3028 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3029 archive=$(%(mmake)-%(subpackage)-archbase) \
3030 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3031 suffixes="%(suffixes)" \
3032 destination=$(%(mmake)-portdir)
3034 #MM- %(mmake) : %(mmake)-%(subpackage)
3036 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3038 %(mmake)-%(subpackage)-package-basename := \
3039 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3041 ifneq (%(create_pkg),no)
3042 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3045 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3046 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) install_env=%(install_env) use_build_env=%(use_build_env) \
3047 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3048 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3049 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3051 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3052 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3055 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3057 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3058 #that $^ and $@ have exactly the same mtime, and in that case make tries
3059 #to rebuild $@ again, which would fail because the directory where
3060 #the package got installed would not exist anymore.
3061 #We work this around by using an if statement to manually check the mtimes.
3062 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3063 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3065 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3066 mkdir -p "$(DISTDIR)/Packages" ; \
3067 mkdir -p "$(%(mmake)-prefix)" ; \
3068 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3069 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3070 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3073 #------------------------------------------------------------------------------
3076 #------------------------------------------------------------------------------
3077 # Joins the features of %fetch and %build_with_configure, taking advantage of
3078 # the naming scheme of GNU packages. GNU packages names are in the form
3080 # <package name>-<version number>.<archive format suffix>
3082 # If a patch is provided, it *must* be named the following way:
3084 # <package name>-<version number>-aros.diff
3086 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3087 # CD'ing into the archive's extracted directory.
3089 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3090 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3091 # to make that patch fully comprehensive.
3093 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3097 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3099 # - prefix = defaults to $(GNUDIR).
3100 # - aros_prefix = defaults to /GNU.
3102 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3103 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3104 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
3106 GNU_REPOSITORY := gnu://
3108 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3109 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3110 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3111 patch="%(patch)" patch_repo="%(patch_repo)" \
3112 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3113 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3116 #------------------------------------------------------------------------------
3119 #------------------------------------------------------------------------------
3120 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3121 # that the package is a "Development" package, and as such it needs to be placed
3122 # under the $(AROS_DEVELOPMENT) directory, as a default.
3124 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3125 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3126 # "mmake" argument, because the metatarget is implicitely defined as
3128 # #MM- development-%(package)
3130 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3131 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3132 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
3134 #MM- development : development-%(package)
3137 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3138 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
3139 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3140 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3141 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3144 postinstall-%(package)-delete-la-files:
3145 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3148 #------------------------------------------------------------------------------
3150 # Builds a kickstart package in PKG format
3154 # - mmake = target name
3155 # - file = destination file name with path
3156 # - startup = the file which will be put first
3158 # Other arguments are self-explanatory
3160 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
3162 PKG_CLASSES := $(addsuffix .class, %(classes))
3163 PKG_DEVICES := $(addsuffix .device, %(devs))
3164 PKG_HANDLERS := $(addsuffix -handler, %(handlers))
3165 PKG_HIDD := $(addsuffix .hidd, %(hidds))
3166 PKG_LIBS := $(addsuffix .library, %(libs))
3167 PKG_RESOURCES := $(addsuffix .resource, %(res))
3169 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
3170 PKG_DIR := $(dir %(file))
3171 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
3177 %(mmake)-quick : %(file)
3179 %(file): PKG_FILES := $(PKG_FILES)
3180 %(file): $(PKG_DEPS) | $(PKG_DIR)
3181 @$(ECHO) Packaging $@...
3182 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
3184 %compress_file mmake=%(mmake) file=%(file)
3186 GLOB_MKDIRS += $(PKG_DIR)
3190 #------------------------------------------------------------------------------
3191 # Compresses %(file) with a gzip.
3192 # Good in conjunction with for example %build_prog
3194 %define compress_file mmake=/A file=/A
3196 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3199 %(mmake)-gz-quick : %(file).gz
3202 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3207 #------------------------------------------------------------------------------
3208 # Links a kickstart module in ELF format
3209 # Arguments are similar to make_package
3211 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3212 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3214 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3215 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3216 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3217 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3218 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3219 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3222 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3224 KOBJ_STARTUP := %(startup)
3227 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3229 TMP_LDFLAGS := %(ldflags)
3231 # Make a list of the lib files this program depends on.
3232 # In LDFLAGS remove white space between -L and directory
3233 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3234 # Filter out only the libdirs and remove -L
3235 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3237 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3238 # Add normal linklib path
3239 TMP_DIRS += $(LIBDIR)/
3240 # add lib and .a to static linklib names
3241 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3242 # search for the linklibs in the given path, ignore ones not found
3243 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3244 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3247 TMP_DIRS += $(dir %(file))
3249 TMP_LDFLAGS += $(GENMAP) %(map)
3250 TMP_DIRS += $(dir %(map))
3253 #MM %(mmake) : %(deps)
3259 %(mmake)-quick : %(file)
3261 %(file): KOBJS := $(KOBJS)
3262 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3263 -noarosc -nosysbase -Wl,-Ur
3264 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3265 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3266 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3267 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3270 %compress_file mmake=%(mmake) file=%(file)
3272 GLOB_MKDIRS += $(TMP_DIRS)