Show an error message when a command name cannot be parsed, e.g. when it
[AROS.git] / config / make.tmpl
blob2f330267bc208d2009b9c0f63ff091f666d468cb
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 ifeq ($(findstring %(compiler),host kernel target),)
288   $(error unknown compiler %(compiler))
289 endif
290 ifeq (%(compiler),target)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
297 endif
298 ifeq (%(compiler),host)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
305 endif
306 ifeq (%(compiler),kernel)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
313 endif
315 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
319 ifeq (%(dflags),)
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
324   endif
325 else
326   ifeq (%(nix),yes)
327     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
328   else
329     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
330   endif
331 endif
332 $(TMP_TARGETBASE).d : %(basename).c
333         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
334 %end
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile a C++ source file to an object file and generate
340 # the dependency file. Basename may contain a directory part, then the source
341 # file has to be in that directory. The generated file will be put in the
342 # object directory without the directory.
343 # options
344 # - basename: the basename of the file to compile. Use % for a wildcard rule
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 #   the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 #   it is put in the same directory as the .c file
350 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
352 ifeq (%(targetdir),)
353   TMP_TARGETBASE := %(basename)
354 else
355   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
356 endif
358 # Adjust compiler flags to suit C++
359 TMP_CXXFLAGS := %(cflags)
360 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
361 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
363 ifeq ($(findstring %(compiler),host kernel target),)
364   $(error unknown compiler %(compiler))
365 endif
366 ifeq (%(compiler),target)
367 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
368 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
369 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
370 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
373 endif
374 ifeq (%(compiler),host)
375 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
376 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
377 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
378 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
381 endif
382 ifeq (%(compiler),kernel)
383 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
384 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
387 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
388 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
392 $(TMP_TARGETBASE).o : %(basename).cpp
393         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396   ifeq (%(nix),yes)
397     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
398   else
399     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
400   endif
401 else
402   ifeq (%(nix),yes)
403     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
404   else
405     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
406   endif
407 endif
408 $(TMP_TARGETBASE).d : %(basename).cpp
409         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
410 %end
411 #------------------------------------------------------------------------------
414 #------------------------------------------------------------------------------
415 # Generate a rule to compile multiple C source files to an object file and
416 # generate the corresponding dependency files. The generated file will be put
417 # in the object directory without the directory part of the source file.
418 # options
419 # - basenames: the basenames of the files to compile. The names may include
420 #   relative or absolute path names. No wildcard is allowed
421 # - cflags (default $(CFLAGS)): the C flags to use for compilation
422 # - dflags: the flags used during creation of dependency file. If not specified
423 #   the same value as cflags will be used
424 # - targetdir: the directory to put the .o file and the .d file. By default
425 #   it is put in the same directory as the .c file. When targetdir is not
426 #   empty, path names will be stripped from the file names so that all files
427 #   are in that dir and not in subdirectories.
428 # - compiler (default target): compiler to use, target, kernel or host
429 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
430     compiler=target
432 ifeq (%(targetdir),)
433 TMP_TARGETS := $(addsuffix .o,%(basenames))
434 TMP_DTARGETS := $(addsuffix .d,%(basenames))
435 TMP_WILDCARD := %
436 else
437 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
438 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
439 TMP_WILDCARD := %(targetdir)/%
441 # Be sure that all .c files are generated
442 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
444 # Be sure that all .c files are found
445 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
446 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
447 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
448 ifneq ($(TMP_DIRS),)
449     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
450     vpath %.c $(TMP_DIRS)
451 endif
453 endif
455 ifeq ($(findstring %(compiler),host kernel target),)
456   $(error unknown compiler %(compiler))
457 endif
458 ifeq (%(compiler),target)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
460 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
462 endif
463 ifeq (%(compiler),host)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
467 endif
468 ifeq (%(compiler),kernel)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
471 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
472 endif
474 $(TMP_TARGETS) : CFLAGS := %(cflags)
475 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
476         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
478 ifeq (%(dflags),)
479 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
480 else
481 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
482 endif
483 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
484         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
485 %end
486 #------------------------------------------------------------------------------
489 #------------------------------------------------------------------------------
490 # Generate a rule to compile multiple C++ source files to an object file and
491 # generate the corresponding dependency files. The generated file will be put
492 # in the object directory without the directory part of the source file.
493 # options
494 # - basenames: the basenames of the files to compile. The names may include
495 #   relative or absolute path names. No wildcard is allowed. basenames will be 
496 #   matched to supported AROS_CXXEXTS.
497 # - cflags (default $(CFLAGS)): the C flags to use for compilation
498 # - dflags: the flags used during creation of dependency file. If not specified
499 #   the same value as cflags will be used
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 #   it is put in the same directory as the .c file. When targetdir is not
502 #   empty, path names will be stripped from the file names so that all files
503 #   are in that dir and not in subdirectories.
504 # - compiler (default target): compiler to use, target, kernel or host
505 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
506     targetdir= compiler=target
508 # Adjust compiler flags to suit C++
509 TMP_CXXFLAGS := %(cflags)
510 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
511 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
513 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
514 ifneq ($(TMP_CXXABSBASENAMES),)
515 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
517 # Identify the "real" c++ files from the passed in basenames
518 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
520 ifeq (%(targetdir),)
521   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
522   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
523   TMP_WILDCARD := %
524 else
525   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
526   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
527   TMP_WILDCARD := %(targetdir)/%
529   # Be sure that all source files are generated
530   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
531 endif
533 ifeq ($(findstring %(compiler),host kernel target),)
534   $(error unknown compiler %(compiler))
535 endif
536 ifeq (%(compiler),target)
537   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_CFLAGS)
538   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
539   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
540 endif
541 ifeq (%(compiler),host)
542   TMP_CXXCMD:=$(HOST_CXX)
543   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
544   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
545 endif
546 ifeq (%(compiler),kernel)
547   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
548   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
549   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
550 endif
552 ifeq (%(dflags),)
553   TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
554 else
555   ifeq (%(dflags),%(cflags))
556     TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
557   else
558     TMP_CXXDFLAGS:=%(dflags)
559   endif
560 endif
562 define cxx_multi_recipe_template
563  $(1).o : $(2)
564         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
566  $(1).d : $(2)
567         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
568 endef
569 ifeq (%(targetdir),)
570   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
571 else
572   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
573 endif
574 endif
575 %end
576 #------------------------------------------------------------------------------
579 #------------------------------------------------------------------------------
580 # Generate a rule to compile an ObjC source file to an object file and generate
581 # the dependency file. Basename may contain a directory part, then the source
582 # file has to be in that directory. The generated file will be put in the
583 # object directory without the directory.
584 # options
585 # - basename: the basename of the file to compile. Use % for a wildcard rule
586 # - cflags (default $(CFLAGS)): the C flags to use for compilation
587 # - dflags: the flags used during creation of dependency file. If not specified
588 #   the same value as cflags will be used
589 # - targetdir: the directory to put the .o file and the .d file. By default
590 #   it is put in the same directory as the .m file
591 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
593 ifeq (%(targetdir),)
594   TMP_TARGETBASE := %(basename)
595 else
596   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
597 endif
599 # Adjust compiler flags to suit ObjC
600 TMP_OBJCFLAGS := %(cflags)
601 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
602 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
604 ifeq ($(findstring %(compiler),host kernel target),)
605   $(error unknown compiler %(compiler))
606 endif
607 ifeq (%(compiler),target)
608 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
609 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
610 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
611 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
612 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
613 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
614 endif
615 ifeq (%(compiler),host)
616 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
617 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
618 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
619 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
622 endif
623 ifeq (%(compiler),kernel)
624 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
625 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
626 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
627 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
628 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
629 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
630 endif
632 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
633 $(TMP_TARGETBASE).o : %(basename).m
634         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
636 ifeq (%(dflags),)
637   ifeq (%(nix),yes)
638     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
639   else
640     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
641   endif
642 else
643   ifeq (%(nix),yes)
644     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
645   else
646     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
647   endif
648 endif
649 $(TMP_TARGETBASE).d : %(basename).m
650         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
651 %end
652 #------------------------------------------------------------------------------
654 #------------------------------------------------------------------------------
655 # Generate a rule to compile multiple ObjC source files to an object file and
656 # generate the corresponding dependency files. The generated file will be put
657 # in the object directory without the directory part of the source file.
658 # options
659 # - basenames: the basenames of the files to compile. The names may include
660 #   relative or absolute path names. No wildcard is allowed
661 # - cflags (default $(CFLAGS)): the C flags to use for compilation
662 # - dflags: the flags used during creation of dependency file. If not specified
663 #   the same value as cflags will be used
664 # - targetdir: the directory to put the .o file and the .d file. By default
665 #   it is put in the same directory as the .m file. When targetdir is not
666 #   empty, path names will be stripped from the file names so that all files
667 #   are in that dir and not in subdirectories.
668 # - compiler (default target): compiler to use, target, kernel or host
669 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
670     targetdir= compiler=target
672 # Adjust compiler flags to suit ObjC
673 TMP_OBJCFLAGS := %(cflags)
674 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
675 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
677 ifeq (%(targetdir),)
678   TMP_TARGETS := $(addsuffix .o,%(basenames))
679   TMP_DTARGETS := $(addsuffix .d,%(basenames))
680   TMP_WILDCARD := %
681 else
682   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
683   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
684   TMP_WILDCARD := %(targetdir)/%
686   # Be sure that all .m files are generated
687   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
689   # Be sure that all .m files are found
690   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
691   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
692   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
693   ifneq ($(TMP_DIRS),)
694     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
695     vpath %.m $(TMP_DIRS)
696   endif
697 endif
699 # Define the use of cross compiler
700 ifeq ($(TARGET_OBJC),)
701   TMP_CC := $(TARGET_CC)
702 else
703   TMP_CC := $(TARGET_OBJC)
704 endif
706 ifeq ($(findstring %(compiler),host kernel target),)
707   $(error unknown compiler %(compiler))
708 endif
709 ifeq (%(compiler),target)
710   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
711   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
712   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
713 endif
714 ifeq (%(compiler),host)
715   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
716   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
717   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
718 endif
719 ifeq (%(compiler),kernel)
720   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
721   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
722   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
723 endif
725 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
726 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
727         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
729 ifeq (%(dflags),)
730   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
731 else
732   ifeq (%(dflags),%(cflags))
733     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
734   else
735     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
736   endif
737 endif
738 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
739         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
740 %end
741 #------------------------------------------------------------------------------
744 #------------------------------------------------------------------------------
745 # Make an alias from one arch specific build to another arch.
746 # arguments:
747 # - mainmmake: the mmake of the module in the main tree
748 # - arch: the current arch
749 # - alias: the alias to which this should point
750 %define rule_archalias mainmmake=\A arch=\A alias=\A
752 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
753 %end
754 #------------------------------------------------------------------------------
757 #------------------------------------------------------------------------------
758 # Generate a rule to assemble a source file to an object file. Basename may
759 # contain a directory part, then the source file has to be in that directory.
760 # The generated file will be put in the object directory without the directory.
761 # options
762 # - basename: the basename of the file to compile. Use % for a wildcard rule
763 # - flags (default $(AFLAGS)): the asm flags to use for assembling
764 # - targetdir: the directory to put the .o file in. By default it is put in the
765 #   same directory as the .s file
766 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
768 ifeq (%(targetdir),)
769 %(basename).o : AFLAGS := %(aflags)
770 %(basename).o : %(basename).s
771         %assemble_q
772 %(basename).o : %(basename).S
773         %assemble_q
775 else
776 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
777 %(targetdir)/$(notdir %(basename)).o : %(basename).s
778         %assemble_q
779 %(targetdir)/$(notdir %(basename)).o : %(basename).S
780         %assemble_q
782 endif
783 %end
784 #------------------------------------------------------------------------------
787 #------------------------------------------------------------------------------
788 # Generate a rule to assemble multiple source files to an object file. The
789 # generated file will be put in the object directory with the directory part
790 # of the source file stripped off.
791 # options
792 # - basenames: the basenames of the files to compile. The names may include
793 #   relative or absolute path names. No wildcard is allowed
794 # - aflags (default $(AFLAGS)): the flags to use for assembly
795 # - targetdir: the directory to put the .o file and the .d file. By default
796 #   it is put in the same directory as the .c file. When targetdir is not
797 #   empty, path names will be stripped from the file names so that all files
798 #   are in that dir and not in subdirectories.
799 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
801 ifeq (%(targetdir),)
802 TMP_TARGETS := $(addsuffix .o,%(basenames))
803 TMP_WILDCARD := %
804 else
805 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
806 TMP_WILDCARD := %(targetdir)/%
808 # Be sure that all .s files are generated
809 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
811 # Be sure that all .c files are found
812 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
813 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
814 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
815 ifneq ($(TMP_DIRS),)
816     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
817     vpath %%(suffix) $(TMP_DIRS)
818 endif
820 endif
822 ifeq ($(findstring %(compiler),host kernel target),)
823   $(error unknown compiler %(compiler))
824 endif
825 ifeq (%(compiler),target)
826 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
827 endif
828 ifeq (%(compiler),host)
829 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
830 endif
831 ifeq (%(compiler),kernel)
832 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
833 endif
835 $(TMP_TARGETS) : AFLAGS := %(aflags)
836 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
837         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
838 %end
839 #------------------------------------------------------------------------------
842 #------------------------------------------------------------------------------
843 # Link %(objs) to %(prog) using the libraries in %(uselibs)
844 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
845     usehostlibs= usestartup=yes detach=no nix=no linker=target
847 TMP_EXTRA_LDFLAGS := 
848 TMP_EXTRA_LIBS :=
849 ifeq (%(nix),yes)
850     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
851 endif
852 ifeq (%(usestartup),no)
853     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
854     ifeq (%(linker),target)
855         TMP_EXTRA_LDFLAGS += -nostdc
856         TMP_EXTRA_LIBS += libinit autoinit
857     endif
858 endif
859 ifeq (%(detach),yes)
860     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
861 endif
863 # Make a list of the lib files this program depends on.
864 # In LDFLAGS remove white space between -L and directory
865 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
866 # Filter out only the libdirs and remove -L
867 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
868 # Add trailing /
869 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
870 # Add normal linklib path
871 TMP_DIRS += $(AROS_LIB)/
872 # add lib and .a to static linklib names
873 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
874 ifeq (%(usestartup),yes)
875     TMP_LIBS += startup.o
876 endif
877 ifeq (%(detach),yes)
878     TMP_LIBS += detach.o
879 endif
880 # search for the linklibs in the given path, ignore ones not found
881 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
882     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
885 ifeq (%(linker),target)
886 %(prog) : CMD:=$(TARGET_CC)
887 %(prog) : STRIPCMD:=$(TARGET_STRIP)
888 endif
889 ifeq (%(linker),host)
890 %(prog) : CMD:=$(HOST_CC)
891 %(prog) : STRIPCMD:=$(HOST_STRIP)
892 endif
893 ifeq (%(linker),kernel)
894 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
895 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
896 endif
898 %(prog) : OBJS := %(objs)
899 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
900 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
901 %(prog) : %(objs) $(TMP_DEPLIBS)
902         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
903 %end
904 #------------------------------------------------------------------------------
907 #------------------------------------------------------------------------------
908 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
909 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
910 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
911     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
912     usestartup=yes detach=no
914 TMP_EXTRA_LDFLAGS := 
915 TMP_EXTRA_LIBS :=
916 ifeq (%(nix),yes)
917     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
918 endif
919 ifeq (%(usestartup),no)
920     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
921     TMP_EXTRA_LIBS += libinit autoinit
922 endif
923 ifeq (%(detach),yes)
924     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
925 endif
927 # Make a list of the lib files the programs depend on.
928 # In LDFLAGS remove white space between -L and directory
929 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
930 # Filter out only the libdirs and remove -L
931 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
932 # Add trailing /
933 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
934 # Add normal linklib path
935 TMP_DIRS += $(AROS_LIB)/
936 # add lib and .a to static linklib names
937 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
938 # search for the linklibs in the given path, ignore ones not found
939 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
940     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
942 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
944 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
945 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
946 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
947         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
948 %end
949 #------------------------------------------------------------------------------
952 #------------------------------------------------------------------------------
953 # Link the %(objs) to the library %(libdir)/lib%(libname).a
954 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
956 ifeq (%(linker),target)
957 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
958 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
959 endif
960 ifeq (%(linker),host)
961 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
962 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
963 endif
964 ifeq (%(linker),kernel)
965 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
966 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
967 endif
969 %(libdir)/lib%(libname).a : %(objs)
970         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
971 %end
972 #------------------------------------------------------------------------------
974 #------------------------------------------------------------------------------
975 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
976 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
977 # The -nostdc flag is added so that modules are not linked with stdc.library,
978 # stdcio.library or posixc.library
979 # (see /config/specs.in file)
980 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
981     cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
983 TMP_LDFLAGS  := %(ldflags)
984 # Make a list of the lib files the programs depend on.
985 # In LDFLAGS remove white space between -L and directory
986 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
987 # Filter out only the libdirs and remove -L
988 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
989 # Add trailing /
990 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
991 # Add normal linklib path
992 TMP_DIRS += $(AROS_LIB)/
993 # add lib and .a to static linklib names
994 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
995 # search for the linklibs in the given path, ignore ones not found
996 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
997     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1000 %(module) : LIB_NAMES := %(uselibs)
1001 %(module) : OBJS := %(objs)
1002 %(module) : ENDTAG := %(endobj)
1003 %(module) : ERR := %(err)
1004 %(module) : OBJDIR := %(objdir)
1005 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1006 ifeq (%(usehostlibs),)
1007 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1008 else
1009 # Warning: the -L/usr/lib here can result in modules
1010 # linking against host libs instead of AROS libs (e.g stdc++) !!
1011 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1012                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1013 endif 
1014 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1015         %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1017 %end
1018 #------------------------------------------------------------------------------
1021 #------------------------------------------------------------------------------
1022 # Generate the libdefs.h include file for a module.
1023 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1025 TMP_TARGET := %(modname)_libdefs.h
1026 TMP_DEPS := $(GENMODULE)
1027 TMP_OPTS := 
1028 ifneq (%(conffile),)
1029     ifeq ($(dir %(conffile)),./)
1030         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1031         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1032     else
1033         TMP_OPTS += -c %(conffile)
1034         TMP_DEPS += %(conffile)
1035     endif 
1036 else
1037     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1038     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1039 endif
1040 ifneq (%(modsuffix),)
1041     TMP_OPTS += -s %(modsuffix)
1042 endif
1043 ifneq (%(targetdir),)
1044     TMP_OPTS += -d %(targetdir)
1045     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1046 endif
1047 ifneq (%(version),)
1048     TMP_OPTS += -v %(version)
1049 endif
1051 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1052 $(TMP_TARGET) : MODNAME := %(modname)
1053 $(TMP_TARGET) : MODTYPE := %(modtype)
1054 $(TMP_TARGET) : $(TMP_DEPS)
1055         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1056         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1057 %end
1058 #------------------------------------------------------------------------------
1060 #------------------------------------------------------------------------------
1061 # Generate the _lib.fd file for a module.
1062 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1064 TMP_TARGET := %(modname)_lib.fd
1065 TMP_DEPS := $(GENMODULE)
1066 TMP_OPTS := 
1067 ifneq (%(conffile),)
1068     ifeq ($(dir %(conffile)),./)
1069         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1070         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1071     else
1072         TMP_OPTS += -c %(conffile)
1073         TMP_DEPS += %(conffile)
1074     endif 
1075 else
1076     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1077     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1078 endif
1079 ifneq (%(modsuffix),)
1080     TMP_OPTS += -s %(modsuffix)
1081 endif
1082 ifneq (%(targetdir),)
1083     TMP_OPTS += -d %(targetdir)
1084     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1085 endif
1087 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1088 $(TMP_TARGET) : MODNAME := %(modname)
1089 $(TMP_TARGET) : MODTYPE := %(modtype)
1090 $(TMP_TARGET) : $(TMP_DEPS)
1091         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1092         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1093 %end
1094 #------------------------------------------------------------------------------
1096 #------------------------------------------------------------------------------
1097 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1098 # generated file in this Makefile
1099 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1100     targetdir=
1102 TMP_TARGET := Makefile.%(modname)%(modtype)
1103 TMP_DEPS := $(GENMODULE)
1104 TMP_OPTS := 
1105 ifneq (%(conffile),)
1106     ifeq ($(dir %(conffile)),./)
1107         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1108         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1109     else
1110         TMP_OPTS += -c %(conffile)
1111         TMP_DEPS += %(conffile)
1112     endif 
1113 else
1114     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1115     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1116 endif
1117 ifneq (%(modsuffix),)
1118     TMP_OPTS += -s %(modsuffix)
1119 endif
1120 ifneq (%(targetdir),)
1121     TMP_OPTS += -d %(targetdir)
1122     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1123 endif
1125 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1126 $(TMP_TARGET) : MODNAME := %(modname)
1127 $(TMP_TARGET) : MODTYPE := %(modtype)
1128 $(TMP_TARGET) : $(TMP_DEPS)
1129         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1130 %end
1131 #------------------------------------------------------------------------------
1134 #------------------------------------------------------------------------------
1135 # Generate the support files for compiling a module. This includes include
1136 # files and source files. This rule has to be preceeded by
1137 # %rule_genmodule_makefile
1138 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1139     conffile=
1141 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1142                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1143 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1144                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1146 TMP_DEPS := $(GENMODULE)
1147 TMP_OPTS :=
1149 ifneq (%(conffile),)
1150     ifeq ($(dir %(conffile)),./)
1151         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1152         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1153     else
1154         TMP_OPTS += -c %(conffile)
1155         TMP_DEPS += %(conffile)
1156     endif 
1157 else
1158     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1159     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1160 endif
1161 ifneq (%(modsuffix),)
1162     TMP_OPTS += -s %(modsuffix)
1163 endif
1164 ifneq (%(targetdir),)
1165     TMP_OPTS += -d %(targetdir)
1166     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1167     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1168 endif
1170 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1171 $(TMP_TARGETS) : MODNAME := %(modname)
1172 $(TMP_TARGETS) : MODTYPE := %(modtype)
1173 $(TMP_TARGETS) : $(TMP_DEPS)
1174         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1175 ifneq (%(conffile),lib.conf)
1176         @$(IF) $(TEST) -f lib.conf; then \
1177           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1178         fi
1179 endif
1180         @$(IF) $(TEST) -f libdefs.h; then \
1181           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1182         fi
1183         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1184 %end
1185 #------------------------------------------------------------------------------
1188 #------------------------------------------------------------------------------
1189 # Generate the support files for compiling a module. This includes include
1190 # files and source files.
1191 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1192     targetdir= conffile=
1194 ifneq ($(%(modname)_INCLUDES),)
1195 TMP_TARGETS := $(%(modname)_INCLUDES)
1197 TMP_DEPS := $(GENMODULE)
1198 TMP_OPTS :=
1200 ifneq (%(conffile),)
1201     ifeq ($(dir %(conffile)),./)
1202         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1203         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1204     else
1205         TMP_OPTS += -c %(conffile)
1206         TMP_DEPS += %(conffile)
1207     endif 
1208 else
1209     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1210     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1211 endif
1212 ifneq (%(modsuffix),)
1213     TMP_OPTS += -s %(modsuffix)
1214 endif
1215 ifneq (%(targetdir),)
1216     TMP_OPTS += -d %(targetdir)
1217     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1218 endif
1220 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1221 $(TMP_TARGETS) : MODNAME := %(modname)
1222 $(TMP_TARGETS) : MODTYPE := %(modtype)
1223 $(TMP_TARGETS) : $(TMP_DEPS)
1224         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1225         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1226 endif
1227 %end
1228 #------------------------------------------------------------------------------
1230 #------------------------------------------------------------------------------
1231 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1232 # 'start' is an optional starting address
1233 # 'ldflags' is optional additional flags for the linker
1234 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1236 BD_OUTDIR := $(dir %(file))
1237 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1238 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1239 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1240 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1241 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1242 BD_OBJS += %(objs)
1244 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1246 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1247         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1248         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1249         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1251 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1252     GLOB_MKDIRS += $(BD_OUTDIR)
1253 endif
1255 %end
1257 #------------------------------------------------------------------------------
1258 # Common rules for all makefiles
1259 %define common
1260 # Delete generated makefiles
1262 clean ::
1263         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1265 include $(SRCDIR)/config/make.tail
1267 BDID := $(BDTARGETID)
1268 %end
1269 #------------------------------------------------------------------------------
1270       
1272 #############################################################################
1273 #############################################################################
1274 ##                                                                         ##
1275 ## Here are the mmakefile build macros. These are macros that takes care   ##
1276 ## of everything to go from the sources to the generated target. Also all  ##
1277 ## intermediate files and directories that are needed are created by these ##
1278 ## rules.                                                                  ##
1279 ##                                                                         ##
1280 #############################################################################
1281 #############################################################################
1283 #------------------------------------------------------------------------------
1284 # Build a program
1285 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1286     objcfiles= \
1287     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1288     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1289     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1290     compiler=target linker=
1292 .PHONY : %(mmake)
1294 BD_PROGNAME  := %(progname)
1295 BD_OBJDIR    := %(objdir)
1296 BD_TARGETDIR := %(targetdir)
1297 BD_LINKER    := %(linker)
1299 # If not supplied, linker is equal to compiler
1300 ifeq ($(BD_LINKER),)
1301     BD_LINKER := %(compiler)
1302 endif
1304 BD_FILES     := %(files)
1305 BD_OBJCFILES := %(objcfiles)
1306 BD_ASMFILES  := %(asmfiles)
1307 BD_CXXFILES := %(cxxfiles)
1309 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1310 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1311 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1313 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1314 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1315 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1317 BD_CFLAGS    := %(cflags)
1318 BD_AFLAGS    := %(aflags)
1319 BD_DFLAGS    := %(dflags)
1320 BD_LDFLAGS   := %(ldflags)
1323 %(mmake)-quick : %(mmake)
1325 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1326 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1328 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1329 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1330     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1331 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1332     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1333 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1334     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1335 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1336     aflags=$(BD_AFLAGS) compiler=%(compiler)
1338 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1339     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1340     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1341     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1342     linker=$(BD_LINKER)
1344 endif
1346 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1348 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1349 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1350 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1352 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1354 %(mmake)-clean ::
1355         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1356         @$(RM) $(FILES)
1358 %end
1359 #------------------------------------------------------------------------------
1362 #------------------------------------------------------------------------------
1363 # Build programs, for every C file an executable will be built with the same
1364 # name as the C file
1365 %define build_progs mmake=/A files=/A nix=no \
1366     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1367     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1368     uselibs= usehostlibs= usestartup=yes detach=no
1370 .PHONY : %(mmake)
1372 BD_OBJDIR    := %(objdir)
1373 BD_TARGETDIR := %(targetdir)
1375 BD_FILES     := %(files)
1376 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1377 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1378 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1380 BD_CFLAGS    := %(cflags)
1381 BD_DFLAGS    := %(dflags)
1382 BD_LDFLAGS   := %(ldflags)
1385 %(mmake)-quick : %(mmake)
1387 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1388 %(mmake) : $(BD_EXES)
1390 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1391 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1392     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1394 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1395     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1396     ldflags=$(BD_LDFLAGS) \
1397     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1398     usestartup="%(usestartup)" detach="%(detach)"
1400 endif
1402 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1404 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1405 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1406 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1408 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1410 %(mmake)-clean ::
1411         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1412         @$(RM) $(FILES)
1414 %end
1415 #------------------------------------------------------------------------------
1418 #------------------------------------------------------------------------------
1419 # Build a module.
1420 # This is a bare version: It just compiles and links the given files. It is
1421 # assumed that all needed boiler plate code is in the files. This should only
1422 # be used for compiling external code. For AROS code use %build_module
1423 %define build_module_simple mmake=/A modname=/A modtype=/A \
1424     files="$(basename $(call WILDCARD, *.c))" \
1425     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1426     objdir=$(OBJDIR) moduledir= \
1427     uselibs= usehostlibs= compiler=target
1429 # Define metamake targets and their dependencies
1430 #MM %(mmake) : core-linklibs includes-generate-deps
1431 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1432 #MM %(mmake)-kobj-quick
1433 #MM %(mmake)-quick
1434 #MM %(mmake)-clean
1436 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1438 .PHONY : $(BD_ALLTARGETS)
1440 ifeq (%(modname),)
1441 $(error using %build_module_simple: modname may not be empty)
1442 endif
1443 ifeq (%(modtype),)
1444 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1445 endif
1447 # Default values for variables and arguments
1448 BD_DEFLINKLIBNAME := %(modname)
1449 BD_DEFDFLAGS := %(cflags)
1450 OBJDIR ?= $(GENDIR)/$(CURDIR)
1451 BD_MODDIR := %(moduledir)
1452 ifeq ($(BD_MODDIR),)
1453   ifeq (%(modtype),library)
1454     BD_MODDIR  := $(AROS_LIBRARIES)
1455   endif
1456   ifeq (%(modtype),gadget)
1457     BD_MODDIR  := $(AROS_GADGETS)
1458   endif
1459   ifeq (%(modtype),datatype)
1460     BD_MODDIR  := $(AROS_DATATYPES)
1461   endif
1462   ifeq (%(modtype),handler)
1463     BD_MODDIR  := $(AROS_FS)
1464   endif
1465   ifeq (%(modtype),device)
1466     BD_MODDIR  := $(AROS_DEVS)
1467   endif
1468   ifeq (%(modtype),resource)
1469     BD_MODDIR  := $(AROS_RESOURCES)
1470   endif
1471   ifeq (%(modtype),hook)
1472     BD_MODDIR  := $(AROS_RESOURCES)
1473   endif
1474   ifeq (%(modtype),mui)
1475     BD_MODDIR  := $(AROS_CLASSES)/Zune
1476   endif
1477   ifeq (%(modtype),mcc)
1478     BD_MODDIR  := $(AROS_CLASSES)/Zune
1479   endif
1480   ifeq (%(modtype),mcp)
1481     BD_MODDIR  := $(AROS_CLASSES)/Zune
1482   endif
1483   ifeq (%(modtype),usbclass)
1484     BD_MODDIR  := $(AROS_CLASSES)/USB
1485   endif
1486   ifeq (%(modtype),hidd)
1487     BD_MODDIR  := $(AROS_DRIVERS)
1488   endif
1489   ifeq (%(modtype),printer)
1490     BD_MODDIR  := $(AROS_PRINTERS)
1491   endif
1492 endif
1493 ifeq ($(BD_MODDIR),)
1494   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1495 endif
1497 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1498 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1499 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1501 %rule_compile_multi \
1502     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1503     cflags="%(cflags)" dflags="%(dflags)" \
1504     compiler=%(compiler)
1506 # Handlers use dash instead of dot in their names
1507 ifeq (%(modtype),handler)
1508 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1509 else
1510 ifeq (%(modtype),printer)
1511 BD_MODULE := $(BD_MODDIR)/%(modname)
1512 else
1513 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1514 endif
1515 endif
1516 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1518 %(mmake)-quick : %(mmake)
1519 %(mmake)-kobj-quick : $(BD_KOBJ)
1520 %(mmake)       : $(BD_MODULE)
1521 %(mmake)-kobj  : $(BD_KOBJ)
1523 # The module is linked from all the compiled .o files
1524 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1526 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1527 # This breaks con-handler build. Here we work around this
1528 ifeq (%(modname),con)
1529     BD_ERR := $(notdir $(BD_MODULE)).err
1530 else
1531     BD_ERR := %(modname).err
1532 endif
1534 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1535                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1536                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1537                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1539 # Link kernel object file
1540 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1542 # Make these symbols local
1543 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1544             UtilityBase ExpansionBase KeymapBase KernelBase
1546 BD_SYMBOLS := $(BD_KBASE)
1548 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1549 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1550 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1551 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1552 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1553 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1554         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1555         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1556         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1559 ## Dependency fine-tuning
1561 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1562 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1564 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1565 $(BD_MODULE) : | $(BD_MODDIR)
1566 $(BD_KOBJ) : | $(KOBJSDIR)
1567 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1569 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1570 %(mmake)-clean ::
1571         @$(ECHO) "Cleaning up for module %(modname)"
1572         @$(RM) $(FILES)
1573 %end
1574 #------------------------------------------------------------------------------
1577 #------------------------------------------------------------------------------
1578 # Build a module - core routine
1579 # Explanation of this macro is done in the developer's manual
1580 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1581   files="$(basename $(call WILDCARD, *.c))" \
1582   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1583   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1584   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1585   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1586   compiler=target nostartup=yes archspecific=no \
1587   build_abi= build_library=
1589 # We will employ a terrifying, but unavoidable, hack here.
1590 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1591 # ignores GNU Make ifeq() statements, but will process any #MM
1592 # headed lines in the file.
1594 # So, to make the following #MM lines conditional on whether we want
1595 # to build the ABI, Library, or both, we define build_abi= and 
1596 # build_library as 'M' to enable, or '' to disable, which allows genmf
1597 # to do the following conversions:
1599 #  #%(build_abi)M includes-foo: foo-include
1600 #    becomes, when build_abi=M
1601 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1602 #    but, when build_abi= ...
1603 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1605 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1607 # Define metamake targets and their dependencies
1608 #MM %(mmake)
1609 #MM %(mmake)-quick
1610 #MM %(mmake)-makefile
1611 #MM %(mmake)-clean
1613 # ABI targets:
1614 #M%(build_abi)- includes-all : %(mmake)-includes
1615 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1616 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1617 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1618 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1619 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1620 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1621 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1622 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1623 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1624 #M%(build_abi) %(mmake)-includes-quick
1625 #M%(build_abi) %(mmake)-includes-dirs
1626 #M%(build_abi) %(mmake)-fd
1628 # Library targets
1629 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1630 #%(build_library)M %(mmake)-kobj-quick : 
1632 # Library with ABI targets:
1633 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1634 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1636 # All MetaMake targets defined by this macro
1637 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1639 ifeq (%(build_library),M)
1640 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1641 endif
1643 ifeq (%(build_abi),M)
1644 BD_ALLTARGETS += %(mmake)-includes \
1645                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1646                  %(mmake)-linklib %(mmake)-fd
1647 endif
1649 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1651 ifeq (%(modname),)
1652 $(error using %build_module: modname may not be empty)
1653 endif
1654 ifeq (%(modtype),)
1655 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1656 endif
1658 # Default values for variables and arguments
1659 BD_DEFLINKLIBNAME := %(modname)
1660 BD_DEFDFLAGS := %(cflags)
1661 OBJDIR ?= $(GENDIR)/$(CURDIR)
1663 ## Create genmodule include Makefile for the module
1665 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1667 %rule_genmodule_makefile \
1668     modname=%(modname) modtype=%(modtype) \
1669     modsuffix=%(modsuffix) targetdir=%(objdir) \
1670     conffile=%(conffile)
1672 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1674 GLOB_MKDIRS += %(objdir)
1676 # Do not parse these statements if metatarget is not appropriate
1677 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1679 include %(objdir)/Makefile.%(modname)%(modtype)
1681 BD_DEFMODDIR := $(%(modname)_MODDIR)
1682 ifeq (%(archspecific),yes)
1683 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1684 endif
1687 ## include files generation
1689 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1690 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1691 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1693 ifeq (%(build_abi),M)
1694 %(mmake)-includes-quick : %(mmake)-includes
1695 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1696     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1697     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1699 ifneq ($(%(modname)_INCLUDES),)
1700 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1701                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1702                          conffile=%(conffile)
1704 %rule_copy_diff_multi \
1705     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1706     stampfile=%(objdir)/%(modname)_geninc
1708 %rule_copy_diff_multi \
1709     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1710     stampfile=%(objdir)/%(modname)_incs
1712 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1714 TMP%(modname)_INCDIRS := \
1715     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1716     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1717     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1718 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1720 endif
1722 endif
1724 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1725                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1726                            conffile=%(conffile) version=%(version)
1728 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1729 $(BD_DEFLIBDEFSINC) :
1730         @$(ECHO) "Generating $@"
1731         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1733 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1734 GLOB_MKDIRS += %(objdir)/include
1736 ## Extra genmodule src files generation
1737 ## 
1738 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1739                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1740                       conffile=%(conffile)
1743 ifeq (%(build_abi),M)
1744 ## Create FD file
1745 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1746 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1748 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1749                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1751 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1753 GLOB_MKDIRS += $(BD_FDDIR)
1754 endif
1756 ## Compilation
1758 BD_FILES      := %(files)
1759 BD_CXXFILES := %(cxxfiles)
1761 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1763 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1764 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1766 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1767 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1768 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1770 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1771 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1773 ifeq (%(modtype),library)
1774     BD_LIBSUFFIX := 
1775 else
1776     BD_LIBSUFFIX := .%(modtype)
1777 endif
1779 ifeq (%(build_abi),M)
1780 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1781 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1782 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1783     BD_LINKLIB :=
1784 else
1785     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1786     ifneq (%(modname),%(linklibname))
1787         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1788     endif
1789 endif
1790 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1792 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1793 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1794 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1795     BD_RELLINKLIB :=
1796 else
1797     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1798     ifneq (%(modname),%(linklibname))
1799         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1800     endif
1801 endif
1802 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1803 endif
1805 ifneq ($(BD_CXXFILES),)
1806 BD_LINKCMD=$(AROS_CXX)
1807 else
1808 BD_LINKCMD=$(AROS_CC)
1809 endif
1811 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1812 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1813     $(BD_RELLINKLIBCFILES)
1815 %rule_compile_multi \
1816     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1817     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1818     compiler=%(compiler)
1819 %rule_compile_multi \
1820     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1821     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1822     compiler=%(compiler)
1823 %rule_compile_cxx_multi \
1824     basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1825     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1826     compiler=%(compiler)
1828 ifneq ($(BD_LINKLIBAFILES),)
1829 %rule_assemble_multi \
1830     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1831 endif
1833 ## Linking
1835 ifeq (%(modsuffix),)
1836 BD_SUFFIX := %(modtype)
1837 else
1838 BD_SUFFIX := %(modsuffix)
1839 endif
1841 ifeq (%(build_library),M)
1842 # Handlers use dash instead of dot in their names
1843 ifeq ($(BD_SUFFIX),handler)
1844 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1845 else
1846 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1847 endif
1848 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1849 else
1850 BD_MODULE :=
1851 BD_KOBJ   :=
1852 endif
1854 %(mmake)-quick      : %(mmake)
1855 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1856 ifeq (%(build_library),M)
1857 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1858 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1859 endif
1860 ifeq (%(build_abi),M)
1861 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1862 endif
1864 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1865            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1867 ifeq (%(nostartup),yes)
1868 # Handlers always have entry point
1869 ifneq (%(modtype),handler)
1870 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1871 endif
1872 endif
1874 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1875 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1876                  %(linklibobjs)
1877 BD_RELLINKLIBOBJS \
1878               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1879                  %(linklibobjs)
1881 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1882 # This breaks con-handler build. Here we work around this
1883 ifeq (%(modname),con)
1884     BD_ERR := $(notdir $(BD_MODULE)).err
1885 else
1886     BD_ERR := %(modname).err
1887 endif
1889 ifeq (%(build_library),M)
1890 # The module is linked from all the compiled .o files
1891 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1892                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1893                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1894                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1895 endif
1897 ifeq (%(build_abi),M)
1898 # Link static lib
1899 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1900 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1901 ifneq ($(BD_LINKLIB),)
1902 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1903 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1904 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1905 endif
1907 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1908 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1909 endif
1911 ifneq ($(BD_RELLINKLIB),)
1912 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1913 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1914 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1915 endif
1917 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1918 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1919 endif
1920 endif
1922 ifeq (%(build_library),M)
1923 # Link kernel object file
1924 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1926 # Make these symbols local
1927 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1928             UtilityBase ExpansionBase KeymapBase KernelBase
1930 BD_SYMBOLS := $(BD_KBASE)
1932 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1933 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1934 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1935 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1936 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1937 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1938         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1939         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1940         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1941 endif
1943 ## Dependency fine-tuning
1945 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1947 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
1949 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1950 $(BD_MODULE) : | %(prefix)/%(moduledir)
1951 $(BD_KOBJ)   : | $(KOBJSDIR)
1952 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
1954 # Some include files need to be generated before the .c can be parsed.
1955 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
1957 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1958     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1959 $(BD_DEPS) : $(BD_DFILE_DEPS)
1960 endif
1962 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1963     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1964     %(objdir)/Makefile.%(modname)%(modtype) \
1965     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1966     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1967     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1968     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1969     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1970     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1971     $(BD_ENDOBJS)
1972 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1973 %(mmake)-clean ::
1974         @$(ECHO) "Cleaning up for module %(modname)"
1975         @$(RM) $(FILES)
1977 endif # $(TARGET) in $(BD_ALLTARGETS)
1978 %end
1979 #------------------------------------------------------------------------------
1981 #------------------------------------------------------------------------------
1982 # Build a module - ABI and library
1983 # Explanation of this macro is done in the developer's manual
1984 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1985   files="$(basename $(call WILDCARD, *.c))" \
1986   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1987   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1988   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1989   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1990   compiler=target nostartup=yes archspecific=no
1992 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
1993    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
1994    files="%(files)" cxxfiles="%(cxxfiles)" \
1995    linklibname="%(linklibname)" \
1996    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
1997    cflags="%(cflags)" dflags="%(dflags)" \
1998    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
1999    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2000    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2001    build_abi=M build_library=M
2003 %end
2004 #------------------------------------------------------------------------------
2007 #------------------------------------------------------------------------------
2008 # Build a module skeleton ABI
2009 # This is a stripped-down version of build_module, it only creates include
2010 # files and the linklibs.
2011 # This is used when for plugins or classes with the same API, but no actual
2012 # implementation here.
2013 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2014   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2015   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2016   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2017   compiler=target nostartup=yes archspecific=no
2019 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2020   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2021   linklibname="%(linklibname)" \
2022   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2023   cflags="%(cflags)" dflags="%(dflags)" \
2024   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2025   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2026   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2027   build_abi=M build_library=
2029 %end
2030 #------------------------------------------------------------------------------
2032 #------------------------------------------------------------------------------
2033 # Build a module library - no includes nor linklibs
2034 # Explanation of this macro is done in the developer's manual
2035 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2036   files="$(basename $(call WILDCARD, *.c))" \
2037   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2038   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2039   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2040   uselibs= usehostlibs= \
2041   compiler=target nostartup=yes archspecific=no
2043 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2044    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2045    files="%(files)" cxxfiles="%(cxxfiles)" \
2046    cflags="%(cflags)" dflags="%(dflags)" \
2047    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2048    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2049    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2050    build_abi= build_library=M
2052 %end
2053 #------------------------------------------------------------------------------
2057 #------------------------------------------------------------------------------
2058 # Build a linklib.
2059 # - mmake is the mmaketarget
2060 # - libname is the baselibname e.g. lib%(libname).a will be created
2061 # - files are the C source files to include in the lib. The list of files
2062 #   has to be given without the .c suffix
2063 # - cxxfiles are C++ source files without suffix.
2064 #   NB: files will be matched in the order .cpp > .cxx > .cc
2065 # - asmfiles are the asm files to include in the lib. The list of files has to
2066 #   be given without the .s suffix
2067 # - objs additional object to link into the linklib. The objects have to be
2068 #   given with full absolute path and the .o suffix.
2069 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2070 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2071 # - cflags are the flags to compile the source (default $(CFLAGS))
2072 # - dflags are the flags use during makedepend (default equal to cflags)
2073 # - aflags are the flags use during assembling (default $(AFLAGS))
2074 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2075 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2076   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2077   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2078   aflags=$(AFLAGS) compiler=target
2080 # assign and generate the local variables used in this macro
2081 BD_LIBNAME    := %(libname)
2082 BD_LINKLIB    := %(libdir)/lib%(libname).a
2084 BD_FILES      := %(files)
2085 BD_ASMFILES   := %(asmfiles)
2086 BD_CXXFILES := %(cxxfiles)
2088 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2089 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2090 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2092 BD_OBJS       := $(BD_ARCHOBJS) \
2093                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2094                  %(objs)
2095 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2097 BD_CFLAGS    := %(cflags)
2098 BD_AFLAGS    := %(aflags)
2099 BD_DFLAGS    := %(dflags)
2101 .PHONY : %(mmake) %(mmake)-clean
2103 #MM %(mmake) : includes-generate-deps
2104 %(mmake) : $(BD_LINKLIB)
2106 ifeq ($(TARGET),%(mmake))
2108 %rule_compile_multi basenames=$(BD_FILES) targetdir=%(objdir) \
2109     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2110 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2111     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2112 %rule_assemble basename=% targetdir=%(objdir) \
2113     aflags=$(BD_AFLAGS)
2115 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2116 endif
2118 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2120 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2121 $(BD_LINKLIB) : | %(libdir)
2122 GLOB_MKDIRS += %(objdir) %(libdir)
2124 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2126 %(mmake)-clean ::
2127         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2128         @$(RM) $(FILES)
2130 %end
2131 #------------------------------------------------------------------------------
2134 #------------------------------------------------------------------------------
2135 # Build catalogs.
2136 # - mmake is the mmaketarget
2137 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2138 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2139 # - subdir is the destination subdirectory of the catalogs
2140 # - name is the name of the destination catalog, without the .catalog suffix
2141 # - source is the path to the generated source code file
2142 # - dir is the base destination directory (default $(AROS_CATALOGS))
2143 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2144 # - srcdir is the directory in which the *.cd and *.ct files are searched
2146 %define build_catalogs mmake=/A name=/A subdir=/A \
2147  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2148  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2150 ifeq (%(description),)
2151 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2152 else
2153 BD_DESC := %(description)
2154 endif
2156 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2158 ifeq (%(catalogs),)
2159 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2160 else
2161 BD_LNGS := %(catalogs)
2162 endif
2164 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2165 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2168 %(mmake) : $(BD_OBJS) %(source)
2170 $(BD_OBJS) : | $(BD_DIRS)
2171 GLOB_MKDIRS += $(BD_DIRS)
2173 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2174         @$(ECHO) "Creating   %(name) catalog for language $*."
2175         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2177 ifneq (%(source),)
2178 %(source) : BD_DESC := $(BD_DESC)
2179 %(source) : BD_SRC := $(BD_SRC)
2180 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2181         @$(ECHO) "Creating   %(name) catalog source file $@"
2182         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2183 endif
2185 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2187 %(mmake)-clean ::
2188         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2189         @$(RM) $(FILES)
2191 .PHONY: %(mmake) %(mmake)-clean
2193 %end
2194 #-----------------------------------------------------------------------------
2197 #-----------------------------------------------------------------------------
2198 # Build icons.
2199 # - mmake is the mmaketarget
2200 # - icons is a list of icon base names (ie. without the .info suffix)
2201 # - dir is the destination directory
2202 # - srcdir is where *.png and *.info.src are searched
2203 #-----------------------------------------------------------------------------
2205 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2207 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2210 %(mmake) : $(BD_OBJS)
2212 ifeq (%(image),)
2214 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2215         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2216         @$(ILBMTOICON) $+ $@
2218 else
2220 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2221         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2222         @$(ILBMTOICON) $+ $@
2224 endif
2226 $(BD_OBJS) : | %(dir)
2227 GLOB_MKDIRS += %(dir)
2229 %(mmake)-clean : FILES := $(BD_OBJS)
2231 %(mmake)-clean ::
2232         @$(RM) $(FILES)
2234 .PHONY: %(mmake) %(mmake)-clean
2236 %end
2237 #-----------------------------------------------------------------------------
2240 #------------------------------------------------------------------------------
2241 # Compile files for an arch-specific replacement of code for a module
2242 # - files: the basenames of the C files to compile.
2243 # - asmfiles: the basenames of the asm files to assemble.
2244 # - mainmmake: the mmake of the module in the main directory to compile these
2245 #   arch specific files for.
2246 # - maindir: the object directory for the main module
2247 # - arch: the arch for which to compile these files. It can have the form
2248 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2249 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2250 # - dflags: the flags used during creation of dependency file. If not specified
2251 #   the same value as cflags will be used
2252 # - aflags: the flags used during assembling
2253 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2254 #   the target compiler is used
2255 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2256 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2258 ifeq (%(files) %(asmfiles),)
2259   $(error no files or asmfiles given)
2260 endif
2262 %buildid targets="%(mainmmake)-%(arch)"
2264 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2265 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2266 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2267 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2268 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2269 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2270 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2271 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2272 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2273 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2274 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2275 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2276 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2277 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2278 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2280 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2282 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2283 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2284 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2285 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2286 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2288 ifneq (%(modulename),)
2289 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2290 endif
2292 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2293     BD_TARGET := %(mainmmake)-%(arch)-quick
2294 else
2295     BD_TARGET := %(mainmmake)-%(arch)
2296 endif
2299 ifeq ($(TARGET),$(BD_TARGET))
2300 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2301 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2302 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2303 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2304 endif
2306 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2307 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2310 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2313 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2315 ifeq ($(findstring %(compiler),host kernel target),)
2316   $(error unknown compiler %(compiler))
2317 endif
2318 ifeq (%(compiler),target)
2319 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2320 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2321 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2322 endif
2323 ifeq (%(compiler),host)
2324 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2325 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2326 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2327 endif
2328 ifeq (%(compiler),kernel)
2329 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2330 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2331 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2332 endif
2333 ifneq (%(modulename),)
2334 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2335 else
2336 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2337 endif
2338 ifeq ($(TARGET),$(BD_TARGET))
2339 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2340         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2341 endif
2343 ifeq (%(dflags),)
2344 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2345 else
2346 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2347 endif
2348 ifeq ($(TARGET),$(BD_TARGET))
2349 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2350         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2351 endif
2353 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2355 ifeq ($(TARGET),$(BD_TARGET))
2356 $(BD_OBJDIR$(BDID))/%.o : %.s
2357         %assemble_q opt=$(AFLAGS)
2358 $(BD_OBJDIR$(BDID))/%.o : %.S
2359         %assemble_q opt=$(AFLAGS)
2360 endif
2362 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2363 %end
2364 #------------------------------------------------------------------------------
2367 #------------------------------------------------------------------------------
2368 # generate asm files from c files (for debugging purposes)
2369 %define ctoasm_q
2370 %.s : %.c
2371         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2372         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2373 %end
2374 #------------------------------------------------------------------------------
2377 #------------------------------------------------------------------------------
2378 # Copy files from one directory to another.
2380 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2382 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2384 GLOB_MKDIRS += %(dst)
2386 .PHONY : %(mmake)
2389 %(mmake) : | %(dst) 
2390         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2392 %end
2393 #------------------------------------------------------------------------------
2396 #------------------------------------------------------------------------------
2397 # Copy a directory recursively to another place, preserving the original 
2398 # hierarchical structure
2400 # src: the source directory whose content will be copied.
2401 # dst: the directories where to copy src's content. If not existing, they will be made.
2402 # excludefiles: files which must not be copied. Path must be relative to src.
2404 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2406 .PHONY : %(mmake)
2409 %(mmake) :
2410         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2412 %end
2413 #------------------------------------------------------------------------------
2416 #------------------------------------------------------------------------------
2417 #   Copy include files into the includes directories. There are currently
2418 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2419 #   for building tools that need to run on the host system $(GENINCDIR). The
2420 #   $(GENINCDIR) path must not contain any references to the C runtime
2421 #   library header files.
2423 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2424     dir= compiler=target
2426 ifeq ($(findstring %(compiler),host kernel target),)
2427 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2428 endif
2430 ifneq (%(dir),)
2431 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2432 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2433 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2434 else
2435 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2436 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2437 endif
2439 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2440         @$(CP) $< $@
2443 ifeq (%(compiler),target)
2445 ifneq (%(dir),)
2446 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2447 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2448 else
2449 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2450 endif
2452 BD_INCL_FILES += $(BD_INCL_FILES2)
2454 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2455         @$(CP) $< $@
2456 endif
2459 %(mmake) : $(BD_INCL_FILES)
2461 .PHONY: %(mmake)
2463 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2464 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2465 %end
2466 #------------------------------------------------------------------------------
2469 #------------------------------------------------------------------------------
2470 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2471 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2472 STUBS_MEM := $(addsuffix .o,$(STUBS))
2473 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2474 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2475 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2477 #MM- linklibs : hidd-%(hidd)-stubs
2478 #MM- %(parenttarget): hidd-%(hidd)-stubs
2479 #MM hidd-%(hidd)-stubs : includes includes-copy
2480 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2482 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2483         %mklib_q from=$^
2485 $(STUBS_OBJ) : $(STUBS_SRC) 
2486         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2488 $(STUBS_DEP) : $(STUBS_SRC)
2489         %mkdepend_q flags=%(dflags)
2491 setup ::
2492         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2495 clean ::
2496         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2498 DEPS := $(DEPS) $(STUBS_DEP)
2500 %end
2501 #------------------------------------------------------------------------------
2504 #------------------------------------------------------------------------------
2505 # Build an imported source tree which uses the configure script from the
2506 # autoconf package.  This rule will try to "integrate" the produced files as
2507 # much as possible in the AROS build, for example by putting libraries in the
2508 # standard library directory, includes in the standard include directory, and
2509 # so on. You can however override this behaviour.
2511 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2512 # be %(bindir) (or its deduced value) when running "make install", and
2513 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2514 # configure script some more parameters whose value depends upon the PROGDIR
2515 # env var, so that the program gets all its stuff installed in the proper place
2516 # when building it, but when running it from inside AROS it can also find that
2517 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2518 # the configuration parameters set when running ./configure
2520 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2521 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2522 # to the name which has to follow it.
2524 # Arguments:
2526 #     - mmake           = the meta make target.
2527 #     - package         = name of the package to be built.
2528 #     - srcdir          = the location of the unpacked source code. Defaults
2529 #                         to $(SRCDIR)/$(CURDIR).
2530 #     - prefix          = the target directory. Must be an absolute path of the
2531 #                         host system. Defaults to $(AROS_CONTRIB).
2532 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2533 #                         Defaults to the value of the prefix option.
2534 #     - extraoptions    = additional options for the configure script.
2535 #     - extracflags     = additional flags which are used for both C and C++.
2536 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2537 #                         Defaults to the value of the nix argument.
2538 #     - nix             = enable u*nix path handling, i.e. a path like
2539 #                         /progdir//./file will be translated to
2540 #                         progdir:file during run-time. Defaults to no.
2541 #     - compiler        = target, host or kernel. Defaults to target.
2542 #     - install_target  = the command used for installing. Defaults to install. Leave
2543 #                         it empty if you want to suppress installing.
2544 #     - preconfigure    = a metatarget which is executed before configure is called.
2545 #     - postconfigure   = a metatarget which is executed after configure is called.
2546 #     - postinstall     = a metatarget which is executed after installing.
2547 #     - install_env     = set additional options for installing.
2548 #     - use_build_env   = if yes the configuration environment is used for
2549 #                         installing, too. Defaults to no.
2551 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2552 # like this:
2554 # if nix_dir_layout
2555 #    --prefix = $(aros_prefix)
2556 #    progdir = $(aros_prefix)/bin
2557 # else
2558 #    if nix
2559 #        --prefix = /PROGDIR
2560 #        --bindir = /PROGDIR
2561 #        --sbindir = /PROGDIR
2562 #        --libdir = /LIB
2563 #        --includedir = /INCLUDE
2564 #        --oldincludedir = /INCLUDE   
2565 #    else
2566 #        --prefix = $(aros_prefix)
2567 #    endif
2569 #    progdir = $(aros_prefix)
2571 #    # Install options
2572 #    bindir = $(prefix)
2573 #    sbindir = $(prefix)
2574 #    libdir = $(AROS_LIB)
2575 #    includedir = $(AROS_INCLUDES)
2576 #    oldincludedir = $(AROS_INCLUDES)
2577 # endif
2580 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2581     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2582     install_target=install preconfigure= postconfigure= postinstall= \
2583     install_env= use_build_env=no
2585 ifneq (%(prefix),)
2586     %(mmake)-prefix := %(prefix)
2587 else
2588     %(mmake)-prefix := $(AROS_CONTRIB)
2589 endif
2591 ifneq (%(aros_prefix),)
2592     %(mmake)-aros_prefix := %(aros_prefix)
2593 else
2594     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2595 endif
2597 ifeq (%(nix),yes)
2598     %(mmake)-nix    := -nix
2599     %(mmake)-volpfx := /
2600     %(mmake)-volsfx := /
2601     
2602     ifeq (%(nix_dir_layout),)
2603         %(mmake)-nix_dir_layout := yes
2604     endif
2605 else
2606     %(mmake)-volsfx := :
2607     
2608     ifeq (%(nix_dir_layout),)
2609         %(mmake)-nix_dir_layout := no
2610     endif
2611 endif
2613 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2615 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2616         exec_prefix=$(%(mmake)-prefix) %(install_env)
2618 # Check if chosen compiler is valid
2619 ifeq ($(findstring %(compiler),host target kernel),)
2620   $(error unknown compiler %(compiler))
2621 endif
2623 # Set legacy 'host' variable based on chosen compiler
2624 ifeq (%(compiler),host)
2625     host := yes
2626     ifeq (%(package),)
2627         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2628     else
2629         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2630     endif
2631 else
2632     host := no
2633     ifeq (%(package),)
2634         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2635     else
2636         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2637     endif
2638 endif
2639 ifneq (%(gendir),)
2640     ifeq (%(package),)
2641         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2642     else
2643         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2644     endif
2645 endif
2647 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2648 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2650 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2651     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2652     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2653 else
2654     ifeq (%(nix),yes)
2655         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2656         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2657     else
2658         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2659     endif
2661     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2662     
2663     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2664         sbindir=$(%(mmake)-prefix) \
2665         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2666         oldincludedir=$(AROS_INCLUDES) %(install_env)
2667 endif
2669 ifneq ($(DEBUG),yes)
2670     %(mmake)-s_flag = -s
2671 endif
2673 # Set up build environment, and options for configure script
2674 ifeq (%(compiler),host)
2675     CONFIG_ENV := \
2676         CPP="$(HOST_CPP)" \
2677         CXXCPP="$(HOST_CPP)" \
2678         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2679         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2680         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2681         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2682         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2683         TARGET_NM="$(NM_PLAIN)"
2684 endif
2685 ifeq (%(compiler),target)
2686     CONFIG_ENV := \
2687         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2688         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2689         CPP="$(TARGET_CPP)" \
2690         CXXCPP="$(TARGET_CPP)" \
2691         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2692         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2693         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2694         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2695         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2696         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2697         TARGET_NM="$(NM_PLAIN)" \
2698         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2699         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2700     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2701         --host=$(AROS_TARGET_CPU)-aros\
2702         --target=$(AROS_TARGET_CPU)-aros\
2703         --disable-nls\
2704         --without-x --without-pic --disable-shared
2705 endif
2706 ifeq (%(compiler),kernel)
2707     CONFIG_ENV := \
2708         CPP="$(KERNEL_CPP)" \
2709         CXXCPP="$(KERNEL_CPP)" \
2710         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2711         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2712         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2713         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2714         TARGET_NM="$(NM_PLAIN)"
2715     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2716         --host=$(AROS_TARGET_CPU)-aros\
2717         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2718         --without-x --without-pic --disable-shared
2719 endif
2721 ifeq (%(use_build_env),yes)
2722     BUILD_ENV := $(CONFIG_ENV)
2723 endif
2726 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2728 # When building for the host, we don't need to build the
2729 # linklibs - this is especially true when building the
2730 # crosstool toolchain on 'foreign' architectures (such as
2731 # building PPC on x86)
2733 #MM- %(mmake)-host : setup includes %(mmake)-quick
2734 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2735 #MM- %(mmake): %(mmake)-%(compiler)
2737 # Using -j1 in install_command may result in a warning but finally
2738 # it does its job. make install for gcc does not work reliably for -jN
2739 # where N > 1.
2740 ifneq (%(install_target),)
2741     %(mmake)-install_command = \
2742         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2743         -C $(%(mmake)-pkgdir) %(install_target) -j1
2745     %(mmake)-uninstall_command = \
2746     $(RM) $(%(mmake)-installflag) && \
2747     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2748     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2749 else
2750     %(mmake)-install_command   := true
2751     %(mmake)-uninstall_command := true
2752 endif
2754 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2757 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2759 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2760         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2761             $(RM)  $(%(mmake)-installflag) && \
2762             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2763              -C $(%(mmake)-pkgdir) && \
2764             $(%(mmake)-install_command) && \
2765             $(TOUCH) $@ -r $^; \
2766         fi
2768 $(%(mmake)-pkgdir)/.files-touched:
2769         %mkdirs_q $(%(mmake)-pkgdir)
2770         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2771         $(TOUCH) $@
2774 %(mmake)-uninstall :
2775         $(%(mmake)-uninstall_command)
2778 %(mmake)-configure : $(%(mmake)-configflag)
2780 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2781 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2782         $(RM) $@
2783         %mkdirs_q $(%(mmake)-pkgdir)
2784         cd $(%(mmake)-pkgdir) && \
2785         find . -name config.cache -exec $(RM) '{}' \; && \
2786         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2787             %(extraoptions) && \
2788         $(TOUCH) $@
2791 %(mmake)-clean : %(mmake)-uninstall
2792         @$(RM) $(%(mmake)-pkgdir)
2793 %end
2794 #------------------------------------------------------------------------------
2797 #------------------------------------------------------------------------------
2798 # Given an archive name, patches names and locations where to find them, fetch
2799 # the archive and the patches from any of those locations, unpack the archive
2800 # and then apply the patches.
2802 # Locations currently supported are http and ftp sites, plus local filesystem
2803 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2804 # the fetch.sh script needs to be modified, since this macro relies on that script.
2806 # Arguments:
2808 #     - mmake           = mmaketarget
2809 #     - archive_origins = list of locations where to find the archive. They are tried
2810 #                         in sequence, until the archive is found and fetching it 
2811 #                         succeeded. If not specified, the current directory is assumed.
2812 #     - archive         = the archive name. Mandatory.
2813 #     - suffixes        = a list of suffixes to append to the the package name plus the
2814 #                         version. Each one of them is tried until a matching archive is
2815 #                         found. They are appended to patches and these are tried the
2816 #                         same way as packages are.
2817 #     - location        = the local directory where to put the fetched archive and patches.
2818 #                         If not specified, the directory specified by destination is used.
2819 #     - destination     = the directory to unpack the archive to.
2820 #                         If not specified, the current directory is assumed.
2821 #     - patches_origins = list of locations where to find the patches. They are tried
2822 #                         in sequence, until a patch is found and fetching it 
2823 #                         succeeded. If not specified, the current directory is assumed.
2824 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2825 #                         patch_name[:[patch_subdir][:patch_opt]].
2827 #                             - patch_name   = the name of the patch file
2828 #                             - patch_subdir = the directory within \destination\ where to
2829 #                                              apply the patch.
2830 #                             - patch_opt    = any options to pass to the `patch' command
2831 #                                              when applying the patch.
2832 #                         
2833 #                         The patch_subdir and patch_opt fields are optional.
2835 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2836     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2838 .PHONY: %(mmake)
2840 ifneq (%(location),)
2841     %(mmake)-location := %(location)
2842 else
2843     %(mmake)-location := %(destination)
2844 endif
2847 %(mmake) :
2848         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2849         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2850 %end
2851 #------------------------------------------------------------------------------
2854 #------------------------------------------------------------------------------
2855 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2856 # unpatched source tree and runs diff against this and a previously fetched and possibly
2857 # patched tree. Depending on what happens after patching during a normal build it might
2858 # give best results if the new patch is created directly after fetch.
2860 # Arguments:
2862 #     - mmake       = mmaketarget
2863 #     - archive     = archive base name
2864 #     - srcdir      = the top level directory the package is unpacked to, useful if
2865 #                     an archive unpacks to a directory other than its name suggests.
2866 #                     this should not be deeper than a single path element.
2867 #     - suffixes    = a list of suffixes to append to the the package name plus the
2868 #                     version. Each one of them is tried until a matching archive is
2869 #                     found.
2870 #     - destination = the directory to unpack the archive to.
2871 #     - excludes    = diff patterns to exclude files or directories from the patch
2873 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2875 .PHONY: %(mmake)
2877 ifneq (%(excludes),)
2878     %(mmake)-exclude := -X ./exclude.patterns
2879 endif
2881 ifneq (%(srcdir),)
2882     %(mmake)-srcdir := %(srcdir)
2883 else
2884     %(mmake)-srcdir := %(archive)
2885 endif
2888 %(mmake):
2889         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2890         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2891         cd %(destination)/tmp ; \
2892         $(FOR) f in %(excludes) ; do \
2893             $(ECHO) $$f >> ./exclude.patterns ; \
2894         done ; \
2895         diff -ruN $(%(mmake)-exclude) \
2896             $(%(mmake)-srcdir) \
2897             $(%(mmake)-srcdir).aros \
2898             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2899         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2900         $(RM) %(destination)/tmp
2901 %end
2902 #------------------------------------------------------------------------------
2905 #------------------------------------------------------------------------------
2906 # Joins the features of %fetch and %build_with_configure.
2908 # If a patch is provided, it *must* be named the following way:
2910 #    <package name>-<version number>-aros.diff
2912 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2913 # CD'ing into the archive's extracted directory.
2915 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2916 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2917 # to make that patch fully comprehensive.
2919 # Arguments:
2921 #    - mmake            = the meta make target.
2922 #    - package          = the GNU package name, sans version and archive format suffixes.
2923 #    - subpackage       = ???
2924 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2925 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2926 #    - version          = the package's version number, or otherwise any other version string.
2927 #                         It gets appended to the package name to form the basename of the archive.
2928 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2929 #                         version. Each one of them is tried until a matching archive is found.
2930 #                         Defaults to "tar.bz2 tar.gz".
2931 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
2932 #    - builddir         = override the location we expect to run configure/make in.
2933 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2934 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2935 #                         fetched or not. Default to no.
2936 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2937 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2938 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2939 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2940 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2941 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2942 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2943 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2944 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2945 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2946 #    - nix              = same meaning as the one for the %build_with_configure macro.
2947 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
2948 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
2950 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2951     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
2952     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2953     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2955 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2956 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2957 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2958 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2960 %(mmake)-archbase  := %(package)-%(version)
2962 ifeq (%(compiler),host)
2963     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2964 else
2965     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2966 endif
2968 ifeq (%(prefix),)
2969     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2970 else
2971     %(mmake)-prefix := %(prefix)
2972 endif
2974 ifneq (%(subpackage),)
2975     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2976 else
2977     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2978 endif
2980 ifneq (%(srcdir),)
2981     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2982 else
2983     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2984 endif
2986 ifneq (%(builddir),)
2987     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
2988 else
2989     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
2990 endif
2992 ifeq (%(patch),yes)
2993     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
2994 else
2995     %(mmake)-%(subpackage)-patches_specs := ::
2996 endif
2998 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2999     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3000     archive_origins=". %(package_repo)" \
3001     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3003 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3004     archive=$(%(mmake)-%(subpackage)-archbase) \
3005     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3006     suffixes="%(suffixes)" \
3007     destination=$(%(mmake)-portdir)
3009 #MM- %(mmake) : %(mmake)-%(subpackage)
3011 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3013 %(mmake)-%(subpackage)-package-basename := \
3014     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3016 ifneq (%(create_pkg),no)
3017     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3018 endif
3020 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3021      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3022      install_env=%(install_env) use_build_env=%(use_build_env) \
3023      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3024      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3025      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3027 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3028 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3031 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3033 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3034 #that $^ and $@ have exactly the same mtime, and in that case make tries
3035 #to rebuild $@ again, which would fail because the directory where
3036 #the package got installed would not exist anymore. 
3037 #We work this around by using an if statement to manually check the mtimes.
3038 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3039         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3040         $(RM) $@ ; \
3041         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3042         mkdir -p "$(DISTDIR)/Packages" ; \
3043         mkdir -p "$(%(mmake)-prefix)" ; \
3044         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3045         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3046         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3047     fi
3048 %end
3049 #------------------------------------------------------------------------------
3052 #------------------------------------------------------------------------------
3053 # Joins the features of %fetch and %build_with_configure, taking advantage of
3054 # the naming scheme of GNU packages. GNU packages names are in the form
3056 #     <package name>-<version number>.<archive format suffix>
3058 # If a patch is provided, it *must* be named the following way:
3060 #    <package name>-<version number>-aros.diff
3062 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3063 # CD'ing into the archive's extracted directory.
3065 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3066 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3067 # to make that patch fully comprehensive.
3069 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3071 # Arguments:
3073 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3075 #    - prefix           = defaults to $(GNUDIR).
3076 #    - aros_prefix      = defaults to /GNU.
3078 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3079     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3080     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3082 GNU_REPOSITORY := gnu://
3084 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3085     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3086     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3087     patch="%(patch)" patch_repo="%(patch_repo)" \
3088     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3089     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3091 %end
3092 #------------------------------------------------------------------------------
3095 #------------------------------------------------------------------------------
3096 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3097 # that the package is a "Development" package, and as such it needs to be placed
3098 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3100 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3101 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3102 # "mmake" argument, because the metatarget is implicitely defined as
3104 #     #MM- development-%(package)
3106 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3107     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3108     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3110 #MM- development : development-%(package)
3113 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3114    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3115    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3116    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3117    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3120 postinstall-%(package)-delete-la-files:
3121         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3123 %end
3124 #------------------------------------------------------------------------------
3126 # Builds a kickstart package in PKG format
3128 # Arguments:
3130 #    - mmake   = target name
3131 #    - file    = destination file name with path
3133 # Other arguments are self-explanatory
3135 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3136     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3138 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3139 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3140 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3141 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3142 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3143 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3145 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3146 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3147 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3148 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3149 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3150 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3152 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3153     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3154 PKG_DIR   := $(dir %(file))
3157 %(mmake) : %(file)
3160 %(mmake)-quick : %(file)
3162 %(file): $(PKG_FILES) | $(PKG_DIR)
3163         @$(ECHO) Packaging $@...
3164         @$(SRCDIR)/tools/package/pkg c $@ $^
3166 %compress_file mmake=%(mmake) file=%(file)
3168 GLOB_MKDIRS += $(PKG_DIR)
3170 %end
3172 #------------------------------------------------------------------------------
3173 # Compresses %(file) with a gzip.
3174 # Good in conjunction with for example %build_prog
3176 %define compress_file mmake=/A file=/A
3178 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3181 %(mmake)-gz-quick : %(file).gz
3183 %(file).gz: %(file)
3184         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3185         @gzip -9 -f $^
3187 %end
3189 #------------------------------------------------------------------------------
3190 # Links a kickstart module in ELF format
3191 # Arguments are similar to make_package
3193 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3194     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3196 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3197 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3198 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3199 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3200 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3201 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3203 ifeq (%(startup),)
3204     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3205 else
3206     KOBJ_STARTUP := %(startup)
3207 endif
3209 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3211 TMP_LDFLAGS := %(ldflags)
3213 # Make a list of the lib files this program depends on.
3214 # In LDFLAGS remove white space between -L and directory
3215 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3216 # Filter out only the libdirs and remove -L
3217 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3218 # Add trailing /
3219 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3220 # Add normal linklib path
3221 TMP_DIRS += $(AROS_LIB)/
3222 # add lib and .a to static linklib names
3223 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3224 # search for the linklibs in the given path, ignore ones not found
3225 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3226     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3229 TMP_DIRS += $(dir %(file))
3230 ifneq (%(map),)
3231     TMP_LDFLAGS += $(GENMAP) %(map)
3232     TMP_DIRS    += $(dir %(map))
3233 endif
3235 #MM %(mmake) : %(deps)
3238 %(mmake) : %(file)
3241 %(mmake)-quick : %(file)
3243 %(file): KOBJS := $(KOBJS)
3244 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3245                     -nostdc -nosysbase -Wl,-Ur
3246 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3247 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3248         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3249         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3250         @$(STRIP) $@
3252 %compress_file mmake=%(mmake) file=%(file)
3254 GLOB_MKDIRS += $(TMP_DIRS)
3256 %end