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 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16 @$(ECHO) "Compiling $(CURDIR)/$(notdir %(from))"
17 @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
25 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36 @$(ECHO) "Assembling $(notdir %(from))..."
37 @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
45 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,%(to))..."
57 @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
65 $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79 @$(ECHO) "Building $(subst $(TARGETDIR)/,,$@) ..."
80 @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81 $(GENMAP) %(objdir)/%(module).map \
82 %(objs) %(libs) %(endtag) \
83 -o $@ 2>&1 > %(objdir)/%(err); \
85 cat %(objdir)/%(err); \
87 echo "$(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(endtag) -o $@"; \
88 cat %(objdir)/%(err); \
92 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
95 #------------------------------------------------------------------------------
98 #------------------------------------------------------------------------------
100 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
101 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,%(to))..."
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the dependency file %(to) for %(from)
110 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
111 %mkdir_q dir="$(dir %(to))"
112 @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
113 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create one directory without any output
120 %define mkdir_q dir=.
121 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
123 #------------------------------------------------------------------------------
126 #------------------------------------------------------------------------------
127 # Create several directories without any output
128 %define mkdirs_q dirs=/M
129 @$(FOR) dir in %(dirs) ; do \
130 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
133 #------------------------------------------------------------------------------
136 #############################################################################
137 #############################################################################
139 ## Here are the mmakefile macros that are used to do certain tasks in a ##
140 ## mmakefile. They consist of one or more full makefile rules. ##
141 ## In general the files generated in these macros are also defined as ##
142 ## make targets so that they can be used as a dependency in other rules ##
144 #############################################################################
145 #############################################################################
147 #------------------------------------------------------------------------------
148 # Generate a unique id for each of the %build... rules
149 %define buildid targets=/A
151 ifneq ($(filter $(TARGET),%(targets)),)
152 BDTARGETID := $(BDID)
155 #------------------------------------------------------------------------------
158 #------------------------------------------------------------------------------
159 # Copy file %(from) to %(to) in a makefile rule
160 %define rule_copy from=/A to=/A
164 #------------------------------------------------------------------------------
167 #------------------------------------------------------------------------------
168 # Copy the files %(files) to %(targetdir). For each file in %(files),
169 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
170 # appropriate subdirs are not generated by this rule so they have to be
172 %define rule_copy_multi files=/A targetdir=/A srcdir=.
174 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
177 #------------------------------------------------------------------------------
180 #------------------------------------------------------------------------------
181 # Copy the files %(files) to %(targetdir). For each file in %(files),
182 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
183 # %(stampfile) is used to keep track of when the last time the comparison has
184 # been done. The targetdir and the appropriate subdirs are not generated by
185 # this rule so they have to be present.
186 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
187 stampfile=$(TMP_SRCDIR)/.copy_stamp
189 TMP_SRCDIR := %(srcdir)
191 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
193 %(stampfile) : COPYSRCDIR := %(srcdir)
194 %(stampfile) : TGTDIR := %(targetdir)
195 %(stampfile) : FILES := %(files)
196 %(stampfile) : $(addprefix %(srcdir)/,%(files))
197 @for f in $(FILES); do \
198 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
199 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
204 #------------------------------------------------------------------------------
207 #------------------------------------------------------------------------------
208 # Will join all the files in %(from) to %(to). When text is specified it will
210 # Restriction: at the moment when using a non-empty target dir %(from) may
212 %define rule_join to=/A from=/A text=
220 #------------------------------------------------------------------------------
223 #------------------------------------------------------------------------------
224 # Include the dependency files and add some internal rules
225 # When depstargets is provided the depencies will only be included when one of
226 # these targets is the $(TARGET). Otherwise the dependencies will only be
227 # included when the $(TARGET) is not for setup or clean
228 %define include_deps deps=$(DEPS)/M depstargets=
230 ifneq (%(depstargets),)
231 ifneq ($(findstring $(TARGET),%(depstargets)),)
235 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
241 #------------------------------------------------------------------------------
244 #------------------------------------------------------------------------------
245 # Create the directories %(dirs). The creation will be done by adding rules to
246 # the %(setuptarget) make target with setup as the default.
247 %define rule_makedirs dirs=/A setuptarget=setup
249 %(setuptarget) :: %(dirs)
251 GLOB_MKDIRS += %(dirs)
254 #------------------------------------------------------------------------------
257 #------------------------------------------------------------------------------
258 # Generate a rule to compile a C source file to an object file and generate
259 # the dependency file. Basename may contain a directory part, then the source
260 # file has to be in that directory. The generated file will be put in the
261 # object directory without the directory.
263 # - basename: the basename of the file to compile. Use % for a wildcard rule
264 # - cflags (default $(CFLAGS)): the C flags to use for compilation
265 # - dflags: the flags used during creation of dependency file. If not specified
266 # the same value as cflags will be used
267 # - targetdir: the directory to put the .o file and the .d file. By default
268 # it is put in the same directory as the .c file
269 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
272 TMP_TARGETBASE := %(basename)
274 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
277 ifeq ($(findstring %(compiler),host kernel target),)
278 $(error unknown compiler %(compiler))
280 ifeq (%(compiler),target)
281 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
283 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
285 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
288 ifeq (%(compiler),host)
289 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
291 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
296 ifeq (%(compiler),kernel)
297 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
306 $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
308 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
310 $(TMP_TARGETBASE).o : %(basename).c
311 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
315 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
317 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
321 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
323 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
326 $(TMP_TARGETBASE).d : %(basename).c
327 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
329 #------------------------------------------------------------------------------
332 #------------------------------------------------------------------------------
333 # Generate a rule to compile a C++ source file to an object file and generate
334 # the dependency file. Basename may contain a directory part, then the source
335 # file has to be in that directory. The generated file will be put in the
336 # object directory without the directory.
338 # - basename: the basename of the file to compile. Use % for a wildcard rule
339 # - cflags (default $(CFLAGS)): the C flags to use for compilation
340 # - dflags: the flags used during creation of dependency file. If not specified
341 # the same value as cflags will be used
342 # - targetdir: the directory to put the .o file and the .d file. By default
343 # it is put in the same directory as the .c file
344 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
347 TMP_TARGETBASE := %(basename)
349 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
352 # Adjust compiler flags to suit C++
353 TMP_CXXFLAGS := %(cflags)
354 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
355 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
357 ifeq ($(findstring %(compiler),host kernel target),)
358 $(error unknown compiler %(compiler))
360 ifeq (%(compiler),target)
361 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
362 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
363 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
364 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
365 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
366 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
368 ifeq (%(compiler),host)
369 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
370 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
373 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
374 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
376 ifeq (%(compiler),kernel)
377 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
378 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
386 $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_CXXFLAGS)
388 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
390 $(TMP_TARGETBASE).o : %(basename).cpp
391 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
397 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
401 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
403 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
406 $(TMP_TARGETBASE).d : %(basename).cpp
407 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
409 #------------------------------------------------------------------------------
412 #------------------------------------------------------------------------------
413 # Generate a rule to compile multiple C source files to an object file and
414 # generate the corresponding dependency files. The generated file will be put
415 # in the object directory without the directory part of the source file.
417 # - basenames: the basenames of the files to compile. The names may include
418 # relative or absolute path names. No wildcard is allowed
419 # - cflags (default $(CFLAGS)): the C flags to use for compilation
420 # - dflags: the flags used during creation of dependency file. If not specified
421 # the same value as cflags will be used
422 # - targetdir: the directory to put the .o file and the .d file. By default
423 # it is put in the same directory as the .c file. When targetdir is not
424 # empty, path names will be stripped from the file names so that all files
425 # are in that dir and not in subdirectories.
426 # - compiler (default target): compiler to use, target, kernel or host
427 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
431 TMP_TARGETS := $(addsuffix .o,%(basenames))
432 TMP_DTARGETS := $(addsuffix .d,%(basenames))
435 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
436 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
437 TMP_WILDCARD := %(targetdir)/%
439 # Be sure that all .c files are generated
440 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
442 # Be sure that all .c files are found
443 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
444 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
445 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
447 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
448 vpath %.c $(TMP_DIRS)
453 ifeq ($(findstring %(compiler),host kernel target),)
454 $(error unknown compiler %(compiler))
456 ifeq (%(compiler),target)
457 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
458 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
461 ifeq (%(compiler),host)
462 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
463 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
466 ifeq (%(compiler),kernel)
467 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
472 $(TMP_TARGETS) : CFLAGS := %(cflags)
473 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
474 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
477 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
479 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
481 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
482 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
484 #------------------------------------------------------------------------------
487 #------------------------------------------------------------------------------
488 # Generate a rule to compile multiple C++ source files to an object file and
489 # generate the corresponding dependency files. The generated file will be put
490 # in the object directory without the directory part of the source file.
492 # - basenames: the basenames of the files to compile. The names may include
493 # relative or absolute path names. No wildcard is allowed
494 # - cflags (default $(CFLAGS)): the C flags to use for compilation
495 # - dflags: the flags used during creation of dependency file. If not specified
496 # the same value as cflags will be used
497 # - targetdir: the directory to put the .o file and the .d file. By default
498 # it is put in the same directory as the .c file. When targetdir is not
499 # empty, path names will be stripped from the file names so that all files
500 # are in that dir and not in subdirectories.
501 # - compiler (default target): compiler to use, target, kernel or host
502 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
503 targetdir= compiler=target
505 # Adjust compiler flags to suit C++
506 TMP_CXXFLAGS := %(cflags)
507 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
508 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
511 TMP_TARGETS := $(addsuffix .o,%(basenames))
512 TMP_DTARGETS := $(addsuffix .d,%(basenames))
515 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
516 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
517 TMP_WILDCARD := %(targetdir)/%
519 # Be sure that all .cpp files are generated
520 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .cpp,%(basenames))
522 # Be sure that all .cpp files are found
523 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
524 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
525 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
527 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
528 vpath %.cpp $(TMP_DIRS)
533 # Define the use of cross compiler
534 ifeq ($(TARGET_CXX),)
535 TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-g++
537 TMP_CC := $(TARGET_CXX)
540 ifeq ($(findstring %(compiler),host kernel target),)
541 $(error unknown compiler %(compiler))
543 ifeq (%(compiler),target)
544 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
545 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
546 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
548 ifeq (%(compiler),host)
549 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
550 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
551 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
553 ifeq (%(compiler),kernel)
554 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
555 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
556 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
559 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
560 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
561 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
564 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
566 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
568 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
569 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
571 #------------------------------------------------------------------------------
574 #------------------------------------------------------------------------------
575 # Make an alias from one arch specific build to another arch.
577 # - mainmmake: the mmake of the module in the main tree
578 # - arch: the current arch
579 # - alias: the alias to which this should point
580 %define rule_archalias mainmmake=\A arch=\A alias=\A
582 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
584 #------------------------------------------------------------------------------
587 #------------------------------------------------------------------------------
588 # Generate a rule to assemble a source file to an object file. Basename may
589 # contain a directory part, then the source file has to be in that directory.
590 # The generated file will be put in the object directory without the directory.
592 # - basename: the basename of the file to compile. Use % for a wildcard rule
593 # - flags (default $(AFLAGS)): the asm flags to use for assembling
594 # - targetdir: the directory to put the .o file in. By default it is put in the
595 # same directory as the .s file
596 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
599 %(basename).o : AFLAGS := %(aflags)
600 %(basename).o : %(basename).s
602 %(basename).o : %(basename).S
606 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
607 %(targetdir)/$(notdir %(basename)).o : %(basename).s
609 %(targetdir)/$(notdir %(basename)).o : %(basename).S
614 #------------------------------------------------------------------------------
617 #------------------------------------------------------------------------------
618 # Generate a rule to assemble multiple source files to an object file. The
619 # generated file will be put in the object directory with the directory part
620 # of the source file stripped off.
622 # - basenames: the basenames of the files to compile. The names may include
623 # relative or absolute path names. No wildcard is allowed
624 # - aflags (default $(AFLAGS)): the flags to use for assembly
625 # - targetdir: the directory to put the .o file and the .d file. By default
626 # it is put in the same directory as the .c file. When targetdir is not
627 # empty, path names will be stripped from the file names so that all files
628 # are in that dir and not in subdirectories.
629 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
632 TMP_TARGETS := $(addsuffix .o,%(basenames))
635 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
636 TMP_WILDCARD := %(targetdir)/%
638 # Be sure that all .s files are generated
639 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
641 # Be sure that all .c files are found
642 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
643 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
644 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
646 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
647 vpath %%(suffix) $(TMP_DIRS)
652 ifeq ($(findstring %(compiler),host kernel target),)
653 $(error unknown compiler %(compiler))
655 ifeq (%(compiler),target)
656 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
658 ifeq (%(compiler),host)
659 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
661 ifeq (%(compiler),kernel)
662 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
665 $(TMP_TARGETS) : AFLAGS := %(aflags)
666 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
667 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
669 #------------------------------------------------------------------------------
672 #------------------------------------------------------------------------------
673 # Link %(objs) to %(prog) using the libraries in %(uselibs)
674 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
675 usehostlibs= usestartup=yes detach=no nix=no linker=target
680 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
682 ifeq (%(usestartup),no)
683 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
684 ifeq (%(linker),target)
685 TMP_EXTRA_LIBS += arosc.static libinit autoinit
689 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
692 # Make a list of the lib files this program depends on.
693 # In LDFLAGS remove white space between -L and directory
694 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
695 # Filter out only the libdirs and remove -L
696 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
698 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
699 # Add normal linklib path
700 TMP_DIRS += $(LIBDIR)/
701 # add lib and .a to static linklib names
702 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
703 # search for the linklibs in the given path, ignore ones not found
704 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
705 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
708 ifeq (%(linker),target)
709 %(prog) : CMD:=$(TARGET_CC)
710 %(prog) : STRIPCMD:=$(TARGET_STRIP)
712 ifeq (%(linker),host)
713 %(prog) : CMD:=$(HOST_CC)
714 %(prog) : STRIPCMD:=$(HOST_STRIP)
716 ifeq (%(linker),kernel)
717 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
718 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
721 %(prog) : OBJS := %(objs)
722 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
723 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
724 %(prog) : %(objs) $(TMP_DEPLIBS)
725 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
727 #------------------------------------------------------------------------------
730 #------------------------------------------------------------------------------
731 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
732 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
733 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
734 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
735 usestartup=yes detach=no
740 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
742 ifeq (%(usestartup),no)
743 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
744 TMP_EXTRA_LIBS += arosc.static libinit autoinit
747 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
750 # Make a list of the lib files the programs depend on.
751 # In LDFLAGS remove white space between -L and directory
752 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
753 # Filter out only the libdirs and remove -L
754 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
756 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
757 # Add normal linklib path
758 TMP_DIRS += $(LIBDIR)/
759 # add lib and .a to static linklib names
760 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
761 # search for the linklibs in the given path, ignore ones not found
762 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
763 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
766 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
767 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
768 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
769 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
771 #------------------------------------------------------------------------------
774 #------------------------------------------------------------------------------
775 # Link the %(objs) to the library %(libdir)/lib%(libname).a
776 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
778 ifeq (%(linker),target)
779 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
780 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
782 ifeq (%(linker),host)
783 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
784 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
786 ifeq (%(linker),kernel)
787 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
788 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
791 %(libdir)/lib%(libname).a : %(objs)
792 %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
794 #------------------------------------------------------------------------------
796 #------------------------------------------------------------------------------
797 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
798 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
799 # The -noarosc flag is added so that modules are not linked with arosc.library
800 # (see /config/specs.in file)
801 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
802 ldflags=$(LDFLAGS) uselibs= usehostlibs=
804 TMP_LDFLAGS := %(ldflags)
805 # Make a list of the lib files the programs depend on.
806 # In LDFLAGS remove white space between -L and directory
807 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
808 # Filter out only the libdirs and remove -L
809 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
811 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
812 # Add normal linklib path
813 TMP_DIRS += $(LIBDIR)/
814 # add lib and .a to static linklib names
815 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
816 # search for the linklibs in the given path, ignore ones not found
817 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
818 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
821 %(module) : LIB_NAMES := %(uselibs)
822 %(module) : OBJS := %(objs)
823 %(module) : ENDTAG := %(endobj)
824 %(module) : ERR := %(err)
825 %(module) : OBJDIR := %(objdir)
826 %(module) : LDFLAGS := $(TMP_LDFLAGS)
827 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
828 -L/usr/lib $(addprefix -l,%(usehostlibs))
829 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
830 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
833 #------------------------------------------------------------------------------
836 #------------------------------------------------------------------------------
837 # Generate the libdefs.h include file for a module.
838 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
840 TMP_TARGET := %(modname)_libdefs.h
841 TMP_DEPS := $(GENMODULE)
844 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
845 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
847 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
848 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
850 ifneq (%(modsuffix),)
851 TMP_OPTS += -s %(modsuffix)
853 ifneq (%(targetdir),)
854 TMP_OPTS += -d %(targetdir)
855 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
858 TMP_OPTS += -v %(version)
861 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
862 $(TMP_TARGET) : MODNAME := %(modname)
863 $(TMP_TARGET) : MODTYPE := %(modtype)
864 $(TMP_TARGET) : $(TMP_DEPS)
865 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
866 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
868 #------------------------------------------------------------------------------
870 #------------------------------------------------------------------------------
871 # Generate the _lib.fd file for a module.
872 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
874 TMP_TARGET := %(modname)_lib.fd
875 TMP_DEPS := $(GENMODULE)
878 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
879 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
881 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
882 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
884 ifneq (%(modsuffix),)
885 TMP_OPTS += -s %(modsuffix)
887 ifneq (%(targetdir),)
888 TMP_OPTS += -d %(targetdir)
889 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
892 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
893 $(TMP_TARGET) : MODNAME := %(modname)
894 $(TMP_TARGET) : MODTYPE := %(modtype)
895 $(TMP_TARGET) : $(TMP_DEPS)
896 @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
897 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
899 #------------------------------------------------------------------------------
901 #------------------------------------------------------------------------------
902 # Generate a Makefile.%(modname) with the genmodule program and include this
903 # generated file in this Makefile
904 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
907 TMP_TARGET := Makefile.%(modname)
908 TMP_DEPS := $(GENMODULE)
911 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
912 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
914 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
915 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
917 ifneq (%(modsuffix),)
918 TMP_OPTS += -s %(modsuffix)
920 ifneq (%(targetdir),)
921 TMP_OPTS += -d %(targetdir)
922 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
925 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
926 $(TMP_TARGET) : MODNAME := %(modname)
927 $(TMP_TARGET) : MODTYPE := %(modtype)
928 $(TMP_TARGET) : $(TMP_DEPS)
929 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
931 #------------------------------------------------------------------------------
934 #------------------------------------------------------------------------------
935 # Generate the support files for compiling a module. This includes include
936 # files and source files. This rule has to be preceeded by
937 # %rule_genmodule_makefile
938 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
941 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
942 $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
943 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
944 $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
946 TMP_DEPS := $(GENMODULE)
950 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
951 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
953 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
954 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
956 ifneq (%(modsuffix),)
957 TMP_OPTS += -s %(modsuffix)
959 ifneq (%(targetdir),)
960 TMP_OPTS += -d %(targetdir)
961 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
962 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
965 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
966 $(TMP_TARGETS) : MODNAME := %(modname)
967 $(TMP_TARGETS) : MODTYPE := %(modtype)
968 $(TMP_TARGETS) : $(TMP_DEPS)
969 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
970 ifneq (%(conffile),lib.conf)
971 @$(IF) $(TEST) -f lib.conf; then \
972 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
975 @$(IF) $(TEST) -f libdefs.h; then \
976 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
978 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
980 #------------------------------------------------------------------------------
983 #------------------------------------------------------------------------------
984 # Generate the support files for compiling a module. This includes include
985 # files and source files.
986 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
989 ifneq ($(%(modname)_INCLUDES),)
990 TMP_TARGETS := $(%(modname)_INCLUDES)
992 TMP_DEPS := $(GENMODULE)
996 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
997 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
999 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1000 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1002 ifneq (%(modsuffix),)
1003 TMP_OPTS += -s %(modsuffix)
1005 ifneq (%(targetdir),)
1006 TMP_OPTS += -d %(targetdir)
1007 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1010 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1011 $(TMP_TARGETS) : MODNAME := %(modname)
1012 $(TMP_TARGETS) : MODTYPE := %(modtype)
1013 $(TMP_TARGETS) : $(TMP_DEPS)
1014 @$(ECHO) "Generating include files"
1015 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1018 #------------------------------------------------------------------------------
1021 #------------------------------------------------------------------------------
1022 # Common rules for all makefiles
1024 # Delete generated makefiles
1027 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1029 include $(SRCDIR)/config/make.tail
1031 BDID := $(BDTARGETID)
1033 #------------------------------------------------------------------------------
1036 #############################################################################
1037 #############################################################################
1039 ## Here are the mmakefile build macros. These are macros that takes care ##
1040 ## of everything to go from the sources to the generated target. Also all ##
1041 ## intermediate files and directories that are needed are created by these ##
1044 #############################################################################
1045 #############################################################################
1047 #------------------------------------------------------------------------------
1049 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1050 asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1051 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1052 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1053 compiler=target linker= srcdir=
1057 BD_PROGNAME := %(progname)
1058 BD_OBJDIR := %(objdir)
1059 BD_TARGETDIR := %(targetdir)
1060 BD_LINKER := %(linker)
1062 # If not supplied, linker is equal to compiler
1063 ifeq ($(BD_LINKER),)
1064 BD_LINKER := %(compiler)
1067 BD_FILES := %(files)
1068 BD_CXXFILES := %(cxxfiles)
1069 BD_ASMFILES := %(asmfiles)
1071 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
1072 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1073 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1075 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))
1076 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES)))
1078 BD_CFLAGS := %(cflags)
1079 BD_AFLAGS := %(aflags)
1080 BD_DFLAGS := %(dflags)
1081 BD_LDFLAGS := %(ldflags)
1084 %(mmake)-quick : %(mmake)
1086 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1087 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1089 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1090 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1091 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1092 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1093 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1094 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1095 aflags=$(BD_AFLAGS) compiler=%(compiler)
1097 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1098 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1099 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1100 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1105 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1107 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1108 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1109 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1111 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1114 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1118 #------------------------------------------------------------------------------
1121 #------------------------------------------------------------------------------
1122 # Build programs, for every C file an executable will be built with the same
1123 # name as the C file
1124 %define build_progs mmake=/A files=/A nix=no \
1125 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1126 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1127 uselibs= usehostlibs= usestartup=yes detach=no
1131 BD_OBJDIR := %(objdir)
1132 BD_TARGETDIR := %(targetdir)
1134 BD_FILES := %(files)
1135 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1136 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1137 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1139 BD_CFLAGS := %(cflags)
1140 BD_DFLAGS := %(dflags)
1141 BD_LDFLAGS := %(ldflags)
1144 %(mmake)-quick : %(mmake)
1146 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1147 %(mmake) : $(BD_EXES)
1149 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1150 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1151 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1153 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1154 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1155 ldflags=$(BD_LDFLAGS) \
1156 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1157 usestartup="%(usestartup)" detach="%(detach)"
1161 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1163 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1164 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1165 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1167 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1170 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1174 #------------------------------------------------------------------------------
1177 #------------------------------------------------------------------------------
1179 # This is a bare version: It just compiles and links the given files. It is
1180 # assumed that all needed boiler plate code is in the files. This should only
1181 # be used for compiling external code. For AROS code use %build_module
1182 %define build_module_simple mmake=/A modname=/A modtype=/A \
1183 files="$(basename $(call WILDCARD, *.c))" \
1184 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1185 objdir=$(OBJDIR) moduledir= \
1186 uselibs= usehostlibs= compiler=target
1188 # Define metamake targets and their dependencies
1189 #MM %(mmake) : core-linklibs includes-generate-deps
1190 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1191 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1192 #MM %(mmake)-kobj-quick
1193 #MM %(mmake)-pkg-quick
1197 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1199 .PHONY : $(BD_ALLTARGETS)
1202 $(error using %build_module_simple: modname may not be empty)
1205 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1208 # Default values for variables and arguments
1209 BD_DEFLINKLIBNAME := %(modname)
1210 BD_DEFDFLAGS := %(cflags)
1211 OBJDIR ?= $(GENDIR)/$(CURDIR)
1212 BD_MODDIR := %(moduledir)
1213 ifeq ($(BD_MODDIR),)
1214 ifeq (%(modtype),library)
1215 BD_MODDIR := $(AROS_LIBS)
1217 ifeq (%(modtype),gadget)
1218 BD_MODDIR := $(AROS_GADGETS)
1220 ifeq (%(modtype),datatype)
1221 BD_MODDIR := $(AROS_DATATYPES)
1223 ifeq (%(modtype),handler)
1224 BD_MODDIR := $(AROS_FS)
1226 ifeq (%(modtype),device)
1227 BD_MODDIR := $(AROS_DEVS)
1229 ifeq (%(modtype),resource)
1230 BD_MODDIR := $(AROS_RESOURCES)
1232 ifeq (%(modtype),hook)
1233 BD_MODDIR := $(AROS_RESOURCES)
1235 ifeq (%(modtype),mui)
1236 BD_MODDIR := $(AROS_CLASSES)/Zune
1238 ifeq (%(modtype),mcc)
1239 BD_MODDIR := $(AROS_CLASSES)/Zune
1241 ifeq (%(modtype),mcp)
1242 BD_MODDIR := $(AROS_CLASSES)/Zune
1244 ifeq (%(modtype),usbclass)
1245 BD_MODDIR := $(AROS_CLASSES)/USB
1247 ifeq (%(modtype),hidd)
1248 BD_MODDIR := $(AROS_DRIVERS)
1250 ifeq (%(modtype),printer)
1251 BD_MODDIR := $(AROS_PRINTERS)
1254 ifeq ($(BD_MODDIR),)
1255 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1258 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1259 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1260 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1262 %rule_compile_multi \
1263 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1264 cflags="%(cflags)" dflags="%(dflags)" \
1265 compiler=%(compiler)
1267 # Handlers use dash instead of dot in their names
1268 ifeq (%(modtype),handler)
1269 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1270 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1272 ifeq (%(modtype),printer)
1273 BD_MODULE := $(BD_MODDIR)/%(modname)
1274 BD_PKGMOD := $(PKGDIR)/%(modname)
1276 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1277 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1280 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1282 %(mmake)-quick : %(mmake)
1283 %(mmake)-pkg-quick : $(BD_PKGMOD)
1284 %(mmake)-kobj-quick : $(BD_KOBJ)
1285 %(mmake) : $(BD_MODULE)
1286 %(mmake)-pkg : $(BD_PKGMOD)
1287 %(mmake)-kobj : $(BD_KOBJ)
1289 # The module is linked from all the compiled .o files
1290 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1292 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1293 # This breaks con-handler build. Here we work around this
1294 ifeq (%(modname),con)
1295 BD_ERR := $(notdir $(BD_MODULE)).err
1297 BD_ERR := %(modname).err
1300 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1301 endobj= err=$(BD_ERR) objdir=%(objdir) \
1302 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1304 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1305 endobj= err=$(BD_ERR) objdir=%(objdir) \
1306 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1308 # Link kernel object file
1309 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1311 # Make these symbols local
1312 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1313 UtilityBase ExpansionBase KeymapBase KernelBase
1315 BD_SYMBOLS := $(BD_KBASE)
1317 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1318 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1319 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1320 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1321 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1322 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1323 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1324 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1325 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1328 ## Dependency fine-tuning
1330 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1331 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1333 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1334 $(BD_MODULE) : | $(BD_MODDIR)
1335 $(BD_KOBJ) : | $(KOBJSDIR)
1336 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1338 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1340 @$(ECHO) "Cleaning up for module %(modname)"
1343 #------------------------------------------------------------------------------
1346 #------------------------------------------------------------------------------
1348 # Explanation of this macro is done in the developer's manual
1349 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1350 conffile= files="$(basename $(call WILDCARD, *.c))" \
1351 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1352 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1353 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1354 compiler=target nostartup=yes
1356 # Define metamake targets and their dependencies
1357 #MM- includes-all : %(mmake)-includes
1358 #MM- linklibs-%(modname): %(mmake)-linklib
1359 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1360 #MM- includes-%(modname): %(mmake)-includes
1361 #MM- includes-%(modname)_rel : %(mmake)-includes
1362 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1363 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1364 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1365 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1366 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1367 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1368 #MM %(mmake)-quick : %(mmake)-includes-quick
1369 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1370 #MM includes-generate-deps %(mmake)-fd
1371 #MM %(mmake)-includes-quick
1372 #MM %(mmake)-includes-dirs
1374 #MM %(mmake)-makefile
1377 # All MetaMake targets defined by this macro
1378 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1379 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1380 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1381 %(mmake)-linklib %(mmake)-fd
1383 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1386 $(error using %build_module: modname may not be empty)
1389 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1392 # Default values for variables and arguments
1393 BD_DEFLINKLIBNAME := %(modname)
1394 BD_DEFDFLAGS := %(cflags)
1395 OBJDIR ?= $(GENDIR)/$(CURDIR)
1397 ## Create genmodule include Makefile for the module
1399 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1401 %rule_genmodule_makefile \
1402 modname=%(modname) modtype=%(modtype) \
1403 modsuffix=%(modsuffix) targetdir=%(objdir) \
1404 conffile=%(conffile)
1406 %(objdir)/Makefile.%(modname) : | %(objdir)
1408 GLOB_MKDIRS += %(objdir)
1410 # Do not parse these statements if metatarget is not appropriate
1411 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1413 include %(objdir)/Makefile.%(modname)
1415 BD_DEFMODDIR := $(%(modname)_MODDIR)
1418 ## include files generation
1420 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1421 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1422 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1424 %(mmake)-includes-quick : %(mmake)-includes
1425 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1426 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1427 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1429 ifneq ($(%(modname)_INCLUDES),)
1430 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1431 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1432 conffile=%(conffile)
1434 %rule_copy_diff_multi \
1435 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1436 stampfile=%(objdir)/%(modname)_geninc
1438 %rule_copy_diff_multi \
1439 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1440 stampfile=%(objdir)/%(modname)_incs
1442 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1444 TMP%(modname)_INCDIRS := \
1445 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1446 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1447 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1448 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1452 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1453 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1454 conffile=%(conffile) version=%(version)
1456 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1457 $(BD_DEFLIBDEFSINC) :
1458 @$(ECHO) "generating $@"
1459 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1461 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1462 GLOB_MKDIRS += %(objdir)/include
1464 ## Extra genmodule src files generation
1466 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1467 modsuffix=%(modsuffix) targetdir=%(objdir) \
1468 conffile=%(conffile)
1472 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1473 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1475 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1476 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1478 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1480 GLOB_MKDIRS += $(BD_FDDIR)
1485 BD_FILES := %(files)
1486 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1487 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1488 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1490 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1491 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1492 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1494 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1495 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1497 ifeq (%(modtype),library)
1500 BD_LIBSUFFIX := .%(modtype)
1503 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1504 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1505 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1508 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1510 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1512 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1513 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1514 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1517 BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1519 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1521 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1522 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1523 $(BD_RELLINKLIBCFILES)
1525 %rule_compile_multi \
1526 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1527 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1528 compiler=%(compiler)
1529 %rule_compile_multi \
1530 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1531 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1532 compiler=%(compiler)
1534 ifneq ($(BD_LINKLIBAFILES),)
1535 %rule_assemble_multi \
1536 basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1541 ifeq (%(modsuffix),)
1542 BD_SUFFIX := %(modtype)
1544 BD_SUFFIX := %(modsuffix)
1547 # Handlers use dash instead of dot in their names
1548 ifeq ($(BD_SUFFIX),handler)
1549 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1550 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1552 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1553 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1555 BD_KOBJ := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1557 %(mmake)-quick : %(mmake)
1558 %(mmake) : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1559 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1560 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1561 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1562 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1563 %(mmake)-linklib : $(BD_LINKLIB) $(BD_RELLINKLIB)
1565 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1566 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1568 ifeq (%(nostartup),yes)
1569 # Handlers always have entry point
1570 ifneq (%(modtype),handler)
1571 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1575 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1576 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1579 := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1582 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1583 # This breaks con-handler build. Here we work around this
1584 ifeq (%(modname),con)
1585 BD_ERR := $(notdir $(BD_MODULE)).err
1587 BD_ERR := %(modname).err
1590 # The module is linked from all the compiled .o files
1591 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1592 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1593 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1595 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1596 endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1597 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1600 ifneq ($(BD_LINKLIB),)
1601 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1603 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1604 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1607 ifneq ($(BD_RELLINKLIB),)
1608 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1610 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1611 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1614 # Link kernel object file
1615 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1617 # Make these symbols local
1618 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1619 UtilityBase ExpansionBase KeymapBase KernelBase
1621 BD_SYMBOLS := $(BD_KBASE)
1623 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1624 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1625 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1626 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1627 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1628 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1629 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)"
1630 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1631 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1633 ## Dependency fine-tuning
1635 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1636 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1638 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1639 $(BD_MODULE) : | %(prefix)/%(moduledir)
1640 $(BD_PKGMOD) : | $(PKGDIR)
1641 $(BD_KOBJ) : | $(KOBJSDIR)
1642 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1644 # Some include files need to be generated before the .c can be parsed.
1645 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1647 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1648 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1649 $(BD_DEPS) : $(BD_DFILE_DEPS)
1652 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1653 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1654 %(objdir)/Makefile.%(modname) \
1655 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1656 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1657 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1658 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1659 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1660 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1662 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1664 @$(ECHO) "Cleaning up for module %(modname)"
1667 endif # $(TARGET) in $(BD_ALLTARGETS)
1669 #------------------------------------------------------------------------------
1672 #------------------------------------------------------------------------------
1673 # Build a module skeleton
1674 # This is a stripped-down version of build_module, it only creates include files,
1675 # but no actual object. This is used when for plugins or classes with the same
1676 # API, but no actual implementation here.
1677 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1679 objdir=$(OBJDIR) prefix=$(AROSDIR)
1681 # Define metamake targets and their dependencies
1682 #MM- includes-all : %(mmake)-includes
1683 #MM %(mmake) : %(mmake)-includes core-linklibs
1684 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1685 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1686 #MM %(mmake)-linklib : %(mmake)-includes
1687 #MM %(mmake)-quick : %(mmake)-includes-quick
1688 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1689 #MM includes-generate-deps
1690 #MM %(mmake)-includes-quick
1691 #MM %(mmake)-includes-dirs
1692 #MM %(mmake)-makefile
1695 # All MetaMake targets defined by this macro
1696 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1697 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1698 %(mmake)-kobj %(mmake)-pkg
1700 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1703 $(error using %build_module_skeleton: modname may not be empty)
1706 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1709 # Default values for variables and arguments
1710 BD_DEFLINKLIBNAME := %(modname)
1711 BD_DEFDFLAGS := %(cflags)
1712 OBJDIR ?= $(GENDIR)/$(CURDIR)
1714 ## Create genmodule include Makefile for the module
1716 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1718 %rule_genmodule_makefile \
1719 modname=%(modname) modtype=%(modtype) \
1720 modsuffix=%(modsuffix) targetdir=%(objdir) \
1721 conffile=%(conffile)
1723 %(objdir)/Makefile.%(modname) : | %(objdir)
1725 GLOB_MKDIRS += %(objdir)
1727 # Do not parse these statements if metatarget is not appropriate
1728 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1730 include %(objdir)/Makefile.%(modname)
1732 BD_DEFMODDIR := $(%(modname)_MODDIR)
1735 ## include files generation
1737 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1738 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1739 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1741 %(mmake)-includes-quick : %(mmake)-includes
1742 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1743 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1744 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1746 ifneq ($(%(modname)_INCLUDES),)
1747 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1748 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1749 conffile=%(conffile)
1751 %rule_copy_diff_multi \
1752 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1753 stampfile=%(objdir)/%(modname)_geninc
1755 %rule_copy_diff_multi \
1756 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1757 stampfile=%(objdir)/%(modname)_incs
1759 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1761 TMP%(modname)_INCDIRS := \
1762 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1763 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1764 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1765 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1769 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1770 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1771 conffile=%(conffile)
1773 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1774 $(BD_DEFLIBDEFSINC) :
1775 @$(ECHO) "generating $@"
1776 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1778 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1779 GLOB_MKDIRS += %(objdir)/include
1781 ## Extra genmodule src files generation
1783 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1784 modsuffix=%(modsuffix) targetdir=%(objdir) \
1785 conffile=%(conffile)
1787 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1788 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1789 %(objdir)/Makefile.%(modname) \
1790 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1791 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1792 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1793 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1794 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1796 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1798 @$(ECHO) "Cleaning up for module %(modname)"
1801 endif # $(TARGET) in $(BD_ALLTARGETS)
1803 #------------------------------------------------------------------------------
1806 #------------------------------------------------------------------------------
1808 # - mmake is the mmaketarget
1809 # - libname is the baselibname e.g. lib%(libname).a will be created
1810 # - files are the C source files to include in the lib. The list of files
1811 # has to be given without the .c suffix
1812 # - asmfiles are the asm files to include in the lib. The list of files has to
1813 # be given without the .s suffix
1814 # - objs additional object to link into the linklib. The objects have to be
1815 # given with full absolute path and the .o suffix.
1816 # - cflags are the flags to compile the source (default $(CFLAGS))
1817 # - dflags are the flags use during makedepend (default equal to cflags)
1818 # - aflags are the flags use during assembling (default $(AFLAGS))
1819 # - objdir is where the .o are generated
1820 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1821 %define build_linklib mmake=/A libname=/A \
1822 files="$(basename $(call WILDCARD, *.c))" \
1823 cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1824 asmfiles= objs= compiler=target \
1825 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1827 # assign and generate the local variables used in this macro
1828 OBJDIR ?= $(GENDIR)/$(CURDIR)
1830 BD_FILES := %(files)
1831 BD_CXXFILES := %(cxxfiles)
1832 BD_ASMFILES := %(asmfiles)
1834 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1835 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1836 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1838 BD_OBJS := $(BD_ARCHOBJS) \
1839 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
1841 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1843 BD_CFLAGS := %(cflags)
1845 BD_DFLAGS := $(BD_CFLAGS)
1847 BD_DFLAGS := %(dflags)
1849 BD_AFLAGS := %(aflags)
1851 BD_LINKLIB := %(libdir)/lib%(libname).a
1853 .PHONY : %(mmake) %(mmake)-clean
1855 #MM %(mmake) : includes-generate-deps
1856 %(mmake) : $(BD_LINKLIB)
1860 @$(RM) $(BD_OBJS) $(BD_DEPS)
1862 ifeq ($(TARGET),%(mmake))
1863 ifneq ($(dir $(BD_FILES)),./)
1864 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1865 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1868 %rule_compile basename=% targetdir=%(objdir) \
1869 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1870 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1871 compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1872 %rule_assemble basename=% targetdir=%(objdir) \
1875 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1878 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1880 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1881 $(BD_LINKLIB) : | %(libdir)
1882 GLOB_MKDIRS += %(objdir) %(libdir)
1885 #------------------------------------------------------------------------------
1888 #------------------------------------------------------------------------------
1890 # - mmake is the mmaketarget
1891 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1892 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1893 # - subdir is the destination subdirectory of the catalogs
1894 # - name is the name of the destination catalog, without the .catalog suffix
1895 # - source is the path to the generated source code file
1896 # - dir is the base destination directory (default $(AROS_CATALOGS))
1897 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1898 # - srcdir is the directory in which the *.cd and *.ct files are searched
1900 %define build_catalogs mmake=/A name=/A subdir=/A \
1901 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1902 sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
1904 ifeq (%(description),)
1905 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1907 BD_DESC := %(description)
1910 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1913 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1915 BD_LNGS := %(catalogs)
1918 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1919 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1922 %(mmake) : $(BD_OBJS) %(source)
1924 $(BD_OBJS) : | $(BD_DIRS)
1925 GLOB_MKDIRS += $(BD_DIRS)
1927 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1928 @$(ECHO) "Creating %(name) catalog for language $*."
1929 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1932 %(source) : BD_DESC := $(BD_DESC)
1933 %(source) : BD_SRC := $(BD_SRC)
1934 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
1935 @$(ECHO) "Creating %(name) catalog source file $@"
1936 @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
1941 $(RM) $(BD_OBJS) %(source)
1943 .PHONY: %(mmake) %(mmake)-clean
1946 #-----------------------------------------------------------------------------
1949 #-----------------------------------------------------------------------------
1951 # - mmake is the mmaketarget
1952 # - icons is a list of icon base names (ie. without the .info suffix)
1953 # - dir is the destination directory
1954 # - srcdir is where *.png and *.info.src are searched
1955 #-----------------------------------------------------------------------------
1957 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1959 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1962 %(mmake) : $(BD_OBJS)
1966 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1967 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
1968 @$(ILBMTOICON) $+ $@
1972 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1973 @$(ECHO) "Creating $(subst $(TARGETDIR)/,,$@)..."
1974 @$(ILBMTOICON) $+ $@
1978 $(BD_OBJS) : | %(dir)
1979 GLOB_MKDIRS += %(dir)
1981 %(mmake)-clean : FILES := $(BD_OBJS)
1986 .PHONY: %(mmake) %(mmake)-clean
1989 #-----------------------------------------------------------------------------
1992 #------------------------------------------------------------------------------
1993 # Compile files for an arch-specific replacement of code for a module
1994 # - files: the basenames of the C files to compile.
1995 # - asmfiles: the basenames of the asm files to assemble.
1996 # - mainmmake: the mmake of the module in the main directory to compile these
1997 # arch specific files for.
1998 # - maindir: the object directory for the main module
1999 # - arch: the arch for which to compile these files. It can have the form
2000 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2001 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2002 # - dflags: the flags used during creation of dependency file. If not specified
2003 # the same value as cflags will be used
2004 # - aflags: the flags used during assembling
2005 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2006 # the target compiler is used
2007 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2008 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2010 ifeq (%(files) %(asmfiles),)
2011 $(error no files or asmfiles given)
2014 %buildid targets="%(mainmmake)-%(arch)"
2016 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2017 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2018 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2019 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2020 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2021 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2022 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2023 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2024 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2025 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2026 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2027 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2028 #MM- %(mainmmake)-pkg : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2029 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2030 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2031 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2032 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2033 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2034 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2035 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2036 #MM %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2038 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2040 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
2041 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2042 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2043 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2044 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2046 ifneq (%(modulename),)
2047 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2050 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2051 BD_TARGET := %(mainmmake)-%(arch)-quick
2053 BD_TARGET := %(mainmmake)-%(arch)
2057 ifeq ($(TARGET),$(BD_TARGET))
2058 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2059 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2060 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2061 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2064 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2065 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2068 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2071 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2073 ifeq ($(findstring %(compiler),host kernel target),)
2074 $(error unknown compiler %(compiler))
2076 ifeq (%(compiler),target)
2077 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2078 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2079 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2081 ifeq (%(compiler),host)
2082 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2083 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2084 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2086 ifeq (%(compiler),kernel)
2087 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2088 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2089 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2091 ifneq (%(modulename),)
2092 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2094 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2096 ifeq ($(TARGET),$(BD_TARGET))
2097 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2098 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2102 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2104 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2106 ifeq ($(TARGET),$(BD_TARGET))
2107 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2108 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2111 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2113 ifeq ($(TARGET),$(BD_TARGET))
2114 $(BD_OBJDIR$(BDID))/%.o : %.s
2115 %assemble_q opt=$(AFLAGS)
2116 $(BD_OBJDIR$(BDID))/%.o : %.S
2117 %assemble_q opt=$(AFLAGS)
2120 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2122 #------------------------------------------------------------------------------
2125 #------------------------------------------------------------------------------
2126 # generate asm files from c files (for debugging purposes)
2129 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2130 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2132 #------------------------------------------------------------------------------
2135 #------------------------------------------------------------------------------
2136 # Copy files from one directory to another.
2138 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2140 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2142 GLOB_MKDIRS += %(dst)
2148 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2151 #------------------------------------------------------------------------------
2154 #------------------------------------------------------------------------------
2155 # Copy a directory recursively to another place, preserving the original
2156 # hierarchical structure
2158 # src: the source directory whose content will be copied
2159 # dst: the directory where to copy src's content. If not existing, it will be made.
2161 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2163 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2164 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
2165 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
2167 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2168 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2170 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2175 %(mmake): | $(GENDIR)/$(CURDIR)
2176 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2177 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
2178 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2179 for d in $(%(mmake)_DIRS); do \
2180 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
2182 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
2183 for f in $(%(mmake)_FILES); do \
2184 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2186 for dst in %(dst); do \
2187 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2191 #------------------------------------------------------------------------------
2194 #------------------------------------------------------------------------------
2195 # Copy include files into the includes directories. There are currently
2196 # two include directories. One for building AROS $(AROS_INCLUDES) and one
2197 # for building tools that need to run on the host system $(GENINCDIR). The
2198 # $(GENINCDIR) path must not contain any references to the C runtime
2199 # library header files.
2201 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2202 dir= compiler=target
2204 ifeq ($(findstring %(compiler),host kernel target),)
2205 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2209 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2210 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2211 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2213 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2214 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2217 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2221 ifeq (%(compiler),target)
2224 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2225 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2227 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2230 BD_INCL_FILES += $(BD_INCL_FILES2)
2232 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2237 %(mmake) : $(BD_INCL_FILES)
2241 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2242 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2244 #------------------------------------------------------------------------------
2247 #------------------------------------------------------------------------------
2248 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2249 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2250 STUBS_MEM := $(addsuffix .o,$(STUBS))
2251 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2252 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2253 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2255 #MM- linklibs : hidd-%(hidd)-stubs
2256 #MM- %(parenttarget): hidd-%(hidd)-stubs
2257 #MM hidd-%(hidd)-stubs : includes includes-copy
2258 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2260 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2263 $(STUBS_OBJ) : $(STUBS_SRC)
2264 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2266 $(STUBS_DEP) : $(STUBS_SRC)
2267 %mkdepend_q flags=%(dflags)
2270 %mkdirs_q $(OBJDIR) $(LIBDIR)
2274 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2276 DEPS := $(DEPS) $(STUBS_DEP)
2279 #------------------------------------------------------------------------------
2282 #------------------------------------------------------------------------------
2283 # Build an imported source tree which uses the configure script from the
2284 # autoconf package. This rule will try to "integrate" the produced files as
2285 # much as possible in the AROS build, for example by putting libraries in the
2286 # standard library directory, includes in the standard include directory, and
2287 # so on. You can however override this behaviour.
2289 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2290 # be %(bindir) (or its deduced value) when running "make install", and
2291 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2292 # configure script some more parameters whose value depends upon the PROGDIR
2293 # env var, so that the program gets all its stuff installed in the proper place
2294 # when building it, but when running it from inside AROS it can also find that
2295 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2296 # the configuration parameters set when running ./configure
2298 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2299 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2300 # to the name which has to follow it.
2303 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2304 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2305 install_target=install preconfigure= postconfigure= postinstall= \
2306 install_env= use_build_env=no
2309 %(mmake)-prefix := %(prefix)
2311 %(mmake)-prefix := $(AROS_CONTRIB)
2314 ifneq (%(aros_prefix),)
2315 %(mmake)-aros_prefix := %(aros_prefix)
2317 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2321 %(mmake)-nix := -nix
2322 %(mmake)-volpfx := /
2323 %(mmake)-volsfx := /
2325 ifeq (%(nix_dir_layout),)
2326 %(mmake)-nix_dir_layout := yes
2329 %(mmake)-volsfx := :
2331 ifeq (%(nix_dir_layout),)
2332 %(mmake)-nix_dir_layout := no
2336 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2338 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2339 exec_prefix=$(%(mmake)-prefix) %(install_env)
2341 # Check if chosen compiler is valid
2342 ifeq ($(findstring %(compiler),host target kernel),)
2343 $(error unknown compiler %(compiler))
2346 # Set legacy 'host' variable based on chosen compiler
2347 ifeq (%(compiler),host)
2350 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2352 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2357 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2359 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2363 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2364 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2366 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2367 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2368 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2371 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2372 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2374 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2377 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2379 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2380 sbindir=$(%(mmake)-prefix) \
2381 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2382 oldincludedir=$(AROS_INCLUDES) %(install_env)
2385 ifneq ($(DEBUG),yes)
2386 %(mmake)-s_flag = -s
2389 # Set up build environment, and options for configure script
2390 ifeq (%(compiler),host)
2393 CXXCPP="$(HOST_CPP)" \
2394 CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2395 CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2396 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2397 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2398 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2399 TARGET_NM="$(NM_PLAIN)"
2401 ifeq (%(compiler),target)
2403 PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2404 PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2405 CPP="$(TARGET_CPP)" \
2406 CXXCPP="$(TARGET_CPP)" \
2407 CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2408 CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2409 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2410 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2411 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2412 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2413 TARGET_NM="$(NM_PLAIN)" \
2414 CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2415 CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2416 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2417 --host=$(AROS_TARGET_CPU)-aros\
2418 --target=$(AROS_TARGET_CPU)-aros\
2420 --without-x --without-pic --disable-shared
2422 ifeq (%(compiler),kernel)
2424 CPP="$(KERNEL_CPP)" \
2425 CXXCPP="$(KERNEL_CPP)" \
2426 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2427 CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2428 AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2429 TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2430 TARGET_NM="$(NM_PLAIN)"
2431 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2432 --host=$(AROS_TARGET_CPU)-aros\
2433 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2434 --without-x --without-pic --disable-shared
2437 ifeq (%(use_build_env),yes)
2438 BUILD_ENV := $(CONFIG_ENV)
2442 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2444 # When building for the host, we don't need to build the
2445 # linklibs - this is especially true when building the
2446 # crosstool toolchain on 'foreign' architectures (such as
2447 # building PPC on x86)
2449 #MM- %(mmake)-host : setup includes %(mmake)-quick
2450 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2451 #MM- %(mmake): %(mmake)-%(compiler)
2453 # Using -j1 in install_command may result in a warning but finally
2454 # it does its job. make install for gcc does not work reliably for -jN
2456 ifneq (%(install_target),)
2457 %(mmake)-install_command = \
2458 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2459 -C $(%(mmake)-pkgdir) %(install_target) -j1
2461 %(mmake)-uninstall_command = \
2462 $(RM) $(%(mmake)-installflag) && \
2463 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2464 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2466 %(mmake)-install_command := true
2467 %(mmake)-uninstall_command := true
2470 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2473 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2475 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2476 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2477 $(RM) $(%(mmake)-installflag) && \
2478 $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2479 -C $(%(mmake)-pkgdir) && \
2480 $(%(mmake)-install_command) && \
2481 $(TOUCH) $@ -r $^; \
2484 $(%(mmake)-pkgdir)/.files-touched:
2485 %mkdirs_q $(%(mmake)-pkgdir)
2486 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2490 %(mmake)-uninstall :
2491 $(%(mmake)-uninstall_command)
2494 %(mmake)-configure : $(%(mmake)-configflag)
2496 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2497 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2499 %mkdirs_q $(%(mmake)-pkgdir)
2500 cd $(%(mmake)-pkgdir) && \
2501 find . -name config.cache -exec $(RM) '{}' \; && \
2502 $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2503 %(extraoptions) && \
2507 %(mmake)-clean : %(mmake)-uninstall
2508 @$(RM) $(%(mmake)-pkgdir)
2510 #------------------------------------------------------------------------------
2513 #------------------------------------------------------------------------------
2514 # Given an archive name, patches names and locations where to find them, fetch
2515 # the archive and the patches from any of those locations, unpack the archive
2516 # and then apply the patches.
2518 # Locations currently supported are http and ftp sites, plus local filesystem
2519 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2520 # the fetch.sh script needs to be modified, since this macro relies on that script.
2524 # - mmake = mmaketarget
2525 # - archive_origins = list of locations where to find the archive. They are tried
2526 # in sequence, until the archive is found and fetching it
2527 # succeeded. If not specified, the current directory is assumed.
2528 # - archive = the archive name. Mandatory.
2529 # - suffixes = a list of suffixes to append to the the package name plus the
2530 # version. Each one of them is tried until a matching archive is
2531 # found. They are appended to patches and these are tried the
2532 # same way as packages are.
2533 # - location = the local directory where to put the fetched archive and patches.
2534 # If not specified, the directory specified by destination is used.
2535 # - destination = the directory to unpack the archive to.
2536 # If not specified, the current directory is assumed.
2537 # - patches_origins = list of locations where to find the patches. They are tried
2538 # in sequence, until a patch is found and fetching it
2539 # succeeded. If not specified, the current directory is assumed.
2540 # - patches_specs = list of "patch specs". A patch spec is of the form
2541 # patch_name[:[patch_subdir][:patch_opt]].
2543 # - patch_name = the name of the patch file
2544 # - patch_subdir = the directory within \destination\ where to
2546 # - patch_opt = any options to pass to the `patch' command
2547 # when applying the patch.
2549 # The patch_subdir and patch_opt fields are optional.
2551 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2552 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2556 ifneq (%(location),)
2557 %(mmake)-location := %(location)
2559 %(mmake)-location := %(destination)
2564 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2565 -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2567 #------------------------------------------------------------------------------
2570 #------------------------------------------------------------------------------
2571 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2572 # unpatched source tree and runs diff against this and a previously fetched and possibly
2573 # patched tree. Depending on what happens after patching during a normal build it might
2574 # give best results if the new patch is created directly after fetch.
2578 # - mmake = mmaketarget
2579 # - archive = archive base name
2580 # - srcdir = directory the package is unpacked to, useful if archive unpacks to
2581 # a directory other than its name suggests.
2582 # - suffixes = a list of suffixes to append to the the package name plus the
2583 # version. Each one of them is tried until a matching archive is
2585 # - destination = the directory to unpack the archive to.
2586 # - excludes = diff patterns to exclude files or directories from the patch
2588 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2592 ifneq (%(excludes),)
2593 %(mmake)-exclude := -X ./exclude.patterns
2597 %(mmake)-srcdir := %(srcdir)
2599 %(mmake)-srcdir := %(archive)
2604 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2605 $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2606 cd %(destination)/tmp ; \
2607 $(FOR) f in %(excludes) ; do \
2608 $(ECHO) $$f >> ./exclude.patterns ; \
2610 diff -ruN $(%(mmake)-exclude) \
2611 $(%(mmake)-srcdir) \
2612 $(%(mmake)-srcdir).aros \
2613 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2614 $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2615 $(RM) %(destination)/tmp
2617 #------------------------------------------------------------------------------
2620 #------------------------------------------------------------------------------
2621 # Joins the features of %fetch and %build_with_configure, taking advantage of
2622 # the naming scheme of GNU packages. GNU packages names are in the form
2624 # <package name>-<version number>.<archive format suffix>
2626 # If a patch is provided, it *must* be named the following way:
2628 # <package name>-<version number>-aros.diff
2630 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2631 # CD'ing into the archive's extracted directory.
2633 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2634 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2635 # to make that patch fully comprehensive.
2637 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2641 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2643 # - package = the GNU package name, sans version and archive format suffixes.
2644 # - version = the package's version number, or otherwise any other version string.
2645 # It gets appended to the package name to form the basename of the archive.
2646 # - suffixes = a list of suffixes to apped to the the package name plus the
2647 # version. Each one of them is tried until a matching archive is found.
2648 # Defaults to "tar.bz2 tar.gz".
2649 # - destination = same meaning as the one for the %fetch macro
2650 # - location = same meaning as the one for the %fetch macro
2651 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2652 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2654 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2655 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2657 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2659 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2660 # - extracflags = same meaning as the one for the %build_with_configure macro.
2661 # - postinstall = same meaning as the one for the %build_with_configure macro.
2662 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2664 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2665 srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2666 preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2668 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2669 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2670 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2671 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2673 %(mmake)-archbase := %(package)-%(version)
2675 ifeq (%(compiler),host)
2676 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2678 %(mmake)-portdir := $(PORTSDIR)/%(package)
2682 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2684 %(mmake)-prefix := %(prefix)
2687 ifneq (%(subpackage),)
2688 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2690 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2694 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2696 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2700 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2702 %(mmake)-%(subpackage)-patches_specs := ::
2705 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2706 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2707 archive_origins=". %(package_repo)" \
2708 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2710 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2711 archive=$(%(mmake)-%(subpackage)-archbase) \
2712 srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2713 suffixes="%(suffixes)" \
2714 destination=$(%(mmake)-portdir)
2716 #MM- %(mmake) : %(mmake)-%(subpackage)
2718 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2720 %(mmake)-%(subpackage)-package-basename := \
2721 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2723 ifneq (%(create_pkg),no)
2724 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2727 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2728 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2729 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2730 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2731 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2733 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2734 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2737 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2739 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2740 #that $^ and $@ have exactly the same mtime, and in that case make tries
2741 #to rebuild $@ again, which would fail because the directory where
2742 #the package got installed would not exist anymore.
2743 #We work this around by using an if statement to manually check the mtimes.
2744 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2745 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2747 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2748 mkdir -p "$(DISTDIR)/Packages" ; \
2749 mkdir -p "$(%(mmake)-prefix)" ; \
2750 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2751 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2752 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2755 #------------------------------------------------------------------------------
2758 #------------------------------------------------------------------------------
2759 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2760 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2761 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
2763 GNU_REPOSITORY := gnu://
2765 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2766 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2767 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2768 patch="%(patch)" patch_repo="%(patch_repo)" \
2769 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2770 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2773 #------------------------------------------------------------------------------
2776 #------------------------------------------------------------------------------
2777 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2778 # that the package is a "Development" package, and as such it needs to be placed
2779 # under the $(AROS_DEVELOPMENT) directory, as a default.
2781 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2782 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2783 # "mmake" argument, because the metatarget is implicitely defined as
2785 # #MM- development-%(package)
2787 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2788 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2789 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
2791 #MM- development : development-%(package)
2794 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2795 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2796 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2797 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2798 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2801 postinstall-%(package)-delete-la-files:
2802 $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2805 #------------------------------------------------------------------------------
2807 # Builds a kickstart package in PKG format
2808 # mmake - target name
2809 # file - Destination file name with path
2810 # startup - The file which will be put first
2811 # Other arguments are self-explanatory
2813 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2815 PKG_CLASSES := $(addsuffix .class, %(classes))
2816 PKG_DEVICES := $(addsuffix .device, %(devs))
2817 PKG_HANDLERS := $(addsuffix -handler, %(handlers))
2818 PKG_HIDD := $(addsuffix .hidd, %(hidds))
2819 PKG_LIBS := $(addsuffix .library, %(libs))
2820 PKG_RESOURCES := $(addsuffix .resource, %(res))
2822 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2823 PKG_DIR := $(dir %(file))
2824 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2830 %(mmake)-quick : %(file)
2832 %(file): PKG_FILES := $(PKG_FILES)
2833 %(file): $(PKG_DEPS) | $(PKG_DIR)
2834 @$(ECHO) Packaging $@...
2835 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2837 %compress_file mmake=%(mmake) file=%(file)
2839 GLOB_MKDIRS += $(PKG_DIR)
2843 #------------------------------------------------------------------------------
2844 # Compresses %(file) with a gzip.
2845 # Good in conjunction with for example %build_prog
2847 %define compress_file mmake=/A file=/A
2849 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2852 %(mmake)-gz-quick : %(file).gz
2855 @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2860 #------------------------------------------------------------------------------
2861 # Links a kickstart module in ELF format
2862 # Arguments are similar to make_package
2864 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2865 startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2867 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2868 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2869 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2870 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2871 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2872 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2875 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2877 KOBJ_STARTUP := %(startup)
2880 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2882 TMP_LDFLAGS := %(ldflags)
2884 # Make a list of the lib files this program depends on.
2885 # In LDFLAGS remove white space between -L and directory
2886 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2887 # Filter out only the libdirs and remove -L
2888 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2890 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2891 # Add normal linklib path
2892 TMP_DIRS += $(LIBDIR)/
2893 # add lib and .a to static linklib names
2894 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2895 # search for the linklibs in the given path, ignore ones not found
2896 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2897 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2900 TMP_DIRS += $(dir %(file))
2902 TMP_LDFLAGS += $(GENMAP) %(map)
2903 TMP_DIRS += $(dir %(map))
2906 #MM %(mmake) : %(deps)
2912 %(mmake)-quick : %(file)
2914 %(file): KOBJS := $(KOBJS)
2915 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2916 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2917 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2918 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
2919 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS) -noarosc
2922 %compress_file mmake=%(mmake) file=%(file)
2924 GLOB_MKDIRS += $(TMP_DIRS)
2928 #------------------------------------------------------------------------------
2929 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2930 # 'start' is an optional starting address
2931 # 'ldflags' is optional additional flags for the linker
2932 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2934 BD_OUTDIR := $(dir %(file))
2935 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2936 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2937 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2939 %(file) : %(objs) $(BD_OUTDIR)
2940 @$(ECHO) "Linking $(subst $(TARGETDIR)/,,$@)..."
2941 @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2942 @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2944 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2945 GLOB_MKDIRS += $(BD_OUTDIR)