forgotten commit - fixes and corrections to CPPFLAGS usage.
[AROS.git] / config / make.tmpl
blob5809588cd99f93d671abb17715e32d81867e4144
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_SYSROOT)" opt="$(CFLAGS) $(CPPFLAGS)" 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) -D__SRCFILENAME__="\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))"\" -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) -D__SRCFILENAME__=\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))\" -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) -D__SRCFILENAME__=\"$(subst $(TOP)/,,$(subst $(SRCDIR)/,,$(abspath %(from))))\" -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) $(TARGET_SYSROOT)" opt="$(AFLAGS) $(CPPFLAGS)" 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) $(TARGET_SYSROOT)" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP) objdir=$(GENDIR)/$(CURDIR)
66         @$(eval LINKTARGET=%(to))
67         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$(LINKTARGET))..."
68         @$(eval LINKTMPFILE=%(objdir)/$(notdir $(LINKTARGET)))
69         @$(IF) %(cmd) %(from) -o $(LINKTMPFILE) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
70                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
71                                 $(ECHO) "$(LINKTARGET): %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" >> $(GENDIR)/errors ; \
72                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
73                 else \
74                         $(NOP) ; \
75                 fi ; \
76                 $(CP) $(LINKTMPFILE) $(LINKTARGET) ; \
77         else \
78                 $(ECHO) "Link failed: %(cmd) %(from) -o $(LINKTARGET) %(opt) %(libs)" 1>&2 ; \
79                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
80                 exit 1 ; \
81         fi
82         @$(IF) [ "$(DEBUG)" = "yes" ]; then \
83                 %(strip) $(LINKTARGET) --only-keep-debug -o $(LINKTARGET).dbg; \
84         fi
85         @%(strip) $(LINKTARGET)
86 %end
87 #------------------------------------------------------------------------------
90 #-------------------------------------------------------------------------
91 # Link a module based upon a number of arguments and the standard $(LIBS)
92 # and $(DEPLIBS) make variables.
94 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
95         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
96         @$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
97                 $(GENMAP) %(objdir)/%(module).map \
98                 %(objs) %(libs) %(ldflags) %(endtag) \
99                 -o $@ 2>&1 > %(objdir)/%(err); \
100         then \
101                 cat %(objdir)/%(err); \
102         else \
103                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
104                 cat %(objdir)/%(err); \
105                 exit 1; \
106         fi
107         @$(IF) $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
108         @$(IF) [ "$(DEBUG)" = "yes" ]; then \
109                 $(STRIP) $@ --only-keep-debug -o $@.dbg; \
110         fi
111         @$(STRIP) $@
112 %end
113 #------------------------------------------------------------------------------
116 #------------------------------------------------------------------------------
117 # Create the library
118 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
119         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
120         @%(ar) %(to) %(from)
121         @%(ranlib) %(to)
122 %end
123 #------------------------------------------------------------------------------
126 #------------------------------------------------------------------------------
127 # Create the dependency file %(to) for %(from)
128 %define mkdepend_q flags="$(CFLAGS) $(CPPFLAGS)" from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
129         %mkdir_q dir="$(dir %(to))"
130         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
131         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create one directory without any output
138 %define mkdir_q dir=.
139         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
140 %end
141 #------------------------------------------------------------------------------
144 #------------------------------------------------------------------------------
145 # Create several directories without any output
146 %define mkdirs_q dirs=/M
147         @$(FOR) dir in %(dirs) ; do \
148                 $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
149         done
150 %end
151 #------------------------------------------------------------------------------
154 #############################################################################
155 #############################################################################
156 ##                                                                         ##
157 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
158 ## mmakefile. They consist of one or more full makefile rules.             ##
159 ## In general the files generated in these macros are also defined as      ##
160 ## make targets so that they can be used as a dependency in other rules    ##
161 ##                                                                         ##
162 #############################################################################
163 #############################################################################
165 #------------------------------------------------------------------------------
166 # Generate a unique id for each of the %build... rules
167 %define buildid targets=/A
168 BDID := $(BDID)_
169 ifneq ($(filter $(TARGET),%(targets)),)
170 BDTARGETID := $(BDID)
171 endif
172 %end
173 #------------------------------------------------------------------------------
176 #------------------------------------------------------------------------------
177 # Copy file %(from) to %(to) in a makefile rule
178 %define rule_copy from=/A to=/A
179 %(to) : %(from)
180         @$(CP) $< $@
181 %end
182 #------------------------------------------------------------------------------
185 #------------------------------------------------------------------------------
186 # Copy the files %(files) to %(targetdir). For each file in %(files),
187 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
188 # appropriate subdirs are not generated by this rule so they have to be
189 # present.
190 %define rule_copy_multi files=/A targetdir=/A srcdir=.
192 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
193         @$(CP) $< $@
194 %end
195 #------------------------------------------------------------------------------
198 #------------------------------------------------------------------------------
199 # Copy the files %(files) to %(targetdir). For each file in %(files),
200 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
201 # %(stampfile) is used to keep track of when the last time the comparison has
202 # been done. The targetdir and the appropriate subdirs are not generated by 
203 # this rule so they have to be present.
204 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
205     stampfile=$(TMP_SRCDIR)/.copy_stamp
207 TMP_SRCDIR := %(srcdir)
209 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
211 %(stampfile) : COPYSRCDIR := %(srcdir)
212 %(stampfile) : TGTDIR := %(targetdir)
213 %(stampfile) : FILES := %(files)
214 %(stampfile) : $(addprefix %(srcdir)/,%(files))
215         @for f in $(FILES); do \
216              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
217                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
218              fi ; \
219         done
220         @$(TOUCH) $@
221 %end
222 #------------------------------------------------------------------------------
225 #------------------------------------------------------------------------------
226 # Will join all the files in %(from) to %(to). When text is specified it will
227 # be displayed.
228 # Restriction: at the moment when using a non-empty target dir %(from) may
229 # not have 
230 %define rule_join to=/A from=/A text=
232 %(to) : %(from)
233 ifneq (%(text),)
234         @$(ECHO) %(text)
235 endif
236         @$(CAT) $^ >$@
237 %end
238 #------------------------------------------------------------------------------
241 #------------------------------------------------------------------------------
242 # Include the dependency files and add some internal rules
243 # When depstargets is provided the depencies will only be included when one of
244 # these targets is the $(TARGET). Otherwise the dependencies will only be
245 # included when the $(TARGET) is not for setup or clean 
246 %define include_deps deps=$(DEPS)/M  depstargets=
247 ifneq (%(deps),)
248   ifneq (%(depstargets),)
249     ifneq ($(findstring $(TARGET),%(depstargets)),)
250       -include %(deps)
251     endif
252   else
253     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
254       -include %(deps)
255     endif
256   endif
257 endif
258 %end
259 #------------------------------------------------------------------------------
262 #------------------------------------------------------------------------------
263 # Create the directories %(dirs). The creation will be done by adding rules to
264 # the %(setuptarget) make target with setup as the default. 
265 %define rule_makedirs dirs=/A setuptarget=setup
267 %(setuptarget) :: %(dirs)
269 GLOB_MKDIRS += %(dirs)
271 %end
272 #------------------------------------------------------------------------------
275 #------------------------------------------------------------------------------
276 # Generate a rule to compile a C source file to an object file and generate
277 # the dependency file. Basename may contain a directory part, then the source
278 # file has to be in that directory. The generated file will be put in the
279 # object directory without the directory.
280 # options
281 # - basename: the basename of the file to compile. Use % for a wildcard rule
282 # - cflags (default $(CFLAGS)): the C flags to use for compilation
283 # - dflags: the flags used during creation of dependency file. If not specified
284 #   the same value as cflags will be used
285 # - targetdir: the directory to put the .o file and the .d file. By default
286 #   it is put in the same directory as the .c file
287 %define rule_compile basename=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= targetdir= compiler=target
289 BD_NIXFLAG ?= -nix
291 ifeq (%(targetdir),)
292   TMP_TARGETBASE := %(basename)
293 else
294   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
295 endif
297 # Adjust compiler flags to suit C
298 TMP_CPPFLAGS := %(cppflags)
299 TMP_CFLAGS := %(cflags)
300 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
301 ifeq (%(dflags),)
302   TMP_DFLAGS := $(TMP_CFLAGS)
303 else
304   TMP_DFLAGS := %(dflags)
305 endif
307 ifeq ($(findstring %(compiler),host kernel target),)
308   $(error unknown compiler %(compiler))
309 endif
310 ifeq (%(compiler),target)
311 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
312 BD_STRIP ?= $(TARGET_STRIP)
313 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
314 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
315 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
316 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
317 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
318 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_DFLAGS)
319 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
320 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
321 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
322 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
323 endif
324 ifeq (%(compiler),host)
325 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
326 BD_STRIP ?= $(HOST_STRIP)
327 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
328 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
329 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
330 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
331 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
332 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
333 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
334 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
335 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
336 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
337 endif
338 ifeq (%(compiler),kernel)
339 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
340 BD_STRIP ?= $(ECHO) >/dev/null
341 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
342 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
343 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
344 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
345 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
346 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
347 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
348 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
349 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
350 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
351 endif
353 $(TMP_TARGETBASE).o : CPPFLAGS := $(TMP_CPPFLAGS)
354 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
355 $(TMP_TARGETBASE).o : %(basename).c
356         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
358 ifeq (%(nix),yes)
359   $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
360 endif
361 $(TMP_TARGETBASE).d : %(basename).c
362         %mkdepend_q cc=$(TMP_CMD) flags="$(TMP_DFLAGS) $(TMP_CPPFLAGS)"
363 %end
364 #------------------------------------------------------------------------------
367 #------------------------------------------------------------------------------
368 # Generate a rule to compile a C++ source file to an object file and generate
369 # the dependency file. Basename may contain a directory part, then the source
370 # file has to be in that directory. The generated file will be put in the
371 # object directory without the directory.
372 # options
373 # - basename: the basename of the file to compile. Use % for a wildcard rule
374 # - cflags (default $(CFLAGS)): the C flags to use for compilation
375 # - dflags: the flags used during creation of dependency file. If not specified
376 #   the same value as cflags will be used
377 # - targetdir: the directory to put the .o file and the .d file. By default
378 #   it is put in the same directory as the .c file
379 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) cppflags=$(CPPFLAGS) dxxflags= targetdir= compiler=target
381 ifneq (%(basename),)
382 BD_NIXFLAG ?= -nix
383 ifeq (%(targetdir),)
384   TMP_TARGETBASE := %(basename)
385 else
386   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
387 endif
389 # Adjust compiler flags to suit C++
390 TMP_CPPFLAGS := %(cppflags)
391 TMP_CXXFLAGS := %(cxxflags) 
392 ifeq (%(dxxflags),)
393   TMP_DXXFLAGS := %(cxxflags)
394 else
395   TMP_DXXFLAGS := %(dxxflags)
396 endif
398 ifeq ($(findstring %(compiler),host kernel target),)
399   $(error unknown compiler %(compiler))
400 endif
401 ifeq (%(compiler),target)
402 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
403 BD_STRIP ?= $(TARGET_STRIP)
404 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
405 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
406 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
407 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
408 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TMP_CXXFLAGS) $(SAFETY_CFLAGS)
409 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TMP_DXXFLAGS)
410 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
411 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
412 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
413 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
414 endif
415 ifeq (%(compiler),host)
416 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
417 BD_STRIP ?= $(HOST_STRIP)
418 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
419 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
420 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
421 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
422 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS) 
423 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
424 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
425 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
426 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
427 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
428 endif
429 ifeq (%(compiler),kernel)
430 KERNEL_CXX ?= $(KERNEL_CC)
431 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
432 BD_STRIP ?= $(ECHO) >/dev/null
433 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
434 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
435 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
436 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
437 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
438 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
439 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
440 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
441 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
442 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
443 endif
445 $(TMP_TARGETBASE).o : CPPFLAGS := $(TMP_CPPFLAGS)
446 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
447 $(TMP_TARGETBASE).o : %(basename).cpp
448         %compile_q cmd=$(TMP_CMD) opt="$(CXXFLAGS) $(CPPFLAGS)" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
450 ifeq (%(nix),yes)
451   $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
452 endif
453 $(TMP_TARGETBASE).d : %(basename).cpp
454         %mkdepend_q cc=$(TMP_CMD) flags="$(TMP_DXXFLAGS) $(TMP_CPPFLAGS)"
456 endif
458 %end
459 #------------------------------------------------------------------------------
462 #------------------------------------------------------------------------------
463 # Generate a rule to compile an ObjC source file to an object file and generate
464 # the dependency file. Basename may contain a directory part, then the source
465 # file has to be in that directory. The generated file will be put in the
466 # object directory without the directory.
467 # options
468 # - basename: the basename of the file to compile. Use % for a wildcard rule
469 # - cflags (default $(CFLAGS)): the C flags to use for compilation
470 # - dflags: the flags used during creation of dependency file. If not specified
471 #   the same value as cflags will be used
472 # - targetdir: the directory to put the .o file and the .d file. By default
473 #   it is put in the same directory as the .m file
474 %define rule_compile_objc basename=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= targetdir= compiler=target
476 ifneq (%(basename),)
477 BD_NIXFLAG ?= -nix
478 ifeq (%(targetdir),)
479   TMP_TARGETBASE := %(basename)
480 else
481   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
482 endif
484 # Adjust compiler flags to suit ObjC
485 TMP_CPPFLAGS :=  %(cppflags)
486 TMP_OBJCFLAGS := %(cflags)
487 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
488 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
489 ifeq (%(dflags),)
490   TMP_OBJCDFLAGS := %(cflags)
491 else
492   TMP_OBJCDFLAGS := %(dflags)
493 endif
495 # Define the use of cross compiler
496 ifeq ($(TARGET_OBJC),)
497   TMP_CC := $(TARGET_CC)
498 else
499   TMP_CC := $(TARGET_OBJC)
500 endif
502 ifeq ($(findstring %(compiler),host kernel target),)
503   $(error unknown compiler %(compiler))
504 endif
505 ifeq (%(compiler),target)
506 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
507 BD_STRIP ?= $(TARGET_STRIP)
508 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
509 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
510 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
511 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
512 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS) $(SAFETY_CFLAGS)
513 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
514 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
515 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
516 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
517 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
518 endif
519 ifeq (%(compiler),host)
520 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
521 BD_STRIP ?= $(HOST_STRIP)
522 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
523 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
524 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
525 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
526 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
527 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
528 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
529 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
530 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
531 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
532 endif
533 ifeq (%(compiler),kernel)
534 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
535 BD_STRIP ?= $(ECHO) >/dev/null
536 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
537 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
538 $(TMP_TARGETBASE).o : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
539 $(TMP_TARGETBASE).d : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
540 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
541 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
542 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
543 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
544 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
545 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
546 endif
548 $(TMP_TARGETBASE).o : CPPFLAGS := $(TMP_CPPFLAGS)
549 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
550 $(TMP_TARGETBASE).o : %(basename).m
551         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
553 ifeq (%(nix),yes)
554   $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
555 endif
556 $(TMP_TARGETBASE).d : %(basename).m
557         %mkdepend_q cc=$(TMP_CMD) flags="$(TMP_OBJCDFLAGS) $(TMP_CPPFLAGS)"
559 endif
561 %end
562 #------------------------------------------------------------------------------
565 #------------------------------------------------------------------------------
566 # Generate a rule to compile multiple C source files to an object file and
567 # generate the corresponding dependency files. The generated file will be put
568 # in the object directory without the directory part of the source file.
569 # options
570 # - basenames: the basenames of the files to compile. The names may include
571 #   relative or absolute path names. No wildcard is allowed
572 # - cflags (default $(CFLAGS)): the C flags to use for compilation
573 # - dflags: the flags used during creation of dependency file. If not specified
574 #   the same value as cflags will be used
575 # - targetdir: the directory to put the .o file and the .d file. By default
576 #   it is put in the same directory as the .c file. When targetdir is not
577 #   empty, path names will be stripped from the file names so that all files
578 #   are in that dir and not in subdirectories.
579 # - compiler (default target): compiler to use, target, kernel or host
580 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= srcdir= targetdir= \
581     compiler=target
583 ifeq (%(srcdir),)
584 TMP_SRCWILDCARD := %
585 else
586 TMP_SRCWILDCARD := %(srcdir)/%
587 endif
589 ifeq (%(targetdir),)
590 TMP_TARGETS := $(addsuffix .o,%(basenames))
591 TMP_DTARGETS := $(addsuffix .d,%(basenames))
592 TMP_TGTWILDCARD := %
593 else
594 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
595 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
596 TMP_TGTWILDCARD := %(targetdir)/%
598 # Be sure that all .c files are generated
599 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
601 # Be sure that all .c files are found
602 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
603 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
604 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
605 ifneq ($(TMP_DIRS),)
606     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
607     vpath %.c $(TMP_DIRS)
608 endif
610 endif
612 TMP_CPPFLAGS := %(cppflags)
613 TMP_CFLAGS := %(cflags)
614 ifeq (%(dflags),)
615   TMP_DFLAGS := %(cflags)
616 else
617   TMP_DFLAGS := %(dflags)
618 endif
620 ifeq ($(findstring %(compiler),host kernel target),)
621   $(error unknown compiler %(compiler))
622 endif
623 ifeq (%(compiler),target)
624 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
625 BD_STRIP ?= $(TARGET_STRIP)
626 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
627 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
628 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
629 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
630 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TMP_DFLAGS)
631 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
632 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
633 endif
634 ifeq (%(compiler),host)
635 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
636 BD_STRIP ?= $(HOST_STRIP)
637 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
638 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
639 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
640 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
641 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
642 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
643 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
644 endif
645 ifeq (%(compiler),kernel)
646 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
647 BD_STRIP ?= $(ECHO) >/dev/null
648 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
649 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
650 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
651 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
652 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
653 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
654 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
655 endif
657 $(TMP_TARGETS) : CPPFLAGS := $(TMP_CPPFLAGS)
658 $(TMP_TARGETS) : CFLAGS := $(TMP_CFLAGS)
659 $(TMP_TARGETS) : $(TMP_TGTWILDCARD).o : $(TMP_SRCWILDCARD).c
660         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
662 $(TMP_DTARGETS) : $(TMP_TGTWILDCARD).d : $(TMP_SRCWILDCARD).c
663         %mkdepend_q cc=$(CMD) flags="$(TMP_DFLAGS) $(TMP_CPPFLAGS)"
664 %end
665 #------------------------------------------------------------------------------
668 #------------------------------------------------------------------------------
669 # Generate a rule to compile multiple C++ source files to an object file and
670 # generate the corresponding dependency files. The generated file will be put
671 # in the object directory without the directory part of the source file.
672 # options
673 # - basenames: the basenames of the files to compile. The names may include
674 #   relative or absolute path names. No wildcard is allowed. basenames will be 
675 #   matched to supported AROS_CXXEXTS.
676 # - cflags (default $(CFLAGS)): the C flags to use for compilation
677 # - dflags: the flags used during creation of dependency file. If not specified
678 #   the same value as cflags will be used
679 # - targetdir: the directory to put the .o file and the .d file. By default
680 #   it is put in the same directory as the .c file. When targetdir is not
681 #   empty, path names will be stripped from the file names so that all files
682 #   are in that dir and not in subdirectories.
683 # - compiler (default target): compiler to use, target, kernel or host
684 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) cppflags=$(CPPFLAGS) dxxflags= \
685     targetdir= compiler=target
687 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
689 ifneq ($(TMP_CXXABSBASENAMES),)
691 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
693 # Identify the "real" c++ files from the passed in basenames
694 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
696 ifeq (%(targetdir),)
697   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
698   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
699   TMP_WILDCARD := %
700 else
701   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
702   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
703   TMP_WILDCARD := %(targetdir)/%
705   # Be sure that all source files are generated
706   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
707 endif
709 # Adjust compiler flags to suit C++
710 TMP_CPPFLAGS := %(cppflags)
711 TMP_CXXFLAGS := %(cxxflags)
712 ifeq (%(dxxflags),)
713   TMP_DXXFLAGS := %(cxxflags)
714 else
715   TMP_DXXFLAGS := %(dxxflags)
716 endif
718 ifeq ($(findstring %(compiler),host kernel target),)
719   $(error unknown compiler %(compiler))
720 endif
721 ifeq (%(compiler),host)
722   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
723   BD_STRIP ?= $(HOST_STRIP)
724   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
725   TMP_CXXCMD:=$(HOST_CXX)
726   TMP_CPPFLAGS := $(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
727   TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
728   TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
729   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
730   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
731 endif
732 ifeq (%(compiler),target)
733   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
734   BD_STRIP ?= $(TARGET_STRIP)
735   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
736   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
737   TMP_CPPFLAGS := $(TMP_CPPFLAGS)
738   TMP_CXXFLAGS := $(TMP_CXXFLAGS) $(SAFETY_CFLAGS)
739   TMP_DXXFLAGS := $(TMP_DXXFLAGS)
740   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
741   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
742 endif
743 ifeq (%(compiler),kernel)
744   KERNEL_CXX ?= $(KERNEL_CC)
745   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
746   BD_STRIP ?= $(ECHO) >/dev/null
747   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
748   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
749   TMP_CXXFLAGS := $(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
750   TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS) 
751   TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
752   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
753   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
754 endif
756 define cxx_multi_recipe_template
757  $(1).o : $(2)
758         %compile_q cmd=$(TMP_CXXCMD) opt="$(TMP_CXXFLAGS) $(TMP_CPPFLAGS)" iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
760  $(1).d : $(2)
761         %mkdepend_q cc=$(TMP_CXXCMD) flags="$(TMP_DXXFLAGS) $(TMP_CPPFLAGS)" from=$(2) to=$(1).d
762 endef
763 ifeq (%(targetdir),)
764   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
765 else
766   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
767 endif
769 endif
771 %end
772 #------------------------------------------------------------------------------
775 #------------------------------------------------------------------------------
776 # Generate a rule to compile multiple ObjC source files to an object file and
777 # generate the corresponding dependency files. The generated file will be put
778 # in the object directory without the directory part of the source file.
779 # options
780 # - basenames: the basenames of the files to compile. The names may include
781 #   relative or absolute path names. No wildcard is allowed
782 # - cflags (default $(CFLAGS)): the C flags to use for compilation
783 # - dflags: the flags used during creation of dependency file. If not specified
784 #   the same value as cflags will be used
785 # - targetdir: the directory to put the .o file and the .d file. By default
786 #   it is put in the same directory as the .m file. When targetdir is not
787 #   empty, path names will be stripped from the file names so that all files
788 #   are in that dir and not in subdirectories.
789 # - compiler (default target): compiler to use, target, kernel or host
790 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags= \
791     targetdir= compiler=target
793 ifneq (%(basenames),)
795 ifeq (%(targetdir),)
796   TMP_TARGETS := $(addsuffix .o,%(basenames))
797   TMP_DTARGETS := $(addsuffix .d,%(basenames))
798   TMP_WILDCARD := %
799 else
800   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
801   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
802   TMP_WILDCARD := %(targetdir)/%
804   # Be sure that all .m files are generated
805   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
807   # Be sure that all .m files are found
808   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
809   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
810   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
811   ifneq ($(TMP_DIRS),)
812     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
813     vpath %.m $(TMP_DIRS)
814   endif
815 endif
817 # Define the use of cross compiler
818 ifeq ($(TARGET_OBJC),)
819   TMP_CC := $(TARGET_CC)
820 else
821   TMP_CC := $(TARGET_OBJC)
822 endif
824 # Adjust compiler flags to suit ObjC
825 TMP_CPPFLAGS := %(cppflags)
826 TMP_OBJCFLAGS := %(cflags)
827 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPER)/include
828 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
829 ifeq (%(dflags),)
830   TMP_OBJCDFLAGS := %(cflags)
831 else
832   TMP_OBJCDFLAGS := %(dflags)
833 endif
835 ifeq ($(findstring %(compiler),host kernel target),)
836   $(error unknown compiler %(compiler))
837 endif
838 ifeq (%(compiler),target)
839   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
840   BD_STRIP ?= $(TARGET_STRIP)
841   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
842   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
843   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
844   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TMP_OBJCFLAGS)  $(SAFETY_CFLAGS)
845   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TMP_OBJCDFLAGS)
846   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
847   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
848 endif
849 ifeq (%(compiler),host)
850   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
851   BD_STRIP ?= $(HOST_STRIP)
852   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
853   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
854   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(HOST_CPPFLAGS) $(TMP_CPPFLAGS)
855   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
856   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
857   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
858   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
859 endif
860 ifeq (%(compiler),kernel)
861   KERNEL_OBJC ?= $(KERNEL_CC)
862   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
863   BD_STRIP ?= $(ECHO) >/dev/null
864   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
865   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
866   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS) 
867   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS) 
868   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS) 
869   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
870   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
871 endif
873 $(TMP_TARGETS) : CPPFLAGS := $(TMP_CPPFLAGS)
874 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
875 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
876         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
878 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
879         %mkdepend_q cc=$(CMD) flags="$(TMP_OBJCDFLAGS) $(TMP_CPPFLAGS)"
881 endif
883 %end
884 #------------------------------------------------------------------------------
887 #------------------------------------------------------------------------------
888 # Make an alias from one arch specific build to another arch.
889 # arguments:
890 # - mainmmake: the mmake of the module in the main tree
891 # - arch: the current arch
892 # - alias: the alias to which this should point
893 %define rule_archalias mainmmake=\A arch=\A alias=\A
895 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
896 %end
897 #------------------------------------------------------------------------------
900 #------------------------------------------------------------------------------
901 # Generate a rule to assemble a source file to an object file. Basename may
902 # contain a directory part, then the source file has to be in that directory.
903 # The generated file will be put in the object directory without the directory.
904 # options
905 # - basename: the basename of the file to compile. Use % for a wildcard rule
906 # - flags (default $(AFLAGS)): the asm flags to use for assembling
907 # - targetdir: the directory to put the .o file in. By default it is put in the
908 #   same directory as the .s file
909 %define rule_assemble basename=/A aflags=$(AFLAGS) cppflags=$(CPPFLAGS) targetdir=
911 ifeq (%(targetdir),)
912 %(basename).o : CPPFLAGS := %(cppflags)
913 %(basename).o : AFLAGS := %(aflags)
914 %(basename).o : %(basename).s
915         %assemble_q
916 %(basename).o : %(basename).S
917         %assemble_q
919 else
920 %(targetdir)/$(notdir %(basename)).o : CPPFLAGS := %(cppflags)
921 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
922 %(targetdir)/$(notdir %(basename)).o : %(basename).s
923         %assemble_q
924 %(targetdir)/$(notdir %(basename)).o : %(basename).S
925         %assemble_q
927 endif
928 %end
929 #------------------------------------------------------------------------------
932 #------------------------------------------------------------------------------
933 # Generate a rule to assemble multiple source files to an object file. The
934 # generated file will be put in the object directory with the directory part
935 # of the source file stripped off.
936 # options
937 # - basenames: the basenames of the files to compile. The names may include
938 #   relative or absolute path names. No wildcard is allowed
939 # - aflags (default $(AFLAGS)): the flags to use for assembly
940 # - targetdir: the directory to put the .o file and the .d file. By default
941 #   it is put in the same directory as the .c file. When targetdir is not
942 #   empty, path names will be stripped from the file names so that all files
943 #   are in that dir and not in subdirectories.
944 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A cppflags=$(CPPFLAGS) aflags=$(AFLAGS) targetdir= suffix=.s
946 ifeq (%(targetdir),)
947 TMP_TARGETS := $(addsuffix .o,%(basenames))
948 TMP_WILDCARD := %
949 else
950 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
951 TMP_WILDCARD := %(targetdir)/%
953 # Be sure that all .s files are generated
954 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
956 # Be sure that all .c files are found
957 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
958 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
959 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
960 ifneq ($(TMP_DIRS),)
961     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
962     vpath %%(suffix) $(TMP_DIRS)
963 endif
965 endif
967 BD_ASSEMBLER ?= %(cmd)
969 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
971 $(TMP_TARGETS) : CPPFLAGS := %(cppflags)
972 $(TMP_TARGETS) : AFLAGS := %(aflags)
973 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
974         %assemble_q cmd=$(TMP_CMD)
975 %end
976 #------------------------------------------------------------------------------
979 #------------------------------------------------------------------------------
980 # Link %(objs) to %(prog) using the libraries in %(uselibs)
981 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
982     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
984 TMP_EXTRA_LDFLAGS := 
985 TMP_EXTRA_LIBS :=
986 ifeq (%(nix),yes)
987     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
988 endif
989 ifeq (%(usestartup),no)
990     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
991 endif
992 ifeq (%(detach),yes)
993     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
994 endif
996 # Make a list of the lib files this program depends on.
997 # In LDFLAGS remove white space between -L and directory
998 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
999 # Filter out only the libdirs and remove -L
1000 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1001 # Add trailing /
1002 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1003 # Add normal linklib path
1004 TMP_DIRS += $(AROS_LIB)/
1005 # add lib and .a to static linklib names
1006 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1007 ifeq (%(usestartup),yes)
1008     TMP_LIBS += startup.o
1009 endif
1010 ifeq (%(detach),yes)
1011     TMP_LIBS += detach.o
1012 endif
1013 # search for the linklibs in the given path, ignore ones not found
1014 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1015     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1018 %(prog) : OBJDIR := %(objdir)
1019 %(prog) : OBJS := %(objs)
1020 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1021 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1022 %(prog) : %(objs) $(TMP_DEPLIBS)
1023         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1024 %end
1025 #------------------------------------------------------------------------------
1028 #------------------------------------------------------------------------------
1029 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
1030 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
1031 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
1032     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
1033     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
1035 TMP_EXTRA_LDFLAGS := 
1036 TMP_EXTRA_LIBS :=
1037 ifeq (%(nix),yes)
1038     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
1039 endif
1040 ifeq (%(usestartup),no)
1041     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
1042 endif
1043 ifeq (%(detach),yes)
1044     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
1045 endif
1047 # Make a list of the lib files the programs depend on.
1048 # In LDFLAGS remove white space between -L and directory
1049 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
1050 # Filter out only the libdirs and remove -L
1051 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1052 # Add trailing /
1053 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1054 # Add normal linklib path
1055 TMP_DIRS += $(AROS_LIB)/
1056 # add lib and .a to static linklib names
1057 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1058 # search for the linklibs in the given path, ignore ones not found
1059 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1060     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1062 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1064 $(TMP_PROGS) : OBJDIR := %(objdir)
1065 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1066 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1067 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1068         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1069 %end
1070 #------------------------------------------------------------------------------
1073 #------------------------------------------------------------------------------
1074 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1075 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1077 ifeq (%(linker),target)
1078 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1079 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1080 endif
1081 ifeq (%(linker),host)
1082 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1083 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1084 endif
1085 ifeq (%(linker),kernel)
1086 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1087 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1088 endif
1090 %(libdir)/lib%(libname).a : %(objs)
1091         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1092 %end
1093 #------------------------------------------------------------------------------
1095 #------------------------------------------------------------------------------
1096 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1097 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1098 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1099     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1101 TMP_LDFLAGS  := %(ldflags)
1102 # Make a list of the lib files the programs depend on.
1103 # In LDFLAGS remove white space between -L and directory
1104 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1105 # Filter out only the libdirs and remove -L
1106 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1107 # Add trailing /
1108 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1109 # Add normal linklib path
1110 TMP_DIRS += $(AROS_LIB)/
1111 # add lib and .a to static linklib names
1112 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1113 # search for the linklibs in the given path, ignore ones not found
1114 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1115     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1118 %(module) : LIB_NAMES := %(uselibs)
1119 %(module) : OBJS := %(objs)
1120 %(module) : ENDTAG := %(endobj)
1121 %(module) : ERR := %(err)
1122 %(module) : OBJDIR := %(objdir)
1123 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1124 ifeq (%(usehostlibs),)
1125 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1126 else
1127 # Warning: the -L/usr/lib here can result in modules
1128 # linking against host libs instead of AROS libs (e.g stdc++) !!
1129 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1130                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1131 endif 
1132 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1133         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1135 %end
1136 #------------------------------------------------------------------------------
1139 #------------------------------------------------------------------------------
1140 # Generate the libdefs.h include file for a module.
1141 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1143 TMP_TARGET := %(modname)_libdefs.h
1144 TMP_DEPS := $(GENMODULE)
1145 TMP_OPTS := 
1146 ifneq (%(conffile),)
1147     ifeq ($(dir %(conffile)),./)
1148         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1149         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1150     else
1151         TMP_OPTS += -c %(conffile)
1152         TMP_DEPS += %(conffile)
1153     endif 
1154 else
1155     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1156     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1157 endif
1158 ifneq (%(modsuffix),)
1159     TMP_OPTS += -s %(modsuffix)
1160 endif
1161 ifneq (%(targetdir),)
1162     TMP_OPTS += -d %(targetdir)
1163     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1164 endif
1165 ifneq (%(version),)
1166     TMP_OPTS += -v %(version)
1167 endif
1169 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1170 $(TMP_TARGET) : MODNAME := %(modname)
1171 $(TMP_TARGET) : MODTYPE := %(modtype)
1172 $(TMP_TARGET) : $(TMP_DEPS)
1173         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1174         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1175 %end
1176 #------------------------------------------------------------------------------
1178 #------------------------------------------------------------------------------
1179 # Generate the _lib.fd file for a module.
1180 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1182 TMP_TARGET := %(modname)_lib.fd
1183 TMP_DEPS := $(GENMODULE)
1184 TMP_OPTS := 
1185 ifneq (%(conffile),)
1186     ifeq ($(dir %(conffile)),./)
1187         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1188         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1189     else
1190         TMP_OPTS += -c %(conffile)
1191         TMP_DEPS += %(conffile)
1192     endif 
1193 else
1194     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1195     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1196 endif
1197 ifneq (%(modsuffix),)
1198     TMP_OPTS += -s %(modsuffix)
1199 endif
1200 ifneq (%(targetdir),)
1201     TMP_OPTS += -d %(targetdir)
1202     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1203 endif
1205 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1206 $(TMP_TARGET) : MODNAME := %(modname)
1207 $(TMP_TARGET) : MODTYPE := %(modtype)
1208 $(TMP_TARGET) : $(TMP_DEPS)
1209         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1210         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1211 %end
1212 #------------------------------------------------------------------------------
1214 #------------------------------------------------------------------------------
1215 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1216 # generated file in this Makefile
1217 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1218     targetdir=
1220 TMP_TARGET := Makefile.%(modname)%(modtype)
1221 TMP_DEPS := $(GENMODULE)
1222 TMP_OPTS := 
1223 ifneq (%(conffile),)
1224     ifeq ($(dir %(conffile)),./)
1225         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1226         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1227     else
1228         TMP_OPTS += -c %(conffile)
1229         TMP_DEPS += %(conffile)
1230     endif 
1231 else
1232     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1233     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1234 endif
1235 ifneq (%(modsuffix),)
1236     TMP_OPTS += -s %(modsuffix)
1237 endif
1238 ifneq (%(targetdir),)
1239     TMP_OPTS += -d %(targetdir)
1240     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1241 endif
1243 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1244 $(TMP_TARGET) : MODNAME := %(modname)
1245 $(TMP_TARGET) : MODTYPE := %(modtype)
1246 $(TMP_TARGET) : $(TMP_DEPS)
1247         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1248 %end
1249 #------------------------------------------------------------------------------
1252 #------------------------------------------------------------------------------
1253 # Generate the support files for compiling a module. This includes include
1254 # files and source files. This rule has to be preceeded by
1255 # %rule_genmodule_makefile
1256 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= stubdir= \
1257     conffile=
1259 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1260 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1261 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1262 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1263                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1265 TMP_DEPS := $(GENMODULE)
1266 TMP_OPTS :=
1268 ifneq (%(conffile),)
1269     ifeq ($(dir %(conffile)),./)
1270         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1271         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1272     else
1273         TMP_OPTS += -c %(conffile)
1274         TMP_DEPS += %(conffile)
1275     endif 
1276 else
1277     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1278     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1279 endif
1280 ifneq (%(modsuffix),)
1281     TMP_OPTS += -s %(modsuffix)
1282 endif
1283 ifneq (%(targetdir),)
1284     TMP_OPTS += -d %(targetdir)
1285     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1286     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1287     TMP_GENFILEFLAG=$(TMP_TARGETDIR)/.%(modname).%(modtype)-genfiles
1288 else
1289     TMP_GENFILEFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-genfiles
1290 endif
1291 ifneq (%(stubdir),)
1292     TMP_OPTS += -l %(stubdir)
1293     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1294     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1295     TMP_TARGETDIRS += %(stubdir)
1296 else
1297 ifneq (%(targetdir),)
1298     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1299 endif
1300 endif
1302 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1303 ifneq ($(TMP_TARGETDIRS),)
1304 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1305 endif
1307 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENFILEFLAG)
1309 $(TMP_GENFILEFLAG) : OPTS := $(TMP_OPTS)
1310 $(TMP_GENFILEFLAG) : MODNAME := %(modname)
1311 $(TMP_GENFILEFLAG) : MODTYPE := %(modtype)
1312 $(TMP_GENFILEFLAG) : $(TMP_DEPS)
1313         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1314 ifneq (%(conffile),lib.conf)
1315         @$(IF) $(TEST) -f lib.conf; then \
1316           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1317         fi
1318 endif
1319         @$(IF) $(TEST) -f libdefs.h; then \
1320           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1321         fi
1322         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1323         @$(TOUCH) $@
1324 %end
1325 #------------------------------------------------------------------------------
1328 #------------------------------------------------------------------------------
1329 # Generate the support files for compiling a module. This includes include
1330 # files and source files.
1331 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1332     targetdir= conffile=
1334 ifneq ($(%(modname)_INCLUDES),)
1336 TMP_TARGETS := $(%(modname)_INCLUDES)
1338 TMP_DEPS := $(GENMODULE)
1339 TMP_OPTS :=
1341 ifneq (%(conffile),)
1342     ifeq ($(dir %(conffile)),./)
1343         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1344         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1345     else
1346         TMP_OPTS += -c %(conffile)
1347         TMP_DEPS += %(conffile)
1348     endif 
1349 else
1350     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1351     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1352 endif
1353 ifneq (%(modsuffix),)
1354     TMP_OPTS += -s %(modsuffix)
1355 endif
1356 ifneq (%(targetdir),)
1357     TMP_OPTS += -d %(targetdir)
1358     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1359     TMP_GENINCFLAG=%(targetdir)/.%(modname).%(modtype)-includes
1360 else
1361     TMP_GENINCFLAG=$(GENDIR)/$(CURDIR)/.%(modname).%(modtype)-includes
1362 endif
1364 $(TMP_TARGETS) : $(TMP_DEPS) $(TMP_GENINCFLAG)
1366 $(TMP_GENINCFLAG) : OPTS := $(TMP_OPTS)
1367 $(TMP_GENINCFLAG) : MODNAME := %(modname)
1368 $(TMP_GENINCFLAG) : MODTYPE := %(modtype)
1369 $(TMP_GENINCFLAG) : $(TMP_DEPS)
1370         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1371         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1372         @$(TOUCH) $@
1373 endif
1374 %end
1375 #------------------------------------------------------------------------------
1377 #------------------------------------------------------------------------------
1378 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1379 # 'start' is an optional starting address
1380 # 'ldflags' is optional additional flags for the linker
1381 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1383 BD_OUTDIR := $(dir %(file))
1384 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1385 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1386 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1387 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1388 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1389 BD_OBJS += %(objs)
1391 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1393 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1394         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1395         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1396         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1398 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1399     GLOB_MKDIRS += $(BD_OUTDIR)
1400 endif
1402 %end
1404 #------------------------------------------------------------------------------
1405 # Common rules for all makefiles
1406 %define common
1407 # Delete generated makefiles
1409 clean ::
1410         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1412 include $(SRCDIR)/config/make.tail
1414 BDID := $(BDTARGETID)
1415 %end
1416 #------------------------------------------------------------------------------
1417       
1419 #############################################################################
1420 #############################################################################
1421 ##                                                                         ##
1422 ## Here are the mmakefile build macros. These are macros that takes care   ##
1423 ## of everything to go from the sources to the generated target. Also all  ##
1424 ## intermediate files and directories that are needed are created by these ##
1425 ## rules.                                                                  ##
1426 ##                                                                         ##
1427 #############################################################################
1428 #############################################################################
1430 #------------------------------------------------------------------------------
1431 # Build a program
1432 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1433     objcfiles= \
1434     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1435     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1436     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1437     includedir= libdir= \
1438     compiler=target linker= lto=$(TARGET_LTO)
1440 .PHONY : %(mmake)
1442 BD_PROGNAME  := %(progname)
1443 BD_OBJDIR    := %(objdir)
1444 BD_TARGETDIR := %(targetdir)
1445 BD_LINKER    := %(linker)
1447 # If not supplied, linker is equal to compiler
1448 ifeq ($(BD_LINKER),)
1449     BD_LINKER := %(compiler)
1450 endif
1452 BD_FILES     := %(files)
1453 BD_OBJCFILES := %(objcfiles)
1454 BD_ASMFILES  := %(asmfiles)
1455 BD_CXXFILES := %(cxxfiles)
1457 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1458 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1459 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1461 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1462 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1463 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1465 BD_CPPFLAGS :=  %(cppflags)
1466 ifneq (%(includedir),)
1467 BD_CPPFLAGS    += -I%(includedir)
1468 endif
1469 BD_CFLAGS    := %(cflags)
1470 BD_CXXFLAGS := %(cxxflags)
1471 ifeq (%(lto),yes)
1472 ifeq (%(compiler),target)
1473 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1474 BD_CXXFLAGS := $(LTO_BINARY_CFLAGS) $(BD_CXXFLAGS)
1475 endif
1476 endif
1477 BD_AFLAGS    := %(aflags)
1478 BD_DFLAGS    := %(dflags)
1479 BD_DXXFLAGS := %(dxxflags)
1480 BD_LDFLAGS   := %(ldflags)
1481 ifneq (%(libdir),)
1482 BD_LDFLAGS   += -L%(libdir)
1483 endif
1486 %(mmake)-quick : %(mmake)
1488 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1489 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1491 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1492 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1493     cppflags=$(BD_CPPFLAGS) cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1494 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1495     cppflags=$(BD_CPPFLAGS) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1496 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1497     cppflags=$(BD_CPPFLAGS) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1498 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1499     cppflags=$(BD_CPPFLAGS) aflags=$(BD_AFLAGS)
1501 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1502     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1503     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1504     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1505     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1507 endif
1509 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1511 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1512 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1513 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1515 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1517 %(mmake)-clean ::
1518         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1519         @$(RM) $(FILES)
1521 %end
1522 #------------------------------------------------------------------------------
1525 #------------------------------------------------------------------------------
1526 # Build programs, for every C file an executable will be built with the same
1527 # name as the C file
1528 %define build_progs mmake=/A files=/A nix=no \
1529     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1530     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1531     includedir= libdir= \
1532     compiler=target \
1533     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1535 .PHONY : %(mmake)
1537 BD_OBJDIR    := %(objdir)
1538 BD_TARGETDIR := %(targetdir)
1540 BD_FILES     := %(files)
1541 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1542 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1543 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1545 BD_CPPFLAGS := %(cppflags)
1546 ifneq (%(includedir),)
1547     BD_CPPFLAGS += -I%(includedir)
1548 endif
1549 BD_CFLAGS    := %(cflags)
1550 ifeq (%(lto),yes)
1551 ifeq (%(compiler),target)
1552 BD_CFLAGS    := $(LTO_BINARY_CFLAGS) $(BD_CFLAGS)
1553 endif
1554 endif
1555 BD_DFLAGS    := %(dflags)
1556 BD_LDFLAGS   := %(ldflags)
1557 ifneq (%(libdir),)
1558     BD_LDFLAGS += -L%(libdir)
1559 endif
1562 %(mmake)-quick : %(mmake)
1564 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1565 %(mmake) : $(BD_EXES)
1567 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1568 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1569     cflags=$(BD_CFLAGS) cppflags=$(BD_CPPFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1571 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1572     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1573     ldflags=$(BD_LDFLAGS) \
1574     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1575     usestartup="%(usestartup)" detach="%(detach)" \
1576     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1578 endif
1580 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1582 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1583 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1584 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1586 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1588 %(mmake)-clean ::
1589         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1590         @$(RM) $(FILES)
1592 %end
1593 #------------------------------------------------------------------------------
1596 #------------------------------------------------------------------------------
1597 # Build a module.
1598 # This is a bare version: It just compiles and links the given files. It is
1599 # assumed that all needed boiler plate code is in the files. This should only
1600 # be used for compiling external code. For AROS code use %build_module
1601 %define build_module_simple mmake=/A modname=/A modtype=/A \
1602     files="$(basename $(call WILDCARD, *.c))" \
1603     cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1604     objdir=$(OBJDIR) moduledir= \
1605     uselibs= usehostlibs= compiler=target lto=$(TARGET_LTO)
1607 # Define metamake targets and their dependencies
1608 #MM %(mmake) : core-linklibs includes-generate-deps
1609 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1610 #MM %(mmake)-kobj-quick
1611 #MM %(mmake)-quick
1612 #MM %(mmake)-clean
1614 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1616 .PHONY : $(BD_ALLTARGETS)
1618 ifeq (%(modname),)
1619 $(error using %build_module_simple: modname may not be empty)
1620 endif
1621 ifeq (%(modtype),)
1622 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1623 endif
1625 # Default values for variables and arguments
1626 BD_DEFLINKLIBNAME := %(modname)
1627 BD_DEFDFLAGS := %(cflags)
1628 ifeq (%(lto),yes)
1629 ifeq (%(compiler),target)
1630 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(BD_DEFDFLAGS)
1631 endif
1632 endif
1633 BD_DEFDXXFLAGS := %(dxxflags)
1634 OBJDIR ?= $(GENDIR)/$(CURDIR)
1635 BD_MODDIR := %(moduledir)
1636 ifeq ($(BD_MODDIR),)
1637   ifeq (%(modtype),library)
1638     BD_MODDIR  := $(AROS_LIBRARIES)
1639   endif
1640   ifeq (%(modtype),gadget)
1641     BD_MODDIR  := $(AROS_GADGETS)
1642   endif
1643   ifeq (%(modtype),datatype)
1644     BD_MODDIR  := $(AROS_DATATYPES)
1645   endif
1646   ifeq (%(modtype),handler)
1647     BD_MODDIR  := $(AROS_FS)
1648   endif
1649   ifeq (%(modtype),device)
1650     BD_MODDIR  := $(AROS_DEVS)
1651   endif
1652   ifeq (%(modtype),resource)
1653     BD_MODDIR  := $(AROS_RESOURCES)
1654   endif
1655   ifeq (%(modtype),hook)
1656     BD_MODDIR  := $(AROS_RESOURCES)
1657   endif
1658   ifeq (%(modtype),mui)
1659     BD_MODDIR  := $(AROS_CLASSES)/Zune
1660   endif
1661   ifeq (%(modtype),mcc)
1662     BD_MODDIR  := $(AROS_CLASSES)/Zune
1663   endif
1664   ifeq (%(modtype),mcp)
1665     BD_MODDIR  := $(AROS_CLASSES)/Zune
1666   endif
1667   ifeq (%(modtype),usbclass)
1668     BD_MODDIR  := $(AROS_CLASSES)/USB
1669   endif
1670   ifeq (%(modtype),hidd)
1671     BD_MODDIR  := $(AROS_DRIVERS)
1672   endif
1673   ifeq (%(modtype),printer)
1674     BD_MODDIR  := $(AROS_PRINTERS)
1675   endif
1676 endif
1677 ifeq ($(BD_MODDIR),)
1678   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1679 endif
1681 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1682 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1683 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1685 %rule_compile_multi \
1686     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1687     cflags="$(BD_DEFDFLAGS)" cppflags="%(cppflags)" dflags="%(dflags)" \
1688     compiler="%(compiler)"
1690 # Handlers use dash instead of dot in their names
1691 ifeq (%(modtype),handler)
1692 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1693 else
1694 ifeq (%(modtype),printer)
1695 BD_MODULE := $(BD_MODDIR)/%(modname)
1696 else
1697 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1698 endif
1699 endif
1700 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1702 %(mmake)-quick : %(mmake)
1703 %(mmake)-kobj-quick : $(BD_KOBJ)
1704 %(mmake)       : $(BD_MODULE)
1705 %(mmake)-kobj  : $(BD_KOBJ)
1707 # The module is linked from all the compiled .o files
1708 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1710 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1711 # This breaks con-handler build. Here we work around this
1712 ifeq (%(modname),con)
1713     BD_ERR := $(notdir $(BD_MODULE)).err
1714 else
1715     BD_ERR := %(modname).err
1716 endif
1718 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1719                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1720                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1721                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1723 # Link kernel object file
1724 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1726 # Make these symbols local
1727 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1728             UtilityBase ExpansionBase KeymapBase KernelBase
1730 BD_SYMBOLS := $(BD_KBASE)
1732 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1733 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1734 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1735 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1736 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1737 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1738         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1739         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1740         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1743 ## Dependency fine-tuning
1745 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1746 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1748 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1749 $(BD_MODULE) : | $(BD_MODDIR)
1750 $(BD_KOBJ) : | $(KOBJSDIR)
1751 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1753 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1754 %(mmake)-clean ::
1755         @$(ECHO) "Cleaning up for module %(modname)"
1756         @$(RM) $(FILES)
1757 %end
1758 #------------------------------------------------------------------------------
1761 #------------------------------------------------------------------------------
1762 # Build a module - core routine
1763 # Explanation of this macro is done in the developer's manual
1764 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1765   files="$(basename $(call WILDCARD, *.c))" \
1766   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1767   linklibfiles= linklibobjs= cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1768   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1769   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1770   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
1771   includedir= libdir= \
1772   build_abi= build_library=
1774 # We will employ a terrifying, but unavoidable, hack here.
1775 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1776 # ignores GNU Make ifeq() statements, but will process any #MM
1777 # headed lines in the file.
1779 # So, to make the following #MM lines conditional on whether we want
1780 # to build the ABI, Library, or both, we define build_abi= and 
1781 # build_library as 'M' to enable, or '' to disable, which allows genmf
1782 # to do the following conversions:
1784 #  #%(build_abi)M includes-foo: foo-include
1785 #    becomes, when build_abi=M
1786 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1787 #    but, when build_abi= ...
1788 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1790 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1792 # Define metamake targets and their dependencies
1793 #MM %(mmake)
1794 #MM %(mmake)-quick
1795 #MM %(mmake)-makefile
1796 #MM %(mmake)-clean
1798 # ABI targets:
1799 #M%(build_abi)- includes-all : %(mmake)-includes
1800 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1801 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1802 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1803 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1804 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1805 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1806 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1807 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1808 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1809 #M%(build_abi) %(mmake)-includes-quick
1810 #M%(build_abi) %(mmake)-includes-dirs
1811 #M%(build_abi) %(mmake)-fd
1813 # Library targets
1814 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1815 #%(build_library)M %(mmake)-kobj-quick : 
1817 # Library with ABI targets:
1818 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1819 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1821 # All MetaMake targets defined by this macro
1822 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1824 ifeq (%(build_library),M)
1825 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1826 endif
1828 ifeq (%(build_abi),M)
1829 BD_ALLTARGETS += %(mmake)-includes \
1830                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1831                  %(mmake)-linklib %(mmake)-fd
1832 endif
1834 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1836 ifeq (%(modname),)
1837 $(error using %build_module: modname may not be empty)
1838 endif
1839 ifeq (%(modtype),)
1840 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1841 endif
1843 # Default values for variables and arguments
1844 BD_DEFLINKLIBNAME := %(modname)
1845 BD_DEFCPPFLAGS := %(cppflags)
1846 ifneq (%(includedir),)
1847     BD_DEFCPPFLAGS += -I%(includedir)
1848 endif
1849 BD_DEFDFLAGS := %(cflags)
1850 BD_DEFDXXFLAGS := %(cxxflags)
1851 ifeq (%(lto),yes)
1852 ifeq (%(compiler),target)
1853 BD_DEFDFLAGS    := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDFLAGS)
1854 BD_DEFDXXFLAGS := $(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH) $(BD_DEFDXXFLAGS)
1855 endif
1856 endif
1857 OBJDIR ?= $(GENDIR)/$(CURDIR)
1859 ## Create genmodule include Makefile for the module
1861 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1863 %rule_genmodule_makefile \
1864     modname="%(modname)" modtype="%(modtype)" \
1865     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1866     conffile="%(conffile)"
1868 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1870 GLOB_MKDIRS += %(objdir)
1872 # Do not parse these statements if metatarget is not appropriate
1873 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1875 # suppress makes warning that the Makefile doesnt yet exist
1876 # on early passes (it will generate the file as needed though)
1877 # when we include it.
1878 -include %(objdir)/Makefile.%(modname)%(modtype)
1880 BD_DEFMODDIR := $(%(modname)_MODDIR)
1881 ifeq (%(archspecific),yes)
1882 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1883 endif
1886 ## include files generation
1888 ifneq (%(includedir),)
1889 BD_INCDIR    := %(includedir)
1890 else
1891 BD_INCDIR    := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_INCLUDE)
1892 endif
1893 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1894 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1896 ifeq (%(build_abi),M)
1897 %(mmake)-includes-quick : %(mmake)-includes
1898 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1899     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1900     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1902 ifneq ($(%(modname)_INCLUDES),)
1903 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1904                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1905                          conffile="%(conffile)"
1907 %rule_copy_diff_multi \
1908     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1909     stampfile="%(objdir)/%(modname)_geninc"
1911 %rule_copy_diff_multi \
1912     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1913     stampfile="%(objdir)/%(modname)_incs"
1915 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1917 TMP%(modname)_INCDIRS := \
1918     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1919     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1920     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1921 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1923 endif
1925 endif
1927 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1928     modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1929     conffile="%(conffile)" version="%(version)"
1931 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1932 $(BD_DEFLIBDEFSINC) :
1933         @$(ECHO) "Generating $@"
1934         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1936 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1937 GLOB_MKDIRS += %(objdir)/include
1939 ## Extra genmodule src files generation
1940 ## 
1941 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1942     modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1943     conffile="%(conffile)"
1945 GLOB_MKDIRS += %(objdir)/linklib
1947 ifeq (%(build_abi),M)
1948 ## Create FD file
1949 ifeq (%(includedir),)
1950 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/fd
1951 else
1952 BD_FDDIR := %(includedir)/../fd
1953 endif
1954 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1956 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1957     modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1959 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1961 GLOB_MKDIRS += $(BD_FDDIR)
1962 endif
1964 ## Compilation
1966 BD_FILES      := %(files)
1967 BD_CXXFILES := %(cxxfiles)
1969 BD_LIBFILES := %(linklibfiles)
1971 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1973 BD_FILEMATCH = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
1974 BD_MATCHARCH = $(foreach matchfile,$(2),$(foreach archfile,$(1),$(if $(call BD_FILEMATCH,$(archfile),$(notdir $(matchfile))),$(matchfile),)))
1975 BD_FILTERARCH = $(filter-out $(call BD_MATCHARCH,$(1),$(2)),$(2))
1976 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1977 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1979 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1980 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1981 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1982 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1983 BD_NARCHFILES := $(call BD_FILTERARCH,$(BD_ARCHFILES),$(BD_FILES))
1984 BD_NLIBARCHFILES := $(call BD_FILTERARCH,$(BD_LIBARCHFILES),$(BD_LIBFILES))
1985 BD_ARCHNLIBFILES := $(call BD_FILTERARCH,$(BD_LIBFILES),$(BD_LIBARCHFILES))
1987 BD_CPPFLAGS      := %(cppflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1988 ifneq (%(includedir),)
1989 BD_CPPFLAGS        += -I%(includedir)
1990 endif
1991 BD_CFLAGS        := %(cflags) $(%(modname)_CFLAGS)
1992 BD_LINKLIBCFLAGS := %(cflags) $(%(modname)_LINKLIBCFLAGS)
1993 BD_CXXFLAGS      := %(cxxflags) $(%(modname)_CXXFLAGS)
1994 ifeq (%(lto),yes)
1995 ifeq (%(compiler),target)
1996 BD_LTOFLAGS=$(LTO_BINARY_CFLAGS) $(CFLAGS_NO_STRICT_ALIASING) $(NOWARN_LTO_TYPE_MISMATCH)
1997 BD_CFLAGS        := $(BD_LTOFLAGS) $(BD_CFLAGS)
1998 BD_LINKLIBCFLAGS := $(BD_LTOFLAGS) $(BD_LINKLIBCFLAGS)
1999 BD_CXXFLAGS      := $(BD_LTOFLAGS) $(BD_CXXFLAGS)
2000 endif
2001 endif
2002 BD_DFLAGS        := %(dflags) $(%(modname)_DFLAGS)
2003 BD_LINKLIBDFLAGS := %(dflags) $(%(modname)_LINKLIBDFLAGS)
2004 BD_DXXFLAGS      := %(dxxflags) $(%(modname)_DXXFLAGS)
2006 ifeq (%(modtype),library)
2007     BD_LIBSUFFIX := 
2008 else
2009     BD_LIBSUFFIX := .%(modtype)
2010 endif
2012 ifeq (%(libdir),)
2013 BD_LIBDIR := %(prefix)/$(AROS_DIR_DEVELOPER)/$(AROS_DIR_LIB)
2014 else
2015 BD_LIBDIR := %(libdir)
2016 endif
2018 ifeq (%(build_abi),M)
2019 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
2020 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
2021 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
2022     BD_LINKLIB :=
2023 else
2024     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
2025     ifneq (%(modname),%(linklibname))
2026         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
2027     endif
2028 endif
2029 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
2031 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
2032 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
2033 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
2034     BD_RELLINKLIB :=
2035 else
2036     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
2037     ifneq (%(modname),%(linklibname))
2038         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
2039     endif
2040 endif
2041 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
2042 endif
2044 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
2045 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
2046                  %(linklibobjs)
2047 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
2048                  %(linklibobjs)
2049 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
2050 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
2052 BD_CCFILES := $(BD_NARCHFILES)
2053 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
2054 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2055 BD_LINKLIBCCGENFILES := $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
2057 %rule_compile_cxx_multi \
2058     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2059     cppflags=$(BD_CPPFLAGS) cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
2060     compiler="%(compiler)"
2061 %rule_compile_multi \
2062     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
2063     cppflags=$(BD_CPPFLAGS) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
2064     compiler="%(compiler)"
2065 %rule_compile_multi \
2066     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
2067     cppflags="$(BD_CPPFLAGS) -D__AROS__" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
2068     compiler="%(compiler)"
2069 %rule_compile_multi \
2070     basenames=$(BD_NLIBARCHFILES) targetdir="%(objdir)/linklib" \
2071     cppflags="$(BD_CPPFLAGS) -D__AROS__" cflags=$(BD_LINKLIBCFLAGS) dflags=$(BD_LINKLIBDFLAGS) \
2072     compiler="%(compiler)"
2073 %rule_compile_multi \
2074     basenames=$(BD_LINKLIBCCGENFILES) srcdir="%(objdir)/linklib" targetdir="%(objdir)/linklib" \
2075     cppflags="$(BD_CPPFLAGS) -D__AROS__" cflags=$(BD_LINKLIBCFLAGS) dflags=$(BD_LINKLIBDFLAGS) \
2076     compiler="%(compiler)"
2078 ifneq ($(BD_LINKLIBAFILES),)
2079 %rule_assemble_multi \
2080     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
2081 endif
2083 ## Linking
2085 ifeq (%(modsuffix),)
2086 BD_SUFFIX := %(modtype)
2087 else
2088 BD_SUFFIX := %(modsuffix)
2089 endif
2091 ifeq (%(build_library),M)
2092 # Handlers use dash instead of dot in their names
2093 ifeq ($(BD_SUFFIX),handler)
2094 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2095 else
2096 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2097 endif
2098 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2099 else
2100 BD_MODULE :=
2101 BD_KOBJ   :=
2102 endif
2104 %(mmake)-quick      : %(mmake)
2105 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2106 ifeq (%(build_library),M)
2107 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2108 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2109 endif
2110 ifeq (%(build_abi),M)
2111 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2112 endif
2114 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2115            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2117 ifeq (%(nostartup),yes)
2118 # Handlers always have entry point
2119 ifneq (%(modtype),handler)
2120 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2121 endif
2122 endif
2124 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2125 # This breaks con-handler build. Here we work around this
2126 ifeq (%(modname),con)
2127     BD_ERR := $(notdir $(BD_MODULE)).err
2128 else
2129     BD_ERR := %(modname).err
2130 endif
2132 ifeq (%(build_library),M)
2133 # The module is linked from all the compiled .o files
2134 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2135                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2136                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2137                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2138 endif
2140 ifeq (%(build_abi),M)
2141 # Link static lib
2142 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2143 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2144 ifneq ($(BD_LINKLIB),)
2145 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2146 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2147 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2148 endif
2150 $(BD_LINKLIB) : | $(BD_LIBDIR)
2151 GLOB_MKDIRS += $(BD_LIBDIR)
2152 endif
2154 ifneq ($(BD_RELLINKLIB),)
2155 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2156 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2157 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2158 endif
2160 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2161 GLOB_MKDIRS += $(BD_LIBDIR)
2162 endif
2163 endif
2165 ifeq (%(build_library),M)
2166 # Link kernel object file
2167 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2169 # Make these symbols local
2170 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2171             UtilityBase ExpansionBase KeymapBase KernelBase
2173 BD_SYMBOLS := $(BD_KBASE)
2175 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2176 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2177 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2178 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2179 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2180 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2181         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2182         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2183         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2184 endif
2186 ## Dependency fine-tuning
2188 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2190 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2192 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2193 $(BD_MODULE) : | %(prefix)/%(moduledir)
2194 $(BD_KOBJ)   : | $(KOBJSDIR)
2195 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2197 # Some include files need to be generated before the .c can be parsed.
2198 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2200 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2201     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2202 $(BD_DEPS) : $(BD_DFILE_DEPS)
2203 endif
2205 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2206     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2207     %(objdir)/Makefile.%(modname)%(modtype) \
2208     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2209     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2210     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2211     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2212     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2213     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2214     $(BD_ENDOBJS)
2215 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2216 %(mmake)-clean ::
2217         @$(ECHO) "Cleaning up for module %(modname)"
2218         @$(RM) $(FILES)
2220 endif # $(TARGET) in $(BD_ALLTARGETS)
2221 %end
2222 #------------------------------------------------------------------------------
2224 #------------------------------------------------------------------------------
2225 # Build a module - ABI and library
2226 # Explanation of this macro is done in the developer's manual
2227 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2228   files="$(basename $(call WILDCARD, *.c))" \
2229   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2230   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2231   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2232   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2233   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2234   includedir= libdir=
2236 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2237    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2238    files="%(files)" cxxfiles="%(cxxfiles)" \
2239    linklibname="%(linklibname)" \
2240    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2241    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2242    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2243    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2244    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2245    includedir="%(includedir)" libdir="%(libdir)" \
2246    build_abi=M build_library=M
2248 %end
2249 #------------------------------------------------------------------------------
2252 #------------------------------------------------------------------------------
2253 # Build a module skeleton ABI
2254 # This is a stripped-down version of build_module, it only creates include
2255 # files and the linklibs.
2256 # This is used when for plugins or classes with the same API, but no actual
2257 # implementation here.
2258 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2259   linklibfiles= linklibobjs= cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2260   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2261   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2262   compiler=target nostartup=yes archspecific=no \
2263   includedir= libdir=
2265 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2266   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2267   linklibname="%(linklibname)" \
2268   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2269   cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2270   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2271   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2272   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2273   includedir="%(includedir)" libdir="%(libdir)" \
2274   build_abi=M build_library=
2276 %end
2277 #------------------------------------------------------------------------------
2279 #------------------------------------------------------------------------------
2280 # Build a module library - no includes nor linklibs
2281 # Explanation of this macro is done in the developer's manual
2282 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2283   files="$(basename $(call WILDCARD, *.c))" \
2284   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2285   cflags=$(CFLAGS) cppflags=$(CPPFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2286   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2287   uselibs= usehostlibs= \
2288   compiler=target lto=$(TARGET_LTO) nostartup=yes archspecific=no \
2289   includedir= libdir=
2291 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2292    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2293    files="%(files)" cxxfiles="%(cxxfiles)" \
2294    cflags="%(cflags)" cppflags="%(cppflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2295    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2296    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" lto=%(lto) \
2297    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2298   includedir="%(includedir)" libdir="%(libdir)" \
2299    build_abi= build_library=M
2301 %end
2302 #------------------------------------------------------------------------------
2306 #------------------------------------------------------------------------------
2307 # Build a linklib.
2308 # - mmake is the mmaketarget
2309 # - libname is the baselibname e.g. lib%(libname).a will be created
2310 # - files are the C source files to include in the lib. The list of files
2311 #   has to be given without the .c suffix
2312 # - cxxfiles are C++ source files without suffix.
2313 #   NB: files will be matched in the order .cpp > .cxx > .cc
2314 # - asmfiles are the asm files to include in the lib. The list of files has to
2315 #   be given without the .s suffix
2316 # - objs additional object to link into the linklib. The objects have to be
2317 #   given with full absolute path and the .o suffix.
2318 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2319 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2320 # - cflags are the flags to compile the source (default $(CFLAGS))
2321 # - dflags are the flags used during makedepend (default equal to cflags)
2322 # - aflags are the flags used during assembling (default $(AFLAGS))
2323 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2324   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2325   includedir= \
2326   cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2327   aflags=$(AFLAGS) compiler=target lto=$(TARGET_LTO)
2329 # assign and generate the local variables used in this macro
2330 BD_LIBNAME    := %(libname)
2331 BD_LINKLIB    := %(libdir)/lib%(libname).a
2333 BD_FILES      := %(files)
2334 BD_ASMFILES   := %(asmfiles)
2335 BD_CXXFILES := %(cxxfiles)
2337 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2338 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2339 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2341 BD_OBJS       := $(BD_ARCHOBJS) \
2342                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2343                  %(objs)
2344 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2346 BD_CPPFLAGS := %(cppflags)
2347 ifneq (%(includedir),)
2348 BD_CPPFLAGS    += -I%(includedir)
2349 endif
2350 BD_CFLAGS    := %(cflags)
2351 BD_CXXFLAGS := %(cxxflags)
2352 ifeq (%(lto),yes)
2353 ifeq (%(compiler),target)
2354 BD_CFLAGS    := $(LTO_CFLAGS) $(BD_CFLAGS)
2355 BD_CXXFLAGS := $(LTO_CFLAGS) $(BD_CXXFLAGS)
2356 endif
2357 endif
2358 BD_AFLAGS    := %(aflags)
2359 BD_DFLAGS    := %(dflags)
2360 BD_DXXFLAGS := %(dxxflags)
2362 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2365 %(mmake)-quick : %(mmake)
2367 #MM %(mmake) : includes-generate-deps
2368 %(mmake) : $(BD_LINKLIB)
2370 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2372 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2373     compiler="%(compiler)" cppflags=$(BD_CPPFLAGS) cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2374 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2375     compiler="%(compiler)" cppflags=$(BD_CPPFLAGS) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2376 %rule_assemble basename=% targetdir="%(objdir)" \
2377     aflags=$(BD_AFLAGS)
2379 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2380 endif
2382 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2384 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2385 $(BD_LINKLIB) : | %(libdir)
2386 GLOB_MKDIRS += %(objdir) %(libdir)
2388 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2390 %(mmake)-clean ::
2391         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2392         @$(RM) $(FILES)
2394 %end
2395 #------------------------------------------------------------------------------
2398 #------------------------------------------------------------------------------
2399 # Build catalogs.
2400 # - mmake is the mmaketarget
2401 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2402 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2403 # - subdir is the destination subdirectory of the catalogs
2404 # - name is the name of the destination catalog, without the .catalog suffix
2405 # - source is the path to the generated source code file
2406 # - dir is the base destination directory (default $(AROS_CATALOGS))
2407 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2408 # - srcdir is the directory in which the *.cd and *.ct files are searched
2410 %define build_catalogs mmake=/A name=/A subdir=/A \
2411  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2412  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2414 ifeq (%(description),)
2415 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2416 else
2417 BD_DESC := %(description)
2418 endif
2420 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2422 ifeq (%(catalogs),)
2423 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2424 else
2425 BD_LNGS := %(catalogs)
2426 endif
2428 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2429 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2432 %(mmake) : $(BD_OBJS) %(source)
2434 $(BD_OBJS) : | $(BD_DIRS)
2435 GLOB_MKDIRS += $(BD_DIRS)
2437 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2438         @$(ECHO) "Creating   %(name) catalog for language $*."
2439         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2441 ifneq (%(source),)
2442 %(source) : BD_DESC := $(BD_DESC)
2443 %(source) : BD_SRC := $(BD_SRC)
2444 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2445         @$(ECHO) "Creating   %(name) catalog source file $@"
2446         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2447 endif
2449 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2451 %(mmake)-clean ::
2452         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2453         @$(RM) $(FILES)
2455 .PHONY: %(mmake) %(mmake)-clean
2457 %end
2458 #-----------------------------------------------------------------------------
2461 #-----------------------------------------------------------------------------
2462 # Build icons.
2463 # - mmake is the mmaketarget
2464 # - icons is a list of icon base names (i.e. without the .info suffix)
2465 # - dir is the destination directory
2466 # - srcdir is where *.png and *.info.src are sought
2467 #-----------------------------------------------------------------------------
2469 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2471 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2474 %(mmake) : $(BD_OBJS)
2476 ifeq (%(image),)
2478 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2479         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2480         @$(ILBMTOICON) $+ $@
2482 else
2484 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2485         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2486         @$(ILBMTOICON) $+ $@
2488 endif
2490 $(BD_OBJS) : | %(dir)
2491 GLOB_MKDIRS += %(dir)
2493 %(mmake)-clean : FILES := $(BD_OBJS)
2495 %(mmake)-clean ::
2496         @$(RM) $(FILES)
2498 .PHONY: %(mmake) %(mmake)-clean
2500 %end
2501 #-----------------------------------------------------------------------------
2504 #------------------------------------------------------------------------------
2505 # Compile files for an arch-specific replacement of code for a module
2506 # - files: the basenames of the C files to compile.
2507 # - asmfiles: the basenames of the asm files to assemble.
2508 # - mainmmake: the mmake of the module in the main directory to compile these
2509 #   arch specific files for.
2510 # - maindir: the object directory for the main module
2511 # - arch: the arch for which to compile these files. It can have the form
2512 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2513 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2514 # - dflags: the flags used during creation of dependency file. If not specified
2515 #   the same value as cflags will be used
2516 # - aflags: the flags used during assembling
2517 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2518 #   the target compiler is used
2519 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2520  cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2522 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2523     $(error no files or asmfiles given)
2524 endif
2526 ifneq (%(cxxfiles),)
2527     $(error cxx support is TODO)
2528 endif
2530 %buildid targets="%(mainmmake)-%(arch)"
2532 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2533 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2534 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2535 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2536 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2537 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2538 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2539 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2540 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2541 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2542 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2543 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2544 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2545 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2546 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2548 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2550 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2551 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2552 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2553 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2554 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2555 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2556 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2557 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2559 ifneq (%(modulename),)
2560 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2561 endif
2563 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2564     BD_TARGET := %(mainmmake)-%(arch)-quick
2565 else
2566     BD_TARGET := %(mainmmake)-%(arch)
2567 endif
2570 ifeq ($(TARGET),$(BD_TARGET))
2571 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2572 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2573 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2574 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2575 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2576 endif
2578 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2579 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2582 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2585 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2587 ifeq ($(findstring %(compiler),host kernel target),)
2588     $(error unknown compiler %(compiler))
2589 endif
2590 ifneq (%(modulename),)
2591 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=%(cppflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2592 else
2593 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2594 endif
2595 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2596 ifeq (%(compiler),target)
2597 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
2598 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(TMP_CPPFLAGS)
2599 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(TMP_CFLAGS) $(SAFETY_CFLAGS)
2600 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2601 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2602 endif
2603 ifeq (%(compiler),host)
2604 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2605 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2606 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2607 endif
2608 ifeq (%(compiler),kernel)
2609 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
2610 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CPPFLAGS:=$(KERNEL_CPPFLAGS) $(TMP_CPPFLAGS)
2611 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
2612 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2613 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2614 endif
2616 ifeq ($(TARGET),$(BD_TARGET))
2617 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2618         %compile_q cmd=$(TMP_CMD) opt="$(TMP_CFLAGS) $(TMP_CPPFLAGS)" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2619 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2620         %compile_q cmd=$(TMP_CMD) opt="$(TMP_CFLAGS) $(TMP_CPPFLAGS)" iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2621 endif
2623 ifeq (%(dflags),)
2624 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=%(cppflags) $(BD_DEFLIBDEFSINC$(BDID))
2625 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
2626 else
2627 $(BD_DEPS$(BDID)) : TMP_CPPFLAGS:=%(cppflags)
2628 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2629 endif
2630 ifeq ($(TARGET),$(BD_TARGET))
2631 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2632         %mkdepend_q cc=$(TMP_CMD) flags="$(TMP_DFLAGS) $(TMP_CPPFLAGS)"
2634 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2635         %mkdepend_q cc=$(TMP_CMD) flags="$(TMP_DFLAGS) $(TMP_CPPFLAGS)"
2636 endif
2638 $(BD_ASMOBJS$(BDID)) : CPPFLAGS:=%(cppflags)
2639 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2641 ifeq ($(TARGET),$(BD_TARGET))
2642 $(BD_OBJDIR$(BDID))/%.o : %.s
2643         %assemble_q
2644 $(BD_OBJDIR$(BDID))/%.o : %.S
2645         %assemble_q
2646 endif
2648 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2649 %end
2650 #------------------------------------------------------------------------------
2653 #------------------------------------------------------------------------------
2654 # generate asm files from c files (for debugging purposes)
2655 %define ctoasm_q
2656 %.s : %.c
2657         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2658         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(CPPFLAGS) $< -c -o $@
2659 %end
2660 #------------------------------------------------------------------------------
2663 #------------------------------------------------------------------------------
2664 # Copy files from one directory to another.
2666 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2668 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2670 GLOB_MKDIRS += %(dst)
2672 .PHONY : %(mmake)
2675 %(mmake) : | %(dst) 
2676         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2678 %end
2679 #------------------------------------------------------------------------------
2682 #------------------------------------------------------------------------------
2683 # Copy a directory recursively to another place, preserving the original 
2684 # hierarchical structure
2686 # src: the source directory whose content will be copied.
2687 # dst: the directories where to copy src's content. If not existing, they will be made.
2688 # excludefiles: files which must not be copied. Path must be relative to src.
2690 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2692 .PHONY : %(mmake)
2695 %(mmake) :
2696         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2698 %end
2699 #------------------------------------------------------------------------------
2702 #------------------------------------------------------------------------------
2703 #   Copy include files into the includes directories. There are currently
2704 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2705 #   for building tools that need to run on the host system $(GENINCDIR). The
2706 #   $(GENINCDIR) path must not contain any references to the C runtime
2707 #   library header files.
2709 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2710     dir= compiler=target includedir=$(AROS_INCLUDES)
2712 ifeq ($(findstring %(compiler),host kernel target),)
2713 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2714 endif
2716 ifneq (%(dir),)
2717 TMP_DIR := %(dir)
2718 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2719 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2720 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2721 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2722 ifeq ($(TMP_DIRFIRST),/)
2723 BD_INC_PATH := %(dir)/
2724 else
2725 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2726 endif
2727 else
2728 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2729 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2730 endif
2732 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2733         @$(CP) $< $@
2735 ifeq (%(compiler),target)
2737 ifneq (%(dir),)
2738 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2739 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2740 else
2741 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2742 endif
2744 BD_INCL_FILES += $(BD_INCL_FILES2)
2746 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2747         @$(CP) $< $@
2748 endif
2751 %(mmake) : $(BD_INCL_FILES)
2753 .PHONY: %(mmake)
2755 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2756 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2757 %end
2758 #------------------------------------------------------------------------------
2761 #------------------------------------------------------------------------------
2762 %define make_hidd_stubs hidd=/A cppflags=$(CPPFLAGS) cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2763 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2764 STUBS_MEM := $(addsuffix .o,$(STUBS))
2765 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2766 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2767 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2769 #MM- linklibs : hidd-%(hidd)-stubs
2770 #MM- %(parenttarget): hidd-%(hidd)-stubs
2771 #MM hidd-%(hidd)-stubs : includes includes-copy
2772 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2774 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2775         %mklib_q from=$^
2777 $(STUBS_OBJ) : $(STUBS_SRC) 
2778         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT)" opt="%(cflags) %(cppflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2780 $(STUBS_DEP) : $(STUBS_SRC)
2781         %mkdepend_q flags="%(dflags) %(cppflags)"
2783 setup ::
2784         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2787 clean ::
2788         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2790 DEPS := $(DEPS) $(STUBS_DEP)
2792 %end
2793 #------------------------------------------------------------------------------
2796 #------------------------------------------------------------------------------
2797 # Build an imported source tree which uses the configure script from the
2798 # autoconf package.  This rule will try to "integrate" the produced files as
2799 # much as possible in the AROS build, for example by putting libraries in the
2800 # standard library directory, includes in the standard include directory, and
2801 # so on. You can however override this behaviour.
2803 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2804 # be %(bindir) (or its deduced value) when running "make install", and
2805 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2806 # configure script some more parameters whose value depends upon the PROGDIR
2807 # env var, so that the program gets all its stuff installed in the proper place
2808 # when building it, but when running it from inside AROS it can also find that
2809 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2810 # the configuration parameters set when running ./configure
2812 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2813 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2814 # to the name which has to follow it.
2816 # Arguments:
2818 #     - mmake           = the meta make target.
2819 #     - package         = name of the package to be built.
2820 #     - srcdir          = the location of the unpacked source code. Defaults
2821 #                         to $(SRCDIR)/$(CURDIR).
2822 #     - prefix          = the target directory. Must be an absolute path of the
2823 #                         host system. Defaults to $(AROS_CONTRIB).
2824 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2825 #                         Defaults to the value of the prefix option.
2826 #     - extraoptions    = additional options for the configure script.
2827 #     - usecppflags      = enable the use of cpp flags. some external configure
2828 #                         scripts will not set their own cppflags if it is already
2829 #                         set, so this allows them to be disabled (unless you can provide
2830 #                         all the options they would need)
2831 #     - extracppflags      = additional preprocessor flags.
2832 #     - extracflags     = additional flags to use with the C compiler.
2833 #     - extracxxflags   = additional flags to use with the C++ compiler.
2834 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2835 #                         Defaults to the value of the nix argument.
2836 #     - nix             = enable u*nix path handling, i.e. a path like
2837 #                         /progdir//./file will be translated to
2838 #                         progdir:file during run-time. Defaults to no.
2839 #     - compiler        = target, host or kernel. Defaults to target.
2840 #     - install_target  = the command used for installing. Defaults to install. Leave
2841 #                         it empty if you want to suppress installing.
2842 #     - preconfigure    = a metatarget which is executed before configure is called.
2843 #     - postconfigure   = a metatarget which is executed after configure is called.
2844 #     - postinstall     = a metatarget which is executed after installing.
2845 #     - install_env     = set additional options for installing.
2846 #     - use_build_env   = if yes the configuration environment is used for
2847 #                         installing, too. Defaults to no.
2849 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2850 # like this:
2852 # if nix_dir_layout
2853 #    --prefix = $(aros_prefix)
2854 #    progdir = $(aros_prefix)/bin
2855 # else
2856 #    if nix
2857 #        --prefix = /PROGDIR
2858 #        --bindir = /PROGDIR
2859 #        --sbindir = /PROGDIR
2860 #        --libdir = /LIB
2861 #        --includedir = /INCLUDE
2862 #        --oldincludedir = /INCLUDE   
2863 #    else
2864 #        --prefix = $(aros_prefix)
2865 #    endif
2867 #    progdir = $(aros_prefix)
2869 #    # Install options
2870 #    bindir = $(prefix)
2871 #    sbindir = $(prefix)
2872 #    libdir = $(AROS_LIB)
2873 #    includedir = $(AROS_INCLUDES)
2874 #    oldincludedir = $(AROS_INCLUDES)
2875 # endif
2878 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) \
2879     prefix= gendir= basedir=$(CURDIR) extraoptions= \
2880     usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
2881     aros_prefix= nix_dir_layout= nix=no compiler=target crossbuild=no \
2882     install_target=install preconfigure= postconfigure= postinstall= \
2883     config_env_extra= install_env= use_build_env=no buildflags=yes gnuflags=yes
2885 ifneq (%(prefix),)
2886     %(mmake)-prefix := %(prefix)
2887 else
2888     %(mmake)-prefix := $(AROS_CONTRIB)
2889 endif
2891 ifneq (%(aros_prefix),)
2892     %(mmake)-aros_prefix := %(aros_prefix)
2893 else
2894     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2895 endif
2897 BD_NIXFLAG ?= -nix
2899 ifeq (%(nix),yes)
2900     %(mmake)-nix    := $(BD_NIXFLAG)
2901     %(mmake)-volpfx := /
2902     %(mmake)-volsfx := /
2903     
2904     ifeq (%(nix_dir_layout),)
2905         %(mmake)-nix_dir_layout := yes
2906     endif
2907 else
2908     %(mmake)-volsfx := :
2909     
2910     ifeq (%(nix_dir_layout),)
2911         %(mmake)-nix_dir_layout := no
2912     endif
2913 endif
2915 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2917 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2918         exec_prefix=$(%(mmake)-prefix) %(install_env)
2920 # Check if chosen compiler is valid
2921 ifeq ($(findstring %(compiler),host target kernel),)
2922   $(error unknown compiler %(compiler))
2923 endif
2925 # Set legacy 'host' variable based on chosen compiler
2926 ifeq (%(compiler),host)
2927     host := yes
2928     ifeq (%(basedir),)
2929         %(mmake)-pkgbasedir := $(HOSTGENDIR)
2930     else
2931         %(mmake)-pkgbasedir := $(HOSTGENDIR)/%(basedir)
2932     endif
2933 else
2934     host := no
2935     ifeq (%(basedir),)
2936         %(mmake)-pkgbasedir := $(GENDIR)
2937     else
2938         %(mmake)-pkgbasedir := $(GENDIR)/%(basedir)
2939     endif
2940 endif
2941 ifneq (%(gendir),)
2942     ifeq (%(basedir),)
2943         %(mmake)-pkgbasedir := %(gendir)
2944     else
2945         %(mmake)-pkgbasedir := %(gendir)/%(basedir)
2946     endif
2947 endif
2949 ifeq (%(package),)
2950     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)
2951 else
2952     %(mmake)-pkgdir := $(%(mmake)-pkgbasedir)/%(package)
2953 endif
2955 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2956 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2958 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2959     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2960     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2961 else
2962     ifeq (%(nix),yes)
2963         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2964         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2965     else
2966         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2967     endif
2969     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2970     
2971     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2972         sbindir=$(%(mmake)-prefix) \
2973         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2974         oldincludedir=$(AROS_INCLUDES) %(install_env)
2975 endif
2977 ifneq ($(DEBUG),yes)
2978     %(mmake)-s_flag = -s
2979 endif
2981 # Set up build environment, and options for configure script
2982 ifeq (%(compiler),host)
2983     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2984     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2985     # since that won't get picked up during configure.
2986     # We also cannot pass in the compiler including std flags so we need to use
2987     # the "plain" host compiler.
2988     %(mmake)-cfg-env := %(config_env_extra) \
2989         CPP="$(HOST_CPP)" \
2990         CXXCPP="$(HOST_CPP)" \
2991         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2992         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2993         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2994         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2995         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2996         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2997         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2998         TARGET_AS="$(TARGET_AS)" \
2999         OBJCOPY="$(OBJCOPY)" \
3000         TARGET_RANLIB="$(RANLIB)" \
3001         TARGET_STRIP="$(STRIP_PLAIN)" \
3002         TARGET_NM="$(NM_PLAIN)" \
3003         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
3004 endif
3005 ifeq (%(compiler),target)
3006     %(mmake)-cfg-env := %(config_env_extra) \
3007         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPER)/lib/pkgconfig" \
3008         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)"
3009     %(mmake)-cfg-env += CPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3010         CXXCPP="$(strip $(TARGET_CPP) $(TARGET_SYSROOT))" \
3011         CC="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3012         CXX="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3013         LD="$(strip $(TARGET_LD))"
3014 ifeq (%(crossbuild),yes)
3015     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3016         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3017 ifeq (%(usecppflags),yes)
3018     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
3019 endif
3020 else
3021     %(mmake)-cfg-env += CFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3022         CXXFLAGS="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))"
3023 ifeq (%(usecppflags),yes)
3024     %(mmake)-cfg-env += CPPFLAGS="$(strip $(USER_CPPFLAGS) %(extracppflags))"
3025 endif
3026 endif
3027     %(mmake)-cfg-env += LDFLAGS="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3028         CC_FOR_BUILD="$(strip $(HOST_DEF_CC))" \
3029         CFLAGS_FOR_BUILD="$(strip $(HOST_CFLAGS) $(%(mmake)-s_flag))" \
3030         CXX_FOR_BUILD="$(strip $(HOST_CXX))" \
3031         CXXFLAGS_FOR_BUILD="$(strip $(HOST_CXXFLAGS) $(%(mmake)-s_flag))" \
3032         LD_FOR_BUILD="$(strip $(HOST_LD))" \
3033         LDFLAGS_FOR_BUILD="$(strip $(HOST_LDFLAGS) $(%(mmake)-s_flag))" \
3034         CC_FOR_HOST="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3035         CFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3036         CXX_FOR_HOST="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3037         CXXFLAGS_FOR_HOST="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3038         LD_FOR_HOST="$(strip $(TARGET_LD))" \
3039         LDFLAGS_FOR_HOST="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3040         CC_FOR_TARGET="$(strip $(TARGET_CC) $(TARGET_SYSROOT))" \
3041         CFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CFLAGS) $(USER_CFLAGS) -L$(AROS_DEVELOPER)/lib %(extracflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3042         CXX_FOR_TARGET="$(strip $(TARGET_CXX) $(TARGET_SYSROOT))" \
3043         CXXFLAGS_FOR_TARGET="$(strip $(ISA_FLAGS) $(USER_INCLUDES) $(BASE_CXXFLAGS) $(USER_CXXFLAGS) -L$(AROS_DEVELOPER)/lib %(extracxxflags) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3044         LD_FOR_TARGET="$(strip $(TARGET_LD))" \
3045         LDFLAGS_FOR_TARGET="$(strip -L$(AROS_DEVELOPER)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag))" \
3046         AR="$(strip $(AR_PLAIN))" \
3047         AS="$(strip $(TARGET_AS))" \
3048         OBJCOPY="$(strip $(OBJCOPY))" \
3049         RANLIB="$(strip $(RANLIB))" \
3050         STRIP="$(strip $(STRIP_PLAIN))" \
3051         TARGET_CC="$(strip $(KERNEL_CC) $(KERNEL_SYSROOT))" \
3052         TARGET_CFLAGS="$(strip $(KERNEL_CFLAGS) $(%(mmake)-s_flag))" \
3053         TARGET_CXX="$(strip $(KERNEL_CXX) $(KERNEL_SYSROOT))" \
3054         TARGET_CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) $(%(mmake)-s_flag))" \
3055         TARGET_AS="$(strip $(TARGET_AS))" \
3056         TARGET_RANLIB="$(strip $(RANLIB))" \
3057         TARGET_STRIP="$(strip $(STRIP_PLAIN))" \
3058         TARGET_NM="$(strip $(NM_PLAIN))"
3059 ifeq (%(buildflags),yes)
3060     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3061     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3062     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3063 endif
3064 ifeq (%(gnuflags),yes)
3065     %(mmake)-config_opts += --without-pic --disable-shared
3066     %(mmake)-config_opts += --disable-nls --without-x
3067 endif
3068 endif
3069 ifeq (%(compiler),kernel)
3070     %(mmake)-cfg-env := %(config_env_extra) \
3071         CPP="$(KERNEL_CPP)" \
3072         CXXCPP="$(KERNEL_CPP)" \
3073         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
3074         CFLAGS="$(strip $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag))" \
3075         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
3076         CXXFLAGS="$(strip $(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag))"
3077 ifeq (%(usecppflags),yes)
3078     %(mmake)-cfg-env += CPPFLAGS="$(strip $(KERNEL_CPPFLAGS) %(extracppflags))"
3079 endif
3080     %(mmake)-cfg-env += AS="$(KERNEL_AS)" \
3081         CC_FOR_BUILD="$(HOST_DEF_CC)" \
3082         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
3083         CXX_FOR_BUILD="$(HOST_CXX)" \
3084         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
3085         RANLIB="$(RANLIB)" \
3086         TARGET_RANLIB="$(RANLIB)" \
3087         TARGET_STRIP="$(STRIP_PLAIN)" \
3088         TARGET_NM="$(NM_PLAIN)"
3089 ifeq (%(buildflags),yes)
3090     %(mmake)-config_opts += --target=$(AROS_TARGET_CPU)-aros
3091     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)
3092     %(mmake)-config_opts += --host=$(AROS_TARGET_CPU)-aros
3093 endif
3094 ifeq (%(gnuflags),yes)
3095     %(mmake)-config_opts += --without-pic --disable-shared
3096     %(mmake)-config_opts += --disable-nls --without-x
3097 endif
3098 endif
3100 ifeq (%(use_build_env),yes)
3101     BUILD_ENV := $(%(mmake)-cfg-env)
3102 endif
3104 ifneq ("$(wildcard %(srcdir)/Makefile)","")
3105 # in an ideal world, we would depend on the files in the source directory,
3106 # so we could copy them when they change. unfortunately filenames with
3107 # spaces causes problems with this
3108 $(%(mmake)-pkgdir)/.local-copy:
3109         %mkdirs_q $(%(mmake)-pkgdir)
3110         @$(ECHO) "Copying Local-Build Sources to  \`$(patsubst $(TOP)/%,%,$(abspath $(%(mmake)-pkgdir)))'"
3111         @$(CP) -Rf "%(srcdir)/." $(%(mmake)-pkgdir)/ && $(TOUCH) $@
3113 $(%(mmake)-pkgdir)/.files-touched : $(%(mmake)-pkgdir)/.local-copy
3115     %(mmake)-cfg-srcdir=$(%(mmake)-pkgdir)
3116 else
3117     %(mmake)-cfg-srcdir=%(srcdir)
3118 endif
3119 %(mmake)-make-env := -C $(%(mmake)-pkgdir)
3121 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3123 # When building for the host, we don't need to build the
3124 # linklibs - this is especially true when building the
3125 # crosstool toolchain on 'foreign' architectures (such as
3126 # building PPC on x86)
3128 #MM- %(mmake)-host : setup includes %(mmake)-quick
3129 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
3130 #MM- %(mmake): %(mmake)-%(compiler)
3132 # Using -j1 in install_command may result in a warning but finally
3133 # it does its job. make install for gcc does not work reliably for -jN
3134 # where N > 1.
3135 ifneq (%(install_target),)
3136     %(mmake)-install_command = \
3137         $(ECHO) "Installing from build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3138         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
3139         $(%(mmake)-make-env) %(install_target) -j1
3141     %(mmake)-uninstall_command = \
3142     $(RM) $(%(mmake)-installflag) && \
3143     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
3144     $(%(mmake)-install_opts) $(%(mmake)-make-env) uninstall
3145 else
3146     %(mmake)-install_command   := true
3147     %(mmake)-uninstall_command := true
3148 endif
3150 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
3153 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3156 # N.B.: the make test for the targets being up to date generates a benign Error 1.
3158 $(%(mmake)-installflag) : $(%(mmake)-configflag)
3159         @$(IF) ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q $(%(mmake)-make-env); then \
3160             $(RM) $(%(mmake)-installflag) && \
3161             $(ECHO) "Performing build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))" && \
3162             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" $(%(mmake)-make-env) && \
3163             $(%(mmake)-install_command) && \
3164             $(TOUCH) $@ -r $^; \
3165         fi
3167 $(%(mmake)-pkgdir)/.files-touched:
3168         %mkdirs_q $(%(mmake)-pkgdir)
3169         @find %(srcdir) -exec $(TOUCH) -c -r $(%(mmake)-cfg-srcdir)/configure '{}' \; && \
3170         $(TOUCH) $@
3173 %(mmake)-uninstall :
3174         $(%(mmake)-uninstall_command)
3177 %(mmake)-configure : $(%(mmake)-configflag)
3179 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo $(%(mmake)-cfg-srcdir) | sed 's/^\(.\):\//\/\1\//')
3180 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3181         @$(RM) $@
3182         %mkdirs_q $(%(mmake)-pkgdir)
3183         @$(ECHO) "Configuring build in         $(subst $(TOP)/,,$(%(mmake)-pkgdir))"
3184         @cd $(%(mmake)-pkgdir) && \
3185         find . -name config.cache -exec $(RM) '{}' \; && \
3186         $(%(mmake)-cfg-env) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) %(extraoptions) && \
3187         $(TOUCH) $@
3190 %(mmake)-clean : %(mmake)-uninstall
3191         @$(RM) $(%(mmake)-pkgdir)
3192 %end
3193 #------------------------------------------------------------------------------
3196 #------------------------------------------------------------------------------
3197 # Build an imported source tree which uses cmake 
3199 # Arguments:
3201 #     - mmake           = the meta make target.
3202 #     - package         = name of the package to be built.
3203 #     - srcdir          = the location of the unpacked source code. Defaults
3204 #                         to $(SRCDIR)/$(CURDIR).
3205 #     - prefix          = the target directory. Must be an absolute path of the
3206 #                         host system. Defaults to $(AROS_CONTRIB).
3207 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3208 #                         Defaults to the value of the prefix option.
3209 #     - extraoptions    = additional options for the cmake script.
3210 #     - usecppflags     = enable the use of cpp flags. some external cmake
3211 #                         scripts will not set their own cppflags if it is already
3212 #                         set, so this allows them to be disabled (unless you can provide
3213 #                         all the options they would need)
3214 #     - cppflags        = preprocessor flags.
3215 #     - cflags          = flags to use with the C compiler.
3216 #     - cxxflags        = flags to use with the C++ compiler.
3217 #     - installoptions    = additional options for the install step.
3220 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3221     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3222     usecppflags=yes cppflags=$(CPPFLAGS) cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3224 ifneq (%(prefix),)
3225     %(mmake)-prefix := %(prefix)
3226 else
3227     %(mmake)-prefix := $(AROS_CONTRIB)
3228 endif
3230 ifneq (%(aros_prefix),)
3231     %(mmake)-aros_prefix := %(aros_prefix)
3232 else
3233     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3234 endif
3236 ifeq (%(compiler),host)
3237     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3238     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3239     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3240     BD_CPPFLAGS := $(HOST_CPPFLAGS)
3241     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3242     ifeq (%(usecppflags),yes)
3243         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3244     endif
3245     %(mmake)-cmake_opts += -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))"
3246     ifeq (%(package),)
3247         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3248     else
3249         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3250     endif
3251 else
3252     BD_LDFLAGS   := %(ldflags)
3253     BD_CFLAGS := %(cflags) 
3254     BD_CXXFLAGS := %(cxxflags)
3255     BD_CPPFLAGS := %(cppflags)
3256     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(strip $(BD_CFLAGS))"
3257     ifeq (%(usecppflags),yes)
3258         %(mmake)-cmake_opts += -DCMAKE_CPP_FLAGS="$(BD_CPPFLAGS)"
3259     endif
3260     %(mmake)-cmake_opts  += -DCMAKE_CXX_FLAGS="$(strip $(BD_CXXFLAGS))" -DCMAKE_EXE_LINKER_FLAGS="$(strip $(BD_LDFLAGS))"
3261     ifeq (%(package),)
3262         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3263     else
3264         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3265     endif
3266 endif
3267 ifneq (%(gendir),)
3268     ifeq (%(package),)
3269         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3270     else
3271         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3272     endif
3273 endif
3275 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3276 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3278 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3280 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3282 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3285 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3287 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3288         $(IF) ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3289             $(RM)  $(%(mmake)-installflag) && \
3290             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3291             cd $(%(mmake)-pkgdir) && \
3292             cmake %(installoptions) -P cmake_install.cmake && \
3293             $(TOUCH) $@ -r $^; \
3294         fi
3296 $(%(mmake)-pkgdir)/.files-touched:
3297         %mkdirs_q $(%(mmake)-pkgdir)
3298         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3299         $(TOUCH) $@
3302 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3304 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3305 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3306         $(RM) $@
3307         %mkdirs_q $(%(mmake)-pkgdir)
3308         cd $(%(mmake)-pkgdir) && \
3309         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3310         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3311         $(TOUCH) $@
3314 %(mmake)-clean : %(mmake)-uninstall
3315         @$(RM) $(%(mmake)-pkgdir)
3316 %end
3317 #------------------------------------------------------------------------------
3320 #------------------------------------------------------------------------------
3321 # Given an archive name, patches names and locations where to find them, fetch
3322 # the archive and the patches from any of those locations, unpack the archive
3323 # and then apply the patches.
3325 # Locations currently supported are http and ftp sites, plus local filesystem
3326 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3327 # the fetch.sh script needs to be modified, since this macro relies on that script.
3329 # Arguments:
3331 #     - mmake           = mmaketarget
3332 #     - archive_origins = list of locations where to find the archive. They are tried
3333 #                         in sequence, until the archive is found and fetching it 
3334 #                         succeeded. If not specified, the current directory is assumed.
3335 #     - archive         = the archive name. Mandatory.
3336 #     - suffixes        = a list of suffixes to append to the package name plus the
3337 #                         version. Each one of them is tried until a matching archive is
3338 #                         found. They are appended to patches and these are tried the
3339 #                         same way as packages are.
3340 #     - location        = the local directory where to put the fetched archive and patches.
3341 #                         If not specified, the directory specified by destination is used.
3342 #     - destination     = the directory to unpack the archive to.
3343 #                         If not specified, the current directory is assumed.
3344 #     - patches_origins = list of locations where to find the patches. They are tried
3345 #                         in sequence, until a patch is found and fetching it 
3346 #                         succeeded. If not specified, the current directory is assumed.
3347 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3348 #                         patch_name[:[patch_subdir][:patch_opt]].
3350 #                             - patch_name   = the name of the patch file
3351 #                             - patch_subdir = the directory within \destination\ where to
3352 #                                              apply the patch.
3353 #                             - patch_opt    = any options to pass to the `patch' command
3354 #                                              when applying the patch.
3355 #                         
3356 #                         The patch_subdir and patch_opt fields are optional.
3358 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3359     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3361 .PHONY: %(mmake)
3363 ifneq (%(location),)
3364     %(mmake)-location := %(location)
3365 else
3366     %(mmake)-location := %(destination)
3367 endif
3370 %(mmake) :
3371         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3372         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3373 %end
3374 #------------------------------------------------------------------------------
3377 #------------------------------------------------------------------------------
3378 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3379 # unpatched source tree and runs diff against this and a previously fetched and possibly
3380 # patched tree. Depending on what happens after patching during a normal build it might
3381 # give best results if the new patch is created directly after fetch.
3383 # Arguments:
3385 #     - mmake       = mmaketarget
3386 #     - archive     = archive base name
3387 #     - srcdir      = the top level directory the package is unpacked to, useful if
3388 #                     an archive unpacks to a directory other than its name suggests.
3389 #                     this should not be deeper than a single path element.
3390 #     - suffixes    = a list of suffixes to append to the the package name plus the
3391 #                     version. Each one of them is tried until a matching archive is
3392 #                     found.
3393 #     - destination = the directory to unpack the archive to.
3394 #     - excludes    = diff patterns to exclude files or directories from the patch
3396 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3398 .PHONY: %(mmake)
3400 ifneq (%(excludes),)
3401     %(mmake)-exclude := -X ./exclude.patterns
3402 endif
3404 ifneq (%(srcdir),)
3405     %(mmake)-srcdir := %(srcdir)
3406 else
3407     %(mmake)-srcdir := %(archive)
3408 endif
3410 #MM- %(mmake) : %(mmake)-diff
3411 #MM- %(mmake)-quick : %(mmake)-diff
3414 %(mmake)-diff:
3415         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3416         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3417         cd %(destination)/tmp ; \
3418         $(FOR) f in %(excludes) ; do \
3419             $(ECHO) $$f >> ./exclude.patterns ; \
3420         done ; \
3421         diff -ruN $(%(mmake)-exclude) \
3422             $(%(mmake)-srcdir) \
3423             $(%(mmake)-srcdir).aros \
3424             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3425         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3426         $(RM) %(destination)/tmp
3427 %end
3428 #------------------------------------------------------------------------------
3431 #------------------------------------------------------------------------------
3432 # Joins the features of %fetch and %build_with_configure.
3434 # If a patch is provided, it *must* be named the following way:
3436 #    <package name>-<version number>-aros.diff
3438 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3439 # CD'ing into the archive's extracted directory.
3441 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3442 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3443 # to make that patch fully comprehensive.
3445 # Arguments:
3447 #    - mmake            = the meta make target.
3448 #    - package          = the GNU package name, sans version and archive format suffixes.
3449 #    - subpackage       = ???
3450 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3451 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3452 #    - version          = the package's version number, or otherwise any other version string.
3453 #                         It gets appended to the package name to form the basename of the archive.
3454 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3455 #                         version. Each one of them is tried until a matching archive is found.
3456 #                         Defaults to "tar.bz2 tar.gz".
3457 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3458 #    - builddir         = override the location we expect to run configure/make in.
3459 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3460 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3461 #                         fetched or not. Default to no.
3462 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3463 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3464 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3465 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3466 #    - usecppflags      = same meaning as the one for the %build_with_configure macro.
3467 #    - extracppflags    = same meaning as the one for the %build_with_configure macro.
3468 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3469 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3470 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3471 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3472 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3473 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3474 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3475 #    - nix              = same meaning as the one for the %build_with_configure macro.
3476 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3477 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3479 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target crossbuild=no install_target=install \
3480     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= basedir=$(CURDIR) package_repo= patch=no patch_repo= \
3481     prefix= aros_prefix= preconfigure= postconfigure= postinstall= \
3482     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)" \
3483     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no buildflags=yes gnuflags=yes
3485 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3486 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3487 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3488 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3490 %(mmake)-archbase  := %(package)-%(version)
3492 ifeq (%(compiler),host)
3493     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3494 else
3495     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3496 endif
3498 ifeq (%(prefix),)
3499     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3500 else
3501     %(mmake)-prefix := %(prefix)
3502 endif
3504 ifneq (%(subpackage),)
3505     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3506 else
3507     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3508 endif
3510 ifneq (%(srcdir),)
3511     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3512 else
3513     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3514 endif
3516 ifneq (%(builddir),)
3517     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3518 else
3519     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3520 endif
3522 ifeq (%(patch),yes)
3523     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3524 else
3525     %(mmake)-%(subpackage)-patches_specs := ::
3526 endif
3528 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3529     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3530     archive_origins=". %(package_repo)" \
3531     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3533 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3534     archive=$(%(mmake)-%(subpackage)-archbase) \
3535     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3536     suffixes="%(suffixes)" \
3537     destination=$(%(mmake)-portdir)
3539 #MM- %(mmake) : %(mmake)-%(subpackage)
3541 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3543 %(mmake)-%(subpackage)-package-basename := \
3544     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3546 ifneq (%(create_pkg),no)
3547     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3548 endif
3550 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)"  crossbuild="%(crossbuild)" install_target="%(install_target)" \
3551      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" basedir="%(basedir)" \
3552      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3553      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3554      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3555      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" buildflags=%(buildflags) gnuflags=%(gnuflags)
3557 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3558 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3561 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3563 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3564 #that $^ and $@ have exactly the same mtime, and in that case make tries
3565 #to rebuild $@ again, which would fail because the directory where
3566 #the package got installed would not exist anymore. 
3567 #We work this around by using an if statement to manually check the mtimes.
3568 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3569         @$(IF) $(TEST) $(%(mmake)-installflag) -nt $@ || ! $(TEST) -f $@; then \
3570             $(RM) $@ ; \
3571             $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3572             $(MKDIR) -p "$(DISTDIR)/Packages" ; \
3573             $(MKDIR) -p "$(%(mmake)-prefix)" ; \
3574             cd $(%(mmake)-%(subpackage)-package-dir) ; \
3575             tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3576             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3577         fi
3578 %end
3579 #------------------------------------------------------------------------------
3582 #------------------------------------------------------------------------------
3583 # Joins the features of %fetch and %build_with_configure, taking advantage of
3584 # the naming scheme of GNU packages. GNU packages names are in the form
3586 #     <package name>-<version number>.<archive format suffix>
3588 # If a patch is provided, it *must* be named the following way:
3590 #    <package name>-<version number>-aros.diff
3592 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3593 # CD'ing into the archive's extracted directory.
3595 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3596 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3597 # to make that patch fully comprehensive.
3599 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3601 # Arguments:
3603 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3605 #    - prefix           = defaults to $(GNUDIR).
3606 #    - aros_prefix      = defaults to /GNU.
3608 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A crossbuild=no suffixes="tar.bz2 tar.gz" \
3609     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3610     aros_prefix=/GNU config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3611     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3613 GNU_REPOSITORY := gnu://
3615 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3616     crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3617     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3618     patch="%(patch)" patch_repo="%(patch_repo)" \
3619     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracppflags="%(extracppflags)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3620     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=%(nix)
3622 %end
3623 #------------------------------------------------------------------------------
3626 #------------------------------------------------------------------------------
3627 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3628 # that the package is a "Developer" package, and as such it needs to be placed
3629 # under the $(AROS_DEVELOPER) directory, as a default. 
3631 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3632 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3633 # "mmake" argument, because the metatarget is implicitely defined as
3635 #     #MM- development-%(package)
3637 %define fetch_and_build_gnu_development package=/A subpackage= version=/A  crossbuild=no suffixes="tar.bz2 tar.gz" \
3638     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPER) \
3639     aros_prefix=/Developer config_env_extra= preconfigure= postconfigure= postinstall=  nix=yes \
3640     extraoptions= usecppflags=yes extracppflags= extracflags="$(OPTIMIZATION_CFLAGS)" extracxxflags="$(OPTIMIZATION_CFLAGS)"
3642 #MM- development : development-%(package)
3645 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3646    version="%(version)" crossbuild="%(crossbuild)" suffixes="%(suffixes)" srcdir="%(srcdir)" \
3647    package_repo="%(package_repo)" \
3648    patch="%(patch)" patch_repo="%(patch_repo)" \
3649    prefix="%(prefix)"  aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" usecppflags="%(usecppflags)" extracflags="%(extracflags)" extracppflags="%(extracppflags)" extracxxflags="%(extracxxflags)" \
3650    config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" nix=%(nix)
3653 postinstall-%(package)-delete-la-files:
3654         $(RM) %(prefix)/lib/*.la
3656 %end
3657 #------------------------------------------------------------------------------
3659 # Builds a kickstart package in PKG format
3661 # Arguments:
3663 #    - mmake   = target name
3664 #    - file    = destination file name with path
3666 # Other arguments are self-explanatory
3668 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3669     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3671 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3672 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3673 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3674 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3675 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3676 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3678 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3679 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3680 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3681 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3682 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3683 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3685 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3686     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3687 PKG_DIR   := $(dir %(file))
3690 %(mmake) : %(file)
3693 %(mmake)-quick : %(file)
3695 %(file): $(PKG_FILES) | $(PKG_DIR)
3696         @$(ECHO) Packaging $@...
3697         @$(SRCDIR)/tools/package/pkg c $@ $^
3699 %compress_file mmake="%(mmake)" file="%(file)"
3701 GLOB_MKDIRS += $(PKG_DIR)
3703 %end
3705 #------------------------------------------------------------------------------
3706 # Compresses %(file) with a gzip.
3707 # Good in conjunction with for example %build_prog
3709 %define compress_file mmake=/A file=/A
3711 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3714 %(mmake)-gz-quick : %(file).gz
3716 %(file).gz: %(file)
3717         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3718         @gzip -9 -f $^
3720 %end
3722 #------------------------------------------------------------------------------
3723 # Links a kickstart module in ELF format
3724 # Arguments are similar to make_package
3726 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3727     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3729 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3730 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3731 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3732 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3733 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3734 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3736 ifeq (%(startup),)
3737     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3738 else
3739     KOBJ_STARTUP := %(startup)
3740 endif
3742 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3744 TMP_LDFLAGS := %(ldflags)
3746 # Make a list of the lib files this program depends on.
3747 # In LDFLAGS remove white space between -L and directory
3748 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3749 # Filter out only the libdirs and remove -L
3750 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3751 # Add trailing /
3752 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3753 # Add normal linklib path
3754 TMP_DIRS += $(AROS_LIB)/
3755 # add lib and .a to static linklib names
3756 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3757 # search for the linklibs in the given path, ignore ones not found
3758 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3759     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3762 TMP_DIRS += $(dir %(file))
3763 ifneq (%(map),)
3764     TMP_LDFLAGS += $(GENMAP) %(map)
3765     TMP_DIRS    += $(dir %(map))
3766 endif
3768 #MM %(mmake) : %(deps)
3771 %(mmake) : %(file)
3774 %(mmake)-quick : %(file)
3776 %(file): KOBJS := $(KOBJS)
3777 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3778                     -static -nosysbase -Wl,-Ur
3779 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3780 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3781         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3782         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3783 ifeq ($(DEBUG),yes)
3784         @$(STRIP) $@ --only-keep-debug -o $@.dbg
3785 endif
3786         @$(STRIP) $@
3788 %compress_file mmake="%(mmake)" file="%(file)"
3790 GLOB_MKDIRS += $(TMP_DIRS)
3792 %end