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 %(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 %(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 $(notdir $@) ..."
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 cat %(objdir)/%(err); \
91 @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100 @$(ECHO) "Creating library %(to)..."
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110 %mkdir_q dir="$(dir %(to))"
111 @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112 @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120 @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128 @$(FOR) dir in %(dirs) ; do \
129 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
138 ## Here are the mmakefile macros that are used to do certain tasks in a ##
139 ## mmakefile. They consist of one or more full makefile rules. ##
140 ## In general the files generated in these macros are also defined as ##
141 ## make targets so that they can be used as a dependency in other rules ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186 stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196 @for f in $(FILES); do \
197 $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198 $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
209 # Restriction: at the moment when using a non-empty target dir %(from) may
211 %define rule_join to=/A from=/A text=
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean
227 %define include_deps deps=$(DEPS)/M depstargets=
229 ifneq (%(depstargets),)
230 ifneq ($(findstring $(TARGET),%(depstargets)),)
234 ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default.
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 # the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 # it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
271 TMP_TARGETBASE := %(basename)
273 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
276 ifeq ($(findstring %(compiler),host kernel target),)
277 $(error unknown compiler %(compiler))
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
305 $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
307 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
309 $(TMP_TARGETBASE).o : %(basename).c
310 %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
316 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
320 $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
322 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
325 $(TMP_TARGETBASE).d : %(basename).c
326 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile multiple C source files to an object file and
333 # generate the corresponding dependency files. The generated file will be put
334 # in the object directory without the directory part of the source file.
336 # - basenames: the basenames of the files to compile. The names may include
337 # relative or absolute path names. No wildcard is allowed
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 # the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 # it is put in the same directory as the .c file. When targetdir is not
343 # empty, path names will be stripped from the file names so that all files
344 # are in that dir and not in subdirectories.
345 # - compiler (default target): compiler to use, target, kernel or host
346 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
350 TMP_TARGETS := $(addsuffix .o,%(basenames))
351 TMP_DTARGETS := $(addsuffix .d,%(basenames))
354 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
355 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
356 TMP_WILDCARD := %(targetdir)/%
358 # Be sure that all .c files are generated
359 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
361 # Be sure that all .c files are found
362 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
363 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
364 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
366 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
367 vpath %.c $(TMP_DIRS)
372 ifeq ($(findstring %(compiler),host kernel target),)
373 $(error unknown compiler %(compiler))
375 ifeq (%(compiler),target)
376 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
377 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
378 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
380 ifeq (%(compiler),host)
381 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
382 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
385 ifeq (%(compiler),kernel)
386 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
387 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
388 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
391 $(TMP_TARGETS) : CFLAGS := %(cflags)
392 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
393 %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
396 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
398 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
400 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
401 %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
403 #------------------------------------------------------------------------------
406 #------------------------------------------------------------------------------
407 # Make an alias from one arch specific build to another arch.
409 # - mainmmake: the mmake of the module in the main tree
410 # - arch: the current arch
411 # - alias: the alias to which this should point
412 %define rule_archalias mainmmake=\A arch=\A alias=\A
414 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
416 #------------------------------------------------------------------------------
419 #------------------------------------------------------------------------------
420 # Generate a rule to compile a C source file to a shared object file with a
421 # .so suffix. Basename may contain a directory part, then the source
422 # file has to be in that directory. The generated file will be put in the
423 # object directory without the directory.
425 # - basename: the basename of the file to compile. Use % for a wildcard rule
426 # - cflags (default $(CFLAGS)): the C flags to use for compilation
427 # - targetdir: the directory to put the .o file and the .d file. By default
428 # it is put in the same directory as the .c file
429 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
432 TMP_TARGETBASE := %(basename)
434 TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
437 ifeq ($(findstring %(compiler),host kernel target),)
438 $(error unknown compiler %(compiler))
440 ifeq (%(compiler),target)
441 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
442 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
443 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
445 ifeq (%(compiler),host)
446 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
447 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
448 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
450 ifeq (%(compiler),kernel)
451 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
452 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
453 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
456 $(TMP_TARGETBASE).so : %(basename).c
457 %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
459 #------------------------------------------------------------------------------
462 #------------------------------------------------------------------------------
463 # Generate a rule to assemble a source file to an object file. Basename may
464 # contain a directory part, then the source file has to be in that directory.
465 # The generated file will be put in the object directory without the directory.
467 # - basename: the basename of the file to compile. Use % for a wildcard rule
468 # - flags (default $(AFLAGS)): the asm flags to use for assembling
469 # - targetdir: the directory to put the .o file in. By default it is put in the
470 # same directory as the .s file
471 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
474 %(basename).o : AFLAGS := %(aflags)
475 %(basename).o : %(basename).s
477 %(basename).o : %(basename).S
481 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
482 %(targetdir)/$(notdir %(basename)).o : %(basename).s
484 %(targetdir)/$(notdir %(basename)).o : %(basename).S
489 #------------------------------------------------------------------------------
492 #------------------------------------------------------------------------------
493 # Generate a rule to assemble multiple source files to an object file. The
494 # generated file will be put in the object directory with the directory part
495 # of the source file stripped off.
497 # - basenames: the basenames of the files to compile. The names may include
498 # relative or absolute path names. No wildcard is allowed
499 # - aflags (default $(AFLAGS)): the flags to use for assembly
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 # it is put in the same directory as the .c file. When targetdir is not
502 # empty, path names will be stripped from the file names so that all files
503 # are in that dir and not in subdirectories.
504 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
507 TMP_TARGETS := $(addsuffix .o,%(basenames))
510 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
511 TMP_WILDCARD := %(targetdir)/%
513 # Be sure that all .s files are generated
514 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
516 # Be sure that all .c files are found
517 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
518 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
519 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
521 TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
522 vpath %%(suffix) $(TMP_DIRS)
527 ifeq ($(findstring %(compiler),host kernel target),)
528 $(error unknown compiler %(compiler))
530 ifeq (%(compiler),target)
531 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
533 ifeq (%(compiler),host)
534 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
536 ifeq (%(compiler),kernel)
537 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
540 $(TMP_TARGETS) : AFLAGS := %(aflags)
541 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
542 %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
544 #------------------------------------------------------------------------------
547 #------------------------------------------------------------------------------
548 # Link %(objs) to %(prog) using the libraries in %(uselibs)
549 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
550 usehostlibs= usestartup=yes detach=no nix=no linker=target
554 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
556 ifeq (%(usestartup),no)
557 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
560 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
563 # Make a list of the lib files this program depends on.
564 # In LDFLAGS remove white space between -L and directory
565 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
566 # Filter out only the libdirs and remove -L
567 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
569 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
570 # Add normal linklib path
571 TMP_DIRS += $(LIBDIR)/
572 # add lib and .a to static linklib names
573 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
574 # search for the linklibs in the given path, ignore ones not found
575 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
576 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
579 ifeq (%(linker),target)
580 %(prog) : CMD:=$(TARGET_CC)
581 %(prog) : STRIPCMD:=$(TARGET_STRIP)
583 ifeq (%(linker),host)
584 %(prog) : CMD:=$(HOST_CC)
585 %(prog) : STRIPCMD:=$(HOST_STRIP)
587 ifeq (%(linker),kernel)
588 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
589 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
592 %(prog) : OBJS := %(objs)
593 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
594 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
595 %(prog) : %(objs) $(TMP_DEPLIBS)
596 %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
598 #------------------------------------------------------------------------------
601 #------------------------------------------------------------------------------
602 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
603 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
604 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
605 objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
606 usestartup=yes detach=no
610 TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
612 ifeq (%(usestartup),no)
613 TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
616 TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
619 # Make a list of the lib files the programs depend on.
620 # In LDFLAGS remove white space between -L and directory
621 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
622 # Filter out only the libdirs and remove -L
623 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
625 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
626 # Add normal linklib path
627 TMP_DIRS += $(LIBDIR)/
628 # add lib and .a to static linklib names
629 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
630 # search for the linklibs in the given path, ignore ones not found
631 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
632 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
635 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
636 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
637 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
638 %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
640 #------------------------------------------------------------------------------
643 #------------------------------------------------------------------------------
644 # Link the %(objs) to the library %(libdir)/lib%(libname).a
645 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
647 %(libdir)/lib%(libname).a : %(objs)
650 #------------------------------------------------------------------------------
653 #------------------------------------------------------------------------------
654 # Link the %(objs) to the library %(libdir)/lib%(libname).so
655 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
657 %(libdir)/lib%(libname).so : %(objs)
658 @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
660 #------------------------------------------------------------------------------
663 #------------------------------------------------------------------------------
664 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
665 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
666 # The -noarosc flag is added so that modules are not linked with arosc.library
667 # (see /config/specs.in file)
668 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
669 ldflags=$(LDFLAGS) uselibs= usehostlibs=
671 TMP_LDFLAGS := %(ldflags)
672 # Make a list of the lib files the programs depend on.
673 # In LDFLAGS remove white space between -L and directory
674 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
675 # Filter out only the libdirs and remove -L
676 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
678 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
679 # Add normal linklib path
680 TMP_DIRS += $(LIBDIR)/
681 # add lib and .a to static linklib names
682 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
683 # search for the linklibs in the given path, ignore ones not found
684 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
685 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
688 %(module) : OBJS := %(objs)
689 %(module) : ENDTAG := %(endobj)
690 %(module) : ERR := %(err)
691 %(module) : OBJDIR := %(objdir)
692 %(module) : LDFLAGS := $(TMP_LDFLAGS)
693 %(module) : LIBS := $(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))
694 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
695 %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
698 #------------------------------------------------------------------------------
701 #------------------------------------------------------------------------------
702 # Generate the libdefs.h include file for a module.
703 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir=
705 TMP_TARGET := %(modname)_libdefs.h
706 TMP_DEPS := $(GENMODULE)
709 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
710 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
712 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
713 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
715 ifneq (%(modsuffix),)
716 TMP_OPTS += -s %(modsuffix)
718 ifneq (%(targetdir),)
719 TMP_OPTS += -d %(targetdir)
720 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
723 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
724 $(TMP_TARGET) : MODNAME := %(modname)
725 $(TMP_TARGET) : MODTYPE := %(modtype)
726 $(TMP_TARGET) : $(TMP_DEPS)
727 @$(ECHO) "Generating $(notdir $@)"
728 @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
730 #------------------------------------------------------------------------------
733 #------------------------------------------------------------------------------
734 # Generate a Makefile.%(modname) with the genmodule program and include this
735 # generated file in this Makefile
736 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
739 TMP_TARGET := Makefile.%(modname)
740 TMP_DEPS := $(GENMODULE)
743 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
744 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
746 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
747 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
749 ifneq (%(modsuffix),)
750 TMP_OPTS += -s %(modsuffix)
752 ifneq (%(targetdir),)
753 TMP_OPTS += -d %(targetdir)
754 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
757 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
758 $(TMP_TARGET) : MODNAME := %(modname)
759 $(TMP_TARGET) : MODTYPE := %(modtype)
760 $(TMP_TARGET) : $(TMP_DEPS)
761 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
763 #------------------------------------------------------------------------------
766 #------------------------------------------------------------------------------
767 # Generate the support files for compiling a module. This includes include
768 # files and source files. This rule has to be preceeded by
769 # %rule_genmodule_makefile
770 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
773 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
774 $(%(modname)_LINKLIBFILES)
775 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
777 TMP_DEPS := $(GENMODULE)
781 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
782 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
784 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
785 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
787 ifneq (%(modsuffix),)
788 TMP_OPTS += -s %(modsuffix)
790 ifneq (%(targetdir),)
791 TMP_OPTS += -d %(targetdir)
792 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
793 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
796 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
797 $(TMP_TARGETS) : MODNAME := %(modname)
798 $(TMP_TARGETS) : MODTYPE := %(modtype)
799 $(TMP_TARGETS) : $(TMP_DEPS)
800 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
801 ifneq (%(conffile),lib.conf)
802 @$(IF) $(TEST) -f lib.conf; then \
803 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
806 @$(IF) $(TEST) -f libdefs.h; then \
807 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
809 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
811 #------------------------------------------------------------------------------
814 #------------------------------------------------------------------------------
815 # Generate the support files for compiling a module. This includes include
816 # files and source files.
817 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
820 ifneq ($(%(modname)_INCLUDES),)
821 TMP_TARGETS := $(%(modname)_INCLUDES)
823 TMP_DEPS := $(GENMODULE)
827 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
828 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
830 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
831 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
833 ifneq (%(modsuffix),)
834 TMP_OPTS += -s %(modsuffix)
836 ifneq (%(targetdir),)
837 TMP_OPTS += -d %(targetdir)
838 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
841 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
842 $(TMP_TARGETS) : MODNAME := %(modname)
843 $(TMP_TARGETS) : MODTYPE := %(modtype)
844 $(TMP_TARGETS) : $(TMP_DEPS)
845 @$(ECHO) "Generating include files"
846 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
849 #------------------------------------------------------------------------------
852 #------------------------------------------------------------------------------
853 # Common rules for all makefiles
855 # Delete generated makefiles
858 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
860 include $(SRCDIR)/config/make.tail
862 BDID := $(BDTARGETID)
864 #------------------------------------------------------------------------------
867 #############################################################################
868 #############################################################################
870 ## Here are the mmakefile build macros. These are macros that takes care ##
871 ## of everything to go from the sources to the generated target. Also all ##
872 ## intermediate files and directories that are needed are created by these ##
875 #############################################################################
876 #############################################################################
878 #------------------------------------------------------------------------------
880 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
881 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
882 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
883 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
884 compiler=target srcdir=
888 BD_PROGNAME := %(progname)
889 BD_OBJDIR := %(objdir)
890 BD_TARGETDIR := %(targetdir)
893 BD_ASMFILES := %(asmfiles)
895 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
896 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
897 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
899 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
900 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
902 BD_CFLAGS := %(cflags)
903 BD_AFLAGS := %(aflags)
904 BD_DFLAGS := %(dflags)
905 BD_LDFLAGS := %(ldflags)
908 %(mmake)-quick : %(mmake)
910 #MM %(mmake) : includes-generate-deps linklibs-core
911 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
913 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
914 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
915 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
916 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
917 aflags=$(BD_AFLAGS) compiler=%(compiler)
919 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
920 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
921 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
922 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
927 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
929 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
930 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
931 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
933 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
936 @$(ECHO) "Cleaning up for metatarget %(mmake)"
940 #------------------------------------------------------------------------------
943 #------------------------------------------------------------------------------
944 # Build programs, for every C file an executable will be built with the same
946 %define build_progs mmake=/A files=/A nix=no \
947 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
948 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
949 uselibs= usehostlibs= usestartup=yes detach=no
953 BD_OBJDIR := %(objdir)
954 BD_TARGETDIR := %(targetdir)
957 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
958 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
959 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
961 BD_CFLAGS := %(cflags)
962 BD_DFLAGS := %(dflags)
963 BD_LDFLAGS := %(ldflags)
966 %(mmake)-quick : %(mmake)
968 #MM %(mmake) : includes-generate-deps
969 %(mmake) : $(BD_EXES)
971 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
972 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
973 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
975 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
976 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
977 ldflags=$(BD_LDFLAGS) \
978 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
979 usestartup="%(usestartup)" detach="%(detach)"
983 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
985 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
986 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
987 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
989 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
992 @$(ECHO) "Cleaning up for metatarget %(mmake)"
996 #------------------------------------------------------------------------------
999 #------------------------------------------------------------------------------
1001 # This is a bare version: It just compiles and links the given files. It is
1002 # assumed that all needed boiler plate code is in the files. This should only
1003 # be used for compiling external code. For AROS code use %build_module
1004 %define build_module_simple mmake=/A modname=/A modtype=/A \
1005 files="$(basename $(call WILDCARD, *.c))" \
1006 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1007 objdir=$(OBJDIR) moduledir= \
1008 uselibs= usehostlibs= compiler=target
1010 # Define metamake targets and their dependencies
1011 #MM %(mmake) : core-linklibs includes-generate-deps
1012 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1013 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1017 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1019 .PHONY : $(BD_ALLTARGETS)
1022 $(error using %build_module_simple: modname may not be empty)
1025 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1028 # Default values for variables and arguments
1029 BD_DEFLINKLIBNAME := %(modname)
1030 BD_DEFDFLAGS := %(cflags)
1031 OBJDIR ?= $(GENDIR)/$(CURDIR)
1032 BD_MODDIR := %(moduledir)
1033 ifeq ($(BD_MODDIR),)
1034 ifeq (%(modtype),library)
1035 BD_MODDIR := $(AROS_LIBS)
1037 ifeq (%(modtype),gadget)
1038 BD_MODDIR := $(AROS_GADGETS)
1040 ifeq (%(modtype),datatype)
1041 BD_MODDIR := $(AROS_DATATYPES)
1043 ifeq (%(modtype),handler)
1044 BD_MODDIR := $(AROS_FS)
1046 ifeq (%(modtype),device)
1047 BD_MODDIR := $(AROS_DEVS)
1049 ifeq (%(modtype),resource)
1050 BD_MODDIR := $(AROS_RESOURCES)
1052 ifeq (%(modtype),hook)
1053 BD_MODDIR := $(AROS_RESOURCES)
1055 ifeq (%(modtype),mui)
1056 BD_MODDIR := $(AROS_CLASSES)/Zune
1058 ifeq (%(modtype),mcc)
1059 BD_MODDIR := $(AROS_CLASSES)/Zune
1061 ifeq (%(modtype),mcp)
1062 BD_MODDIR := $(AROS_CLASSES)/Zune
1064 ifeq (%(modtype),usbclass)
1065 BD_MODDIR := $(AROS_CLASSES)/USB
1067 ifeq (%(modtype),hidd)
1068 BD_MODDIR := $(AROS_DRIVERS)
1071 ifeq ($(BD_MODDIR),)
1072 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1075 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1076 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1077 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1079 %rule_compile_multi \
1080 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1081 cflags="%(cflags)" dflags="%(dflags)" \
1082 compiler=%(compiler)
1084 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1085 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1086 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1088 %(mmake)-quick : %(mmake)
1089 %(mmake) : $(BD_MODULE)
1090 %(mmake)-pkg : $(BD_PKGMOD)
1091 %(mmake)-kobj : $(BD_KOBJ)
1093 # The module is linked from all the compiled .o files
1094 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1096 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1097 endobj= err=%(modname).err objdir=%(objdir) \
1098 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1100 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1101 endobj= err=%(modname).err objdir=%(objdir) \
1102 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1104 # Link kernel object file
1105 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1107 # Make these symbols local
1108 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1109 UtilityBase ExpansionBase KeymapBase KernelBase
1111 BD_SYMBOLS := $(BD_KBASE)
1113 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1114 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1115 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1116 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1117 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1118 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1119 @$(ECHO) "Linking $@"
1120 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1121 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1124 ## Dependency fine-tuning
1126 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1127 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1129 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1130 $(BD_MODULE) : | $(BD_MODDIR)
1131 $(BD_KOBJ) : | $(KOBJSDIR)
1132 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1134 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1136 @$(ECHO) "Cleaning up for module %(modname)"
1139 #------------------------------------------------------------------------------
1142 #------------------------------------------------------------------------------
1144 # Explanation of this macro is done in the developer's manual
1145 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1146 conffile= files="$(basename $(call WILDCARD, *.c))" \
1147 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1148 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1149 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1152 # Define metamake targets and their dependencies
1153 #MM- includes-all : %(mmake)-includes
1154 #MM %(mmake) : %(mmake)-includes core-linklibs
1155 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1156 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1157 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1158 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1159 #MM %(mmake)-linklib : %(mmake)-includes
1160 #MM %(mmake)-quick : %(mmake)-includes-quick
1161 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1162 #MM includes-generate-deps
1163 #MM %(mmake)-includes-quick
1164 #MM %(mmake)-includes-dirs
1165 #MM %(mmake)-makefile
1168 # All MetaMake targets defined by this macro
1169 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1170 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1171 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick %(mmake)-linklib
1173 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1176 $(error using %build_module: modname may not be empty)
1179 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1182 # Default values for variables and arguments
1183 BD_DEFLINKLIBNAME := %(modname)
1184 BD_DEFDFLAGS := %(cflags)
1185 OBJDIR ?= $(GENDIR)/$(CURDIR)
1187 ## Create genmodule include Makefile for the module
1189 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1191 %rule_genmodule_makefile \
1192 modname=%(modname) modtype=%(modtype) \
1193 modsuffix=%(modsuffix) targetdir=%(objdir) \
1194 conffile=%(conffile)
1196 %(objdir)/Makefile.%(modname) : | %(objdir)
1198 GLOB_MKDIRS += %(objdir)
1200 # Do not parse these statements if metatarget is not appropriate
1201 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1203 include %(objdir)/Makefile.%(modname)
1205 BD_DEFMODDIR := $(%(modname)_MODDIR)
1208 ## include files generation
1210 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1211 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1212 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1214 %(mmake)-includes-quick : %(mmake)-includes
1215 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1216 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1217 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1219 ifneq ($(%(modname)_INCLUDES),)
1220 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1221 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1222 conffile=%(conffile)
1224 %rule_copy_diff_multi \
1225 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1226 stampfile=%(objdir)/%(modname)_geninc
1228 %rule_copy_diff_multi \
1229 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1230 stampfile=%(objdir)/%(modname)_incs
1232 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1234 TMP%(modname)_INCDIRS := \
1235 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1236 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1237 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1238 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1242 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1243 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1244 conffile=%(conffile)
1246 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1247 $(BD_DEFLIBDEFSINC) :
1248 @$(ECHO) "generating $@"
1249 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1251 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1252 GLOB_MKDIRS += %(objdir)/include
1254 ## Extra genmodule src files generation
1256 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1257 modsuffix=%(modsuffix) targetdir=%(objdir) \
1258 conffile=%(conffile)
1262 BD_FILES := %(files)
1263 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1264 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1265 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1267 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1268 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1269 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1271 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1272 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1274 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1275 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1276 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1279 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1281 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1283 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1284 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES)
1286 %rule_compile_multi \
1287 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1288 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1289 compiler=%(compiler)
1290 %rule_compile_multi \
1291 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1292 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1293 compiler=%(compiler)
1295 ifneq ($(BD_LINKLIBAFILES),)
1296 %rule_assemble_multi \
1297 basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1302 ifeq (%(modsuffix),)
1303 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modtype)
1304 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1305 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1307 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1308 BD_PKGMOD := $(PKGDIR)/%(modname).%(modsuffix)
1309 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1312 %(mmake)-quick : %(mmake)
1313 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1314 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB)
1315 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB)
1316 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1317 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1318 %(mmake)-linklib : $(BD_LINKLIB)
1320 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1321 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1322 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1323 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1324 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1327 # The module is linked from all the compiled .o files
1328 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1329 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1330 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1332 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1333 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1334 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1337 ifneq ($(BD_LINKLIB),)
1338 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1340 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1341 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1344 # Link kernel object file
1345 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1347 # Make these symbols local
1348 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1349 UtilityBase ExpansionBase KeymapBase KernelBase
1351 BD_SYMBOLS := $(BD_KBASE)
1353 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1354 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1355 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1356 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1357 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1358 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1359 @$(ECHO) "Linking $@"
1360 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1361 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1363 ## Dependency fine-tuning
1365 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1366 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1368 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1369 $(BD_MODULE) : | %(prefix)/%(moduledir)
1370 $(BD_PKGMOD) : | $(PKGDIR)
1371 $(BD_KOBJ) : | $(KOBJSDIR)
1372 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1374 # Some include files need to be generated before the .c can be parsed.
1375 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
1377 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1378 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1379 $(BD_DEPS) : $(BD_DFILE_DEPS)
1382 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1383 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1384 %(objdir)/Makefile.%(modname) \
1385 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1386 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1387 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1388 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1389 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1390 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1392 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1394 @$(ECHO) "Cleaning up for module %(modname)"
1397 endif # $(TARGET) in $(BD_ALLTARGETS)
1399 #------------------------------------------------------------------------------
1402 #------------------------------------------------------------------------------
1403 # Build a module skeleton
1404 # This is a stripped-down version of build_module, it only creates include files,
1405 # but no actual object. This is used when for plugins or classes with the same
1406 # API, but no actual implementation here.
1407 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1409 objdir=$(OBJDIR) prefix=$(AROSDIR)
1411 # Define metamake targets and their dependencies
1412 #MM- includes-all : %(mmake)-includes
1413 #MM %(mmake) : %(mmake)-includes core-linklibs
1414 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1415 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1416 #MM %(mmake)-linklib : %(mmake)-includes
1417 #MM %(mmake)-quick : %(mmake)-includes-quick
1418 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1419 #MM includes-generate-deps
1420 #MM %(mmake)-includes-quick
1421 #MM %(mmake)-includes-dirs
1422 #MM %(mmake)-makefile
1425 # All MetaMake targets defined by this macro
1426 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1427 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1428 %(mmake)-kobj %(mmake)-pkg
1430 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1433 $(error using %build_module_skeleton: modname may not be empty)
1436 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1439 # Default values for variables and arguments
1440 BD_DEFLINKLIBNAME := %(modname)
1441 BD_DEFDFLAGS := %(cflags)
1442 OBJDIR ?= $(GENDIR)/$(CURDIR)
1444 ## Create genmodule include Makefile for the module
1446 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1448 %rule_genmodule_makefile \
1449 modname=%(modname) modtype=%(modtype) \
1450 modsuffix=%(modsuffix) targetdir=%(objdir) \
1451 conffile=%(conffile)
1453 %(objdir)/Makefile.%(modname) : | %(objdir)
1455 GLOB_MKDIRS += %(objdir)
1457 # Do not parse these statements if metatarget is not appropriate
1458 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1460 include %(objdir)/Makefile.%(modname)
1462 BD_DEFMODDIR := $(%(modname)_MODDIR)
1465 ## include files generation
1467 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1468 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1469 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1471 %(mmake)-includes-quick : %(mmake)-includes
1472 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1473 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1474 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1476 ifneq ($(%(modname)_INCLUDES),)
1477 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1478 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1479 conffile=%(conffile)
1481 %rule_copy_diff_multi \
1482 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1483 stampfile=%(objdir)/%(modname)_geninc
1485 %rule_copy_diff_multi \
1486 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1487 stampfile=%(objdir)/%(modname)_incs
1489 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1491 TMP%(modname)_INCDIRS := \
1492 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1493 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1494 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1495 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1499 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1500 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1501 conffile=%(conffile)
1503 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1504 $(BD_DEFLIBDEFSINC) :
1505 @$(ECHO) "generating $@"
1506 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1508 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1509 GLOB_MKDIRS += %(objdir)/include
1511 ## Extra genmodule src files generation
1513 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1514 modsuffix=%(modsuffix) targetdir=%(objdir) \
1515 conffile=%(conffile)
1517 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1518 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1519 %(objdir)/Makefile.%(modname) \
1520 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1521 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1522 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1523 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1524 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1526 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1528 @$(ECHO) "Cleaning up for module %(modname)"
1531 endif # $(TARGET) in $(BD_ALLTARGETS)
1533 #------------------------------------------------------------------------------
1536 #------------------------------------------------------------------------------
1538 # - mmake is the mmaketarget
1539 # - libname is the baselibname e.g. lib%(libname).a will be created
1540 # - files are the C source files to include in the lib. The list of files
1541 # has to be given without the .c suffix
1542 # - asmfiles are the asm files to include in the lib. The list of files has to
1543 # be given without the .s suffix
1544 # - objs additional object to link into the linklib. The objects have to be
1545 # given with full absolute path and the .o suffix.
1546 # - cflags are the flags to compile the source (default $(CFLAGS))
1547 # - dflags are the flags use during makedepend (default equal to cflags)
1548 # - aflags are the flags use during assembling (default $(AFLAGS))
1549 # - objdir is where the .o are generated
1550 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1551 %define build_linklib mmake=/A libname=/A \
1552 files="$(basename $(call WILDCARD, *.c))" asmfiles= objs= \
1553 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1555 # assign and generate the local variables used in this macro
1556 OBJDIR ?= $(GENDIR)/$(CURDIR)
1558 BD_FILES := %(files)
1559 BD_ASMFILES := %(asmfiles)
1561 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1562 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1563 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1565 BD_OBJS := $(BD_ARCHOBJS) \
1566 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1568 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1570 BD_CFLAGS := %(cflags)
1572 BD_DFLAGS := $(BD_CFLAGS)
1574 BD_DFLAGS := %(dflags)
1576 BD_AFLAGS := %(aflags)
1578 BD_LINKLIB := %(libdir)/lib%(libname).a
1580 .PHONY : %(mmake) %(mmake)-clean
1582 #MM %(mmake) : includes-generate-deps
1583 %(mmake) : $(BD_LINKLIB)
1587 @$(RM) $(BD_OBJS) $(BD_DEPS)
1589 ifeq ($(TARGET),%(mmake))
1590 ifneq ($(dir $(BD_FILES)),./)
1591 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1592 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1595 %rule_compile basename=% targetdir=%(objdir) \
1596 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1597 %rule_assemble basename=% targetdir=%(objdir) \
1601 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1603 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1605 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1606 $(BD_LINKLIB) : | %(libdir)
1607 GLOB_MKDIRS += %(objdir) %(libdir)
1610 #------------------------------------------------------------------------------
1613 #------------------------------------------------------------------------------
1615 # - mmake is the mmaketarget
1616 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1617 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1618 # - subdir is the destination subdirectory of the catalogs
1619 # - name is the name of the destination catalog, without the .catalog suffix
1620 # - source is the path to the generated source code file
1621 # - dir is the base destination directory (default $(AROS_CATALOGS))
1622 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1623 # - srcdir is the directory in which the *.cd and *.ct files are searched
1625 %define build_catalogs mmake=/A name=/A subdir=/A \
1626 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1627 sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1629 ifeq (%(description),)
1630 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1632 BD_DESC := %(description)
1636 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1638 BD_LNGS := %(catalogs)
1641 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1642 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1645 %(mmake) : $(BD_OBJS) %(source)
1647 $(BD_OBJS) : | $(BD_DIRS)
1648 GLOB_MKDIRS += $(BD_DIRS)
1650 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1651 @$(ECHO) "Creating %(name) catalog for language $*."
1652 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1655 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1656 %(source) : $(BD_DESC).cd | $(dir %(source))
1657 @$(ECHO) "Creating %(name) catalog source file %(source)"
1658 @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1663 $(RM) $(BD_OBJS) %(source)
1665 .PHONY: %(mmake) %(mmake)-clean
1668 #-----------------------------------------------------------------------------
1671 #-----------------------------------------------------------------------------
1673 # - mmake is the mmaketarget
1674 # - icons is a list of icon base names (ie. without the .info suffix)
1675 # - dir is the destination directory
1676 # - srcdir is where *.png and *.info.src are searched
1677 #-----------------------------------------------------------------------------
1679 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1681 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1684 %(mmake) : $(BD_OBJS)
1688 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1689 @$(ECHO) Creating $(notdir $@)...
1690 @$(ILBMTOICON) $+ $@
1694 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1695 @$(ECHO) Creating $(notdir $@)...
1696 @$(ILBMTOICON) $+ $@
1700 $(BD_OBJS) : | %(dir)
1701 GLOB_MKDIRS += %(dir)
1703 %(mmake)-clean : FILES := $(BD_OBJS)
1708 .PHONY: %(mmake) %(mmake)-clean
1711 #-----------------------------------------------------------------------------
1714 #------------------------------------------------------------------------------
1715 # Compile files for an arch-specific replacement of code for a module
1716 # - files: the basenames of the C files to compile.
1717 # - asmfiles: the basenames of the asm files to assemble.
1718 # - mainmmake: the mmake of the module in the main directory to compile these
1719 # arch specific files for.
1720 # - maindir: the object directory for the main module
1721 # - arch: the arch for which to compile these files. It can have the form
1722 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1723 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1724 # - dflags: the flags used during creation of dependency file. If not specified
1725 # the same value as cflags will be used
1726 # - aflags: the flags used during assembling
1727 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1728 # the target compiler is used
1729 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1730 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1732 ifeq (%(files) %(asmfiles),)
1733 $(error no files or asmfiles given)
1736 %buildid targets="%(mainmmake)-%(arch)"
1738 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1739 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1740 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1741 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1742 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1743 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1744 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1745 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1746 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1747 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1748 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1749 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1750 #MM- %(mainmmake)-pkg : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1751 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1752 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1753 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1754 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1755 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1756 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1757 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1758 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1760 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1763 $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1766 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
1767 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1768 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1769 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1770 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1772 ifneq (%(modulename),)
1773 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1776 ifeq ($(TARGET),%(mainmmake)-%(arch))
1777 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1778 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1779 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1780 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1783 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1784 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1787 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1789 ifeq ($(findstring %(compiler),host kernel target),)
1790 $(error unknown compiler %(compiler))
1792 ifeq (%(compiler),target)
1793 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1794 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1795 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1797 ifeq (%(compiler),host)
1798 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1799 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1800 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1802 ifeq (%(compiler),kernel)
1803 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1804 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1805 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1807 ifneq (%(modulename),)
1808 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1810 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1812 ifeq ($(TARGET),%(mainmmake)-%(arch))
1813 $(BD_OBJDIR$(BDID))/%.o : %.c
1814 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1818 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1820 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1822 ifeq ($(TARGET),%(mainmmake)-%(arch))
1823 $(BD_OBJDIR$(BDID))/%.d : %.c
1824 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1827 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1829 ifeq ($(TARGET),%(mainmmake)-%(arch))
1830 $(BD_OBJDIR$(BDID))/%.o : %.s
1831 %assemble_q opt=$(AFLAGS)
1832 $(BD_OBJDIR$(BDID))/%.o : %.S
1833 %assemble_q opt=$(AFLAGS)
1836 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1838 #------------------------------------------------------------------------------
1841 #------------------------------------------------------------------------------
1842 # generate asm files from c files (for debugging purposes)
1845 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1846 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1848 #------------------------------------------------------------------------------
1851 #------------------------------------------------------------------------------
1852 # Copy files from one directory to another.
1854 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1856 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1858 GLOB_MKDIRS += %(dst)
1864 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1867 #------------------------------------------------------------------------------
1870 #------------------------------------------------------------------------------
1871 # Copy a directory recursively to another place, preserving the original
1872 # hierarchical structure
1874 # src: the source directory whose content will be copied
1875 # dst: the directory where to copy src's content. If not existing, it will be made.
1877 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
1879 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1880 %(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)
1881 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
1883 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
1884 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
1886 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
1891 %(mmake): | $(GENDIR)/$(CURDIR)
1892 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1893 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
1894 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1895 for d in $(%(mmake)_DIRS); do \
1896 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
1898 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1899 for f in $(%(mmake)_FILES); do \
1900 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1902 for dst in %(dst); do \
1903 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1907 #------------------------------------------------------------------------------
1910 #------------------------------------------------------------------------------
1911 # Copy include files into the includes directories. There are currently
1912 # two include directories. One for building AROS $(AROS_INCLUDES) and one
1913 # for building tools that need to run on the host system $(GENINCDIR). The
1914 # $(GENINCDIR) path must not contain any references to the C runtime
1915 # library header files.
1917 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1918 dir= compiler=target
1920 ifeq ($(findstring %(compiler),host kernel target),)
1921 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1925 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
1926 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
1927 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1929 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1930 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1933 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1937 ifeq (%(compiler),target)
1940 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
1941 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
1943 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1946 BD_INCL_FILES += $(BD_INCL_FILES2)
1948 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1953 %(mmake) : $(BD_INCL_FILES)
1957 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
1958 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
1960 #------------------------------------------------------------------------------
1963 #------------------------------------------------------------------------------
1964 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1965 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
1966 STUBS_MEM := $(addsuffix .o,$(STUBS))
1967 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
1968 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
1969 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1971 #MM- linklibs : hidd-%(hidd)-stubs
1972 #MM- %(parenttarget): hidd-%(hidd)-stubs
1973 #MM hidd-%(hidd)-stubs : includes includes-copy
1974 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1976 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1979 $(STUBS_OBJ) : $(STUBS_SRC)
1980 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
1982 $(STUBS_DEP) : $(STUBS_SRC)
1983 %mkdepend_q flags=%(dflags)
1986 %mkdirs_q $(OBJDIR) $(LIBDIR)
1990 -@$(RM) $(HIDD_LIB) $(OBJDIR)
1992 DEPS := $(DEPS) $(STUBS_DEP)
1995 #------------------------------------------------------------------------------
1998 #------------------------------------------------------------------------------
1999 # Build an imported source tree which uses the configure script from the
2000 # autoconf package. This rule will try to "integrate" the produced files as
2001 # much as possible in the AROS build, for example by putting libraries in the
2002 # standard library directory, includes in the standard include directory, and
2003 # so on. You can however override this behaviour.
2005 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2006 # be %(bindir) (or its deduced value) when running "make install", and
2007 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2008 # configure script some more parameters whose value depends upon the PROGDIR
2009 # env var, so that the program gets all its stuff installed in the proper place
2010 # when building it, but when running it from inside AROS it can also find that
2011 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2012 # the configuration parameters set when running ./configure
2014 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2015 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2016 # to the name which has to follow it.
2019 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2020 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2021 install_target=install preconfigure= postconfigure= postinstall= \
2025 %(mmake)-prefix := %(prefix)
2027 %(mmake)-prefix := $(AROS_CONTRIB)
2030 ifneq (%(aros_prefix),)
2031 %(mmake)-aros_prefix := %(aros_prefix)
2033 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2037 %(mmake)-nix := -nix
2038 %(mmake)-volpfx := /
2039 %(mmake)-volsfx := /
2041 ifeq (%(nix_dir_layout),)
2042 %(mmake)-nix_dir_layout := yes
2045 %(mmake)-volsfx := :
2047 ifeq (%(nix_dir_layout),)
2048 %(mmake)-nix_dir_layout := no
2052 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2054 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2055 exec_prefix=$(%(mmake)-prefix) %(install_env)
2057 # Check if chosen compiler is valid
2058 ifeq ($(findstring %(compiler),host target kernel),)
2059 $(error unknown compiler %(compiler))
2062 # Set legacy 'host' variable based on chosen compiler
2063 ifeq (%(compiler),host)
2066 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2068 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2073 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2075 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2079 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2080 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2082 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2083 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2084 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2087 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2088 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2090 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2093 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2095 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2096 sbindir=$(%(mmake)-prefix) \
2097 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2098 oldincludedir=$(AROS_INCLUDES) %(install_env)
2101 ifneq ($(DEBUG),yes)
2102 %(mmake)-s_flag = -s
2105 # Set up build environment, and options for configure script
2106 ifeq (%(compiler),host)
2108 CC="$(HOST_CC) $(HOST_CFLAGS)" \
2109 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2110 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2111 TARGET_RANLIB="$(RANLIB)"
2112 %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2114 ifeq (%(compiler),target)
2116 CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2117 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2118 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2119 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2120 TARGET_RANLIB="$(RANLIB)"
2121 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2122 --host=$(AROS_TARGET_CPU)-aros\
2123 --target=$(AROS_TARGET_CPU)-aros\
2125 --without-x --without-pic --disable-shared
2127 ifeq (%(compiler),kernel)
2129 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2130 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2131 TARGET_RANLIB="$(RANLIB)"
2132 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2133 --host=$(AROS_TARGET_CPU)-aros\
2134 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2135 --without-x --without-pic --disable-shared
2139 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2141 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2143 # Using -j1 in install_command may result in a warning but finally
2144 # it does its job. make install for gcc does not work reliably for -jN
2146 ifneq (%(install_target),)
2147 %(mmake)-install_command = \
2148 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2149 -C $(%(mmake)-pkgdir) %(install_target) -j1
2151 %(mmake)-uninstall_command = \
2152 $(RM) $(%(mmake)-installflag) && \
2153 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2154 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2156 %(mmake)-install_command := true
2157 %(mmake)-uninstall_command := true
2160 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2163 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2165 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2166 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2167 $(RM) $(%(mmake)-installflag) && \
2168 $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2169 -C $(%(mmake)-pkgdir) && \
2170 $(%(mmake)-install_command) && \
2171 $(TOUCH) $@ -r $^; \
2174 $(%(mmake)-pkgdir)/.files-touched:
2175 %mkdirs_q $(%(mmake)-pkgdir)
2176 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2180 %(mmake)-uninstall :
2181 $(%(mmake)-uninstall_command)
2184 %(mmake)-configure : $(%(mmake)-configflag)
2186 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2187 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2189 %mkdirs_q $(%(mmake)-pkgdir)
2190 cd $(%(mmake)-pkgdir) && \
2191 find . -name config.cache -exec $(RM) '{}' \; && \
2192 $(COMPILER_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2193 %(extraoptions) && \
2197 %(mmake)-clean : %(mmake)-uninstall
2198 @$(RM) $(%(mmake)-pkgdir)
2200 #------------------------------------------------------------------------------
2203 #------------------------------------------------------------------------------
2204 # Given an archive name, patches names and locations where to find them, fetch
2205 # the archive and the patches from any of those locations, unpack the archive
2206 # and then apply the patches.
2208 # Locations currently supported are http and ftp sites, plus local filesystem
2209 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2210 # the fetch.sh script needs to be modified, since this macro relies on that script.
2214 # - mmake = mmaketarget
2215 # - archive_origins = list of locations where to find the archive. They are tried
2216 # in sequence, until the archive is found and fetching it
2217 # succeeded. If not specified, the current directory is assumed.
2218 # - archive = the archive name. Mandatory.
2219 # - suffixes = a list of suffixes to append to the the package name plus the
2220 # version. Each one of them is tried until a matching archive is
2221 # found. They are appended to patches and these are tried the
2222 # same way as packages are.
2223 # - location = the local directory where to put the fetched archive and patches.
2224 # If not specified, the directory specified by destination is used.
2225 # - destination = the directory to unpack the archive to.
2226 # If not specified, the current directory is assumed.
2227 # - patches_origins = list of locations where to find the patches. They are tried
2228 # in sequence, until a patch is found and fetching it
2229 # succeeded. If not specified, the current directory is assumed.
2230 # - patches_specs = list of "patch specs". A patch spec is of the form
2231 # patch_name[:[patch_subdir][:patch_opt]].
2233 # - patch_name = the name of the patch file
2234 # - patch_subdir = the directory within \destination\ where to
2236 # - patch_opt = any options to pass to the `patch' command
2237 # when applying the patch.
2239 # The patch_subdir and patch_opt fields are optional.
2241 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2242 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2246 ifneq (%(location),)
2247 %(mmake)-location := %(location)
2249 %(mmake)-location := %(destination)
2254 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2255 -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2257 #------------------------------------------------------------------------------
2260 #------------------------------------------------------------------------------
2261 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2262 # unpatched source tree and runs diff against this and a previously fetched and possibly
2263 # patched tree. Depending on what happens after patching during a normal build it might
2264 # give best results if the new patch is created directly after fetch.
2268 # - mmake = mmaketarget
2269 # - archive = archive base name
2270 # - suffixes = a list of suffixes to append to the the package name plus the
2271 # version. Each one of them is tried until a matching archive is
2273 # - destination = the directory to unpack the archive to.
2274 # - excludes = diff patterns to exclude files or directories from the patch
2276 %define create_patch mmake=/A archive=/A suffixes="tar.bz2 tar.gz" destination=/A excludes=
2280 ifneq (%(excludes),)
2281 %(mmake)-exclude := -X ./exclude.patterns
2286 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2287 $(MV) %(destination)/%(archive) %(destination)/tmp/%(archive).aros ; \
2288 cd %(destination)/tmp ; \
2289 $(FOR) f in %(excludes) ; do \
2290 $(ECHO) $$f >> ./exclude.patterns ; \
2292 diff -ruN $(%(mmake)-exclude) \
2295 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2296 $(MV) %(destination)/tmp/%(archive).aros %(destination)/%(archive) ; \
2297 $(RM) %(destination)/tmp
2299 #------------------------------------------------------------------------------
2302 #------------------------------------------------------------------------------
2303 # Joins the features of %fetch and %build_with_configure, taking advantage of
2304 # the naming scheme of GNU packages. GNU packages names are in the form
2306 # <package name>-<version number>.<archive format suffix>
2308 # If a patch is provided, it *must* be named the following way:
2310 # <package name>-<version number>-aros.diff
2312 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2313 # CD'ing into the archive's extracted directory.
2315 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2316 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2317 # to make that patch fully comprehensive.
2319 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2323 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2325 # - package = the GNU package name, sans version and archive format suffixes.
2326 # - version = the package's version number, or otherwise any other version string.
2327 # It gets appended to the package name to form the basename of the archive.
2328 # - suffixes = a list of suffixes to apped to the the package name plus the
2329 # version. Each one of them is tried until a matching archive is found.
2330 # Defaults to "tar.bz2 tar.gz".
2331 # - destination = same meaning as the one for the %fetch macro
2332 # - location = same meaning as the one for the %fetch macro
2333 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2334 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2336 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2337 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2339 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2341 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2342 # - extracflags = same meaning as the one for the %build_with_configure macro.
2343 # - postinstall = same meaning as the one for the %build_with_configure macro.
2344 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2346 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2347 srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2348 preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2350 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2351 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2352 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2353 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2355 %(mmake)-archbase := %(package)-%(version)
2357 ifeq (%(compiler),host)
2358 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2360 %(mmake)-portdir := $(PORTSDIR)/%(package)
2364 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2366 %(mmake)-prefix := %(prefix)
2369 ifneq (%(subpackage),)
2370 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2372 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2376 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2378 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2382 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2384 %(mmake)-%(subpackage)-patches_specs := ::
2387 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2388 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2389 archive_origins=". %(package_repo)" \
2390 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2392 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2393 archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" destination=$(%(mmake)-portdir)
2395 #MM- %(mmake) : %(mmake)-%(subpackage)
2397 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2399 %(mmake)-%(subpackage)-package-basename := \
2400 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2402 ifneq (%(create_pkg),no)
2403 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2406 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2407 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2408 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2409 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2410 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2412 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2413 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2416 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2418 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2419 #that $^ and $@ have exactly the same mtime, and in that case make tries
2420 #to rebuild $@ again, which would fail because the directory where
2421 #the package got installed would not exist anymore.
2422 #We work this around by using an if statement to manually check the mtimes.
2423 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2424 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2426 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2427 mkdir -p "$(DISTDIR)/Packages" ; \
2428 mkdir -p "$(%(mmake)-prefix)" ; \
2429 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2430 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2431 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2434 #------------------------------------------------------------------------------
2437 #------------------------------------------------------------------------------
2438 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2439 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2440 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
2442 GNU_REPOSITORY := gnu://
2444 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2445 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2446 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2447 patch="%(patch)" patch_repo="%(patch_repo)" \
2448 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2449 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2452 #------------------------------------------------------------------------------
2455 #------------------------------------------------------------------------------
2456 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2457 # that the package is a "Development" package, and as such it needs to be placed
2458 # under the $(AROS_DEVELOPMENT) directory, as a default.
2460 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2461 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2462 # "mmake" argument, because the metatarget is implicitely defined as
2464 # #MM- development-%(package)
2466 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2467 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2468 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
2470 #MM- development : development-%(package)
2473 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2474 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2475 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2476 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2477 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2480 #------------------------------------------------------------------------------
2482 # Builds a kickstart package in PKG format
2483 # mmake - target name
2484 # file - Destination file name with path
2485 # startup - The file which will be put first
2486 # Other arguments are self-explanatory
2488 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2490 PKG_CLASSES := $(addsuffix .class, %(classes))
2491 PKG_DEVICES := $(addsuffix .device, %(devs))
2492 PKG_HANDLERS := $(addsuffix .handler, %(handlers))
2493 PKG_HIDD := $(addsuffix .hidd, %(hidds))
2494 PKG_LIBS := $(addsuffix .library, %(libs))
2495 PKG_RESOURCES := $(addsuffix .resource, %(res))
2497 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2498 PKG_DIR := $(dir %(file))
2499 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2505 %(mmake)-quick : %(file)
2507 %(file): PKG_FILES := $(PKG_FILES)
2508 %(file): $(PKG_DEPS) | $(PKG_DIR)
2509 @$(ECHO) Packaging $@...
2510 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2512 GLOB_MKDIRS += $(PKG_DIR)
2515 #------------------------------------------------------------------------------
2517 # Links a kickstart module in ELF format
2518 # Arguments are similar to make_package
2520 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2521 startup= uselibs= ldflags=$(LDFLAGS) map=
2523 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2524 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2525 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2526 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2527 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2528 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2531 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2533 KOBJ_STARTUP := %(startup)
2536 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2538 TMP_LDFLAGS := %(ldflags)
2540 # Make a list of the lib files this program depends on.
2541 # In LDFLAGS remove white space between -L and directory
2542 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2543 # Filter out only the libdirs and remove -L
2544 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2546 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2547 # Add normal linklib path
2548 TMP_DIRS += $(LIBDIR)/
2549 # add lib and .a to static linklib names
2550 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2551 # search for the linklibs in the given path, ignore ones not found
2552 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2553 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2556 TMP_DIRS += $(dir %(file))
2558 TMP_LDFLAGS += $(GENMAP) %(map)
2559 TMP_DIRS += $(dir %(map))
2566 %(mmake)-quick : %(file)
2568 %(file): KOBJS := $(KOBJS)
2569 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2570 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2571 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2572 @$(ECHO) Linking $@...
2573 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
2575 GLOB_MKDIRS += $(TMP_DIRS)
2579 #------------------------------------------------------------------------------
2580 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2581 # 'start' is an optional starting address
2582 # 'ldflags' is optional additional flags for the linker
2583 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2585 BD_OUTDIR := $(dir %(file))
2586 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2588 %(file) : %(objs) $(BD_OUTDIR)
2589 @$(ECHO) Linking $@...
2590 @$(KERNEL_LD) -melf_i386 --oformat=binary -e %(start) -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2591 @cd $(BD_TMPDIR) && $(KERNEL_LD) -r --format binary %(ldflags) %(name) -o $@
2593 GLOB_MKDIRS += $(BD_OUTDIR)