C:List: Compiler delint
[AROS.git] / config / make.tmpl
blob01847e04e93e6c488a688d2e15340354d6b5e1d8
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
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.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16 %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
17 else
18 %(var) := %(string)
19 endif
20 %end
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         @$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31             else \
32                 $(NOP) ; \
33             fi ; \
34         else \
35             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37             exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51             else \
52                 $(NOP) ; \
53             fi ; \
54         else \
55             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57             exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(from) -o %(to) %(libs) %(opt) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(libs) %(opt)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(libs) %(opt)" 1>&2 ; \
76             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
77             exit 1 ; \
78         fi; \
79         %(strip) %(to)
80 %end
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd=$(AROS_CC) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) -nostdc \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(ldflags) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) -nostdc $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
98             cat %(objdir)/%(err); \
99             exit 1; \
100         fi
102         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
103         @$(STRIP) $@
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the library
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
112         @%(ar) %(to) %(from)
113         @%(ranlib) %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121         %mkdir_q dir="$(dir %(to))"
122         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
124 %end
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
148 ##                                                                         ##
149 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
150 ## mmakefile. They consist of one or more full makefile rules.             ##
151 ## In general the files generated in these macros are also defined as      ##
152 ## make targets so that they can be used as a dependency in other rules    ##
153 ##                                                                         ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
160 BDID := $(BDID)_
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
163 endif
164 %end
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
171 %(to) : %(from)
172         @$(CP) $< $@
173 %end
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
181 # present.
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185         @$(CP) $< $@
186 %end
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by 
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197     stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207         @for f in $(FILES); do \
208              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
210              fi ; \
211         done
212         @$(TOUCH) $@
213 %end
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
219 # be displayed.
220 # Restriction: at the moment when using a non-empty target dir %(from) may
221 # not have 
222 %define rule_join to=/A from=/A text=
224 %(to) : %(from)
225 ifneq (%(text),)
226         @$(ECHO) %(text)
227 endif
228         @$(CAT) $^ >$@
229 %end
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean 
238 %define include_deps deps=$(DEPS)/M  depstargets=
239 ifneq (%(deps),)
240   ifneq (%(depstargets),)
241     ifneq ($(findstring $(TARGET),%(depstargets)),)
242       -include %(deps)
243     endif
244   else
245     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
246       -include %(deps)
247     endif
248   endif
249 endif
250 %end
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default. 
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
263 %end
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
272 # options
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 #   the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 #   it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
281 ifeq (%(targetdir),)
282   TMP_TARGETBASE := %(basename)
283 else
284   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
285 endif
287 # Adjust compiler flags to suit C
288 TMP_CFLAGS := %(cflags)
289 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
291 ifeq ($(findstring %(compiler),host kernel target),)
292   $(error unknown compiler %(compiler))
293 endif
294 ifeq (%(compiler),target)
295 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
296 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
297 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
298 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
301 endif
302 ifeq (%(compiler),host)
303 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
304 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
305 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
306 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
307 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
308 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
309 endif
310 ifeq (%(compiler),kernel)
311 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
312 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
313 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
314 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
315 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
316 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
317 endif
319 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
320 $(TMP_TARGETBASE).o : %(basename).c
321         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
323 ifeq (%(dflags),)
324   ifeq (%(nix),yes)
325     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
326   else
327     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
328   endif
329 else
330   ifeq (%(nix),yes)
331     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
332   else
333     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
334   endif
335 endif
336 $(TMP_TARGETBASE).d : %(basename).c
337         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
338 %end
339 #------------------------------------------------------------------------------
342 #------------------------------------------------------------------------------
343 # Generate a rule to compile a C++ source file to an object file and generate
344 # the dependency file. Basename may contain a directory part, then the source
345 # file has to be in that directory. The generated file will be put in the
346 # object directory without the directory.
347 # options
348 # - basename: the basename of the file to compile. Use % for a wildcard rule
349 # - cflags (default $(CFLAGS)): the C flags to use for compilation
350 # - dflags: the flags used during creation of dependency file. If not specified
351 #   the same value as cflags will be used
352 # - targetdir: the directory to put the .o file and the .d file. By default
353 #   it is put in the same directory as the .c file
354 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
356 ifeq (%(targetdir),)
357   TMP_TARGETBASE := %(basename)
358 else
359   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
360 endif
362 # Adjust compiler flags to suit C++
363 TMP_CXXFLAGS := %(cflags)
364 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include 
365 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
367 ifeq ($(findstring %(compiler),host kernel target),)
368   $(error unknown compiler %(compiler))
369 endif
370 ifeq (%(compiler),target)
371 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
372 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
373 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
374 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
375 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
376 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
377 endif
378 ifeq (%(compiler),host)
379 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
380 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
385 endif
386 ifeq (%(compiler),kernel)
387 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
388 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
389 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
390 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
391 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
392 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
393 endif
395 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
396 $(TMP_TARGETBASE).o : %(basename).cpp
397         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
399 ifeq (%(dflags),)
400   ifeq (%(nix),yes)
401     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
402   else
403     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
404   endif
405 else
406   ifeq (%(nix),yes)
407     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
408   else
409     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
410   endif
411 endif
412 $(TMP_TARGETBASE).d : %(basename).cpp
413         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
414 %end
415 #------------------------------------------------------------------------------
418 #------------------------------------------------------------------------------
419 # Generate a rule to compile multiple C source files to an object file and
420 # generate the corresponding dependency files. The generated file will be put
421 # in the object directory without the directory part of the source file.
422 # options
423 # - basenames: the basenames of the files to compile. The names may include
424 #   relative or absolute path names. No wildcard is allowed
425 # - cflags (default $(CFLAGS)): the C flags to use for compilation
426 # - dflags: the flags used during creation of dependency file. If not specified
427 #   the same value as cflags will be used
428 # - targetdir: the directory to put the .o file and the .d file. By default
429 #   it is put in the same directory as the .c file. When targetdir is not
430 #   empty, path names will be stripped from the file names so that all files
431 #   are in that dir and not in subdirectories.
432 # - compiler (default target): compiler to use, target, kernel or host
433 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
434     compiler=target
436 ifeq (%(targetdir),)
437 TMP_TARGETS := $(addsuffix .o,%(basenames))
438 TMP_DTARGETS := $(addsuffix .d,%(basenames))
439 TMP_WILDCARD := %
440 else
441 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
442 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
443 TMP_WILDCARD := %(targetdir)/%
445 # Be sure that all .c files are generated
446 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
448 # Be sure that all .c files are found
449 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
450 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
451 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
452 ifneq ($(TMP_DIRS),)
453     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
454     vpath %.c $(TMP_DIRS)
455 endif
457 endif
459 ifeq ($(findstring %(compiler),host kernel target),)
460   $(error unknown compiler %(compiler))
461 endif
462 ifeq (%(compiler),target)
463 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
466 endif
467 ifeq (%(compiler),host)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
471 endif
472 ifeq (%(compiler),kernel)
473 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
474 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
475 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
476 endif
478 $(TMP_TARGETS) : CFLAGS := %(cflags)
479 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
480         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
482 ifeq (%(dflags),)
483 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
484 else
485 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
486 endif
487 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
488         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
489 %end
490 #------------------------------------------------------------------------------
493 #------------------------------------------------------------------------------
494 # Generate a rule to compile multiple C++ source files to an object file and
495 # generate the corresponding dependency files. The generated file will be put
496 # in the object directory without the directory part of the source file.
497 # options
498 # - basenames: the basenames of the files to compile. The names may include
499 #   relative or absolute path names. No wildcard is allowed. basenames will be 
500 #   matched to supported AROS_CXXEXTS.
501 # - cflags (default $(CFLAGS)): the C flags to use for compilation
502 # - dflags: the flags used during creation of dependency file. If not specified
503 #   the same value as cflags will be used
504 # - targetdir: the directory to put the .o file and the .d file. By default
505 #   it is put in the same directory as the .c file. When targetdir is not
506 #   empty, path names will be stripped from the file names so that all files
507 #   are in that dir and not in subdirectories.
508 # - compiler (default target): compiler to use, target, kernel or host
509 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
510     targetdir= compiler=target
512 # Adjust compiler flags to suit C++
513 TMP_CXXFLAGS := %(cflags)
514 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
515 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include
517 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
518 ifneq ($(TMP_CXXABSBASENAMES),)
519 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
521 # Identify the "real" c++ files from the passed in basenames
522 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
524 ifeq (%(targetdir),)
525   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
526   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
527   TMP_WILDCARD := %
528 else
529   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
530   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
531   TMP_WILDCARD := %(targetdir)/%
533   # Be sure that all source files are generated
534   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
535 endif
537 ifeq ($(findstring %(compiler),host kernel target),)
538   $(error unknown compiler %(compiler))
539 endif
540 ifeq (%(compiler),target)
541   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_CFLAGS)
542   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
543   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
544 endif
545 ifeq (%(compiler),host)
546   TMP_CXXCMD:=$(HOST_CXX)
547   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
548   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
549 endif
550 ifeq (%(compiler),kernel)
551   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
552   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
553   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
554 endif
556 ifeq (%(dflags),)
557   TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
558 else
559   ifeq (%(dflags),%(cflags))
560     TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
561   else
562     TMP_CXXDFLAGS:=%(dflags)
563   endif
564 endif
566 define cxx_multi_recipe_template
567  $(1).o : $(2)
568         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
570  $(1).d : $(2)
571         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
572 endef
573 ifeq (%(targetdir),)
574   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
575 else
576   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
577 endif
578 endif
579 %end
580 #------------------------------------------------------------------------------
583 #------------------------------------------------------------------------------
584 # Generate a rule to compile an ObjC source file to an object file and generate
585 # the dependency file. Basename may contain a directory part, then the source
586 # file has to be in that directory. The generated file will be put in the
587 # object directory without the directory.
588 # options
589 # - basename: the basename of the file to compile. Use % for a wildcard rule
590 # - cflags (default $(CFLAGS)): the C flags to use for compilation
591 # - dflags: the flags used during creation of dependency file. If not specified
592 #   the same value as cflags will be used
593 # - targetdir: the directory to put the .o file and the .d file. By default
594 #   it is put in the same directory as the .m file
595 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
597 ifeq (%(targetdir),)
598   TMP_TARGETBASE := %(basename)
599 else
600   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
601 endif
603 # Adjust compiler flags to suit ObjC
604 TMP_OBJCFLAGS := %(cflags)
605 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
606 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
608 ifeq ($(findstring %(compiler),host kernel target),)
609   $(error unknown compiler %(compiler))
610 endif
611 ifeq (%(compiler),target)
612 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
613 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
614 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
615 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
616 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
617 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
618 endif
619 ifeq (%(compiler),host)
620 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
621 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
622 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
623 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
624 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
625 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
626 endif
627 ifeq (%(compiler),kernel)
628 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
629 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
630 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
631 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
632 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
633 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
634 endif
636 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
637 $(TMP_TARGETBASE).o : %(basename).m
638         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
640 ifeq (%(dflags),)
641   ifeq (%(nix),yes)
642     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
643   else
644     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
645   endif
646 else
647   ifeq (%(nix),yes)
648     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
649   else
650     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
651   endif
652 endif
653 $(TMP_TARGETBASE).d : %(basename).m
654         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
655 %end
656 #------------------------------------------------------------------------------
658 #------------------------------------------------------------------------------
659 # Generate a rule to compile multiple ObjC source files to an object file and
660 # generate the corresponding dependency files. The generated file will be put
661 # in the object directory without the directory part of the source file.
662 # options
663 # - basenames: the basenames of the files to compile. The names may include
664 #   relative or absolute path names. No wildcard is allowed
665 # - cflags (default $(CFLAGS)): the C flags to use for compilation
666 # - dflags: the flags used during creation of dependency file. If not specified
667 #   the same value as cflags will be used
668 # - targetdir: the directory to put the .o file and the .d file. By default
669 #   it is put in the same directory as the .m file. When targetdir is not
670 #   empty, path names will be stripped from the file names so that all files
671 #   are in that dir and not in subdirectories.
672 # - compiler (default target): compiler to use, target, kernel or host
673 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
674     targetdir= compiler=target
676 # Adjust compiler flags to suit ObjC
677 TMP_OBJCFLAGS := %(cflags)
678 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
679 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
681 ifeq (%(targetdir),)
682   TMP_TARGETS := $(addsuffix .o,%(basenames))
683   TMP_DTARGETS := $(addsuffix .d,%(basenames))
684   TMP_WILDCARD := %
685 else
686   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
687   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
688   TMP_WILDCARD := %(targetdir)/%
690   # Be sure that all .m files are generated
691   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
693   # Be sure that all .m files are found
694   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
695   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
696   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
697   ifneq ($(TMP_DIRS),)
698     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
699     vpath %.m $(TMP_DIRS)
700   endif
701 endif
703 # Define the use of cross compiler
704 ifeq ($(TARGET_OBJC),)
705   TMP_CC := $(TARGET_CC)
706 else
707   TMP_CC := $(TARGET_OBJC)
708 endif
710 ifeq ($(findstring %(compiler),host kernel target),)
711   $(error unknown compiler %(compiler))
712 endif
713 ifeq (%(compiler),target)
714   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
715   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
716   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
717 endif
718 ifeq (%(compiler),host)
719   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
720   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
721   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
722 endif
723 ifeq (%(compiler),kernel)
724   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
725   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
726   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
727 endif
729 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
730 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
731         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
733 ifeq (%(dflags),)
734   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
735 else
736   ifeq (%(dflags),%(cflags))
737     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
738   else
739     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
740   endif
741 endif
742 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
743         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
744 %end
745 #------------------------------------------------------------------------------
748 #------------------------------------------------------------------------------
749 # Make an alias from one arch specific build to another arch.
750 # arguments:
751 # - mainmmake: the mmake of the module in the main tree
752 # - arch: the current arch
753 # - alias: the alias to which this should point
754 %define rule_archalias mainmmake=\A arch=\A alias=\A
756 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
757 %end
758 #------------------------------------------------------------------------------
761 #------------------------------------------------------------------------------
762 # Generate a rule to assemble a source file to an object file. Basename may
763 # contain a directory part, then the source file has to be in that directory.
764 # The generated file will be put in the object directory without the directory.
765 # options
766 # - basename: the basename of the file to compile. Use % for a wildcard rule
767 # - flags (default $(AFLAGS)): the asm flags to use for assembling
768 # - targetdir: the directory to put the .o file in. By default it is put in the
769 #   same directory as the .s file
770 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
772 ifeq (%(targetdir),)
773 %(basename).o : AFLAGS := %(aflags)
774 %(basename).o : %(basename).s
775         %assemble_q
776 %(basename).o : %(basename).S
777         %assemble_q
779 else
780 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
781 %(targetdir)/$(notdir %(basename)).o : %(basename).s
782         %assemble_q
783 %(targetdir)/$(notdir %(basename)).o : %(basename).S
784         %assemble_q
786 endif
787 %end
788 #------------------------------------------------------------------------------
791 #------------------------------------------------------------------------------
792 # Generate a rule to assemble multiple source files to an object file. The
793 # generated file will be put in the object directory with the directory part
794 # of the source file stripped off.
795 # options
796 # - basenames: the basenames of the files to compile. The names may include
797 #   relative or absolute path names. No wildcard is allowed
798 # - aflags (default $(AFLAGS)): the flags to use for assembly
799 # - targetdir: the directory to put the .o file and the .d file. By default
800 #   it is put in the same directory as the .c file. When targetdir is not
801 #   empty, path names will be stripped from the file names so that all files
802 #   are in that dir and not in subdirectories.
803 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
805 ifeq (%(targetdir),)
806 TMP_TARGETS := $(addsuffix .o,%(basenames))
807 TMP_WILDCARD := %
808 else
809 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
810 TMP_WILDCARD := %(targetdir)/%
812 # Be sure that all .s files are generated
813 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
815 # Be sure that all .c files are found
816 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
817 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
818 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
819 ifneq ($(TMP_DIRS),)
820     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
821     vpath %%(suffix) $(TMP_DIRS)
822 endif
824 endif
826 ifeq ($(findstring %(compiler),host kernel target),)
827   $(error unknown compiler %(compiler))
828 endif
829 ifeq (%(compiler),target)
830 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
831 endif
832 ifeq (%(compiler),host)
833 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
834 endif
835 ifeq (%(compiler),kernel)
836 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
837 endif
839 $(TMP_TARGETS) : AFLAGS := %(aflags)
840 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
841         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
842 %end
843 #------------------------------------------------------------------------------
846 #------------------------------------------------------------------------------
847 # Link %(objs) to %(prog) using the libraries in %(uselibs)
848 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
849     usehostlibs= usestartup=yes detach=no nix=no linker=target
851 TMP_EXTRA_LDFLAGS := 
852 TMP_EXTRA_LIBS :=
853 ifeq (%(nix),yes)
854     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
855 endif
856 ifeq (%(usestartup),no)
857     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
858     ifeq (%(linker),target)
859         TMP_EXTRA_LDFLAGS += -nostdc
860         TMP_EXTRA_LIBS += libinit autoinit
861     endif
862 endif
863 ifeq (%(detach),yes)
864     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
865 endif
867 # Make a list of the lib files this program depends on.
868 # In LDFLAGS remove white space between -L and directory
869 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
870 # Filter out only the libdirs and remove -L
871 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
872 # Add trailing /
873 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
874 # Add normal linklib path
875 TMP_DIRS += $(AROS_LIB)/
876 # add lib and .a to static linklib names
877 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
878 ifeq (%(usestartup),yes)
879     TMP_LIBS += startup.o
880 endif
881 ifeq (%(detach),yes)
882     TMP_LIBS += detach.o
883 endif
884 # search for the linklibs in the given path, ignore ones not found
885 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
886     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
889 ifeq (%(linker),target)
890 %(prog) : CMD:=$(TARGET_CC)
891 %(prog) : STRIPCMD:=$(TARGET_STRIP)
892 endif
893 ifeq (%(linker),host)
894 %(prog) : CMD:=$(HOST_CC)
895 %(prog) : STRIPCMD:=$(HOST_STRIP)
896 endif
897 ifeq (%(linker),kernel)
898 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
899 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
900 endif
902 %(prog) : OBJS := %(objs)
903 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
904 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
905 %(prog) : %(objs) $(TMP_DEPLIBS)
906         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
907 %end
908 #------------------------------------------------------------------------------
911 #------------------------------------------------------------------------------
912 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
913 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
914 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
915     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
916     usestartup=yes detach=no
918 TMP_EXTRA_LDFLAGS := 
919 TMP_EXTRA_LIBS :=
920 ifeq (%(nix),yes)
921     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
922 endif
923 ifeq (%(usestartup),no)
924     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
925     TMP_EXTRA_LIBS += libinit autoinit
926 endif
927 ifeq (%(detach),yes)
928     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
929 endif
931 # Make a list of the lib files the programs depend on.
932 # In LDFLAGS remove white space between -L and directory
933 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
934 # Filter out only the libdirs and remove -L
935 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
936 # Add trailing /
937 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
938 # Add normal linklib path
939 TMP_DIRS += $(AROS_LIB)/
940 # add lib and .a to static linklib names
941 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
942 # search for the linklibs in the given path, ignore ones not found
943 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
944     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
946 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
948 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
949 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
950 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
951         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
952 %end
953 #------------------------------------------------------------------------------
956 #------------------------------------------------------------------------------
957 # Link the %(objs) to the library %(libdir)/lib%(libname).a
958 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
960 ifeq (%(linker),target)
961 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
962 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
963 endif
964 ifeq (%(linker),host)
965 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
966 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
967 endif
968 ifeq (%(linker),kernel)
969 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
970 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
971 endif
973 %(libdir)/lib%(libname).a : %(objs)
974         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
975 %end
976 #------------------------------------------------------------------------------
978 #------------------------------------------------------------------------------
979 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
980 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
981 # The -nostdc flag is added so that modules are not linked with stdc.library,
982 # stdcio.library or posixc.library
983 # (see /config/specs.in file)
984 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
985     cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
987 TMP_LDFLAGS  := %(ldflags)
988 # Make a list of the lib files the programs depend on.
989 # In LDFLAGS remove white space between -L and directory
990 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
991 # Filter out only the libdirs and remove -L
992 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
993 # Add trailing /
994 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
995 # Add normal linklib path
996 TMP_DIRS += $(AROS_LIB)/
997 # add lib and .a to static linklib names
998 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
999 # search for the linklibs in the given path, ignore ones not found
1000 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1001     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1004 %(module) : LIB_NAMES := %(uselibs)
1005 %(module) : OBJS := %(objs)
1006 %(module) : ENDTAG := %(endobj)
1007 %(module) : ERR := %(err)
1008 %(module) : OBJDIR := %(objdir)
1009 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1010 ifeq (%(usehostlibs),)
1011 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1012 else
1013 # Warning: the -L/usr/lib here can result in modules
1014 # linking against host libs instead of AROS libs (e.g stdc++) !!
1015 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1016                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1017 endif 
1018 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1019         %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1021 %end
1022 #------------------------------------------------------------------------------
1025 #------------------------------------------------------------------------------
1026 # Generate the libdefs.h include file for a module.
1027 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1029 TMP_TARGET := %(modname)_libdefs.h
1030 TMP_DEPS := $(GENMODULE)
1031 TMP_OPTS := 
1032 ifneq (%(conffile),)
1033     ifeq ($(dir %(conffile)),./)
1034         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1035         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1036     else
1037         TMP_OPTS += -c %(conffile)
1038         TMP_DEPS += %(conffile)
1039     endif 
1040 else
1041     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1042     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1043 endif
1044 ifneq (%(modsuffix),)
1045     TMP_OPTS += -s %(modsuffix)
1046 endif
1047 ifneq (%(targetdir),)
1048     TMP_OPTS += -d %(targetdir)
1049     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1050 endif
1051 ifneq (%(version),)
1052     TMP_OPTS += -v %(version)
1053 endif
1055 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1056 $(TMP_TARGET) : MODNAME := %(modname)
1057 $(TMP_TARGET) : MODTYPE := %(modtype)
1058 $(TMP_TARGET) : $(TMP_DEPS)
1059         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1060         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1061 %end
1062 #------------------------------------------------------------------------------
1064 #------------------------------------------------------------------------------
1065 # Generate the _lib.fd file for a module.
1066 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1068 TMP_TARGET := %(modname)_lib.fd
1069 TMP_DEPS := $(GENMODULE)
1070 TMP_OPTS := 
1071 ifneq (%(conffile),)
1072     ifeq ($(dir %(conffile)),./)
1073         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1074         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1075     else
1076         TMP_OPTS += -c %(conffile)
1077         TMP_DEPS += %(conffile)
1078     endif 
1079 else
1080     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1081     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1082 endif
1083 ifneq (%(modsuffix),)
1084     TMP_OPTS += -s %(modsuffix)
1085 endif
1086 ifneq (%(targetdir),)
1087     TMP_OPTS += -d %(targetdir)
1088     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1089 endif
1091 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1092 $(TMP_TARGET) : MODNAME := %(modname)
1093 $(TMP_TARGET) : MODTYPE := %(modtype)
1094 $(TMP_TARGET) : $(TMP_DEPS)
1095         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1096         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1097 %end
1098 #------------------------------------------------------------------------------
1100 #------------------------------------------------------------------------------
1101 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1102 # generated file in this Makefile
1103 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1104     targetdir=
1106 TMP_TARGET := Makefile.%(modname)%(modtype)
1107 TMP_DEPS := $(GENMODULE)
1108 TMP_OPTS := 
1109 ifneq (%(conffile),)
1110     ifeq ($(dir %(conffile)),./)
1111         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1112         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1113     else
1114         TMP_OPTS += -c %(conffile)
1115         TMP_DEPS += %(conffile)
1116     endif 
1117 else
1118     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1119     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1120 endif
1121 ifneq (%(modsuffix),)
1122     TMP_OPTS += -s %(modsuffix)
1123 endif
1124 ifneq (%(targetdir),)
1125     TMP_OPTS += -d %(targetdir)
1126     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1127 endif
1129 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1130 $(TMP_TARGET) : MODNAME := %(modname)
1131 $(TMP_TARGET) : MODTYPE := %(modtype)
1132 $(TMP_TARGET) : $(TMP_DEPS)
1133         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1134 %end
1135 #------------------------------------------------------------------------------
1138 #------------------------------------------------------------------------------
1139 # Generate the support files for compiling a module. This includes include
1140 # files and source files. This rule has to be preceeded by
1141 # %rule_genmodule_makefile
1142 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1143     conffile=
1145 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1146                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1147 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1148                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1150 TMP_DEPS := $(GENMODULE)
1151 TMP_OPTS :=
1153 ifneq (%(conffile),)
1154     ifeq ($(dir %(conffile)),./)
1155         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1156         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1157     else
1158         TMP_OPTS += -c %(conffile)
1159         TMP_DEPS += %(conffile)
1160     endif 
1161 else
1162     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1163     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1164 endif
1165 ifneq (%(modsuffix),)
1166     TMP_OPTS += -s %(modsuffix)
1167 endif
1168 ifneq (%(targetdir),)
1169     TMP_OPTS += -d %(targetdir)
1170     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1171     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1172 endif
1174 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1175 $(TMP_TARGETS) : MODNAME := %(modname)
1176 $(TMP_TARGETS) : MODTYPE := %(modtype)
1177 $(TMP_TARGETS) : $(TMP_DEPS)
1178         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1179 ifneq (%(conffile),lib.conf)
1180         @$(IF) $(TEST) -f lib.conf; then \
1181           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1182         fi
1183 endif
1184         @$(IF) $(TEST) -f libdefs.h; then \
1185           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1186         fi
1187         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1188 %end
1189 #------------------------------------------------------------------------------
1192 #------------------------------------------------------------------------------
1193 # Generate the support files for compiling a module. This includes include
1194 # files and source files.
1195 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1196     targetdir= conffile=
1198 ifneq ($(%(modname)_INCLUDES),)
1199 TMP_TARGETS := $(%(modname)_INCLUDES)
1201 TMP_DEPS := $(GENMODULE)
1202 TMP_OPTS :=
1204 ifneq (%(conffile),)
1205     ifeq ($(dir %(conffile)),./)
1206         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1207         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1208     else
1209         TMP_OPTS += -c %(conffile)
1210         TMP_DEPS += %(conffile)
1211     endif 
1212 else
1213     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1214     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1215 endif
1216 ifneq (%(modsuffix),)
1217     TMP_OPTS += -s %(modsuffix)
1218 endif
1219 ifneq (%(targetdir),)
1220     TMP_OPTS += -d %(targetdir)
1221     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1222 endif
1224 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1225 $(TMP_TARGETS) : MODNAME := %(modname)
1226 $(TMP_TARGETS) : MODTYPE := %(modtype)
1227 $(TMP_TARGETS) : $(TMP_DEPS)
1228         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1229         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1230 endif
1231 %end
1232 #------------------------------------------------------------------------------
1234 #------------------------------------------------------------------------------
1235 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1236 # 'start' is an optional starting address
1237 # 'ldflags' is optional additional flags for the linker
1238 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1240 BD_OUTDIR := $(dir %(file))
1241 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1242 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1243 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1244 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1245 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1246 BD_OBJS += %(objs)
1248 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1250 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1251         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1252         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1253         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1255 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1256     GLOB_MKDIRS += $(BD_OUTDIR)
1257 endif
1259 %end
1261 #------------------------------------------------------------------------------
1262 # Common rules for all makefiles
1263 %define common
1264 # Delete generated makefiles
1266 clean ::
1267         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1269 include $(SRCDIR)/config/make.tail
1271 BDID := $(BDTARGETID)
1272 %end
1273 #------------------------------------------------------------------------------
1274       
1276 #############################################################################
1277 #############################################################################
1278 ##                                                                         ##
1279 ## Here are the mmakefile build macros. These are macros that takes care   ##
1280 ## of everything to go from the sources to the generated target. Also all  ##
1281 ## intermediate files and directories that are needed are created by these ##
1282 ## rules.                                                                  ##
1283 ##                                                                         ##
1284 #############################################################################
1285 #############################################################################
1287 #------------------------------------------------------------------------------
1288 # Build a program
1289 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1290     objcfiles= \
1291     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1292     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1293     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1294     compiler=target linker=
1296 .PHONY : %(mmake)
1298 BD_PROGNAME  := %(progname)
1299 BD_OBJDIR    := %(objdir)
1300 BD_TARGETDIR := %(targetdir)
1301 BD_LINKER    := %(linker)
1303 # If not supplied, linker is equal to compiler
1304 ifeq ($(BD_LINKER),)
1305     BD_LINKER := %(compiler)
1306 endif
1308 BD_FILES     := %(files)
1309 BD_OBJCFILES := %(objcfiles)
1310 BD_ASMFILES  := %(asmfiles)
1311 BD_CXXFILES := %(cxxfiles)
1313 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1314 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1315 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1317 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1318 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1319 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1321 BD_CFLAGS    := %(cflags)
1322 BD_AFLAGS    := %(aflags)
1323 BD_DFLAGS    := %(dflags)
1324 BD_LDFLAGS   := %(ldflags)
1327 %(mmake)-quick : %(mmake)
1329 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1330 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1332 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1333 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1334     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1335 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1336     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1337 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1338     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1339 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1340     aflags=$(BD_AFLAGS) compiler=%(compiler)
1342 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1343     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1344     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1345     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1346     linker=$(BD_LINKER)
1348 endif
1350 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1352 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1353 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1354 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1356 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1358 %(mmake)-clean ::
1359         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1360         @$(RM) $(FILES)
1362 %end
1363 #------------------------------------------------------------------------------
1366 #------------------------------------------------------------------------------
1367 # Build programs, for every C file an executable will be built with the same
1368 # name as the C file
1369 %define build_progs mmake=/A files=/A nix=no \
1370     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1371     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1372     uselibs= usehostlibs= usestartup=yes detach=no
1374 .PHONY : %(mmake)
1376 BD_OBJDIR    := %(objdir)
1377 BD_TARGETDIR := %(targetdir)
1379 BD_FILES     := %(files)
1380 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1381 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1382 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1384 BD_CFLAGS    := %(cflags)
1385 BD_DFLAGS    := %(dflags)
1386 BD_LDFLAGS   := %(ldflags)
1389 %(mmake)-quick : %(mmake)
1391 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1392 %(mmake) : $(BD_EXES)
1394 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1395 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1396     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1398 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1399     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1400     ldflags=$(BD_LDFLAGS) \
1401     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1402     usestartup="%(usestartup)" detach="%(detach)"
1404 endif
1406 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1408 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1409 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1410 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1412 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1414 %(mmake)-clean ::
1415         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1416         @$(RM) $(FILES)
1418 %end
1419 #------------------------------------------------------------------------------
1422 #------------------------------------------------------------------------------
1423 # Build a module.
1424 # This is a bare version: It just compiles and links the given files. It is
1425 # assumed that all needed boiler plate code is in the files. This should only
1426 # be used for compiling external code. For AROS code use %build_module
1427 %define build_module_simple mmake=/A modname=/A modtype=/A \
1428     files="$(basename $(call WILDCARD, *.c))" \
1429     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1430     objdir=$(OBJDIR) moduledir= \
1431     uselibs= usehostlibs= compiler=target
1433 # Define metamake targets and their dependencies
1434 #MM %(mmake) : core-linklibs includes-generate-deps
1435 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1436 #MM %(mmake)-kobj-quick
1437 #MM %(mmake)-quick
1438 #MM %(mmake)-clean
1440 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1442 .PHONY : $(BD_ALLTARGETS)
1444 ifeq (%(modname),)
1445 $(error using %build_module_simple: modname may not be empty)
1446 endif
1447 ifeq (%(modtype),)
1448 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1449 endif
1451 # Default values for variables and arguments
1452 BD_DEFLINKLIBNAME := %(modname)
1453 BD_DEFDFLAGS := %(cflags)
1454 OBJDIR ?= $(GENDIR)/$(CURDIR)
1455 BD_MODDIR := %(moduledir)
1456 ifeq ($(BD_MODDIR),)
1457   ifeq (%(modtype),library)
1458     BD_MODDIR  := $(AROS_LIBRARIES)
1459   endif
1460   ifeq (%(modtype),gadget)
1461     BD_MODDIR  := $(AROS_GADGETS)
1462   endif
1463   ifeq (%(modtype),datatype)
1464     BD_MODDIR  := $(AROS_DATATYPES)
1465   endif
1466   ifeq (%(modtype),handler)
1467     BD_MODDIR  := $(AROS_FS)
1468   endif
1469   ifeq (%(modtype),device)
1470     BD_MODDIR  := $(AROS_DEVS)
1471   endif
1472   ifeq (%(modtype),resource)
1473     BD_MODDIR  := $(AROS_RESOURCES)
1474   endif
1475   ifeq (%(modtype),hook)
1476     BD_MODDIR  := $(AROS_RESOURCES)
1477   endif
1478   ifeq (%(modtype),mui)
1479     BD_MODDIR  := $(AROS_CLASSES)/Zune
1480   endif
1481   ifeq (%(modtype),mcc)
1482     BD_MODDIR  := $(AROS_CLASSES)/Zune
1483   endif
1484   ifeq (%(modtype),mcp)
1485     BD_MODDIR  := $(AROS_CLASSES)/Zune
1486   endif
1487   ifeq (%(modtype),usbclass)
1488     BD_MODDIR  := $(AROS_CLASSES)/USB
1489   endif
1490   ifeq (%(modtype),hidd)
1491     BD_MODDIR  := $(AROS_DRIVERS)
1492   endif
1493   ifeq (%(modtype),printer)
1494     BD_MODDIR  := $(AROS_PRINTERS)
1495   endif
1496 endif
1497 ifeq ($(BD_MODDIR),)
1498   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1499 endif
1501 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1502 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1503 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1505 %rule_compile_multi \
1506     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1507     cflags="%(cflags)" dflags="%(dflags)" \
1508     compiler=%(compiler)
1510 # Handlers use dash instead of dot in their names
1511 ifeq (%(modtype),handler)
1512 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1513 else
1514 ifeq (%(modtype),printer)
1515 BD_MODULE := $(BD_MODDIR)/%(modname)
1516 else
1517 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1518 endif
1519 endif
1520 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1522 %(mmake)-quick : %(mmake)
1523 %(mmake)-kobj-quick : $(BD_KOBJ)
1524 %(mmake)       : $(BD_MODULE)
1525 %(mmake)-kobj  : $(BD_KOBJ)
1527 # The module is linked from all the compiled .o files
1528 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1530 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1531 # This breaks con-handler build. Here we work around this
1532 ifeq (%(modname),con)
1533     BD_ERR := $(notdir $(BD_MODULE)).err
1534 else
1535     BD_ERR := %(modname).err
1536 endif
1538 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1539                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1540                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1541                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1543 # Link kernel object file
1544 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1546 # Make these symbols local
1547 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1548             UtilityBase ExpansionBase KeymapBase KernelBase
1550 BD_SYMBOLS := $(BD_KBASE)
1552 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1553 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1554 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1555 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1556 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1557 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1558         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1559         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1560         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1563 ## Dependency fine-tuning
1565 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1566 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1568 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1569 $(BD_MODULE) : | $(BD_MODDIR)
1570 $(BD_KOBJ) : | $(KOBJSDIR)
1571 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1573 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1574 %(mmake)-clean ::
1575         @$(ECHO) "Cleaning up for module %(modname)"
1576         @$(RM) $(FILES)
1577 %end
1578 #------------------------------------------------------------------------------
1581 #------------------------------------------------------------------------------
1582 # Build a module - core routine
1583 # Explanation of this macro is done in the developer's manual
1584 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1585   files="$(basename $(call WILDCARD, *.c))" \
1586   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1587   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1588   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1589   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1590   compiler=target nostartup=yes archspecific=no \
1591   build_abi= build_library=
1593 # We will employ a terrifying, but unavoidable, hack here.
1594 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1595 # ignores GNU Make ifeq() statements, but will process any #MM
1596 # headed lines in the file.
1598 # So, to make the following #MM lines conditional on whether we want
1599 # to build the ABI, Library, or both, we define build_abi= and 
1600 # build_library as 'M' to enable, or '' to disable, which allows genmf
1601 # to do the following conversions:
1603 #  #%(build_abi)M includes-foo: foo-include
1604 #    becomes, when build_abi=M
1605 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1606 #    but, when build_abi= ...
1607 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1609 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1611 # Define metamake targets and their dependencies
1612 #MM %(mmake)
1613 #MM %(mmake)-quick
1614 #MM %(mmake)-makefile
1615 #MM %(mmake)-clean
1617 # ABI targets:
1618 #M%(build_abi)- includes-all : %(mmake)-includes
1619 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1620 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1621 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1622 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1623 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1624 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1625 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1626 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1627 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1628 #M%(build_abi) %(mmake)-includes-quick
1629 #M%(build_abi) %(mmake)-includes-dirs
1630 #M%(build_abi) %(mmake)-fd
1632 # Library targets
1633 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1634 #%(build_library)M %(mmake)-kobj-quick : 
1636 # Library with ABI targets:
1637 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1638 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1640 # All MetaMake targets defined by this macro
1641 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1643 ifeq (%(build_library),M)
1644 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1645 endif
1647 ifeq (%(build_abi),M)
1648 BD_ALLTARGETS += %(mmake)-includes \
1649                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1650                  %(mmake)-linklib %(mmake)-fd
1651 endif
1653 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1655 ifeq (%(modname),)
1656 $(error using %build_module: modname may not be empty)
1657 endif
1658 ifeq (%(modtype),)
1659 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1660 endif
1662 # Default values for variables and arguments
1663 BD_DEFLINKLIBNAME := %(modname)
1664 BD_DEFDFLAGS := %(cflags)
1665 OBJDIR ?= $(GENDIR)/$(CURDIR)
1667 ## Create genmodule include Makefile for the module
1669 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1671 %rule_genmodule_makefile \
1672     modname=%(modname) modtype=%(modtype) \
1673     modsuffix=%(modsuffix) targetdir=%(objdir) \
1674     conffile=%(conffile)
1676 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1678 GLOB_MKDIRS += %(objdir)
1680 # Do not parse these statements if metatarget is not appropriate
1681 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1683 include %(objdir)/Makefile.%(modname)%(modtype)
1685 BD_DEFMODDIR := $(%(modname)_MODDIR)
1686 ifeq (%(archspecific),yes)
1687 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1688 endif
1691 ## include files generation
1693 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1694 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1695 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1697 ifeq (%(build_abi),M)
1698 %(mmake)-includes-quick : %(mmake)-includes
1699 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1700     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1701     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1703 ifneq ($(%(modname)_INCLUDES),)
1704 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1705                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1706                          conffile=%(conffile)
1708 %rule_copy_diff_multi \
1709     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1710     stampfile=%(objdir)/%(modname)_geninc
1712 %rule_copy_diff_multi \
1713     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1714     stampfile=%(objdir)/%(modname)_incs
1716 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1718 TMP%(modname)_INCDIRS := \
1719     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1720     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1721     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1722 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1724 endif
1726 endif
1728 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1729                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1730                            conffile=%(conffile) version=%(version)
1732 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1733 $(BD_DEFLIBDEFSINC) :
1734         @$(ECHO) "Generating $@"
1735         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1737 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1738 GLOB_MKDIRS += %(objdir)/include
1740 ## Extra genmodule src files generation
1741 ## 
1742 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1743                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1744                       conffile=%(conffile)
1747 ifeq (%(build_abi),M)
1748 ## Create FD file
1749 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1750 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1752 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1753                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1755 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1757 GLOB_MKDIRS += $(BD_FDDIR)
1758 endif
1760 ## Compilation
1762 BD_FILES      := %(files)
1763 BD_CXXFILES := %(cxxfiles)
1765 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1767 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1768 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1770 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1771 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1772 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1774 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1775 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1777 ifeq (%(modtype),library)
1778     BD_LIBSUFFIX := 
1779 else
1780     BD_LIBSUFFIX := .%(modtype)
1781 endif
1783 ifeq (%(build_abi),M)
1784 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1785 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1786 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1787     BD_LINKLIB :=
1788 else
1789     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1790     ifneq (%(modname),%(linklibname))
1791         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1792     endif
1793 endif
1794 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1796 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1797 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1798 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1799     BD_RELLINKLIB :=
1800 else
1801     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1802     ifneq (%(modname),%(linklibname))
1803         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1804     endif
1805 endif
1806 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1807 endif
1809 ifneq ($(BD_CXXFILES),)
1810 BD_LINKCMD=$(AROS_CXX)
1811 else
1812 BD_LINKCMD=$(AROS_CC)
1813 endif
1815 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1816 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1817     $(BD_RELLINKLIBCFILES)
1819 %rule_compile_multi \
1820     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1821     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1822     compiler=%(compiler)
1823 %rule_compile_multi \
1824     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1825     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1826     compiler=%(compiler)
1827 %rule_compile_cxx_multi \
1828     basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1829     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1830     compiler=%(compiler)
1832 ifneq ($(BD_LINKLIBAFILES),)
1833 %rule_assemble_multi \
1834     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1835 endif
1837 ## Linking
1839 ifeq (%(modsuffix),)
1840 BD_SUFFIX := %(modtype)
1841 else
1842 BD_SUFFIX := %(modsuffix)
1843 endif
1845 ifeq (%(build_library),M)
1846 # Handlers use dash instead of dot in their names
1847 ifeq ($(BD_SUFFIX),handler)
1848 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1849 else
1850 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1851 endif
1852 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1853 else
1854 BD_MODULE :=
1855 BD_KOBJ   :=
1856 endif
1858 %(mmake)-quick      : %(mmake)
1859 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1860 ifeq (%(build_library),M)
1861 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1862 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1863 endif
1864 ifeq (%(build_abi),M)
1865 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1866 endif
1868 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1869            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1871 ifeq (%(nostartup),yes)
1872 # Handlers always have entry point
1873 ifneq (%(modtype),handler)
1874 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1875 endif
1876 endif
1878 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1879 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1880                  %(linklibobjs)
1881 BD_RELLINKLIBOBJS \
1882               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1883                  %(linklibobjs)
1885 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1886 # This breaks con-handler build. Here we work around this
1887 ifeq (%(modname),con)
1888     BD_ERR := $(notdir $(BD_MODULE)).err
1889 else
1890     BD_ERR := %(modname).err
1891 endif
1893 ifeq (%(build_library),M)
1894 # The module is linked from all the compiled .o files
1895 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1896                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1897                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1898                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1899 endif
1901 ifeq (%(build_abi),M)
1902 # Link static lib
1903 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1904 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1905 ifneq ($(BD_LINKLIB),)
1906 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1907 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1908 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1909 endif
1911 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1912 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1913 endif
1915 ifneq ($(BD_RELLINKLIB),)
1916 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1917 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1918 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1919 endif
1921 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1922 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1923 endif
1924 endif
1926 ifeq (%(build_library),M)
1927 # Link kernel object file
1928 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1930 # Make these symbols local
1931 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1932             UtilityBase ExpansionBase KeymapBase KernelBase
1934 BD_SYMBOLS := $(BD_KBASE)
1936 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1937 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1938 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1939 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1940 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1941 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1942         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1943         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1944         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1945 endif
1947 ## Dependency fine-tuning
1949 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1951 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1953 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1954 $(BD_MODULE) : | %(prefix)/%(moduledir)
1955 $(BD_KOBJ)   : | $(KOBJSDIR)
1956 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1958 # Some include files need to be generated before the .c can be parsed.
1959 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
1961 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1962     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1963 $(BD_DEPS) : $(BD_DFILE_DEPS)
1964 endif
1966 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1967     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1968     %(objdir)/Makefile.%(modname)%(modtype) \
1969     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1970     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1971     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1972     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1973     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1974     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1975     $(BD_ENDOBJS)
1976 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1977 %(mmake)-clean ::
1978         @$(ECHO) "Cleaning up for module %(modname)"
1979         @$(RM) $(FILES)
1981 endif # $(TARGET) in $(BD_ALLTARGETS)
1982 %end
1983 #------------------------------------------------------------------------------
1985 #------------------------------------------------------------------------------
1986 # Build a module - ABI and library
1987 # Explanation of this macro is done in the developer's manual
1988 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1989   files="$(basename $(call WILDCARD, *.c))" \
1990   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1991   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1992   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1993   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1994   compiler=target nostartup=yes archspecific=no
1996 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
1997    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
1998    files="%(files)" cxxfiles="%(cxxfiles)" \
1999    linklibname="%(linklibname)" \
2000    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2001    cflags="%(cflags)" dflags="%(dflags)" \
2002    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2003    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2004    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2005    build_abi=M build_library=M
2007 %end
2008 #------------------------------------------------------------------------------
2011 #------------------------------------------------------------------------------
2012 # Build a module skeleton ABI
2013 # This is a stripped-down version of build_module, it only creates include
2014 # files and the linklibs.
2015 # This is used when for plugins or classes with the same API, but no actual
2016 # implementation here.
2017 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2018   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2019   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2020   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2021   compiler=target nostartup=yes archspecific=no
2023 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2024   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2025   linklibname="%(linklibname)" \
2026   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2027   cflags="%(cflags)" dflags="%(dflags)" \
2028   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2029   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2030   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2031   build_abi=M build_library=
2033 %end
2034 #------------------------------------------------------------------------------
2036 #------------------------------------------------------------------------------
2037 # Build a module library - no includes nor linklibs
2038 # Explanation of this macro is done in the developer's manual
2039 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2040   files="$(basename $(call WILDCARD, *.c))" \
2041   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2042   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2043   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2044   uselibs= usehostlibs= \
2045   compiler=target nostartup=yes archspecific=no
2047 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2048    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2049    files="%(files)" cxxfiles="%(cxxfiles)" \
2050    cflags="%(cflags)" dflags="%(dflags)" \
2051    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2052    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2053    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2054    build_abi= build_library=M
2056 %end
2057 #------------------------------------------------------------------------------
2061 #------------------------------------------------------------------------------
2062 # Build a linklib.
2063 # - mmake is the mmaketarget
2064 # - libname is the baselibname e.g. lib%(libname).a will be created
2065 # - files are the C source files to include in the lib. The list of files
2066 #   has to be given without the .c suffix
2067 # - cxxfiles are C++ source files without suffix.
2068 #   NB: files will be matched in the order .cpp > .cxx > .cc
2069 # - asmfiles are the asm files to include in the lib. The list of files has to
2070 #   be given without the .s suffix
2071 # - objs additional object to link into the linklib. The objects have to be
2072 #   given with full absolute path and the .o suffix.
2073 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2074 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2075 # - cflags are the flags to compile the source (default $(CFLAGS))
2076 # - dflags are the flags use during makedepend (default equal to cflags)
2077 # - aflags are the flags use during assembling (default $(AFLAGS))
2078 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2079 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2080   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2081   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2082   aflags=$(AFLAGS) compiler=target
2084 # assign and generate the local variables used in this macro
2085 BD_LIBNAME    := %(libname)
2086 BD_LINKLIB    := %(libdir)/lib%(libname).a
2088 BD_FILES      := %(files)
2089 BD_ASMFILES   := %(asmfiles)
2090 BD_CXXFILES := %(cxxfiles)
2092 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2093 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2094 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2096 BD_OBJS       := $(BD_ARCHOBJS) \
2097                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2098                  %(objs)
2099 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2101 BD_CFLAGS    := %(cflags)
2102 BD_AFLAGS    := %(aflags)
2103 BD_DFLAGS    := %(dflags)
2105 .PHONY : %(mmake) %(mmake)-clean
2107 #MM %(mmake) : includes-generate-deps
2108 %(mmake) : $(BD_LINKLIB)
2110 ifeq ($(TARGET),%(mmake))
2112 %rule_compile_multi basenames=$(BD_FILES) targetdir=%(objdir) \
2113     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2114 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2115     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2116 %rule_assemble basename=% targetdir=%(objdir) \
2117     aflags=$(BD_AFLAGS)
2119 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2120 endif
2122 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2124 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2125 $(BD_LINKLIB) : | %(libdir)
2126 GLOB_MKDIRS += %(objdir) %(libdir)
2128 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2130 %(mmake)-clean ::
2131         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2132         @$(RM) $(FILES)
2134 %end
2135 #------------------------------------------------------------------------------
2138 #------------------------------------------------------------------------------
2139 # Build catalogs.
2140 # - mmake is the mmaketarget
2141 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2142 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2143 # - subdir is the destination subdirectory of the catalogs
2144 # - name is the name of the destination catalog, without the .catalog suffix
2145 # - source is the path to the generated source code file
2146 # - dir is the base destination directory (default $(AROS_CATALOGS))
2147 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2148 # - srcdir is the directory in which the *.cd and *.ct files are searched
2150 %define build_catalogs mmake=/A name=/A subdir=/A \
2151  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2152  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2154 ifeq (%(description),)
2155 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2156 else
2157 BD_DESC := %(description)
2158 endif
2160 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2162 ifeq (%(catalogs),)
2163 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2164 else
2165 BD_LNGS := %(catalogs)
2166 endif
2168 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2169 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2172 %(mmake) : $(BD_OBJS) %(source)
2174 $(BD_OBJS) : | $(BD_DIRS)
2175 GLOB_MKDIRS += $(BD_DIRS)
2177 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2178         @$(ECHO) "Creating   %(name) catalog for language $*."
2179         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2181 ifneq (%(source),)
2182 %(source) : BD_DESC := $(BD_DESC)
2183 %(source) : BD_SRC := $(BD_SRC)
2184 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2185         @$(ECHO) "Creating   %(name) catalog source file $@"
2186         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2187 endif
2189 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2191 %(mmake)-clean ::
2192         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2193         @$(RM) $(FILES)
2195 .PHONY: %(mmake) %(mmake)-clean
2197 %end
2198 #-----------------------------------------------------------------------------
2201 #-----------------------------------------------------------------------------
2202 # Build icons.
2203 # - mmake is the mmaketarget
2204 # - icons is a list of icon base names (ie. without the .info suffix)
2205 # - dir is the destination directory
2206 # - srcdir is where *.png and *.info.src are searched
2207 #-----------------------------------------------------------------------------
2209 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2211 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2214 %(mmake) : $(BD_OBJS)
2216 ifeq (%(image),)
2218 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2219         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2220         @$(ILBMTOICON) $+ $@
2222 else
2224 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2225         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2226         @$(ILBMTOICON) $+ $@
2228 endif
2230 $(BD_OBJS) : | %(dir)
2231 GLOB_MKDIRS += %(dir)
2233 %(mmake)-clean : FILES := $(BD_OBJS)
2235 %(mmake)-clean ::
2236         @$(RM) $(FILES)
2238 .PHONY: %(mmake) %(mmake)-clean
2240 %end
2241 #-----------------------------------------------------------------------------
2244 #------------------------------------------------------------------------------
2245 # Compile files for an arch-specific replacement of code for a module
2246 # - files: the basenames of the C files to compile.
2247 # - asmfiles: the basenames of the asm files to assemble.
2248 # - mainmmake: the mmake of the module in the main directory to compile these
2249 #   arch specific files for.
2250 # - maindir: the object directory for the main module
2251 # - arch: the arch for which to compile these files. It can have the form
2252 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2253 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2254 # - dflags: the flags used during creation of dependency file. If not specified
2255 #   the same value as cflags will be used
2256 # - aflags: the flags used during assembling
2257 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2258 #   the target compiler is used
2259 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2260 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2262 ifeq (%(files) %(asmfiles),)
2263   $(error no files or asmfiles given)
2264 endif
2266 %buildid targets="%(mainmmake)-%(arch)"
2268 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2269 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2270 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2271 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2272 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2273 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2274 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2275 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2276 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2277 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2278 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2279 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2280 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2281 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2282 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2284 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2286 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2287 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2288 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2289 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2290 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2292 ifneq (%(modulename),)
2293 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2294 endif
2296 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2297     BD_TARGET := %(mainmmake)-%(arch)-quick
2298 else
2299     BD_TARGET := %(mainmmake)-%(arch)
2300 endif
2303 ifeq ($(TARGET),$(BD_TARGET))
2304 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2305 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2306 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2307 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2308 endif
2310 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2311 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2314 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2317 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2319 ifeq ($(findstring %(compiler),host kernel target),)
2320   $(error unknown compiler %(compiler))
2321 endif
2322 ifeq (%(compiler),target)
2323 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2324 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2325 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2326 endif
2327 ifeq (%(compiler),host)
2328 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2329 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2330 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2331 endif
2332 ifeq (%(compiler),kernel)
2333 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2334 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2335 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2336 endif
2337 ifneq (%(modulename),)
2338 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2339 else
2340 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2341 endif
2342 ifeq ($(TARGET),$(BD_TARGET))
2343 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2344         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2345 endif
2347 ifeq (%(dflags),)
2348 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2349 else
2350 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2351 endif
2352 ifeq ($(TARGET),$(BD_TARGET))
2353 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2354         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2355 endif
2357 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2359 ifeq ($(TARGET),$(BD_TARGET))
2360 $(BD_OBJDIR$(BDID))/%.o : %.s
2361         %assemble_q opt=$(AFLAGS)
2362 $(BD_OBJDIR$(BDID))/%.o : %.S
2363         %assemble_q opt=$(AFLAGS)
2364 endif
2366 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2367 %end
2368 #------------------------------------------------------------------------------
2371 #------------------------------------------------------------------------------
2372 # generate asm files from c files (for debugging purposes)
2373 %define ctoasm_q
2374 %.s : %.c
2375         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2376         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2377 %end
2378 #------------------------------------------------------------------------------
2381 #------------------------------------------------------------------------------
2382 # Copy files from one directory to another.
2384 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2386 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2388 GLOB_MKDIRS += %(dst)
2390 .PHONY : %(mmake)
2393 %(mmake) : | %(dst) 
2394         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2396 %end
2397 #------------------------------------------------------------------------------
2400 #------------------------------------------------------------------------------
2401 # Copy a directory recursively to another place, preserving the original 
2402 # hierarchical structure
2404 # src: the source directory whose content will be copied.
2405 # dst: the directories where to copy src's content. If not existing, they will be made.
2406 # excludefiles: files which must not be copied. Path must be relative to src.
2408 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2410 .PHONY : %(mmake)
2413 %(mmake) :
2414         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2416 %end
2417 #------------------------------------------------------------------------------
2420 #------------------------------------------------------------------------------
2421 #   Copy include files into the includes directories. There are currently
2422 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2423 #   for building tools that need to run on the host system $(GENINCDIR). The
2424 #   $(GENINCDIR) path must not contain any references to the C runtime
2425 #   library header files.
2427 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2428     dir= compiler=target
2430 ifeq ($(findstring %(compiler),host kernel target),)
2431 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2432 endif
2434 ifneq (%(dir),)
2435 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2436 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2437 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2438 else
2439 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2440 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2441 endif
2443 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2444         @$(CP) $< $@
2447 ifeq (%(compiler),target)
2449 ifneq (%(dir),)
2450 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2451 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2452 else
2453 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2454 endif
2456 BD_INCL_FILES += $(BD_INCL_FILES2)
2458 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2459         @$(CP) $< $@
2460 endif
2463 %(mmake) : $(BD_INCL_FILES)
2465 .PHONY: %(mmake)
2467 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2468 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2469 %end
2470 #------------------------------------------------------------------------------
2473 #------------------------------------------------------------------------------
2474 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2475 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2476 STUBS_MEM := $(addsuffix .o,$(STUBS))
2477 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2478 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2479 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2481 #MM- linklibs : hidd-%(hidd)-stubs
2482 #MM- %(parenttarget): hidd-%(hidd)-stubs
2483 #MM hidd-%(hidd)-stubs : includes includes-copy
2484 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2486 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2487         %mklib_q from=$^
2489 $(STUBS_OBJ) : $(STUBS_SRC) 
2490         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2492 $(STUBS_DEP) : $(STUBS_SRC)
2493         %mkdepend_q flags=%(dflags)
2495 setup ::
2496         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2499 clean ::
2500         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2502 DEPS := $(DEPS) $(STUBS_DEP)
2504 %end
2505 #------------------------------------------------------------------------------
2508 #------------------------------------------------------------------------------
2509 # Build an imported source tree which uses the configure script from the
2510 # autoconf package.  This rule will try to "integrate" the produced files as
2511 # much as possible in the AROS build, for example by putting libraries in the
2512 # standard library directory, includes in the standard include directory, and
2513 # so on. You can however override this behaviour.
2515 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2516 # be %(bindir) (or its deduced value) when running "make install", and
2517 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2518 # configure script some more parameters whose value depends upon the PROGDIR
2519 # env var, so that the program gets all its stuff installed in the proper place
2520 # when building it, but when running it from inside AROS it can also find that
2521 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2522 # the configuration parameters set when running ./configure
2524 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2525 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2526 # to the name which has to follow it.
2528 # Arguments:
2530 #     - mmake           = the meta make target.
2531 #     - package         = name of the package to be built.
2532 #     - srcdir          = the location of the unpacked source code. Defaults
2533 #                         to $(SRCDIR)/$(CURDIR).
2534 #     - prefix          = the target directory. Must be an absolute path of the
2535 #                         host system. Defaults to $(AROS_CONTRIB).
2536 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2537 #                         Defaults to the value of the prefix option.
2538 #     - extraoptions    = additional options for the configure script.
2539 #     - extracflags     = additional flags which are used for both C and C++.
2540 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2541 #                         Defaults to the value of the nix argument.
2542 #     - nix             = enable u*nix path handling, i.e. a path like
2543 #                         /progdir//./file will be translated to
2544 #                         progdir:file during run-time. Defaults to no.
2545 #     - compiler        = target, host or kernel. Defaults to target.
2546 #     - install_target  = the command used for installing. Defaults to install. Leave
2547 #                         it empty if you want to suppress installing.
2548 #     - preconfigure    = a metatarget which is executed before configure is called.
2549 #     - postconfigure   = a metatarget which is executed after configure is called.
2550 #     - postinstall     = a metatarget which is executed after installing.
2551 #     - install_env     = set additional options for installing.
2552 #     - use_build_env   = if yes the configuration environment is used for
2553 #                         installing, too. Defaults to no.
2555 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2556 # like this:
2558 # if nix_dir_layout
2559 #    --prefix = $(aros_prefix)
2560 #    progdir = $(aros_prefix)/bin
2561 # else
2562 #    if nix
2563 #        --prefix = /PROGDIR
2564 #        --bindir = /PROGDIR
2565 #        --sbindir = /PROGDIR
2566 #        --libdir = /LIB
2567 #        --includedir = /INCLUDE
2568 #        --oldincludedir = /INCLUDE   
2569 #    else
2570 #        --prefix = $(aros_prefix)
2571 #    endif
2573 #    progdir = $(aros_prefix)
2575 #    # Install options
2576 #    bindir = $(prefix)
2577 #    sbindir = $(prefix)
2578 #    libdir = $(AROS_LIB)
2579 #    includedir = $(AROS_INCLUDES)
2580 #    oldincludedir = $(AROS_INCLUDES)
2581 # endif
2584 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2585     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2586     install_target=install preconfigure= postconfigure= postinstall= \
2587     install_env= use_build_env=no
2589 ifneq (%(prefix),)
2590     %(mmake)-prefix := %(prefix)
2591 else
2592     %(mmake)-prefix := $(AROS_CONTRIB)
2593 endif
2595 ifneq (%(aros_prefix),)
2596     %(mmake)-aros_prefix := %(aros_prefix)
2597 else
2598     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2599 endif
2601 ifeq (%(nix),yes)
2602     %(mmake)-nix    := -nix
2603     %(mmake)-volpfx := /
2604     %(mmake)-volsfx := /
2605     
2606     ifeq (%(nix_dir_layout),)
2607         %(mmake)-nix_dir_layout := yes
2608     endif
2609 else
2610     %(mmake)-volsfx := :
2611     
2612     ifeq (%(nix_dir_layout),)
2613         %(mmake)-nix_dir_layout := no
2614     endif
2615 endif
2617 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2619 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2620         exec_prefix=$(%(mmake)-prefix) %(install_env)
2622 # Check if chosen compiler is valid
2623 ifeq ($(findstring %(compiler),host target kernel),)
2624   $(error unknown compiler %(compiler))
2625 endif
2627 # Set legacy 'host' variable based on chosen compiler
2628 ifeq (%(compiler),host)
2629     host := yes
2630     ifeq (%(package),)
2631         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2632     else
2633         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2634     endif
2635 else
2636     host := no
2637     ifeq (%(package),)
2638         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2639     else
2640         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2641     endif
2642 endif
2643 ifneq (%(gendir),)
2644     ifeq (%(package),)
2645         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2646     else
2647         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2648     endif
2649 endif
2651 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2652 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2654 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2655     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2656     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2657 else
2658     ifeq (%(nix),yes)
2659         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2660         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2661     else
2662         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2663     endif
2665     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2666     
2667     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2668         sbindir=$(%(mmake)-prefix) \
2669         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2670         oldincludedir=$(AROS_INCLUDES) %(install_env)
2671 endif
2673 ifneq ($(DEBUG),yes)
2674     %(mmake)-s_flag = -s
2675 endif
2677 # Set up build environment, and options for configure script
2678 ifeq (%(compiler),host)
2679     CONFIG_ENV := \
2680         CPP="$(HOST_CPP)" \
2681         CXXCPP="$(HOST_CPP)" \
2682         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2683         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2684         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2685         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2686         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2687         TARGET_NM="$(NM_PLAIN)"
2688 endif
2689 ifeq (%(compiler),target)
2690     CONFIG_ENV := \
2691         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2692         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2693         CFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2694         CXXFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2695         CPP="$(TARGET_CPP)" \
2696         CXXCPP="$(TARGET_CPP)" \
2697         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2698         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2699         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2700         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2701         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2702         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2703         TARGET_NM="$(NM_PLAIN)" \
2704         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2705         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2706     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2707         --host=$(AROS_TARGET_CPU)-aros\
2708         --target=$(AROS_TARGET_CPU)-aros\
2709         --disable-nls\
2710         --without-x --without-pic --disable-shared
2711 endif
2712 ifeq (%(compiler),kernel)
2713     CONFIG_ENV := \
2714         CPP="$(KERNEL_CPP)" \
2715         CXXCPP="$(KERNEL_CPP)" \
2716         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2717         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2718         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2719         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2720         TARGET_NM="$(NM_PLAIN)"
2721     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2722         --host=$(AROS_TARGET_CPU)-aros\
2723         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2724         --without-x --without-pic --disable-shared
2725 endif
2727 ifeq (%(use_build_env),yes)
2728     BUILD_ENV := $(CONFIG_ENV)
2729 endif
2732 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2734 # When building for the host, we don't need to build the
2735 # linklibs - this is especially true when building the
2736 # crosstool toolchain on 'foreign' architectures (such as
2737 # building PPC on x86)
2739 #MM- %(mmake)-host : setup includes %(mmake)-quick
2740 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2741 #MM- %(mmake): %(mmake)-%(compiler)
2743 # Using -j1 in install_command may result in a warning but finally
2744 # it does its job. make install for gcc does not work reliably for -jN
2745 # where N > 1.
2746 ifneq (%(install_target),)
2747     %(mmake)-install_command = \
2748         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2749         -C $(%(mmake)-pkgdir) %(install_target) -j1
2751     %(mmake)-uninstall_command = \
2752     $(RM) $(%(mmake)-installflag) && \
2753     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2754     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2755 else
2756     %(mmake)-install_command   := true
2757     %(mmake)-uninstall_command := true
2758 endif
2760 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2763 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2765 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2766         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2767             $(RM)  $(%(mmake)-installflag) && \
2768             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2769              -C $(%(mmake)-pkgdir) && \
2770             $(%(mmake)-install_command) && \
2771             $(TOUCH) $@ -r $^; \
2772         fi
2774 $(%(mmake)-pkgdir)/.files-touched:
2775         %mkdirs_q $(%(mmake)-pkgdir)
2776         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2777         $(TOUCH) $@
2780 %(mmake)-uninstall :
2781         $(%(mmake)-uninstall_command)
2784 %(mmake)-configure : $(%(mmake)-configflag)
2786 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2787 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2788         $(RM) $@
2789         %mkdirs_q $(%(mmake)-pkgdir)
2790         cd $(%(mmake)-pkgdir) && \
2791         find . -name config.cache -exec $(RM) '{}' \; && \
2792         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2793             %(extraoptions) && \
2794         $(TOUCH) $@
2797 %(mmake)-clean : %(mmake)-uninstall
2798         @$(RM) $(%(mmake)-pkgdir)
2799 %end
2800 #------------------------------------------------------------------------------
2803 #------------------------------------------------------------------------------
2804 # Given an archive name, patches names and locations where to find them, fetch
2805 # the archive and the patches from any of those locations, unpack the archive
2806 # and then apply the patches.
2808 # Locations currently supported are http and ftp sites, plus local filesystem
2809 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2810 # the fetch.sh script needs to be modified, since this macro relies on that script.
2812 # Arguments:
2814 #     - mmake           = mmaketarget
2815 #     - archive_origins = list of locations where to find the archive. They are tried
2816 #                         in sequence, until the archive is found and fetching it 
2817 #                         succeeded. If not specified, the current directory is assumed.
2818 #     - archive         = the archive name. Mandatory.
2819 #     - suffixes        = a list of suffixes to append to the the package name plus the
2820 #                         version. Each one of them is tried until a matching archive is
2821 #                         found. They are appended to patches and these are tried the
2822 #                         same way as packages are.
2823 #     - location        = the local directory where to put the fetched archive and patches.
2824 #                         If not specified, the directory specified by destination is used.
2825 #     - destination     = the directory to unpack the archive to.
2826 #                         If not specified, the current directory is assumed.
2827 #     - patches_origins = list of locations where to find the patches. They are tried
2828 #                         in sequence, until a patch is found and fetching it 
2829 #                         succeeded. If not specified, the current directory is assumed.
2830 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2831 #                         patch_name[:[patch_subdir][:patch_opt]].
2833 #                             - patch_name   = the name of the patch file
2834 #                             - patch_subdir = the directory within \destination\ where to
2835 #                                              apply the patch.
2836 #                             - patch_opt    = any options to pass to the `patch' command
2837 #                                              when applying the patch.
2838 #                         
2839 #                         The patch_subdir and patch_opt fields are optional.
2841 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2842     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2844 .PHONY: %(mmake)
2846 ifneq (%(location),)
2847     %(mmake)-location := %(location)
2848 else
2849     %(mmake)-location := %(destination)
2850 endif
2853 %(mmake) :
2854         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2855         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2856 %end
2857 #------------------------------------------------------------------------------
2860 #------------------------------------------------------------------------------
2861 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2862 # unpatched source tree and runs diff against this and a previously fetched and possibly
2863 # patched tree. Depending on what happens after patching during a normal build it might
2864 # give best results if the new patch is created directly after fetch.
2866 # Arguments:
2868 #     - mmake       = mmaketarget
2869 #     - archive     = archive base name
2870 #     - srcdir      = the top level directory the package is unpacked to, useful if
2871 #                     an archive unpacks to a directory other than its name suggests.
2872 #                     this should not be deeper than a single path element.
2873 #     - suffixes    = a list of suffixes to append to the the package name plus the
2874 #                     version. Each one of them is tried until a matching archive is
2875 #                     found.
2876 #     - destination = the directory to unpack the archive to.
2877 #     - excludes    = diff patterns to exclude files or directories from the patch
2879 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2881 .PHONY: %(mmake)
2883 ifneq (%(excludes),)
2884     %(mmake)-exclude := -X ./exclude.patterns
2885 endif
2887 ifneq (%(srcdir),)
2888     %(mmake)-srcdir := %(srcdir)
2889 else
2890     %(mmake)-srcdir := %(archive)
2891 endif
2894 %(mmake):
2895         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2896         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2897         cd %(destination)/tmp ; \
2898         $(FOR) f in %(excludes) ; do \
2899             $(ECHO) $$f >> ./exclude.patterns ; \
2900         done ; \
2901         diff -ruN $(%(mmake)-exclude) \
2902             $(%(mmake)-srcdir) \
2903             $(%(mmake)-srcdir).aros \
2904             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2905         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2906         $(RM) %(destination)/tmp
2907 %end
2908 #------------------------------------------------------------------------------
2911 #------------------------------------------------------------------------------
2912 # Joins the features of %fetch and %build_with_configure.
2914 # If a patch is provided, it *must* be named the following way:
2916 #    <package name>-<version number>-aros.diff
2918 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2919 # CD'ing into the archive's extracted directory.
2921 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2922 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2923 # to make that patch fully comprehensive.
2925 # Arguments:
2927 #    - mmake            = the meta make target.
2928 #    - package          = the GNU package name, sans version and archive format suffixes.
2929 #    - subpackage       = ???
2930 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2931 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2932 #    - version          = the package's version number, or otherwise any other version string.
2933 #                         It gets appended to the package name to form the basename of the archive.
2934 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2935 #                         version. Each one of them is tried until a matching archive is found.
2936 #                         Defaults to "tar.bz2 tar.gz".
2937 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
2938 #    - builddir         = override the location we expect to run configure/make in.
2939 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2940 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2941 #                         fetched or not. Default to no.
2942 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2943 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2944 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2945 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2946 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2947 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2948 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2949 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2950 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2951 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2952 #    - nix              = same meaning as the one for the %build_with_configure macro.
2953 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
2954 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
2956 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2957     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
2958     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2959     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2961 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2962 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2963 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2964 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2966 %(mmake)-archbase  := %(package)-%(version)
2968 ifeq (%(compiler),host)
2969     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2970 else
2971     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2972 endif
2974 ifeq (%(prefix),)
2975     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2976 else
2977     %(mmake)-prefix := %(prefix)
2978 endif
2980 ifneq (%(subpackage),)
2981     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2982 else
2983     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2984 endif
2986 ifneq (%(srcdir),)
2987     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2988 else
2989     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2990 endif
2992 ifneq (%(builddir),)
2993     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
2994 else
2995     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
2996 endif
2998 ifeq (%(patch),yes)
2999     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3000 else
3001     %(mmake)-%(subpackage)-patches_specs := ::
3002 endif
3004 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3005     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3006     archive_origins=". %(package_repo)" \
3007     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3009 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3010     archive=$(%(mmake)-%(subpackage)-archbase) \
3011     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3012     suffixes="%(suffixes)" \
3013     destination=$(%(mmake)-portdir)
3015 #MM- %(mmake) : %(mmake)-%(subpackage)
3017 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3019 %(mmake)-%(subpackage)-package-basename := \
3020     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3022 ifneq (%(create_pkg),no)
3023     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3024 endif
3026 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3027      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3028      install_env=%(install_env) use_build_env=%(use_build_env) \
3029      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3030      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3031      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3033 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3034 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3037 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3039 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3040 #that $^ and $@ have exactly the same mtime, and in that case make tries
3041 #to rebuild $@ again, which would fail because the directory where
3042 #the package got installed would not exist anymore. 
3043 #We work this around by using an if statement to manually check the mtimes.
3044 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3045         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3046         $(RM) $@ ; \
3047         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3048         mkdir -p "$(DISTDIR)/Packages" ; \
3049         mkdir -p "$(%(mmake)-prefix)" ; \
3050         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3051         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3052         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3053     fi
3054 %end
3055 #------------------------------------------------------------------------------
3058 #------------------------------------------------------------------------------
3059 # Joins the features of %fetch and %build_with_configure, taking advantage of
3060 # the naming scheme of GNU packages. GNU packages names are in the form
3062 #     <package name>-<version number>.<archive format suffix>
3064 # If a patch is provided, it *must* be named the following way:
3066 #    <package name>-<version number>-aros.diff
3068 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3069 # CD'ing into the archive's extracted directory.
3071 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3072 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3073 # to make that patch fully comprehensive.
3075 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3077 # Arguments:
3079 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3081 #    - prefix           = defaults to $(GNUDIR).
3082 #    - aros_prefix      = defaults to /GNU.
3084 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3085     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3086     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3088 GNU_REPOSITORY := gnu://
3090 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3091     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3092     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3093     patch="%(patch)" patch_repo="%(patch_repo)" \
3094     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3095     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3097 %end
3098 #------------------------------------------------------------------------------
3101 #------------------------------------------------------------------------------
3102 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3103 # that the package is a "Development" package, and as such it needs to be placed
3104 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3106 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3107 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3108 # "mmake" argument, because the metatarget is implicitely defined as
3110 #     #MM- development-%(package)
3112 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3113     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3114     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3116 #MM- development : development-%(package)
3119 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3120    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3121    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3122    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3123    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3126 postinstall-%(package)-delete-la-files:
3127         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3129 %end
3130 #------------------------------------------------------------------------------
3132 # Builds a kickstart package in PKG format
3134 # Arguments:
3136 #    - mmake   = target name
3137 #    - file    = destination file name with path
3139 # Other arguments are self-explanatory
3141 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3142     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3144 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3145 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3146 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3147 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3148 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3149 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3151 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3152 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3153 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3154 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3155 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3156 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3158 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3159     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3160 PKG_DIR   := $(dir %(file))
3163 %(mmake) : %(file)
3166 %(mmake)-quick : %(file)
3168 %(file): $(PKG_FILES) | $(PKG_DIR)
3169         @$(ECHO) Packaging $@...
3170         @$(SRCDIR)/tools/package/pkg c $@ $^
3172 %compress_file mmake=%(mmake) file=%(file)
3174 GLOB_MKDIRS += $(PKG_DIR)
3176 %end
3178 #------------------------------------------------------------------------------
3179 # Compresses %(file) with a gzip.
3180 # Good in conjunction with for example %build_prog
3182 %define compress_file mmake=/A file=/A
3184 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3187 %(mmake)-gz-quick : %(file).gz
3189 %(file).gz: %(file)
3190         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3191         @gzip -9 -f $^
3193 %end
3195 #------------------------------------------------------------------------------
3196 # Links a kickstart module in ELF format
3197 # Arguments are similar to make_package
3199 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3200     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3202 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3203 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3204 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3205 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3206 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3207 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3209 ifeq (%(startup),)
3210     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3211 else
3212     KOBJ_STARTUP := %(startup)
3213 endif
3215 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3217 TMP_LDFLAGS := %(ldflags)
3219 # Make a list of the lib files this program depends on.
3220 # In LDFLAGS remove white space between -L and directory
3221 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3222 # Filter out only the libdirs and remove -L
3223 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3224 # Add trailing /
3225 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3226 # Add normal linklib path
3227 TMP_DIRS += $(AROS_LIB)/
3228 # add lib and .a to static linklib names
3229 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3230 # search for the linklibs in the given path, ignore ones not found
3231 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3232     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3235 TMP_DIRS += $(dir %(file))
3236 ifneq (%(map),)
3237     TMP_LDFLAGS += $(GENMAP) %(map)
3238     TMP_DIRS    += $(dir %(map))
3239 endif
3241 #MM %(mmake) : %(deps)
3244 %(mmake) : %(file)
3247 %(mmake)-quick : %(file)
3249 %(file): KOBJS := $(KOBJS)
3250 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3251                     -nostdc -nosysbase -Wl,-Ur
3252 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3253 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3254         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3255         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3256         @$(STRIP) $@
3258 %compress_file mmake=%(mmake) file=%(file)
3260 GLOB_MKDIRS += $(TMP_DIRS)
3262 %end