1 #############################################################################
2 #############################################################################
4 ## Here are the mmakefile macros that are used as commands in the body ##
6 ## They are used to help the portability of mmakefiles to different ##
7 ## platforms and also will handle the error handling in a standard way. ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16 %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26 @$(ECHO) "Compiling $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
35 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
46 @$(ECHO) "Assembling $(notdir %(from))..."
47 @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
55 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,%(to))..."
67 @$(IF) %(cmd) %(from) -o %(to) %(libs) %(opt) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(libs) %(opt)" >> $(GENDIR)/errors ; \
70 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
75 $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(libs) %(opt)" 1>&2 ; \
76 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd=$(AROS_CC) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
90 @if %(cmd) $(NOSTARTUP_LDFLAGS) -nostdc \
91 $(GENMAP) %(objdir)/%(module).map \
92 %(objs) %(libs) %(ldflags) %(endtag) \
93 -o $@ 2>&1 > %(objdir)/%(err); \
95 cat %(objdir)/%(err); \
97 echo "%(cmd) $(NOSTARTUP_LDFLAGS) -nostdc $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
98 cat %(objdir)/%(err); \
102 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121 %mkdir_q dir="$(dir %(to))"
122 @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139 @$(FOR) dir in %(dirs) ; do \
140 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
149 ## Here are the mmakefile macros that are used to do certain tasks in a ##
150 ## mmakefile. They consist of one or more full makefile rules. ##
151 ## In general the files generated in these macros are also defined as ##
152 ## make targets so that they can be used as a dependency in other rules ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197 stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207 @for f in $(FILES); do \
208 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
220 # Restriction: at the moment when using a non-empty target dir %(from) may
222 %define rule_join to=/A from=/A text=
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean
238 %define include_deps deps=$(DEPS)/M depstargets=
240 ifneq (%(depstargets),)
241 ifneq ($(findstring $(TARGET),%(depstargets)),)
245 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default.
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 # the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 # it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
282 TMP_TARGETBASE := %(basename)
284 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
287 ifeq ($(findstring %(compiler),host kernel target),)
288 $(error unknown compiler %(compiler))
290 ifeq (%(compiler),target)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
298 ifeq (%(compiler),host)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
306 ifeq (%(compiler),kernel)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
315 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
321 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
323 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
327 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
329 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
332 $(TMP_TARGETBASE).d : %(basename).c
333 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile a C++ source file to an object file and generate
340 # the dependency file. Basename may contain a directory part, then the source
341 # file has to be in that directory. The generated file will be put in the
342 # object directory without the directory.
344 # - basename: the basename of the file to compile. Use % for a wildcard rule
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 # the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 # it is put in the same directory as the .c file
350 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
353 TMP_TARGETBASE := %(basename)
355 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
358 # Adjust compiler flags to suit C++
359 TMP_CXXFLAGS := %(cflags)
360 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
361 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
363 ifeq ($(findstring %(compiler),host kernel target),)
364 $(error unknown compiler %(compiler))
366 ifeq (%(compiler),target)
367 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
368 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
369 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
370 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
374 ifeq (%(compiler),host)
375 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
376 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
377 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
378 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
382 ifeq (%(compiler),kernel)
383 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
384 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
387 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
388 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
391 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
392 $(TMP_TARGETBASE).o : %(basename).cpp
393 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
397 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
399 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
403 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
405 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
408 $(TMP_TARGETBASE).d : %(basename).cpp
409 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
411 #------------------------------------------------------------------------------
414 #------------------------------------------------------------------------------
415 # Generate a rule to compile multiple C source files to an object file and
416 # generate the corresponding dependency files. The generated file will be put
417 # in the object directory without the directory part of the source file.
419 # - basenames: the basenames of the files to compile. The names may include
420 # relative or absolute path names. No wildcard is allowed
421 # - cflags (default $(CFLAGS)): the C flags to use for compilation
422 # - dflags: the flags used during creation of dependency file. If not specified
423 # the same value as cflags will be used
424 # - targetdir: the directory to put the .o file and the .d file. By default
425 # it is put in the same directory as the .c file. When targetdir is not
426 # empty, path names will be stripped from the file names so that all files
427 # are in that dir and not in subdirectories.
428 # - compiler (default target): compiler to use, target, kernel or host
429 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
433 TMP_TARGETS := $(addsuffix .o,%(basenames))
434 TMP_DTARGETS := $(addsuffix .d,%(basenames))
437 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
438 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
439 TMP_WILDCARD := %(targetdir)/%
441 # Be sure that all .c files are generated
442 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
444 # Be sure that all .c files are found
445 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
446 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
447 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
449 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
450 vpath %.c $(TMP_DIRS)
455 ifeq ($(findstring %(compiler),host kernel target),)
456 $(error unknown compiler %(compiler))
458 ifeq (%(compiler),target)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
460 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
463 ifeq (%(compiler),host)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
468 ifeq (%(compiler),kernel)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
471 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
474 $(TMP_TARGETS) : CFLAGS := %(cflags)
475 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
476 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
479 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
481 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
483 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
484 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
486 #------------------------------------------------------------------------------
489 #------------------------------------------------------------------------------
490 # Generate a rule to compile multiple C++ source files to an object file and
491 # generate the corresponding dependency files. The generated file will be put
492 # in the object directory without the directory part of the source file.
494 # - basenames: the basenames of the files to compile. The names may include
495 # relative or absolute path names. No wildcard is allowed. basenames will be
496 # matched to supported AROS_CXXEXTS.
497 # - cflags (default $(CFLAGS)): the C flags to use for compilation
498 # - dflags: the flags used during creation of dependency file. If not specified
499 # the same value as cflags will be used
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 # it is put in the same directory as the .c file. When targetdir is not
502 # empty, path names will be stripped from the file names so that all files
503 # are in that dir and not in subdirectories.
504 # - compiler (default target): compiler to use, target, kernel or host
505 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
506 targetdir= compiler=target
508 # Adjust compiler flags to suit C++
509 TMP_CXXFLAGS := %(cflags)
510 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
511 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
513 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
514 ifneq ($(TMP_CXXABSBASENAMES),)
515 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
517 # Identify the "real" c++ files from the passed in basenames
518 TMP_CXXFILES := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
521 TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
522 TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
525 TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
526 TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
527 TMP_WILDCARD := %(targetdir)/%
529 # Be sure that all source files are generated
530 $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
533 ifeq ($(findstring %(compiler),host kernel target),)
534 $(error unknown compiler %(compiler))
536 ifeq (%(compiler),target)
537 TMP_CXXCMD:=$(AROS_CXX) $(TARGET_CFLAGS)
538 TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
539 TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
541 ifeq (%(compiler),host)
542 TMP_CXXCMD:=$(HOST_CXX)
543 TMP_CXXIQUOTE:=$(HOST_IQUOTE)
544 TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
546 ifeq (%(compiler),kernel)
547 TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
548 TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
549 TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
553 TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
555 ifeq (%(dflags),%(cflags))
556 TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
558 TMP_CXXDFLAGS:=%(dflags)
562 define cxx_multi_recipe_template
564 %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
567 %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
570 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
572 $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
576 #------------------------------------------------------------------------------
579 #------------------------------------------------------------------------------
580 # Generate a rule to compile an ObjC source file to an object file and generate
581 # the dependency file. Basename may contain a directory part, then the source
582 # file has to be in that directory. The generated file will be put in the
583 # object directory without the directory.
585 # - basename: the basename of the file to compile. Use % for a wildcard rule
586 # - cflags (default $(CFLAGS)): the C flags to use for compilation
587 # - dflags: the flags used during creation of dependency file. If not specified
588 # the same value as cflags will be used
589 # - targetdir: the directory to put the .o file and the .d file. By default
590 # it is put in the same directory as the .m file
591 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
594 TMP_TARGETBASE := %(basename)
596 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
599 # Adjust compiler flags to suit ObjC
600 TMP_OBJCFLAGS := %(cflags)
601 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
602 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
604 ifeq ($(findstring %(compiler),host kernel target),)
605 $(error unknown compiler %(compiler))
607 ifeq (%(compiler),target)
608 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
609 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
610 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
611 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
612 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
613 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
615 ifeq (%(compiler),host)
616 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
617 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
618 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
619 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
623 ifeq (%(compiler),kernel)
624 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
625 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
626 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
627 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
628 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
629 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
632 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
633 $(TMP_TARGETBASE).o : %(basename).m
634 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
638 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
640 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
644 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
646 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
649 $(TMP_TARGETBASE).d : %(basename).m
650 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
652 #------------------------------------------------------------------------------
654 #------------------------------------------------------------------------------
655 # Generate a rule to compile multiple ObjC source files to an object file and
656 # generate the corresponding dependency files. The generated file will be put
657 # in the object directory without the directory part of the source file.
659 # - basenames: the basenames of the files to compile. The names may include
660 # relative or absolute path names. No wildcard is allowed
661 # - cflags (default $(CFLAGS)): the C flags to use for compilation
662 # - dflags: the flags used during creation of dependency file. If not specified
663 # the same value as cflags will be used
664 # - targetdir: the directory to put the .o file and the .d file. By default
665 # it is put in the same directory as the .m file. When targetdir is not
666 # empty, path names will be stripped from the file names so that all files
667 # are in that dir and not in subdirectories.
668 # - compiler (default target): compiler to use, target, kernel or host
669 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
670 targetdir= compiler=target
672 # Adjust compiler flags to suit ObjC
673 TMP_OBJCFLAGS := %(cflags)
674 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
675 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
678 TMP_TARGETS := $(addsuffix .o,%(basenames))
679 TMP_DTARGETS := $(addsuffix .d,%(basenames))
682 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
683 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
684 TMP_WILDCARD := %(targetdir)/%
686 # Be sure that all .m files are generated
687 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
689 # Be sure that all .m files are found
690 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
691 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
692 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
694 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
695 vpath %.m $(TMP_DIRS)
699 # Define the use of cross compiler
700 ifeq ($(TARGET_OBJC),)
701 TMP_CC := $(TARGET_CC)
703 TMP_CC := $(TARGET_OBJC)
706 ifeq ($(findstring %(compiler),host kernel target),)
707 $(error unknown compiler %(compiler))
709 ifeq (%(compiler),target)
710 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
711 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
712 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
714 ifeq (%(compiler),host)
715 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
716 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
717 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
719 ifeq (%(compiler),kernel)
720 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
721 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
722 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
725 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
726 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
727 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
730 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
732 ifeq (%(dflags),%(cflags))
733 $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
735 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
738 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
739 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
741 #------------------------------------------------------------------------------
744 #------------------------------------------------------------------------------
745 # Make an alias from one arch specific build to another arch.
747 # - mainmmake: the mmake of the module in the main tree
748 # - arch: the current arch
749 # - alias: the alias to which this should point
750 %define rule_archalias mainmmake=\A arch=\A alias=\A
752 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
754 #------------------------------------------------------------------------------
757 #------------------------------------------------------------------------------
758 # Generate a rule to assemble a source file to an object file. Basename may
759 # contain a directory part, then the source file has to be in that directory.
760 # The generated file will be put in the object directory without the directory.
762 # - basename: the basename of the file to compile. Use % for a wildcard rule
763 # - flags (default $(AFLAGS)): the asm flags to use for assembling
764 # - targetdir: the directory to put the .o file in. By default it is put in the
765 # same directory as the .s file
766 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
769 %(basename).o : AFLAGS := %(aflags)
770 %(basename).o : %(basename).s
772 %(basename).o : %(basename).S
776 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
777 %(targetdir)/$(notdir %(basename)).o : %(basename).s
779 %(targetdir)/$(notdir %(basename)).o : %(basename).S
784 #------------------------------------------------------------------------------
787 #------------------------------------------------------------------------------
788 # Generate a rule to assemble multiple source files to an object file. The
789 # generated file will be put in the object directory with the directory part
790 # of the source file stripped off.
792 # - basenames: the basenames of the files to compile. The names may include
793 # relative or absolute path names. No wildcard is allowed
794 # - aflags (default $(AFLAGS)): the flags to use for assembly
795 # - targetdir: the directory to put the .o file and the .d file. By default
796 # it is put in the same directory as the .c file. When targetdir is not
797 # empty, path names will be stripped from the file names so that all files
798 # are in that dir and not in subdirectories.
799 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
802 TMP_TARGETS := $(addsuffix .o,%(basenames))
805 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
806 TMP_WILDCARD := %(targetdir)/%
808 # Be sure that all .s files are generated
809 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
811 # Be sure that all .c files are found
812 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
813 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
814 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
816 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
817 vpath %%(suffix) $(TMP_DIRS)
822 ifeq ($(findstring %(compiler),host kernel target),)
823 $(error unknown compiler %(compiler))
825 ifeq (%(compiler),target)
826 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
828 ifeq (%(compiler),host)
829 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
831 ifeq (%(compiler),kernel)
832 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
835 $(TMP_TARGETS) : AFLAGS := %(aflags)
836 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
837 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
839 #------------------------------------------------------------------------------
842 #------------------------------------------------------------------------------
843 # Link %(objs) to %(prog) using the libraries in %(uselibs)
844 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
845 usehostlibs= usestartup=yes detach=no nix=no linker=target
850 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
852 ifeq (%(usestartup),no)
853 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
854 ifeq (%(linker),target)
855 TMP_EXTRA_LDFLAGS += -nostdc
856 TMP_EXTRA_LIBS += libinit autoinit
860 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
863 # Make a list of the lib files this program depends on.
864 # In LDFLAGS remove white space between -L and directory
865 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
866 # Filter out only the libdirs and remove -L
867 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
869 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
870 # Add normal linklib path
871 TMP_DIRS += $(AROS_LIB)/
872 # add lib and .a to static linklib names
873 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
874 ifeq (%(usestartup),yes)
875 TMP_LIBS += startup.o
880 # search for the linklibs in the given path, ignore ones not found
881 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
882 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
885 ifeq (%(linker),target)
886 %(prog) : CMD:=$(TARGET_CC)
887 %(prog) : STRIPCMD:=$(TARGET_STRIP)
889 ifeq (%(linker),host)
890 %(prog) : CMD:=$(HOST_CC)
891 %(prog) : STRIPCMD:=$(HOST_STRIP)
893 ifeq (%(linker),kernel)
894 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
895 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
898 %(prog) : OBJS := %(objs)
899 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
900 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
901 %(prog) : %(objs) $(TMP_DEPLIBS)
902 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
904 #------------------------------------------------------------------------------
907 #------------------------------------------------------------------------------
908 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
909 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
910 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
911 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
912 usestartup=yes detach=no
917 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
919 ifeq (%(usestartup),no)
920 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
921 TMP_EXTRA_LIBS += libinit autoinit
924 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
927 # Make a list of the lib files the programs depend on.
928 # In LDFLAGS remove white space between -L and directory
929 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
930 # Filter out only the libdirs and remove -L
931 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
933 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
934 # Add normal linklib path
935 TMP_DIRS += $(AROS_LIB)/
936 # add lib and .a to static linklib names
937 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
938 # search for the linklibs in the given path, ignore ones not found
939 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
940 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
942 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
944 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
945 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
946 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
947 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
949 #------------------------------------------------------------------------------
952 #------------------------------------------------------------------------------
953 # Link the %(objs) to the library %(libdir)/lib%(libname).a
954 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
956 ifeq (%(linker),target)
957 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
958 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
960 ifeq (%(linker),host)
961 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
962 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
964 ifeq (%(linker),kernel)
965 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
966 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
969 %(libdir)/lib%(libname).a : %(objs)
970 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
972 #------------------------------------------------------------------------------
974 #------------------------------------------------------------------------------
975 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
976 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
977 # The -nostdc flag is added so that modules are not linked with stdc.library,
978 # stdcio.library or posixc.library
979 # (see /config/specs.in file)
980 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
981 cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
983 TMP_LDFLAGS := %(ldflags)
984 # Make a list of the lib files the programs depend on.
985 # In LDFLAGS remove white space between -L and directory
986 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
987 # Filter out only the libdirs and remove -L
988 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
990 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
991 # Add normal linklib path
992 TMP_DIRS += $(AROS_LIB)/
993 # add lib and .a to static linklib names
994 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
995 # search for the linklibs in the given path, ignore ones not found
996 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
997 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1000 %(module) : LIB_NAMES := %(uselibs)
1001 %(module) : OBJS := %(objs)
1002 %(module) : ENDTAG := %(endobj)
1003 %(module) : ERR := %(err)
1004 %(module) : OBJDIR := %(objdir)
1005 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1006 ifeq (%(usehostlibs),)
1007 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1009 # Warning: the -L/usr/lib here can result in modules
1010 # linking against host libs instead of AROS libs (e.g stdc++) !!
1011 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1012 -L/usr/lib $(addprefix -l,%(usehostlibs))
1014 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1015 %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1018 #------------------------------------------------------------------------------
1021 #------------------------------------------------------------------------------
1022 # Generate the libdefs.h include file for a module.
1023 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1025 TMP_TARGET := %(modname)_libdefs.h
1026 TMP_DEPS := $(GENMODULE)
1028 ifneq (%(conffile),)
1029 ifeq ($(dir %(conffile)),./)
1030 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1031 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1033 TMP_OPTS += -c %(conffile)
1034 TMP_DEPS += %(conffile)
1037 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1038 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1040 ifneq (%(modsuffix),)
1041 TMP_OPTS += -s %(modsuffix)
1043 ifneq (%(targetdir),)
1044 TMP_OPTS += -d %(targetdir)
1045 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1048 TMP_OPTS += -v %(version)
1051 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1052 $(TMP_TARGET) : MODNAME := %(modname)
1053 $(TMP_TARGET) : MODTYPE := %(modtype)
1054 $(TMP_TARGET) : $(TMP_DEPS)
1055 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1056 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1058 #------------------------------------------------------------------------------
1060 #------------------------------------------------------------------------------
1061 # Generate the _lib.fd file for a module.
1062 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1064 TMP_TARGET := %(modname)_lib.fd
1065 TMP_DEPS := $(GENMODULE)
1067 ifneq (%(conffile),)
1068 ifeq ($(dir %(conffile)),./)
1069 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1070 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1072 TMP_OPTS += -c %(conffile)
1073 TMP_DEPS += %(conffile)
1076 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1077 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1079 ifneq (%(modsuffix),)
1080 TMP_OPTS += -s %(modsuffix)
1082 ifneq (%(targetdir),)
1083 TMP_OPTS += -d %(targetdir)
1084 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1087 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1088 $(TMP_TARGET) : MODNAME := %(modname)
1089 $(TMP_TARGET) : MODTYPE := %(modtype)
1090 $(TMP_TARGET) : $(TMP_DEPS)
1091 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1092 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1094 #------------------------------------------------------------------------------
1096 #------------------------------------------------------------------------------
1097 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1098 # generated file in this Makefile
1099 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1102 TMP_TARGET := Makefile.%(modname)%(modtype)
1103 TMP_DEPS := $(GENMODULE)
1105 ifneq (%(conffile),)
1106 ifeq ($(dir %(conffile)),./)
1107 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1108 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1110 TMP_OPTS += -c %(conffile)
1111 TMP_DEPS += %(conffile)
1114 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1115 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1117 ifneq (%(modsuffix),)
1118 TMP_OPTS += -s %(modsuffix)
1120 ifneq (%(targetdir),)
1121 TMP_OPTS += -d %(targetdir)
1122 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1125 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1126 $(TMP_TARGET) : MODNAME := %(modname)
1127 $(TMP_TARGET) : MODTYPE := %(modtype)
1128 $(TMP_TARGET) : $(TMP_DEPS)
1129 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1131 #------------------------------------------------------------------------------
1134 #------------------------------------------------------------------------------
1135 # Generate the support files for compiling a module. This includes include
1136 # files and source files. This rule has to be preceeded by
1137 # %rule_genmodule_makefile
1138 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1141 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1142 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1143 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1144 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1146 TMP_DEPS := $(GENMODULE)
1149 ifneq (%(conffile),)
1150 ifeq ($(dir %(conffile)),./)
1151 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1152 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1154 TMP_OPTS += -c %(conffile)
1155 TMP_DEPS += %(conffile)
1158 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1159 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1161 ifneq (%(modsuffix),)
1162 TMP_OPTS += -s %(modsuffix)
1164 ifneq (%(targetdir),)
1165 TMP_OPTS += -d %(targetdir)
1166 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1167 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1170 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1171 $(TMP_TARGETS) : MODNAME := %(modname)
1172 $(TMP_TARGETS) : MODTYPE := %(modtype)
1173 $(TMP_TARGETS) : $(TMP_DEPS)
1174 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1175 ifneq (%(conffile),lib.conf)
1176 @$(IF) $(TEST) -f lib.conf; then \
1177 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1180 @$(IF) $(TEST) -f libdefs.h; then \
1181 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1183 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1185 #------------------------------------------------------------------------------
1188 #------------------------------------------------------------------------------
1189 # Generate the support files for compiling a module. This includes include
1190 # files and source files.
1191 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1192 targetdir= conffile=
1194 ifneq ($(%(modname)_INCLUDES),)
1195 TMP_TARGETS := $(%(modname)_INCLUDES)
1197 TMP_DEPS := $(GENMODULE)
1200 ifneq (%(conffile),)
1201 ifeq ($(dir %(conffile)),./)
1202 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1203 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1205 TMP_OPTS += -c %(conffile)
1206 TMP_DEPS += %(conffile)
1209 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1210 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1212 ifneq (%(modsuffix),)
1213 TMP_OPTS += -s %(modsuffix)
1215 ifneq (%(targetdir),)
1216 TMP_OPTS += -d %(targetdir)
1217 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1220 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1221 $(TMP_TARGETS) : MODNAME := %(modname)
1222 $(TMP_TARGETS) : MODTYPE := %(modtype)
1223 $(TMP_TARGETS) : $(TMP_DEPS)
1224 @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1225 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1228 #------------------------------------------------------------------------------
1230 #------------------------------------------------------------------------------
1231 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1232 # 'start' is an optional starting address
1233 # 'ldflags' is optional additional flags for the linker
1234 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1236 BD_OUTDIR := $(dir %(file))
1237 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1238 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1239 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1240 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1241 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1244 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1246 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1247 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
1248 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1249 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1251 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1252 GLOB_MKDIRS += $(BD_OUTDIR)
1257 #------------------------------------------------------------------------------
1258 # Common rules for all makefiles
1260 # Delete generated makefiles
1263 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1265 include $(SRCDIR)/config/make.tail
1267 BDID := $(BDTARGETID)
1269 #------------------------------------------------------------------------------
1272 #############################################################################
1273 #############################################################################
1275 ## Here are the mmakefile build macros. These are macros that takes care ##
1276 ## of everything to go from the sources to the generated target. Also all ##
1277 ## intermediate files and directories that are needed are created by these ##
1280 #############################################################################
1281 #############################################################################
1283 #------------------------------------------------------------------------------
1285 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1287 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1288 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1289 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1290 compiler=target linker=
1294 BD_PROGNAME := %(progname)
1295 BD_OBJDIR := %(objdir)
1296 BD_TARGETDIR := %(targetdir)
1297 BD_LINKER := %(linker)
1299 # If not supplied, linker is equal to compiler
1300 ifeq ($(BD_LINKER),)
1301 BD_LINKER := %(compiler)
1304 BD_FILES := %(files)
1305 BD_OBJCFILES := %(objcfiles)
1306 BD_ASMFILES := %(asmfiles)
1307 BD_CXXFILES := %(cxxfiles)
1309 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1310 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1311 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1313 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1314 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1315 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1317 BD_CFLAGS := %(cflags)
1318 BD_AFLAGS := %(aflags)
1319 BD_DFLAGS := %(dflags)
1320 BD_LDFLAGS := %(ldflags)
1323 %(mmake)-quick : %(mmake)
1325 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1326 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1328 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1329 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1330 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1331 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1332 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1333 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1334 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1335 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1336 aflags=$(BD_AFLAGS) compiler=%(compiler)
1338 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1339 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1340 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1341 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1346 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1348 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1349 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1350 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1352 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1355 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1359 #------------------------------------------------------------------------------
1362 #------------------------------------------------------------------------------
1363 # Build programs, for every C file an executable will be built with the same
1364 # name as the C file
1365 %define build_progs mmake=/A files=/A nix=no \
1366 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1367 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1368 uselibs= usehostlibs= usestartup=yes detach=no
1372 BD_OBJDIR := %(objdir)
1373 BD_TARGETDIR := %(targetdir)
1375 BD_FILES := %(files)
1376 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1377 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1378 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1380 BD_CFLAGS := %(cflags)
1381 BD_DFLAGS := %(dflags)
1382 BD_LDFLAGS := %(ldflags)
1385 %(mmake)-quick : %(mmake)
1387 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1388 %(mmake) : $(BD_EXES)
1390 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1391 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1392 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1394 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1395 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1396 ldflags=$(BD_LDFLAGS) \
1397 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1398 usestartup="%(usestartup)" detach="%(detach)"
1402 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1404 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1405 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1406 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1408 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1411 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1415 #------------------------------------------------------------------------------
1418 #------------------------------------------------------------------------------
1420 # This is a bare version: It just compiles and links the given files. It is
1421 # assumed that all needed boiler plate code is in the files. This should only
1422 # be used for compiling external code. For AROS code use %build_module
1423 %define build_module_simple mmake=/A modname=/A modtype=/A \
1424 files="$(basename $(call WILDCARD, *.c))" \
1425 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1426 objdir=$(OBJDIR) moduledir= \
1427 uselibs= usehostlibs= compiler=target
1429 # Define metamake targets and their dependencies
1430 #MM %(mmake) : core-linklibs includes-generate-deps
1431 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1432 #MM %(mmake)-kobj-quick
1436 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1438 .PHONY : $(BD_ALLTARGETS)
1441 $(error using %build_module_simple: modname may not be empty)
1444 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1447 # Default values for variables and arguments
1448 BD_DEFLINKLIBNAME := %(modname)
1449 BD_DEFDFLAGS := %(cflags)
1450 OBJDIR ?= $(GENDIR)/$(CURDIR)
1451 BD_MODDIR := %(moduledir)
1452 ifeq ($(BD_MODDIR),)
1453 ifeq (%(modtype),library)
1454 BD_MODDIR := $(AROS_LIBRARIES)
1456 ifeq (%(modtype),gadget)
1457 BD_MODDIR := $(AROS_GADGETS)
1459 ifeq (%(modtype),datatype)
1460 BD_MODDIR := $(AROS_DATATYPES)
1462 ifeq (%(modtype),handler)
1463 BD_MODDIR := $(AROS_FS)
1465 ifeq (%(modtype),device)
1466 BD_MODDIR := $(AROS_DEVS)
1468 ifeq (%(modtype),resource)
1469 BD_MODDIR := $(AROS_RESOURCES)
1471 ifeq (%(modtype),hook)
1472 BD_MODDIR := $(AROS_RESOURCES)
1474 ifeq (%(modtype),mui)
1475 BD_MODDIR := $(AROS_CLASSES)/Zune
1477 ifeq (%(modtype),mcc)
1478 BD_MODDIR := $(AROS_CLASSES)/Zune
1480 ifeq (%(modtype),mcp)
1481 BD_MODDIR := $(AROS_CLASSES)/Zune
1483 ifeq (%(modtype),usbclass)
1484 BD_MODDIR := $(AROS_CLASSES)/USB
1486 ifeq (%(modtype),hidd)
1487 BD_MODDIR := $(AROS_DRIVERS)
1489 ifeq (%(modtype),printer)
1490 BD_MODDIR := $(AROS_PRINTERS)
1493 ifeq ($(BD_MODDIR),)
1494 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1497 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1498 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1499 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1501 %rule_compile_multi \
1502 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1503 cflags="%(cflags)" dflags="%(dflags)" \
1504 compiler=%(compiler)
1506 # Handlers use dash instead of dot in their names
1507 ifeq (%(modtype),handler)
1508 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1510 ifeq (%(modtype),printer)
1511 BD_MODULE := $(BD_MODDIR)/%(modname)
1513 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1516 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1518 %(mmake)-quick : %(mmake)
1519 %(mmake)-kobj-quick : $(BD_KOBJ)
1520 %(mmake) : $(BD_MODULE)
1521 %(mmake)-kobj : $(BD_KOBJ)
1523 # The module is linked from all the compiled .o files
1524 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1526 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1527 # This breaks con-handler build. Here we work around this
1528 ifeq (%(modname),con)
1529 BD_ERR := $(notdir $(BD_MODULE)).err
1531 BD_ERR := %(modname).err
1534 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1535 endobj= err=$(BD_ERR) objdir=%(objdir) \
1536 cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1537 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1539 # Link kernel object file
1540 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1542 # Make these symbols local
1543 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1544 UtilityBase ExpansionBase KeymapBase KernelBase
1546 BD_SYMBOLS := $(BD_KBASE)
1548 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1549 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1550 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1551 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1552 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1553 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1554 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1555 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1556 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1559 ## Dependency fine-tuning
1561 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1562 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1564 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1565 $(BD_MODULE) : | $(BD_MODDIR)
1566 $(BD_KOBJ) : | $(KOBJSDIR)
1567 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1569 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1571 @$(ECHO) "Cleaning up for module %(modname)"
1574 #------------------------------------------------------------------------------
1577 #------------------------------------------------------------------------------
1579 # Explanation of this macro is done in the developer's manual
1580 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1581 files="$(basename $(call WILDCARD, *.c))" \
1582 cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1583 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1584 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1585 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1586 compiler=target nostartup=yes archspecific=no
1588 # Define metamake targets and their dependencies
1589 #MM- includes-all : %(mmake)-includes
1590 #MM- linklibs-%(modname): %(mmake)-linklib
1591 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1592 #MM- includes-%(modname): %(mmake)-includes
1593 #MM- includes-%(modname)_rel : %(mmake)-includes
1594 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1595 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1596 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1597 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1598 #MM %(mmake)-quick : %(mmake)-includes-quick
1599 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1600 #MM includes-generate-deps %(mmake)-fd
1601 #MM %(mmake)-includes-quick
1602 #MM %(mmake)-includes-dirs
1604 #MM %(mmake)-makefile
1607 # All MetaMake targets defined by this macro
1608 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1609 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1610 %(mmake)-kobj %(mmake)-kobj-quick \
1611 %(mmake)-linklib %(mmake)-fd
1613 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1616 $(error using %build_module: modname may not be empty)
1619 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1622 # Default values for variables and arguments
1623 BD_DEFLINKLIBNAME := %(modname)
1624 BD_DEFDFLAGS := %(cflags)
1625 OBJDIR ?= $(GENDIR)/$(CURDIR)
1627 ## Create genmodule include Makefile for the module
1629 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1631 %rule_genmodule_makefile \
1632 modname=%(modname) modtype=%(modtype) \
1633 modsuffix=%(modsuffix) targetdir=%(objdir) \
1634 conffile=%(conffile)
1636 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1638 GLOB_MKDIRS += %(objdir)
1640 # Do not parse these statements if metatarget is not appropriate
1641 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1643 include %(objdir)/Makefile.%(modname)%(modtype)
1645 BD_DEFMODDIR := $(%(modname)_MODDIR)
1646 ifeq (%(archspecific),yes)
1647 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1651 ## include files generation
1653 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1654 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1655 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1657 %(mmake)-includes-quick : %(mmake)-includes
1658 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1659 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1660 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1662 ifneq ($(%(modname)_INCLUDES),)
1663 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1664 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1665 conffile=%(conffile)
1667 %rule_copy_diff_multi \
1668 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1669 stampfile=%(objdir)/%(modname)_geninc
1671 %rule_copy_diff_multi \
1672 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1673 stampfile=%(objdir)/%(modname)_incs
1675 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1677 TMP%(modname)_INCDIRS := \
1678 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1679 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1680 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1681 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1685 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1686 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1687 conffile=%(conffile) version=%(version)
1689 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1690 $(BD_DEFLIBDEFSINC) :
1691 @$(ECHO) "Generating $@"
1692 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1694 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1695 GLOB_MKDIRS += %(objdir)/include
1697 ## Extra genmodule src files generation
1699 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1700 modsuffix=%(modsuffix) targetdir=%(objdir) \
1701 conffile=%(conffile)
1705 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1706 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1708 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1709 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1711 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1713 GLOB_MKDIRS += $(BD_FDDIR)
1718 BD_FILES := %(files)
1719 BD_CXXFILES := %(cxxfiles)
1721 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1723 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1724 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1726 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1727 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1728 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1730 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1731 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1733 ifeq (%(modtype),library)
1736 BD_LIBSUFFIX := .%(modtype)
1739 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1740 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1741 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1744 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1745 ifneq (%(modname),%(linklibname))
1746 BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1749 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1751 ifneq ($(BD_CXXFILES),)
1752 BD_LINKCMD=$(AROS_CXX)
1754 BD_LINKCMD=$(AROS_CC)
1757 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1758 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1759 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1762 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1763 ifneq (%(modname),%(linklibname))
1764 BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1767 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1769 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1770 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1771 $(BD_RELLINKLIBCFILES)
1773 %rule_compile_multi \
1774 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1775 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1776 compiler=%(compiler)
1777 %rule_compile_multi \
1778 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1779 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1780 compiler=%(compiler)
1781 %rule_compile_cxx_multi \
1782 basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1783 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1784 compiler=%(compiler)
1786 ifneq ($(BD_LINKLIBAFILES),)
1787 %rule_assemble_multi \
1788 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1793 ifeq (%(modsuffix),)
1794 BD_SUFFIX := %(modtype)
1796 BD_SUFFIX := %(modsuffix)
1799 # Handlers use dash instead of dot in their names
1800 ifeq ($(BD_SUFFIX),handler)
1801 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1803 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1805 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1807 %(mmake)-quick : %(mmake)
1808 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1809 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1810 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1811 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1813 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1814 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1816 ifeq (%(nostartup),yes)
1817 # Handlers always have entry point
1818 ifneq (%(modtype),handler)
1819 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1823 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1824 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1827 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1830 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1831 # This breaks con-handler build. Here we work around this
1832 ifeq (%(modname),con)
1833 BD_ERR := $(notdir $(BD_MODULE)).err
1835 BD_ERR := %(modname).err
1838 # The module is linked from all the compiled .o files
1839 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1840 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1841 cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1842 uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1845 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1846 BD_MODNAME := $(shell echo %(modname) | tr A-Z a-z)
1847 ifneq ($(BD_LINKLIB),)
1848 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1849 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1850 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1853 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1854 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1857 ifneq ($(BD_RELLINKLIB),)
1858 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1859 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1860 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1863 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1864 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1867 # Link kernel object file
1868 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1870 # Make these symbols local
1871 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1872 UtilityBase ExpansionBase KeymapBase KernelBase
1874 BD_SYMBOLS := $(BD_KBASE)
1876 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1877 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1878 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1879 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1880 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1881 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1882 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1883 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1884 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1886 ## Dependency fine-tuning
1888 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1890 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1892 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1893 $(BD_MODULE) : | %(prefix)/%(moduledir)
1894 $(BD_KOBJ) : | $(KOBJSDIR)
1895 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1897 # Some include files need to be generated before the .c can be parsed.
1898 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
1900 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1901 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1902 $(BD_DEPS) : $(BD_DFILE_DEPS)
1905 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1906 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1907 %(objdir)/Makefile.%(modname)%(modtype) \
1908 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1909 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1910 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1911 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1912 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1913 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1915 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1917 @$(ECHO) "Cleaning up for module %(modname)"
1920 endif # $(TARGET) in $(BD_ALLTARGETS)
1922 #------------------------------------------------------------------------------
1925 #------------------------------------------------------------------------------
1926 # Build a module skeleton
1927 # This is a stripped-down version of build_module, it only creates include files,
1928 # but no actual object. This is used when for plugins or classes with the same
1929 # API, but no actual implementation here.
1930 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1932 objdir=$(OBJDIR) prefix=$(AROSDIR)
1934 # Define metamake targets and their dependencies
1935 #MM- includes-all : %(mmake)-includes
1936 #MM %(mmake) : %(mmake)-includes core-linklibs
1937 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1938 #MM %(mmake)-linklib : %(mmake)-includes
1939 #MM %(mmake)-quick : %(mmake)-includes-quick
1940 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1941 #MM includes-generate-deps
1942 #MM %(mmake)-includes-quick
1943 #MM %(mmake)-includes-dirs
1944 #MM %(mmake)-makefile
1947 # All MetaMake targets defined by this macro
1948 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1949 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1952 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1955 $(error using %build_module_skeleton: modname may not be empty)
1958 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1961 # Default values for variables and arguments
1962 BD_DEFLINKLIBNAME := %(modname)
1963 BD_DEFDFLAGS := %(cflags)
1964 OBJDIR ?= $(GENDIR)/$(CURDIR)
1966 ## Create genmodule include Makefile for the module
1968 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1970 %rule_genmodule_makefile \
1971 modname=%(modname) modtype=%(modtype) \
1972 modsuffix=%(modsuffix) targetdir=%(objdir) \
1973 conffile=%(conffile)
1975 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1977 GLOB_MKDIRS += %(objdir)
1979 # Do not parse these statements if metatarget is not appropriate
1980 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1982 include %(objdir)/Makefile.%(modname)%(modtype)
1984 BD_DEFMODDIR := $(%(modname)_MODDIR)
1987 ## include files generation
1989 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1990 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1991 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1993 %(mmake)-includes-quick : %(mmake)-includes
1994 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1995 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1996 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1998 ifneq ($(%(modname)_INCLUDES),)
1999 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2000 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2001 conffile=%(conffile)
2003 %rule_copy_diff_multi \
2004 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2005 stampfile=%(objdir)/%(modname)_geninc
2007 %rule_copy_diff_multi \
2008 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2009 stampfile=%(objdir)/%(modname)_incs
2011 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2013 TMP%(modname)_INCDIRS := \
2014 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2015 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2016 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2017 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2021 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2022 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2023 conffile=%(conffile)
2025 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2026 $(BD_DEFLIBDEFSINC) :
2027 @$(ECHO) "generating $@"
2028 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2030 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2031 GLOB_MKDIRS += %(objdir)/include
2033 ## Extra genmodule src files generation
2035 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2036 modsuffix=%(modsuffix) targetdir=%(objdir) \
2037 conffile=%(conffile)
2039 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2040 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2041 %(objdir)/Makefile.%(modname)%(modtype) \
2042 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2043 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2044 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2045 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2046 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2048 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2050 @$(ECHO) "Cleaning up for module %(modname)"
2053 endif # $(TARGET) in $(BD_ALLTARGETS)
2055 #------------------------------------------------------------------------------
2058 #------------------------------------------------------------------------------
2060 # - mmake is the mmaketarget
2061 # - libname is the baselibname e.g. lib%(libname).a will be created
2062 # - files are the C source files to include in the lib. The list of files
2063 # has to be given without the .c suffix
2064 # - cxxfiles are C++ source files without suffix.
2065 # NB: files will be matched in the order .cpp > .cxx > .cc
2066 # - asmfiles are the asm files to include in the lib. The list of files has to
2067 # be given without the .s suffix
2068 # - objs additional object to link into the linklib. The objects have to be
2069 # given with full absolute path and the .o suffix.
2070 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2071 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2072 # - cflags are the flags to compile the source (default $(CFLAGS))
2073 # - dflags are the flags use during makedepend (default equal to cflags)
2074 # - aflags are the flags use during assembling (default $(AFLAGS))
2075 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2076 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2077 asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2078 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2079 aflags=$(AFLAGS) compiler=target
2081 # assign and generate the local variables used in this macro
2082 BD_LIBNAME := %(libname)
2083 BD_LINKLIB := %(libdir)/lib%(libname).a
2085 BD_FILES := %(files)
2086 BD_ASMFILES := %(asmfiles)
2087 BD_CXXFILES := %(cxxfiles)
2089 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
2090 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
2091 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2093 BD_OBJS := $(BD_ARCHOBJS) \
2094 $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2096 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
2098 BD_CFLAGS := %(cflags)
2099 BD_AFLAGS := %(aflags)
2100 BD_DFLAGS := %(dflags)
2102 .PHONY : %(mmake) %(mmake)-clean
2104 #MM %(mmake) : includes-generate-deps
2105 %(mmake) : $(BD_LINKLIB)
2107 ifeq ($(TARGET),%(mmake))
2109 %rule_compile_multi basenames=$(BD_FILES) targetdir=%(objdir) \
2110 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2111 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2112 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2113 %rule_assemble basename=% targetdir=%(objdir) \
2116 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2119 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2121 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2122 $(BD_LINKLIB) : | %(libdir)
2123 GLOB_MKDIRS += %(objdir) %(libdir)
2125 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2128 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2132 #------------------------------------------------------------------------------
2135 #------------------------------------------------------------------------------
2137 # - mmake is the mmaketarget
2138 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2139 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2140 # - subdir is the destination subdirectory of the catalogs
2141 # - name is the name of the destination catalog, without the .catalog suffix
2142 # - source is the path to the generated source code file
2143 # - dir is the base destination directory (default $(AROS_CATALOGS))
2144 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2145 # - srcdir is the directory in which the *.cd and *.ct files are searched
2147 %define build_catalogs mmake=/A name=/A subdir=/A \
2148 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2149 sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2151 ifeq (%(description),)
2152 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2154 BD_DESC := %(description)
2157 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2160 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2162 BD_LNGS := %(catalogs)
2165 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2166 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2169 %(mmake) : $(BD_OBJS) %(source)
2171 $(BD_OBJS) : | $(BD_DIRS)
2172 GLOB_MKDIRS += $(BD_DIRS)
2174 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2175 @$(ECHO) "Creating %(name) catalog for language $*."
2176 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2179 %(source) : BD_DESC := $(BD_DESC)
2180 %(source) : BD_SRC := $(BD_SRC)
2181 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2182 @$(ECHO) "Creating %(name) catalog source file $@"
2183 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2186 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2189 @$(ECHO) "Cleaning up for metatarget %(mmake)"
2192 .PHONY: %(mmake) %(mmake)-clean
2195 #-----------------------------------------------------------------------------
2198 #-----------------------------------------------------------------------------
2200 # - mmake is the mmaketarget
2201 # - icons is a list of icon base names (ie. without the .info suffix)
2202 # - dir is the destination directory
2203 # - srcdir is where *.png and *.info.src are searched
2204 #-----------------------------------------------------------------------------
2206 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2208 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
2211 %(mmake) : $(BD_OBJS)
2215 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2216 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2217 @$(ILBMTOICON) $+ $@
2221 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2222 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
2223 @$(ILBMTOICON) $+ $@
2227 $(BD_OBJS) : | %(dir)
2228 GLOB_MKDIRS += %(dir)
2230 %(mmake)-clean : FILES := $(BD_OBJS)
2235 .PHONY: %(mmake) %(mmake)-clean
2238 #-----------------------------------------------------------------------------
2241 #------------------------------------------------------------------------------
2242 # Compile files for an arch-specific replacement of code for a module
2243 # - files: the basenames of the C files to compile.
2244 # - asmfiles: the basenames of the asm files to assemble.
2245 # - mainmmake: the mmake of the module in the main directory to compile these
2246 # arch specific files for.
2247 # - maindir: the object directory for the main module
2248 # - arch: the arch for which to compile these files. It can have the form
2249 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2250 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2251 # - dflags: the flags used during creation of dependency file. If not specified
2252 # the same value as cflags will be used
2253 # - aflags: the flags used during assembling
2254 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2255 # the target compiler is used
2256 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2257 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2259 ifeq (%(files) %(asmfiles),)
2260 $(error no files or asmfiles given)
2263 %buildid targets="%(mainmmake)-%(arch)"
2265 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2266 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2267 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2268 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2269 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2270 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2271 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2272 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2273 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2274 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2275 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2276 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2277 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2278 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2279 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2281 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2283 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2284 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2285 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2286 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2287 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2289 ifneq (%(modulename),)
2290 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2293 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2294 BD_TARGET := %(mainmmake)-%(arch)-quick
2296 BD_TARGET := %(mainmmake)-%(arch)
2300 ifeq ($(TARGET),$(BD_TARGET))
2301 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2302 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2303 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2304 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2307 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2308 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2311 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2314 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2316 ifeq ($(findstring %(compiler),host kernel target),)
2317 $(error unknown compiler %(compiler))
2319 ifeq (%(compiler),target)
2320 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2321 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2322 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2324 ifeq (%(compiler),host)
2325 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2326 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2327 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2329 ifeq (%(compiler),kernel)
2330 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2331 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2332 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2334 ifneq (%(modulename),)
2335 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2337 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2339 ifeq ($(TARGET),$(BD_TARGET))
2340 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2341 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2345 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2347 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2349 ifeq ($(TARGET),$(BD_TARGET))
2350 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2351 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2354 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2356 ifeq ($(TARGET),$(BD_TARGET))
2357 $(BD_OBJDIR$(BDID))/%.o : %.s
2358 %assemble_q opt=$(AFLAGS)
2359 $(BD_OBJDIR$(BDID))/%.o : %.S
2360 %assemble_q opt=$(AFLAGS)
2363 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2365 #------------------------------------------------------------------------------
2368 #------------------------------------------------------------------------------
2369 # generate asm files from c files (for debugging purposes)
2372 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2373 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2375 #------------------------------------------------------------------------------
2378 #------------------------------------------------------------------------------
2379 # Copy files from one directory to another.
2381 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2383 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2385 GLOB_MKDIRS += %(dst)
2391 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2394 #------------------------------------------------------------------------------
2397 #------------------------------------------------------------------------------
2398 # Copy a directory recursively to another place, preserving the original
2399 # hierarchical structure
2401 # src: the source directory whose content will be copied.
2402 # dst: the directories where to copy src's content. If not existing, they will be made.
2403 # excludefiles: files which must not be copied. Path must be relative to src.
2405 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2411 @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2414 #------------------------------------------------------------------------------
2417 #------------------------------------------------------------------------------
2418 # Copy include files into the includes directories. There are currently
2419 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2420 # for building tools that need to run on the host system $(GENINCDIR). The
2421 # $(GENINCDIR) path must not contain any references to the C runtime
2422 # library header files.
2424 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2425 dir= compiler=target
2427 ifeq ($(findstring %(compiler),host kernel target),)
2428 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2432 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2433 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2434 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2436 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2437 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2440 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2444 ifeq (%(compiler),target)
2447 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2448 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2450 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2453 BD_INCL_FILES += $(BD_INCL_FILES2)
2455 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2460 %(mmake) : $(BD_INCL_FILES)
2464 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2465 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2467 #------------------------------------------------------------------------------
2470 #------------------------------------------------------------------------------
2471 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2472 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2473 STUBS_MEM := $(addsuffix .o,$(STUBS))
2474 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2475 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2476 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2478 #MM- linklibs : hidd-%(hidd)-stubs
2479 #MM- %(parenttarget): hidd-%(hidd)-stubs
2480 #MM hidd-%(hidd)-stubs : includes includes-copy
2481 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2483 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2486 $(STUBS_OBJ) : $(STUBS_SRC)
2487 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2489 $(STUBS_DEP) : $(STUBS_SRC)
2490 %mkdepend_q flags=%(dflags)
2493 %mkdirs_q $(OBJDIR) $(AROS_LIB)
2497 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2499 DEPS := $(DEPS) $(STUBS_DEP)
2502 #------------------------------------------------------------------------------
2505 #------------------------------------------------------------------------------
2506 # Build an imported source tree which uses the configure script from the
2507 # autoconf package. This rule will try to "integrate" the produced files as
2508 # much as possible in the AROS build, for example by putting libraries in the
2509 # standard library directory, includes in the standard include directory, and
2510 # so on. You can however override this behaviour.
2512 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2513 # be %(bindir) (or its deduced value) when running "make install", and
2514 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2515 # configure script some more parameters whose value depends upon the PROGDIR
2516 # env var, so that the program gets all its stuff installed in the proper place
2517 # when building it, but when running it from inside AROS it can also find that
2518 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2519 # the configuration parameters set when running ./configure
2521 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2522 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2523 # to the name which has to follow it.
2527 # - mmake = the meta make target.
2528 # - package = name of the package to be built.
2529 # - srcdir = the location of the unpacked source code. Defaults
2530 # to $(SRCDIR)/$(CURDIR).
2531 # - prefix = the target directory. Must be an absolute path of the
2532 # host system. Defaults to $(AROS_CONTRIB).
2533 # - aros_prefix = set a path which is valid within the AROS filesystem.
2534 # Defaults to the value of the prefix option.
2535 # - extraoptions = additional options for the configure script.
2536 # - extracflags = additional flags which are used for both C and C++.
2537 # - nix_dir_layout = if yes the binary will be stored in a bin subdirectory.
2538 # Defaults to the value of the nix argument.
2539 # - nix = enable u*nix path handling, i.e. a path like
2540 # /progdir//./file will be translated to
2541 # progdir:file during run-time. Defaults to no.
2542 # - compiler = target, host or kernel. Defaults to target.
2543 # - install_target = the command used for installing. Defaults to install. Leave
2544 # it empty if you want to suppress installing.
2545 # - preconfigure = a metatarget which is executed before configure is called.
2546 # - postconfigure = a metatarget which is executed after configure is called.
2547 # - postinstall = a metatarget which is executed after installing.
2548 # - install_env = set additional options for installing.
2549 # - use_build_env = if yes the configuration environment is used for
2550 # installing, too. Defaults to no.
2552 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2556 # --prefix = $(aros_prefix)
2557 # progdir = $(aros_prefix)/bin
2560 # --prefix = /PROGDIR
2561 # --bindir = /PROGDIR
2562 # --sbindir = /PROGDIR
2564 # --includedir = /INCLUDE
2565 # --oldincludedir = /INCLUDE
2567 # --prefix = $(aros_prefix)
2570 # progdir = $(aros_prefix)
2573 # bindir = $(prefix)
2574 # sbindir = $(prefix)
2575 # libdir = $(AROS_LIB)
2576 # includedir = $(AROS_INCLUDES)
2577 # oldincludedir = $(AROS_INCLUDES)
2581 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2582 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2583 install_target=install preconfigure= postconfigure= postinstall= \
2584 install_env= use_build_env=no
2587 %(mmake)-prefix := %(prefix)
2589 %(mmake)-prefix := $(AROS_CONTRIB)
2592 ifneq (%(aros_prefix),)
2593 %(mmake)-aros_prefix := %(aros_prefix)
2595 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2599 %(mmake)-nix := -nix
2600 %(mmake)-volpfx := /
2601 %(mmake)-volsfx := /
2603 ifeq (%(nix_dir_layout),)
2604 %(mmake)-nix_dir_layout := yes
2607 %(mmake)-volsfx := :
2609 ifeq (%(nix_dir_layout),)
2610 %(mmake)-nix_dir_layout := no
2614 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2616 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2617 exec_prefix=$(%(mmake)-prefix) %(install_env)
2619 # Check if chosen compiler is valid
2620 ifeq ($(findstring %(compiler),host target kernel),)
2621 $(error unknown compiler %(compiler))
2624 # Set legacy 'host' variable based on chosen compiler
2625 ifeq (%(compiler),host)
2628 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2630 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2635 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2637 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2642 %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2644 %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2648 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2649 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2651 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2652 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2653 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2656 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2657 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2659 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2662 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2664 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2665 sbindir=$(%(mmake)-prefix) \
2666 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2667 oldincludedir=$(AROS_INCLUDES) %(install_env)
2670 ifneq ($(DEBUG),yes)
2671 %(mmake)-s_flag = -s
2674 # Set up build environment, and options for configure script
2675 ifeq (%(compiler),host)
2678 CXXCPP="$(HOST_CPP)" \
2679 CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2680 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2681 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2682 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2683 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2684 TARGET_NM="$(NM_PLAIN)"
2686 ifeq (%(compiler),target)
2688 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2689 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2690 CPP="$(TARGET_CPP)" \
2691 CXXCPP="$(TARGET_CPP)" \
2692 CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2693 CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2694 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2695 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2696 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2697 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2698 TARGET_NM="$(NM_PLAIN)" \
2699 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2700 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2701 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2702 --host=$(AROS_TARGET_CPU)-aros\
2703 --target=$(AROS_TARGET_CPU)-aros\
2705 --without-x --without-pic --disable-shared
2707 ifeq (%(compiler),kernel)
2709 CPP="$(KERNEL_CPP)" \
2710 CXXCPP="$(KERNEL_CPP)" \
2711 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2712 CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2713 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2714 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2715 TARGET_NM="$(NM_PLAIN)"
2716 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2717 --host=$(AROS_TARGET_CPU)-aros\
2718 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2719 --without-x --without-pic --disable-shared
2722 ifeq (%(use_build_env),yes)
2723 BUILD_ENV := $(CONFIG_ENV)
2727 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2729 # When building for the host, we don't need to build the
2730 # linklibs - this is especially true when building the
2731 # crosstool toolchain on 'foreign' architectures (such as
2732 # building PPC on x86)
2734 #MM- %(mmake)-host : setup includes %(mmake)-quick
2735 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2736 #MM- %(mmake): %(mmake)-%(compiler)
2738 # Using -j1 in install_command may result in a warning but finally
2739 # it does its job. make install for gcc does not work reliably for -jN
2741 ifneq (%(install_target),)
2742 %(mmake)-install_command = \
2743 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2744 -C $(%(mmake)-pkgdir) %(install_target) -j1
2746 %(mmake)-uninstall_command = \
2747 $(RM) $(%(mmake)-installflag) && \
2748 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2749 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2751 %(mmake)-install_command := true
2752 %(mmake)-uninstall_command := true
2755 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2758 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2760 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2761 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2762 $(RM) $(%(mmake)-installflag) && \
2763 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2764 -C $(%(mmake)-pkgdir) && \
2765 $(%(mmake)-install_command) && \
2766 $(TOUCH) $@ -r $^; \
2769 $(%(mmake)-pkgdir)/.files-touched:
2770 %mkdirs_q $(%(mmake)-pkgdir)
2771 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2775 %(mmake)-uninstall :
2776 $(%(mmake)-uninstall_command)
2779 %(mmake)-configure : $(%(mmake)-configflag)
2781 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2782 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2784 %mkdirs_q $(%(mmake)-pkgdir)
2785 cd $(%(mmake)-pkgdir) && \
2786 find . -name config.cache -exec $(RM) '{}' \; && \
2787 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2788 %(extraoptions) && \
2792 %(mmake)-clean : %(mmake)-uninstall
2793 @$(RM) $(%(mmake)-pkgdir)
2795 #------------------------------------------------------------------------------
2798 #------------------------------------------------------------------------------
2799 # Given an archive name, patches names and locations where to find them, fetch
2800 # the archive and the patches from any of those locations, unpack the archive
2801 # and then apply the patches.
2803 # Locations currently supported are http and ftp sites, plus local filesystem
2804 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2805 # the fetch.sh script needs to be modified, since this macro relies on that script.
2809 # - mmake = mmaketarget
2810 # - archive_origins = list of locations where to find the archive. They are tried
2811 # in sequence, until the archive is found and fetching it
2812 # succeeded. If not specified, the current directory is assumed.
2813 # - archive = the archive name. Mandatory.
2814 # - suffixes = a list of suffixes to append to the the package name plus the
2815 # version. Each one of them is tried until a matching archive is
2816 # found. They are appended to patches and these are tried the
2817 # same way as packages are.
2818 # - location = the local directory where to put the fetched archive and patches.
2819 # If not specified, the directory specified by destination is used.
2820 # - destination = the directory to unpack the archive to.
2821 # If not specified, the current directory is assumed.
2822 # - patches_origins = list of locations where to find the patches. They are tried
2823 # in sequence, until a patch is found and fetching it
2824 # succeeded. If not specified, the current directory is assumed.
2825 # - patches_specs = list of "patch specs". A patch spec is of the form
2826 # patch_name[:[patch_subdir][:patch_opt]].
2828 # - patch_name = the name of the patch file
2829 # - patch_subdir = the directory within \destination\ where to
2831 # - patch_opt = any options to pass to the `patch' command
2832 # when applying the patch.
2834 # The patch_subdir and patch_opt fields are optional.
2836 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2837 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2841 ifneq (%(location),)
2842 %(mmake)-location := %(location)
2844 %(mmake)-location := %(destination)
2849 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2850 -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2852 #------------------------------------------------------------------------------
2855 #------------------------------------------------------------------------------
2856 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2857 # unpatched source tree and runs diff against this and a previously fetched and possibly
2858 # patched tree. Depending on what happens after patching during a normal build it might
2859 # give best results if the new patch is created directly after fetch.
2863 # - mmake = mmaketarget
2864 # - archive = archive base name
2865 # - srcdir = the top level directory the package is unpacked to, useful if
2866 # an archive unpacks to a directory other than its name suggests.
2867 # this should not be deeper than a single path element.
2868 # - suffixes = a list of suffixes to append to the the package name plus the
2869 # version. Each one of them is tried until a matching archive is
2871 # - destination = the directory to unpack the archive to.
2872 # - excludes = diff patterns to exclude files or directories from the patch
2874 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2878 ifneq (%(excludes),)
2879 %(mmake)-exclude := -X ./exclude.patterns
2883 %(mmake)-srcdir := %(srcdir)
2885 %(mmake)-srcdir := %(archive)
2890 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2891 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2892 cd %(destination)/tmp ; \
2893 $(FOR) f in %(excludes) ; do \
2894 $(ECHO) $$f >> ./exclude.patterns ; \
2896 diff -ruN $(%(mmake)-exclude) \
2897 $(%(mmake)-srcdir) \
2898 $(%(mmake)-srcdir).aros \
2899 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2900 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2901 $(RM) %(destination)/tmp
2903 #------------------------------------------------------------------------------
2906 #------------------------------------------------------------------------------
2907 # Joins the features of %fetch and %build_with_configure.
2909 # If a patch is provided, it *must* be named the following way:
2911 # <package name>-<version number>-aros.diff
2913 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2914 # CD'ing into the archive's extracted directory.
2916 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2917 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2918 # to make that patch fully comprehensive.
2922 # - mmake = the meta make target.
2923 # - package = the GNU package name, sans version and archive format suffixes.
2924 # - subpackage = ???
2925 # - compiler = same meaning as the one for the %build_with_configure macro.
2926 # - install_target = same meaning as the one for the %build_with_configure macro.
2927 # - version = the package's version number, or otherwise any other version string.
2928 # It gets appended to the package name to form the basename of the archive.
2929 # - suffixes = a list of suffixes to apped to the the package name plus the
2930 # version. Each one of them is tried until a matching archive is found.
2931 # Defaults to "tar.bz2 tar.gz".
2932 # - srcdir = the top level directory the package is unpacked to (see create_patch).
2933 # - builddir = override the location we expect to run configure/make in.
2934 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2935 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2936 # fetched or not. Default to no.
2937 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2938 # - prefix = same meaning as the one for the %build_with_configure macro.
2939 # - aros_prefix = same meaning as the one for the %build_with_configure macro.
2940 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2941 # - extracflags = same meaning as the one for the %build_with_configure macro.
2942 # - preconfigure = same meaning as the one for the %build_with_configure macro.
2943 # - postconfigure = same meaning as the one for the %build_with_configure macro.
2944 # - postinstall = same meaning as the one for the %build_with_configure macro.
2945 # - install_env = same meaning as the one for the %build_with_configure macro.
2946 # - use_build_env = same meaning as the one for the %build_with_configure macro.
2947 # - nix = same meaning as the one for the %build_with_configure macro.
2948 # - nix_dir_layout = same meaning as the one for the %build_with_configure macro.
2949 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2951 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2952 version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
2953 prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2954 install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2956 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2957 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2958 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2959 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2961 %(mmake)-archbase := %(package)-%(version)
2963 ifeq (%(compiler),host)
2964 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2966 %(mmake)-portdir := $(PORTSDIR)/%(package)
2970 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2972 %(mmake)-prefix := %(prefix)
2975 ifneq (%(subpackage),)
2976 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2978 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2982 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2984 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2987 ifneq (%(builddir),)
2988 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
2990 %(mmake)-%(subpackage)-builddir := $(%(mmake)-%(subpackage)-srcdir)
2994 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
2996 %(mmake)-%(subpackage)-patches_specs := ::
2999 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3000 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3001 archive_origins=". %(package_repo)" \
3002 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3004 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3005 archive=$(%(mmake)-%(subpackage)-archbase) \
3006 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3007 suffixes="%(suffixes)" \
3008 destination=$(%(mmake)-portdir)
3010 #MM- %(mmake) : %(mmake)-%(subpackage)
3012 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3014 %(mmake)-%(subpackage)-package-basename := \
3015 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3017 ifneq (%(create_pkg),no)
3018 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3021 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3022 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3023 install_env=%(install_env) use_build_env=%(use_build_env) \
3024 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3025 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3026 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3028 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3029 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3032 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3034 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3035 #that $^ and $@ have exactly the same mtime, and in that case make tries
3036 #to rebuild $@ again, which would fail because the directory where
3037 #the package got installed would not exist anymore.
3038 #We work this around by using an if statement to manually check the mtimes.
3039 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3040 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3042 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3043 mkdir -p "$(DISTDIR)/Packages" ; \
3044 mkdir -p "$(%(mmake)-prefix)" ; \
3045 cd $(%(mmake)-%(subpackage)-package-dir) ; \
3046 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3047 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3050 #------------------------------------------------------------------------------
3053 #------------------------------------------------------------------------------
3054 # Joins the features of %fetch and %build_with_configure, taking advantage of
3055 # the naming scheme of GNU packages. GNU packages names are in the form
3057 # <package name>-<version number>.<archive format suffix>
3059 # If a patch is provided, it *must* be named the following way:
3061 # <package name>-<version number>-aros.diff
3063 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3064 # CD'ing into the archive's extracted directory.
3066 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3067 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3068 # to make that patch fully comprehensive.
3070 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3074 # Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3076 # - prefix = defaults to $(GNUDIR).
3077 # - aros_prefix = defaults to /GNU.
3079 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3080 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3081 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
3083 GNU_REPOSITORY := gnu://
3085 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3086 suffixes="%(suffixes)" srcdir="%(srcdir)" \
3087 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3088 patch="%(patch)" patch_repo="%(patch_repo)" \
3089 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3090 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3093 #------------------------------------------------------------------------------
3096 #------------------------------------------------------------------------------
3097 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3098 # that the package is a "Development" package, and as such it needs to be placed
3099 # under the $(AROS_DEVELOPMENT) directory, as a default.
3101 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
3102 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3103 # "mmake" argument, because the metatarget is implicitely defined as
3105 # #MM- development-%(package)
3107 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3108 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3109 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
3111 #MM- development : development-%(package)
3114 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3115 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
3116 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3117 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3118 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3121 postinstall-%(package)-delete-la-files:
3122 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3125 #------------------------------------------------------------------------------
3127 # Builds a kickstart package in PKG format
3131 # - mmake = target name
3132 # - file = destination file name with path
3134 # Other arguments are self-explanatory
3136 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3137 arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3139 PKG_CLASSES := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3140 PKG_DEVICES := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3141 PKG_HANDLERS := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3142 PKG_HIDD := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3143 PKG_LIBS := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3144 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3146 PKG_CLASSES_ARCH := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3147 PKG_DEVICES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3148 PKG_HANDLERS_ARCH := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3149 PKG_HIDD_ARCH := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3150 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3151 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3153 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3154 $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3155 PKG_DIR := $(dir %(file))
3161 %(mmake)-quick : %(file)
3163 %(file): $(PKG_FILES) | $(PKG_DIR)
3164 @$(ECHO) Packaging $@...
3165 @$(SRCDIR)/tools/package/pkg c $@ $^
3167 %compress_file mmake=%(mmake) file=%(file)
3169 GLOB_MKDIRS += $(PKG_DIR)
3173 #------------------------------------------------------------------------------
3174 # Compresses %(file) with a gzip.
3175 # Good in conjunction with for example %build_prog
3177 %define compress_file mmake=/A file=/A
3179 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3182 %(mmake)-gz-quick : %(file).gz
3185 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3190 #------------------------------------------------------------------------------
3191 # Links a kickstart module in ELF format
3192 # Arguments are similar to make_package
3194 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3195 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3197 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3198 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3199 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3200 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3201 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3202 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3205 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3207 KOBJ_STARTUP := %(startup)
3210 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3212 TMP_LDFLAGS := %(ldflags)
3214 # Make a list of the lib files this program depends on.
3215 # In LDFLAGS remove white space between -L and directory
3216 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3217 # Filter out only the libdirs and remove -L
3218 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3220 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3221 # Add normal linklib path
3222 TMP_DIRS += $(AROS_LIB)/
3223 # add lib and .a to static linklib names
3224 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3225 # search for the linklibs in the given path, ignore ones not found
3226 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3227 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3230 TMP_DIRS += $(dir %(file))
3232 TMP_LDFLAGS += $(GENMAP) %(map)
3233 TMP_DIRS += $(dir %(map))
3236 #MM %(mmake) : %(deps)
3242 %(mmake)-quick : %(file)
3244 %(file): KOBJS := $(KOBJS)
3245 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3246 -nostdc -nosysbase -Wl,-Ur
3247 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3248 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3249 @$(ECHO) "Kickstart $(subst $(TARGETDIR)/,,$@)..."
3250 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3253 %compress_file mmake=%(mmake) file=%(file)
3255 GLOB_MKDIRS += $(TMP_DIRS)