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 #------------------------------------------------------------------------------
732 #------------------------------------------------------------------------------
733 # Generate the _lib.fd file for a module.
734 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
736 TMP_TARGET := %(modname)_lib.fd
737 TMP_DEPS := $(GENMODULE)
740 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
741 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
743 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
744 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
746 ifneq (%(modsuffix),)
747 TMP_OPTS += -s %(modsuffix)
749 ifneq (%(targetdir),)
750 TMP_OPTS += -d %(targetdir)
751 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
754 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
755 $(TMP_TARGET) : MODNAME := %(modname)
756 $(TMP_TARGET) : MODTYPE := %(modtype)
757 $(TMP_TARGET) : $(TMP_DEPS)
758 @$(ECHO) "Generating $(notdir $@)"
759 @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
761 #------------------------------------------------------------------------------
763 #------------------------------------------------------------------------------
764 # Generate a Makefile.%(modname) with the genmodule program and include this
765 # generated file in this Makefile
766 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
769 TMP_TARGET := Makefile.%(modname)
770 TMP_DEPS := $(GENMODULE)
773 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
774 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
776 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
777 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
779 ifneq (%(modsuffix),)
780 TMP_OPTS += -s %(modsuffix)
782 ifneq (%(targetdir),)
783 TMP_OPTS += -d %(targetdir)
784 TMP_TARGET := %(targetdir)/$(TMP_TARGET)
787 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
788 $(TMP_TARGET) : MODNAME := %(modname)
789 $(TMP_TARGET) : MODTYPE := %(modtype)
790 $(TMP_TARGET) : $(TMP_DEPS)
791 @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
793 #------------------------------------------------------------------------------
796 #------------------------------------------------------------------------------
797 # Generate the support files for compiling a module. This includes include
798 # files and source files. This rule has to be preceeded by
799 # %rule_genmodule_makefile
800 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
803 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
804 $(%(modname)_LINKLIBFILES)
805 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) $(addsuffix .S, $(%(modname)_LINKLIBAFILES))
807 TMP_DEPS := $(GENMODULE)
811 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
812 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
814 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
815 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
817 ifneq (%(modsuffix),)
818 TMP_OPTS += -s %(modsuffix)
820 ifneq (%(targetdir),)
821 TMP_OPTS += -d %(targetdir)
822 TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
823 TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
826 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
827 $(TMP_TARGETS) : MODNAME := %(modname)
828 $(TMP_TARGETS) : MODTYPE := %(modtype)
829 $(TMP_TARGETS) : $(TMP_DEPS)
830 @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
831 ifneq (%(conffile),lib.conf)
832 @$(IF) $(TEST) -f lib.conf; then \
833 $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
836 @$(IF) $(TEST) -f libdefs.h; then \
837 $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
839 @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
841 #------------------------------------------------------------------------------
844 #------------------------------------------------------------------------------
845 # Generate the support files for compiling a module. This includes include
846 # files and source files.
847 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
850 ifneq ($(%(modname)_INCLUDES),)
851 TMP_TARGETS := $(%(modname)_INCLUDES)
853 TMP_DEPS := $(GENMODULE)
857 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
858 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
860 TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
861 TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
863 ifneq (%(modsuffix),)
864 TMP_OPTS += -s %(modsuffix)
866 ifneq (%(targetdir),)
867 TMP_OPTS += -d %(targetdir)
868 TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
871 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
872 $(TMP_TARGETS) : MODNAME := %(modname)
873 $(TMP_TARGETS) : MODTYPE := %(modtype)
874 $(TMP_TARGETS) : $(TMP_DEPS)
875 @$(ECHO) "Generating include files"
876 @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
879 #------------------------------------------------------------------------------
882 #------------------------------------------------------------------------------
883 # Common rules for all makefiles
885 # Delete generated makefiles
888 @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
890 include $(SRCDIR)/config/make.tail
892 BDID := $(BDTARGETID)
894 #------------------------------------------------------------------------------
897 #############################################################################
898 #############################################################################
900 ## Here are the mmakefile build macros. These are macros that takes care ##
901 ## of everything to go from the sources to the generated target. Also all ##
902 ## intermediate files and directories that are needed are created by these ##
905 #############################################################################
906 #############################################################################
908 #------------------------------------------------------------------------------
910 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) asmfiles= \
911 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
912 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
913 aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
914 compiler=target srcdir=
918 BD_PROGNAME := %(progname)
919 BD_OBJDIR := %(objdir)
920 BD_TARGETDIR := %(targetdir)
923 BD_ASMFILES := %(asmfiles)
925 BD_ARCHOBJS := $(wildcard $(BD_OBJDIR)/arch/*.o)
926 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
927 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
929 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_ASMFILES)))
930 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES)))
932 BD_CFLAGS := %(cflags)
933 BD_AFLAGS := %(aflags)
934 BD_DFLAGS := %(dflags)
935 BD_LDFLAGS := %(ldflags)
938 %(mmake)-quick : %(mmake)
940 #MM %(mmake) : includes-generate-deps linklibs-core
941 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
943 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
944 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
945 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
946 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
947 aflags=$(BD_AFLAGS) compiler=%(compiler)
949 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
950 objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
951 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
952 usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
957 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
959 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
960 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
961 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
963 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
966 @$(ECHO) "Cleaning up for metatarget %(mmake)"
970 #------------------------------------------------------------------------------
973 #------------------------------------------------------------------------------
974 # Build programs, for every C file an executable will be built with the same
976 %define build_progs mmake=/A files=/A nix=no \
977 objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
978 cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
979 uselibs= usehostlibs= usestartup=yes detach=no
983 BD_OBJDIR := %(objdir)
984 BD_TARGETDIR := %(targetdir)
987 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
988 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
989 BD_EXES := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
991 BD_CFLAGS := %(cflags)
992 BD_DFLAGS := %(dflags)
993 BD_LDFLAGS := %(ldflags)
996 %(mmake)-quick : %(mmake)
998 #MM %(mmake) : includes-generate-deps
999 %(mmake) : $(BD_EXES)
1001 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1002 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1003 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1005 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1006 targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1007 ldflags=$(BD_LDFLAGS) \
1008 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1009 usestartup="%(usestartup)" detach="%(detach)"
1013 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1015 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1016 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1017 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1019 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1022 @$(ECHO) "Cleaning up for metatarget %(mmake)"
1026 #------------------------------------------------------------------------------
1029 #------------------------------------------------------------------------------
1031 # This is a bare version: It just compiles and links the given files. It is
1032 # assumed that all needed boiler plate code is in the files. This should only
1033 # be used for compiling external code. For AROS code use %build_module
1034 %define build_module_simple mmake=/A modname=/A modtype=/A \
1035 files="$(basename $(call WILDCARD, *.c))" \
1036 cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1037 objdir=$(OBJDIR) moduledir= \
1038 uselibs= usehostlibs= compiler=target
1040 # Define metamake targets and their dependencies
1041 #MM %(mmake) : core-linklibs includes-generate-deps
1042 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1043 #MM %(mmake)-pkg : core-linklibs includes-generate-deps
1047 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1049 .PHONY : $(BD_ALLTARGETS)
1052 $(error using %build_module_simple: modname may not be empty)
1055 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1058 # Default values for variables and arguments
1059 BD_DEFLINKLIBNAME := %(modname)
1060 BD_DEFDFLAGS := %(cflags)
1061 OBJDIR ?= $(GENDIR)/$(CURDIR)
1062 BD_MODDIR := %(moduledir)
1063 ifeq ($(BD_MODDIR),)
1064 ifeq (%(modtype),library)
1065 BD_MODDIR := $(AROS_LIBS)
1067 ifeq (%(modtype),gadget)
1068 BD_MODDIR := $(AROS_GADGETS)
1070 ifeq (%(modtype),datatype)
1071 BD_MODDIR := $(AROS_DATATYPES)
1073 ifeq (%(modtype),handler)
1074 BD_MODDIR := $(AROS_FS)
1076 ifeq (%(modtype),device)
1077 BD_MODDIR := $(AROS_DEVS)
1079 ifeq (%(modtype),resource)
1080 BD_MODDIR := $(AROS_RESOURCES)
1082 ifeq (%(modtype),hook)
1083 BD_MODDIR := $(AROS_RESOURCES)
1085 ifeq (%(modtype),mui)
1086 BD_MODDIR := $(AROS_CLASSES)/Zune
1088 ifeq (%(modtype),mcc)
1089 BD_MODDIR := $(AROS_CLASSES)/Zune
1091 ifeq (%(modtype),mcp)
1092 BD_MODDIR := $(AROS_CLASSES)/Zune
1094 ifeq (%(modtype),usbclass)
1095 BD_MODDIR := $(AROS_CLASSES)/USB
1097 ifeq (%(modtype),hidd)
1098 BD_MODDIR := $(AROS_DRIVERS)
1101 ifeq ($(BD_MODDIR),)
1102 $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1105 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1106 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1107 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1109 %rule_compile_multi \
1110 basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1111 cflags="%(cflags)" dflags="%(dflags)" \
1112 compiler=%(compiler)
1114 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1115 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1116 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1118 %(mmake)-quick : %(mmake)
1119 %(mmake) : $(BD_MODULE)
1120 %(mmake)-pkg : $(BD_PKGMOD)
1121 %(mmake)-kobj : $(BD_KOBJ)
1123 # The module is linked from all the compiled .o files
1124 BD_OBJS := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1126 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1127 endobj= err=%(modname).err objdir=%(objdir) \
1128 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1130 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1131 endobj= err=%(modname).err objdir=%(objdir) \
1132 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1134 # Link kernel object file
1135 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1137 # Make these symbols local
1138 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1139 UtilityBase ExpansionBase KeymapBase KernelBase
1141 BD_SYMBOLS := $(BD_KBASE)
1143 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1144 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1145 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1146 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1147 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1148 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1149 @$(ECHO) "Linking $@"
1150 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1151 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1154 ## Dependency fine-tuning
1156 BD_DEPS := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1157 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1159 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1160 $(BD_MODULE) : | $(BD_MODDIR)
1161 $(BD_KOBJ) : | $(KOBJSDIR)
1162 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1164 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1166 @$(ECHO) "Cleaning up for module %(modname)"
1169 #------------------------------------------------------------------------------
1172 #------------------------------------------------------------------------------
1174 # Explanation of this macro is done in the developer's manual
1175 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
1176 conffile= files="$(basename $(call WILDCARD, *.c))" \
1177 linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1178 objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1179 linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1182 # Define metamake targets and their dependencies
1183 #MM- includes-all : %(mmake)-includes
1184 #MM %(mmake) : %(mmake)-includes core-linklibs
1185 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1186 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1187 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1188 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1189 #MM %(mmake)-linklib : %(mmake)-includes
1190 #MM %(mmake)-quick : %(mmake)-includes-quick
1191 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1192 #MM includes-generate-deps %(mmake)-fd
1193 #MM %(mmake)-includes-quick
1194 #MM %(mmake)-includes-dirs
1196 #MM %(mmake)-makefile
1199 # All MetaMake targets defined by this macro
1200 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1201 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1202 %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1203 %(mmake)-linklib %(mmake)-fd
1205 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1208 $(error using %build_module: modname may not be empty)
1211 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1214 # Default values for variables and arguments
1215 BD_DEFLINKLIBNAME := %(modname)
1216 BD_DEFDFLAGS := %(cflags)
1217 OBJDIR ?= $(GENDIR)/$(CURDIR)
1219 ## Create genmodule include Makefile for the module
1221 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1223 %rule_genmodule_makefile \
1224 modname=%(modname) modtype=%(modtype) \
1225 modsuffix=%(modsuffix) targetdir=%(objdir) \
1226 conffile=%(conffile)
1228 %(objdir)/Makefile.%(modname) : | %(objdir)
1230 GLOB_MKDIRS += %(objdir)
1232 # Do not parse these statements if metatarget is not appropriate
1233 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1235 include %(objdir)/Makefile.%(modname)
1237 BD_DEFMODDIR := $(%(modname)_MODDIR)
1240 ## include files generation
1242 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1243 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1244 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1246 %(mmake)-includes-quick : %(mmake)-includes
1247 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1248 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1249 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1251 ifneq ($(%(modname)_INCLUDES),)
1252 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1253 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1254 conffile=%(conffile)
1256 %rule_copy_diff_multi \
1257 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1258 stampfile=%(objdir)/%(modname)_geninc
1260 %rule_copy_diff_multi \
1261 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1262 stampfile=%(objdir)/%(modname)_incs
1264 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1266 TMP%(modname)_INCDIRS := \
1267 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1268 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1269 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1270 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1274 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1275 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1276 conffile=%(conffile)
1278 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1279 $(BD_DEFLIBDEFSINC) :
1280 @$(ECHO) "generating $@"
1281 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1283 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1284 GLOB_MKDIRS += %(objdir)/include
1286 ## Extra genmodule src files generation
1288 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1289 modsuffix=%(modsuffix) targetdir=%(objdir) \
1290 conffile=%(conffile)
1294 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1295 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1297 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1298 modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1300 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1302 GLOB_MKDIRS += $(BD_FDDIR)
1307 BD_FILES := %(files)
1308 BD_FDIRS := $(sort $(dir $(BD_FILES)))
1309 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1310 BD_ENDFILES := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1312 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1313 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1314 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1316 BD_CFLAGS := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1317 BD_DFLAGS := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1319 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1320 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1321 ifeq ($(strip $(%(modname)_LINKLIBFILES) %(linklibfiles)),)
1324 BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1326 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1328 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1329 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES)
1331 %rule_compile_multi \
1332 basenames=$(BD_CCFILES) targetdir=%(objdir) \
1333 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1334 compiler=%(compiler)
1335 %rule_compile_multi \
1336 basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1337 cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1338 compiler=%(compiler)
1340 ifneq ($(BD_LINKLIBAFILES),)
1341 %rule_assemble_multi \
1342 basenames=$(BD_LINKLIBAFILES) targetdir=%(objdir) suffix=.S
1347 ifeq (%(modsuffix),)
1348 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modtype)
1349 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1350 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modtype).o
1352 BD_MODULE := %(prefix)/%(moduledir)/%(modname).%(modsuffix)
1353 BD_PKGMOD := $(PKGDIR)/%(modname).%(modsuffix)
1354 BD_KOBJ := $(KOBJSDIR)/%(modname)_%(modsuffix).o
1357 %(mmake)-quick : %(mmake)
1358 %(mmake) : $(BD_MODULE) $(BD_LINKLIB)
1359 %(mmake)-pkg : $(BD_PKGMOD) $(BD_LINKLIB)
1360 %(mmake)-pkg-quick : $(BD_PKGMOD) $(BD_LINKLIB)
1361 %(mmake)-kobj : $(BD_KOBJ) $(BD_LINKLIB)
1362 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB)
1363 %(mmake)-linklib : $(BD_LINKLIB)
1365 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1366 $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1367 BD_STARTOBJS := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1368 BD_ENDOBJS := $(addsuffix .o,$(BD_ENDFILES))
1369 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1372 # The module is linked from all the compiled .o files
1373 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1374 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1375 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1377 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1378 endobj=$(BD_ENDOBJS) err=%(modname).err objdir=%(objdir) \
1379 uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1382 ifneq ($(BD_LINKLIB),)
1383 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1385 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1386 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1389 # Link kernel object file
1390 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1392 # Make these symbols local
1393 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1394 UtilityBase ExpansionBase KeymapBase KernelBase
1396 BD_SYMBOLS := $(BD_KBASE)
1398 BD_KLIB := hiddstubs amiga arossupport rom arosm autoinit libinit
1399 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1400 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1401 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1402 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1403 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1404 @$(ECHO) "Linking $@"
1405 @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1406 @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^libraryset_.*$$/) {print "-L " $$3;}'`
1408 ## Dependency fine-tuning
1410 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1411 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1413 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1414 $(BD_MODULE) : | %(prefix)/%(moduledir)
1415 $(BD_PKGMOD) : | $(PKGDIR)
1416 $(BD_KOBJ) : | $(KOBJSDIR)
1417 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1419 # Some include files need to be generated before the .c can be parsed.
1420 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
1422 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1423 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1424 $(BD_DEPS) : $(BD_DFILE_DEPS)
1427 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1428 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1429 %(objdir)/Makefile.%(modname) \
1430 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1431 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1432 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1433 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1434 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1435 $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1437 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1439 @$(ECHO) "Cleaning up for module %(modname)"
1442 endif # $(TARGET) in $(BD_ALLTARGETS)
1444 #------------------------------------------------------------------------------
1447 #------------------------------------------------------------------------------
1448 # Build a module skeleton
1449 # This is a stripped-down version of build_module, it only creates include files,
1450 # but no actual object. This is used when for plugins or classes with the same
1451 # API, but no actual implementation here.
1452 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1454 objdir=$(OBJDIR) prefix=$(AROSDIR)
1456 # Define metamake targets and their dependencies
1457 #MM- includes-all : %(mmake)-includes
1458 #MM %(mmake) : %(mmake)-includes core-linklibs
1459 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1460 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs
1461 #MM %(mmake)-linklib : %(mmake)-includes
1462 #MM %(mmake)-quick : %(mmake)-includes-quick
1463 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1464 #MM includes-generate-deps
1465 #MM %(mmake)-includes-quick
1466 #MM %(mmake)-includes-dirs
1467 #MM %(mmake)-makefile
1470 # All MetaMake targets defined by this macro
1471 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1472 %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1473 %(mmake)-kobj %(mmake)-pkg
1475 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1478 $(error using %build_module_skeleton: modname may not be empty)
1481 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1484 # Default values for variables and arguments
1485 BD_DEFLINKLIBNAME := %(modname)
1486 BD_DEFDFLAGS := %(cflags)
1487 OBJDIR ?= $(GENDIR)/$(CURDIR)
1489 ## Create genmodule include Makefile for the module
1491 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1493 %rule_genmodule_makefile \
1494 modname=%(modname) modtype=%(modtype) \
1495 modsuffix=%(modsuffix) targetdir=%(objdir) \
1496 conffile=%(conffile)
1498 %(objdir)/Makefile.%(modname) : | %(objdir)
1500 GLOB_MKDIRS += %(objdir)
1502 # Do not parse these statements if metatarget is not appropriate
1503 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1505 include %(objdir)/Makefile.%(modname)
1507 BD_DEFMODDIR := $(%(modname)_MODDIR)
1510 ## include files generation
1512 BD_INCDIR := %(prefix)/$(AROS_DIR_INCLUDE)
1513 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1514 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1516 %(mmake)-includes-quick : %(mmake)-includes
1517 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1518 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1519 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1521 ifneq ($(%(modname)_INCLUDES),)
1522 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1523 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1524 conffile=%(conffile)
1526 %rule_copy_diff_multi \
1527 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1528 stampfile=%(objdir)/%(modname)_geninc
1530 %rule_copy_diff_multi \
1531 files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1532 stampfile=%(objdir)/%(modname)_incs
1534 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1536 TMP%(modname)_INCDIRS := \
1537 %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1538 $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1539 $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1540 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1544 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1545 modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1546 conffile=%(conffile)
1548 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1549 $(BD_DEFLIBDEFSINC) :
1550 @$(ECHO) "generating $@"
1551 @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1553 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1554 GLOB_MKDIRS += %(objdir)/include
1556 ## Extra genmodule src files generation
1558 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1559 modsuffix=%(modsuffix) targetdir=%(objdir) \
1560 conffile=%(conffile)
1562 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1563 $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1564 %(objdir)/Makefile.%(modname) \
1565 $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1566 $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1567 $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1568 %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1569 $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1571 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1573 @$(ECHO) "Cleaning up for module %(modname)"
1576 endif # $(TARGET) in $(BD_ALLTARGETS)
1578 #------------------------------------------------------------------------------
1581 #------------------------------------------------------------------------------
1583 # - mmake is the mmaketarget
1584 # - libname is the baselibname e.g. lib%(libname).a will be created
1585 # - files are the C source files to include in the lib. The list of files
1586 # has to be given without the .c suffix
1587 # - asmfiles are the asm files to include in the lib. The list of files has to
1588 # be given without the .s suffix
1589 # - objs additional object to link into the linklib. The objects have to be
1590 # given with full absolute path and the .o suffix.
1591 # - cflags are the flags to compile the source (default $(CFLAGS))
1592 # - dflags are the flags use during makedepend (default equal to cflags)
1593 # - aflags are the flags use during assembling (default $(AFLAGS))
1594 # - objdir is where the .o are generated
1595 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1596 %define build_linklib mmake=/A libname=/A \
1597 files="$(basename $(call WILDCARD, *.c))" asmfiles= objs= \
1598 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1600 # assign and generate the local variables used in this macro
1601 OBJDIR ?= $(GENDIR)/$(CURDIR)
1603 BD_FILES := %(files)
1604 BD_ASMFILES := %(asmfiles)
1606 BD_ARCHOBJS := $(wildcard %(objdir)/arch/*.o)
1607 BD_ARCHFILES := $(basename $(notdir $(BD_ARCHOBJS)))
1608 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1610 BD_OBJS := $(BD_ARCHOBJS) \
1611 $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_ASMFILES)))) \
1613 BD_DEPS := $(patsubst %.o,%.d,$(BD_OBJS))
1615 BD_CFLAGS := %(cflags)
1617 BD_DFLAGS := $(BD_CFLAGS)
1619 BD_DFLAGS := %(dflags)
1621 BD_AFLAGS := %(aflags)
1623 BD_LINKLIB := %(libdir)/lib%(libname).a
1625 .PHONY : %(mmake) %(mmake)-clean
1627 #MM %(mmake) : includes-generate-deps
1628 %(mmake) : $(BD_LINKLIB)
1632 @$(RM) $(BD_OBJS) $(BD_DEPS)
1634 ifeq ($(TARGET),%(mmake))
1635 ifneq ($(dir $(BD_FILES)),./)
1636 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1637 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1640 %rule_compile basename=% targetdir=%(objdir) \
1641 cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1642 %rule_assemble basename=% targetdir=%(objdir) \
1645 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir)
1648 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1650 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1651 $(BD_LINKLIB) : | %(libdir)
1652 GLOB_MKDIRS += %(objdir) %(libdir)
1655 #------------------------------------------------------------------------------
1658 #------------------------------------------------------------------------------
1660 # - mmake is the mmaketarget
1661 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1662 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1663 # - subdir is the destination subdirectory of the catalogs
1664 # - name is the name of the destination catalog, without the .catalog suffix
1665 # - source is the path to the generated source code file
1666 # - dir is the base destination directory (default $(AROS_CATALOGS))
1667 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1668 # - srcdir is the directory in which the *.cd and *.ct files are searched
1670 %define build_catalogs mmake=/A name=/A subdir=/A \
1671 catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1672 sourcedescription="$(TOOLDIR)/C_h_orig" srcdir="$(SRCDIR)/$(CURDIR)"
1674 ifeq (%(description),)
1675 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1677 BD_DESC := %(description)
1681 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1683 BD_LNGS := %(catalogs)
1686 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1687 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1690 %(mmake) : $(BD_OBJS) %(source)
1692 $(BD_OBJS) : | $(BD_DIRS)
1693 GLOB_MKDIRS += $(BD_DIRS)
1695 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1696 @$(ECHO) "Creating %(name) catalog for language $*."
1697 @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1700 %(source) : TMP_SOURCEDESCRIPTION := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1701 %(source) : $(BD_DESC).cd | $(dir %(source))
1702 @$(ECHO) "Creating %(name) catalog source file %(source)"
1703 @$(FLEXCAT) $(BD_DESC).cd %(source)=$(TMP_SOURCEDESCRIPTION).sd
1708 $(RM) $(BD_OBJS) %(source)
1710 .PHONY: %(mmake) %(mmake)-clean
1713 #-----------------------------------------------------------------------------
1716 #-----------------------------------------------------------------------------
1718 # - mmake is the mmaketarget
1719 # - icons is a list of icon base names (ie. without the .info suffix)
1720 # - dir is the destination directory
1721 # - srcdir is where *.png and *.info.src are searched
1722 #-----------------------------------------------------------------------------
1724 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1726 BD_OBJS := $(addprefix %(dir)/, $(addsuffix .info,%(icons)))
1729 %(mmake) : $(BD_OBJS)
1733 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1734 @$(ECHO) Creating $(notdir $@)...
1735 @$(ILBMTOICON) $+ $@
1739 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1740 @$(ECHO) Creating $(notdir $@)...
1741 @$(ILBMTOICON) $+ $@
1745 $(BD_OBJS) : | %(dir)
1746 GLOB_MKDIRS += %(dir)
1748 %(mmake)-clean : FILES := $(BD_OBJS)
1753 .PHONY: %(mmake) %(mmake)-clean
1756 #-----------------------------------------------------------------------------
1759 #------------------------------------------------------------------------------
1760 # Compile files for an arch-specific replacement of code for a module
1761 # - files: the basenames of the C files to compile.
1762 # - asmfiles: the basenames of the asm files to assemble.
1763 # - mainmmake: the mmake of the module in the main directory to compile these
1764 # arch specific files for.
1765 # - maindir: the object directory for the main module
1766 # - arch: the arch for which to compile these files. It can have the form
1767 # of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1768 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1769 # - dflags: the flags used during creation of dependency file. If not specified
1770 # the same value as cflags will be used
1771 # - aflags: the flags used during assembling
1772 # - compiler: (host, kernel or target) specifies which compiler to use. By default
1773 # the target compiler is used
1774 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1775 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1777 ifeq (%(files) %(asmfiles),)
1778 $(error no files or asmfiles given)
1781 %buildid targets="%(mainmmake)-%(arch)"
1783 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1784 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1785 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1786 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1787 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1788 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1789 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1790 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1791 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1792 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1793 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1794 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1795 #MM- %(mainmmake)-pkg : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1796 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1797 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1798 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1799 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1800 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1801 #MM- %(mainmmake)-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
1802 #MM %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
1803 #MM %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
1805 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
1808 $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1811 BD_OBJDIR$(BDID) := $(GENDIR)/%(maindir)/arch
1812 BD_COBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1813 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1814 BD_OBJS$(BDID) := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1815 BD_DEPS$(BDID) := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1817 ifneq (%(modulename),)
1818 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
1821 ifeq ($(TARGET),%(mainmmake)-%(arch))
1822 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1823 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
1824 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1825 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
1828 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
1829 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
1832 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1834 ifeq ($(findstring %(compiler),host kernel target),)
1835 $(error unknown compiler %(compiler))
1837 ifeq (%(compiler),target)
1838 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
1839 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
1840 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
1842 ifeq (%(compiler),host)
1843 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
1844 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
1845 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
1847 ifeq (%(compiler),kernel)
1848 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
1849 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
1850 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
1852 ifneq (%(modulename),)
1853 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
1855 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1857 ifeq ($(TARGET),%(mainmmake)-%(arch))
1858 $(BD_OBJDIR$(BDID))/%.o : %.c
1859 %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
1863 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
1865 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1867 ifeq ($(TARGET),%(mainmmake)-%(arch))
1868 $(BD_OBJDIR$(BDID))/%.d : %.c
1869 %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
1872 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1874 ifeq ($(TARGET),%(mainmmake)-%(arch))
1875 $(BD_OBJDIR$(BDID))/%.o : %.s
1876 %assemble_q opt=$(AFLAGS)
1877 $(BD_OBJDIR$(BDID))/%.o : %.S
1878 %assemble_q opt=$(AFLAGS)
1881 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1883 #------------------------------------------------------------------------------
1886 #------------------------------------------------------------------------------
1887 # generate asm files from c files (for debugging purposes)
1890 @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1891 @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
1893 #------------------------------------------------------------------------------
1896 #------------------------------------------------------------------------------
1897 # Copy files from one directory to another.
1899 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
1901 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1903 GLOB_MKDIRS += %(dst)
1909 $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
1912 #------------------------------------------------------------------------------
1915 #------------------------------------------------------------------------------
1916 # Copy a directory recursively to another place, preserving the original
1917 # hierarchical structure
1919 # src: the source directory whose content will be copied
1920 # dst: the directory where to copy src's content. If not existing, it will be made.
1922 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
1924 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
1925 %(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)
1926 %(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES)))
1928 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
1929 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
1931 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
1936 %(mmake): | $(GENDIR)/$(CURDIR)
1937 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1938 $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m
1939 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1940 for d in $(%(mmake)_DIRS); do \
1941 $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \
1943 @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \
1944 for f in $(%(mmake)_FILES); do \
1945 $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
1947 for dst in %(dst); do \
1948 $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
1952 #------------------------------------------------------------------------------
1955 #------------------------------------------------------------------------------
1956 # Copy include files into the includes directories. There are currently
1957 # two include directories. One for building AROS $(AROS_INCLUDES) and one
1958 # for building tools that need to run on the host system $(GENINCDIR). The
1959 # $(GENINCDIR) path must not contain any references to the C runtime
1960 # library header files.
1962 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
1963 dir= compiler=target
1965 ifeq ($(findstring %(compiler),host kernel target),)
1966 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
1970 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
1971 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
1972 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
1974 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
1975 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
1978 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
1982 ifeq (%(compiler),target)
1985 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
1986 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
1988 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
1991 BD_INCL_FILES += $(BD_INCL_FILES2)
1993 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
1998 %(mmake) : $(BD_INCL_FILES)
2002 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2003 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2005 #------------------------------------------------------------------------------
2008 #------------------------------------------------------------------------------
2009 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2010 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2011 STUBS_MEM := $(addsuffix .o,$(STUBS))
2012 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2013 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2014 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2016 #MM- linklibs : hidd-%(hidd)-stubs
2017 #MM- %(parenttarget): hidd-%(hidd)-stubs
2018 #MM hidd-%(hidd)-stubs : includes includes-copy
2019 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2021 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2024 $(STUBS_OBJ) : $(STUBS_SRC)
2025 %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2027 $(STUBS_DEP) : $(STUBS_SRC)
2028 %mkdepend_q flags=%(dflags)
2031 %mkdirs_q $(OBJDIR) $(LIBDIR)
2035 -@$(RM) $(HIDD_LIB) $(OBJDIR)
2037 DEPS := $(DEPS) $(STUBS_DEP)
2040 #------------------------------------------------------------------------------
2043 #------------------------------------------------------------------------------
2044 # Build an imported source tree which uses the configure script from the
2045 # autoconf package. This rule will try to "integrate" the produced files as
2046 # much as possible in the AROS build, for example by putting libraries in the
2047 # standard library directory, includes in the standard include directory, and
2048 # so on. You can however override this behaviour.
2050 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2051 # be %(bindir) (or its deduced value) when running "make install", and
2052 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2053 # configure script some more parameters whose value depends upon the PROGDIR
2054 # env var, so that the program gets all its stuff installed in the proper place
2055 # when building it, but when running it from inside AROS it can also find that
2056 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2057 # the configuration parameters set when running ./configure
2059 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2060 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2061 # to the name which has to follow it.
2064 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2065 aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2066 install_target=install preconfigure= postconfigure= postinstall= \
2070 %(mmake)-prefix := %(prefix)
2072 %(mmake)-prefix := $(AROS_CONTRIB)
2075 ifneq (%(aros_prefix),)
2076 %(mmake)-aros_prefix := %(aros_prefix)
2078 %(mmake)-aros_prefix := $(%(mmake)-prefix)
2082 %(mmake)-nix := -nix
2083 %(mmake)-volpfx := /
2084 %(mmake)-volsfx := /
2086 ifeq (%(nix_dir_layout),)
2087 %(mmake)-nix_dir_layout := yes
2090 %(mmake)-volsfx := :
2092 ifeq (%(nix_dir_layout),)
2093 %(mmake)-nix_dir_layout := no
2097 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2099 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2100 exec_prefix=$(%(mmake)-prefix) %(install_env)
2102 # Check if chosen compiler is valid
2103 ifeq ($(findstring %(compiler),host target kernel),)
2104 $(error unknown compiler %(compiler))
2107 # Set legacy 'host' variable based on chosen compiler
2108 ifeq (%(compiler),host)
2111 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2113 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2118 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2120 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2124 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2125 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2127 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2128 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)/bin
2129 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2132 %(mmake)-config_opts := --prefix=/PROGDIR --bindir=/PROGDIR --sbindir=/PROGDIR \
2133 --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE
2135 %(mmake)-config_opts := --prefix=$(%(mmake)-aros_prefix)
2138 %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2140 %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2141 sbindir=$(%(mmake)-prefix) \
2142 libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2143 oldincludedir=$(AROS_INCLUDES) %(install_env)
2146 ifneq ($(DEBUG),yes)
2147 %(mmake)-s_flag = -s
2150 # Set up build environment, and options for configure script
2151 ifeq (%(compiler),host)
2153 CC="$(HOST_CC) $(HOST_CFLAGS)" \
2154 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2155 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2156 TARGET_RANLIB="$(RANLIB)"
2157 %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
2159 ifeq (%(compiler),target)
2161 CC="$(TARGET_CC) $(TARGET_CFLAGS) %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2162 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)"\
2163 TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2164 TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2165 TARGET_RANLIB="$(RANLIB)"
2166 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2167 --host=$(AROS_TARGET_CPU)-aros\
2168 --target=$(AROS_TARGET_CPU)-aros\
2170 --without-x --without-pic --disable-shared
2172 ifeq (%(compiler),kernel)
2174 CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2175 AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2176 TARGET_RANLIB="$(RANLIB)"
2177 %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2178 --host=$(AROS_TARGET_CPU)-aros\
2179 --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2180 --without-x --without-pic --disable-shared
2184 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2186 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
2188 # Using -j1 in install_command may result in a warning but finally
2189 # it does its job. make install for gcc does not work reliably for -jN
2191 ifneq (%(install_target),)
2192 %(mmake)-install_command = \
2193 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2194 -C $(%(mmake)-pkgdir) %(install_target) -j1
2196 %(mmake)-uninstall_command = \
2197 $(RM) $(%(mmake)-installflag) && \
2198 $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2199 $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2201 %(mmake)-install_command := true
2202 %(mmake)-uninstall_command := true
2205 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2208 %(mmake)-build_and_install-quick : $(%(mmake)-installflag)
2210 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2211 if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2212 $(RM) $(%(mmake)-installflag) && \
2213 $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2214 -C $(%(mmake)-pkgdir) && \
2215 $(%(mmake)-install_command) && \
2216 $(TOUCH) $@ -r $^; \
2219 $(%(mmake)-pkgdir)/.files-touched:
2220 %mkdirs_q $(%(mmake)-pkgdir)
2221 find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2225 %(mmake)-uninstall :
2226 $(%(mmake)-uninstall_command)
2229 %(mmake)-configure : $(%(mmake)-configflag)
2231 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2232 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2234 %mkdirs_q $(%(mmake)-pkgdir)
2235 cd $(%(mmake)-pkgdir) && \
2236 find . -name config.cache -exec $(RM) '{}' \; && \
2237 $(COMPILER_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2238 %(extraoptions) && \
2242 %(mmake)-clean : %(mmake)-uninstall
2243 @$(RM) $(%(mmake)-pkgdir)
2245 #------------------------------------------------------------------------------
2248 #------------------------------------------------------------------------------
2249 # Given an archive name, patches names and locations where to find them, fetch
2250 # the archive and the patches from any of those locations, unpack the archive
2251 # and then apply the patches.
2253 # Locations currently supported are http and ftp sites, plus local filesystem
2254 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2255 # the fetch.sh script needs to be modified, since this macro relies on that script.
2259 # - mmake = mmaketarget
2260 # - archive_origins = list of locations where to find the archive. They are tried
2261 # in sequence, until the archive is found and fetching it
2262 # succeeded. If not specified, the current directory is assumed.
2263 # - archive = the archive name. Mandatory.
2264 # - suffixes = a list of suffixes to append to the the package name plus the
2265 # version. Each one of them is tried until a matching archive is
2266 # found. They are appended to patches and these are tried the
2267 # same way as packages are.
2268 # - location = the local directory where to put the fetched archive and patches.
2269 # If not specified, the directory specified by destination is used.
2270 # - destination = the directory to unpack the archive to.
2271 # If not specified, the current directory is assumed.
2272 # - patches_origins = list of locations where to find the patches. They are tried
2273 # in sequence, until a patch is found and fetching it
2274 # succeeded. If not specified, the current directory is assumed.
2275 # - patches_specs = list of "patch specs". A patch spec is of the form
2276 # patch_name[:[patch_subdir][:patch_opt]].
2278 # - patch_name = the name of the patch file
2279 # - patch_subdir = the directory within \destination\ where to
2281 # - patch_opt = any options to pass to the `patch' command
2282 # when applying the patch.
2284 # The patch_subdir and patch_opt fields are optional.
2286 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2287 patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2291 ifneq (%(location),)
2292 %(mmake)-location := %(location)
2294 %(mmake)-location := %(destination)
2299 $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2300 -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2302 #------------------------------------------------------------------------------
2305 #------------------------------------------------------------------------------
2306 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2307 # unpatched source tree and runs diff against this and a previously fetched and possibly
2308 # patched tree. Depending on what happens after patching during a normal build it might
2309 # give best results if the new patch is created directly after fetch.
2313 # - mmake = mmaketarget
2314 # - archive = archive base name
2315 # - suffixes = a list of suffixes to append to the the package name plus the
2316 # version. Each one of them is tried until a matching archive is
2318 # - destination = the directory to unpack the archive to.
2319 # - excludes = diff patterns to exclude files or directories from the patch
2321 %define create_patch mmake=/A archive=/A suffixes="tar.bz2 tar.gz" destination=/A excludes=
2325 ifneq (%(excludes),)
2326 %(mmake)-exclude := -X ./exclude.patterns
2331 @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2332 $(MV) %(destination)/%(archive) %(destination)/tmp/%(archive).aros ; \
2333 cd %(destination)/tmp ; \
2334 $(FOR) f in %(excludes) ; do \
2335 $(ECHO) $$f >> ./exclude.patterns ; \
2337 diff -ruN $(%(mmake)-exclude) \
2340 >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2341 $(MV) %(destination)/tmp/%(archive).aros %(destination)/%(archive) ; \
2342 $(RM) %(destination)/tmp
2344 #------------------------------------------------------------------------------
2347 #------------------------------------------------------------------------------
2348 # Joins the features of %fetch and %build_with_configure, taking advantage of
2349 # the naming scheme of GNU packages. GNU packages names are in the form
2351 # <package name>-<version number>.<archive format suffix>
2353 # If a patch is provided, it *must* be named the following way:
2355 # <package name>-<version number>-aros.diff
2357 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2358 # CD'ing into the archive's extracted directory.
2360 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2361 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
2362 # to make that patch fully comprehensive.
2364 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2368 # - mmake = the meta make target, as would be supplied to the %build_with_configure
2370 # - package = the GNU package name, sans version and archive format suffixes.
2371 # - version = the package's version number, or otherwise any other version string.
2372 # It gets appended to the package name to form the basename of the archive.
2373 # - suffixes = a list of suffixes to apped to the the package name plus the
2374 # version. Each one of them is tried until a matching archive is found.
2375 # Defaults to "tar.bz2 tar.gz".
2376 # - destination = same meaning as the one for the %fetch macro
2377 # - location = same meaning as the one for the %fetch macro
2378 # - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2379 # - patch = "yes" or "no", depending on whether a patch for this package needs to be
2381 # - patch_repo = same meaning as the one of the %fetch macro's %(patches_origins) argument
2382 # - prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2384 # - aros_prefix = same meaning as the one for the %build_with_configure macro. Defaults to
2386 # - extraoptions = same meaning as the one for the %build_with_configure macro.
2387 # - extracflags = same meaning as the one for the %build_with_configure macro.
2388 # - postinstall = same meaning as the one for the %build_with_configure macro.
2389 # - create_pkg = create a distributable package of the compiled sources, defaults to no
2391 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2392 srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2393 preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2395 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2396 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2397 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2398 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2400 %(mmake)-archbase := %(package)-%(version)
2402 ifeq (%(compiler),host)
2403 %(mmake)-portdir := $(HOSTDIR)/Ports/%(package)
2405 %(mmake)-portdir := $(PORTSDIR)/%(package)
2409 %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2411 %(mmake)-prefix := %(prefix)
2414 ifneq (%(subpackage),)
2415 %(mmake)-%(subpackage)-archbase := %(package)-%(subpackage)-%(version)
2417 %(mmake)-%(subpackage)-archbase := %(package)-%(version)
2421 %(mmake)-%(subpackage)-srcdir := %(srcdir)
2423 %(mmake)-%(subpackage)-srcdir := $(%(mmake)-archbase)
2427 %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2429 %(mmake)-%(subpackage)-patches_specs := ::
2432 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2433 location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2434 archive_origins=". %(package_repo)" \
2435 patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2437 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2438 archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" destination=$(%(mmake)-portdir)
2440 #MM- %(mmake) : %(mmake)-%(subpackage)
2442 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2444 %(mmake)-%(subpackage)-package-basename := \
2445 $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2447 ifneq (%(create_pkg),no)
2448 %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2451 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2452 srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2453 nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2454 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2455 %(mmake)-%(subpackage)-make-package" extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2457 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2458 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2461 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2463 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2464 #that $^ and $@ have exactly the same mtime, and in that case make tries
2465 #to rebuild $@ again, which would fail because the directory where
2466 #the package got installed would not exist anymore.
2467 #We work this around by using an if statement to manually check the mtimes.
2468 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2469 @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2471 $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2472 mkdir -p "$(DISTDIR)/Packages" ; \
2473 mkdir -p "$(%(mmake)-prefix)" ; \
2474 cd $(%(mmake)-%(subpackage)-package-dir) ; \
2475 tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2476 bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2479 #------------------------------------------------------------------------------
2482 #------------------------------------------------------------------------------
2483 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2484 srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2485 aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall=
2487 GNU_REPOSITORY := gnu://
2489 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2490 suffixes="%(suffixes)" srcdir="%(srcdir)" \
2491 package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2492 patch="%(patch)" patch_repo="%(patch_repo)" \
2493 prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2494 preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2497 #------------------------------------------------------------------------------
2500 #------------------------------------------------------------------------------
2501 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2502 # that the package is a "Development" package, and as such it needs to be placed
2503 # under the $(AROS_DEVELOPMENT) directory, as a default.
2505 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu
2506 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2507 # "mmake" argument, because the metatarget is implicitely defined as
2509 # #MM- development-%(package)
2511 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2512 srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2513 aros_prefix=/Development preconfigure= postconfigure= postinstall= extraoptions= extracflags=
2515 #MM- development : development-%(package)
2518 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2519 version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)" \
2520 package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2521 aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2522 extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2525 #------------------------------------------------------------------------------
2527 # Builds a kickstart package in PKG format
2528 # mmake - target name
2529 # file - Destination file name with path
2530 # startup - The file which will be put first
2531 # Other arguments are self-explanatory
2533 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2535 PKG_CLASSES := $(addsuffix .class, %(classes))
2536 PKG_DEVICES := $(addsuffix .device, %(devs))
2537 PKG_HANDLERS := $(addsuffix .handler, %(handlers))
2538 PKG_HIDD := $(addsuffix .hidd, %(hidds))
2539 PKG_LIBS := $(addsuffix .library, %(libs))
2540 PKG_RESOURCES := $(addsuffix .resource, %(res))
2542 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2543 PKG_DIR := $(dir %(file))
2544 PKG_DEPS := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2550 %(mmake)-quick : %(file)
2552 %(file): PKG_FILES := $(PKG_FILES)
2553 %(file): $(PKG_DEPS) | $(PKG_DIR)
2554 @$(ECHO) Packaging $@...
2555 @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2557 GLOB_MKDIRS += $(PKG_DIR)
2560 #------------------------------------------------------------------------------
2562 # Links a kickstart module in ELF format
2563 # Arguments are similar to make_package
2565 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2566 startup= uselibs= ldflags=$(LDFLAGS) map=
2568 KOBJ_CLASSES := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2569 KOBJ_DEVICES := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2570 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2571 KOBJ_HIDD := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2572 KOBJ_LIBS := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2573 KOBJ_RES := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2576 KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2578 KOBJ_STARTUP := %(startup)
2581 KOBJS := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2583 TMP_LDFLAGS := %(ldflags)
2585 # Make a list of the lib files this program depends on.
2586 # In LDFLAGS remove white space between -L and directory
2587 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2588 # Filter out only the libdirs and remove -L
2589 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2591 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2592 # Add normal linklib path
2593 TMP_DIRS += $(LIBDIR)/
2594 # add lib and .a to static linklib names
2595 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2596 # search for the linklibs in the given path, ignore ones not found
2597 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2598 $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2601 TMP_DIRS += $(dir %(file))
2603 TMP_LDFLAGS += $(GENMAP) %(map)
2604 TMP_DIRS += $(dir %(map))
2611 %(mmake)-quick : %(file)
2613 %(file): KOBJS := $(KOBJS)
2614 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2615 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2616 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2617 @$(ECHO) Linking $@...
2618 @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
2620 GLOB_MKDIRS += $(TMP_DIRS)
2624 #------------------------------------------------------------------------------
2625 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2626 # 'start' is an optional starting address
2627 # 'ldflags' is optional additional flags for the linker
2628 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2630 BD_OUTDIR := $(dir %(file))
2631 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2633 %(file) : %(objs) $(BD_OUTDIR)
2634 @$(ECHO) Linking $@...
2635 @$(KERNEL_LD) -melf_i386 --oformat=binary -e %(start) -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2636 @cd $(BD_TMPDIR) && $(KERNEL_LD) -r --format binary %(ldflags) %(name) -o $@
2638 GLOB_MKDIRS += $(BD_OUTDIR)