small behaviour change
[AROS.git] / config / make.tmpl
blobf549a832cd397d5dc8f7fec38cd7215e930b8e96
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="$(TARGET_CFLAGS) $(CFLAGS)" from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         @$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                         $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                         tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31                 else \
32                         $(NOP) ; \
33                 fi ; \
34         else \
35                 $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37                 exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd="$(CC) $(TARGET_SYSROOT)" opt=$(AFLAGS) from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                         $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                         $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51                 else \
52                         $(NOP) ; \
53                 fi ; \
54         else \
55                 $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57                 exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd="$(AROS_CC) $(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         %(strip) $(LINKTARGET)
83 %end
84 #------------------------------------------------------------------------------
87 #-------------------------------------------------------------------------
88 # Link a module based upon a number of arguments and the standard $(LIBS)
89 # and $(DEPLIBS) make variables.
91 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
92         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
93         @$(IF) %(cmd) $(NOSTARTUP_LDFLAGS) \
94                 $(GENMAP) %(objdir)/%(module).map \
95                 %(objs) %(libs) %(ldflags) %(endtag) \
96                 -o $@ 2>&1 > %(objdir)/%(err); \
97         then \
98                 cat %(objdir)/%(err); \
99         else \
100                 echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
101                 cat %(objdir)/%(err); \
102                 exit 1; \
103         fi
105         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
106         @$(STRIP) $@
107 %end
108 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the library
113 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
114         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
115         @%(ar) %(to) %(from)
116         @%(ranlib) %(to)
117 %end
118 #------------------------------------------------------------------------------
121 #------------------------------------------------------------------------------
122 # Create the dependency file %(to) for %(from)
123 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
124         %mkdir_q dir="$(dir %(to))"
125         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
126         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
127 %end
128 #------------------------------------------------------------------------------
131 #------------------------------------------------------------------------------
132 # Create one directory without any output
133 %define mkdir_q dir=.
134         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
135 %end
136 #------------------------------------------------------------------------------
139 #------------------------------------------------------------------------------
140 # Create several directories without any output
141 %define mkdirs_q dirs=/M
142         @$(FOR) dir in %(dirs) ; do \
143             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
144         done
145 %end
146 #------------------------------------------------------------------------------
149 #############################################################################
150 #############################################################################
151 ##                                                                         ##
152 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
153 ## mmakefile. They consist of one or more full makefile rules.             ##
154 ## In general the files generated in these macros are also defined as      ##
155 ## make targets so that they can be used as a dependency in other rules    ##
156 ##                                                                         ##
157 #############################################################################
158 #############################################################################
160 #------------------------------------------------------------------------------
161 # Generate a unique id for each of the %build... rules
162 %define buildid targets=/A
163 BDID := $(BDID)_
164 ifneq ($(filter $(TARGET),%(targets)),)
165 BDTARGETID := $(BDID)
166 endif
167 %end
168 #------------------------------------------------------------------------------
171 #------------------------------------------------------------------------------
172 # Copy file %(from) to %(to) in a makefile rule
173 %define rule_copy from=/A to=/A
174 %(to) : %(from)
175         @$(CP) $< $@
176 %end
177 #------------------------------------------------------------------------------
180 #------------------------------------------------------------------------------
181 # Copy the files %(files) to %(targetdir). For each file in %(files),
182 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
183 # appropriate subdirs are not generated by this rule so they have to be
184 # present.
185 %define rule_copy_multi files=/A targetdir=/A srcdir=.
187 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
188         @$(CP) $< $@
189 %end
190 #------------------------------------------------------------------------------
193 #------------------------------------------------------------------------------
194 # Copy the files %(files) to %(targetdir). For each file in %(files),
195 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
196 # %(stampfile) is used to keep track of when the last time the comparison has
197 # been done. The targetdir and the appropriate subdirs are not generated by 
198 # this rule so they have to be present.
199 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
200     stampfile=$(TMP_SRCDIR)/.copy_stamp
202 TMP_SRCDIR := %(srcdir)
204 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
206 %(stampfile) : COPYSRCDIR := %(srcdir)
207 %(stampfile) : TGTDIR := %(targetdir)
208 %(stampfile) : FILES := %(files)
209 %(stampfile) : $(addprefix %(srcdir)/,%(files))
210         @for f in $(FILES); do \
211              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
212                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
213              fi ; \
214         done
215         @$(TOUCH) $@
216 %end
217 #------------------------------------------------------------------------------
220 #------------------------------------------------------------------------------
221 # Will join all the files in %(from) to %(to). When text is specified it will
222 # be displayed.
223 # Restriction: at the moment when using a non-empty target dir %(from) may
224 # not have 
225 %define rule_join to=/A from=/A text=
227 %(to) : %(from)
228 ifneq (%(text),)
229         @$(ECHO) %(text)
230 endif
231         @$(CAT) $^ >$@
232 %end
233 #------------------------------------------------------------------------------
236 #------------------------------------------------------------------------------
237 # Include the dependency files and add some internal rules
238 # When depstargets is provided the depencies will only be included when one of
239 # these targets is the $(TARGET). Otherwise the dependencies will only be
240 # included when the $(TARGET) is not for setup or clean 
241 %define include_deps deps=$(DEPS)/M  depstargets=
242 ifneq (%(deps),)
243   ifneq (%(depstargets),)
244     ifneq ($(findstring $(TARGET),%(depstargets)),)
245       -include %(deps)
246     endif
247   else
248     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
249       -include %(deps)
250     endif
251   endif
252 endif
253 %end
254 #------------------------------------------------------------------------------
257 #------------------------------------------------------------------------------
258 # Create the directories %(dirs). The creation will be done by adding rules to
259 # the %(setuptarget) make target with setup as the default. 
260 %define rule_makedirs dirs=/A setuptarget=setup
262 %(setuptarget) :: %(dirs)
264 GLOB_MKDIRS += %(dirs)
266 %end
267 #------------------------------------------------------------------------------
270 #------------------------------------------------------------------------------
271 # Generate a rule to compile a C source file to an object file and generate
272 # the dependency file. Basename may contain a directory part, then the source
273 # file has to be in that directory. The generated file will be put in the
274 # object directory without the directory.
275 # options
276 # - basename: the basename of the file to compile. Use % for a wildcard rule
277 # - cflags (default $(CFLAGS)): the C flags to use for compilation
278 # - dflags: the flags used during creation of dependency file. If not specified
279 #   the same value as cflags will be used
280 # - targetdir: the directory to put the .o file and the .d file. By default
281 #   it is put in the same directory as the .c file
282 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
284 BD_NIXFLAG ?= -nix
286 ifeq (%(targetdir),)
287   TMP_TARGETBASE := %(basename)
288 else
289   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
290 endif
292 # Adjust compiler flags to suit C
293 TMP_CFLAGS := %(cflags)
294 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
295 ifeq (%(dflags),)
296   TMP_DFLAGS := %(cflags)
297 else
298   TMP_DFLAGS := %(dflags)
299 endif
301 ifeq ($(findstring %(compiler),host kernel target),)
302   $(error unknown compiler %(compiler))
303 endif
304 ifeq (%(compiler),target)
305 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
306 BD_STRIP ?= $(TARGET_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
309 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
310 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
313 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
314 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
315 endif
316 ifeq (%(compiler),host)
317 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
318 BD_STRIP ?= $(HOST_STRIP)
319 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
320 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
321 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
322 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
323 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
324 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
325 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
326 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
327 endif
328 ifeq (%(compiler),kernel)
329 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
330 BD_STRIP ?= $(ECHO) >/dev/null
331 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
332 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
333 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
334 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
335 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
336 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
337 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
338 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
339 endif
341 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
342 $(TMP_TARGETBASE).o : %(basename).c
343         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
345 ifeq (%(nix),yes)
346   $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
347 endif
348 $(TMP_TARGETBASE).d : %(basename).c
349         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
350 %end
351 #------------------------------------------------------------------------------
354 #------------------------------------------------------------------------------
355 # Generate a rule to compile a C++ source file to an object file and generate
356 # the dependency file. Basename may contain a directory part, then the source
357 # file has to be in that directory. The generated file will be put in the
358 # object directory without the directory.
359 # options
360 # - basename: the basename of the file to compile. Use % for a wildcard rule
361 # - cflags (default $(CFLAGS)): the C flags to use for compilation
362 # - dflags: the flags used during creation of dependency file. If not specified
363 #   the same value as cflags will be used
364 # - targetdir: the directory to put the .o file and the .d file. By default
365 #   it is put in the same directory as the .c file
366 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
368 ifneq (%(basename),)
369 BD_NIXFLAG ?= -nix
370 ifeq (%(targetdir),)
371   TMP_TARGETBASE := %(basename)
372 else
373   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
374 endif
376 # Adjust compiler flags to suit C++
377 TMP_CXXFLAGS := %(cxxflags)
378 ifeq (%(dxxflags),)
379   TMP_DXXFLAGS := %(cxxflags)
380 else
381   TMP_DXXFLAGS := %(dxxflags)
382 endif
384 ifeq ($(findstring %(compiler),host kernel target),)
385   $(error unknown compiler %(compiler))
386 endif
387 ifeq (%(compiler),target)
388 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
389 BD_STRIP ?= $(TARGET_STRIP)
390 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
391 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
392 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
393 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
394 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
395 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
396 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
397 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
398 endif
399 ifeq (%(compiler),host)
400 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
401 BD_STRIP ?= $(HOST_STRIP)
402 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
403 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
404 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
405 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
406 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
407 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
408 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
409 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
410 endif
411 ifeq (%(compiler),kernel)
412 KERNEL_CXX ?= $(KERNEL_CC)
413 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
414 BD_STRIP ?= $(ECHO) >/dev/null
415 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
416 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
417 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
418 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
419 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
420 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
421 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
422 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
423 endif
425 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
426 $(TMP_TARGETBASE).o : %(basename).cpp
427         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
429 ifeq (%(nix),yes)
430   $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
431 endif
432 $(TMP_TARGETBASE).d : %(basename).cpp
433         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DXXFLAGS)
435 endif
437 %end
438 #------------------------------------------------------------------------------
441 #------------------------------------------------------------------------------
442 # Generate a rule to compile an ObjC source file to an object file and generate
443 # the dependency file. Basename may contain a directory part, then the source
444 # file has to be in that directory. The generated file will be put in the
445 # object directory without the directory.
446 # options
447 # - basename: the basename of the file to compile. Use % for a wildcard rule
448 # - cflags (default $(CFLAGS)): the C flags to use for compilation
449 # - dflags: the flags used during creation of dependency file. If not specified
450 #   the same value as cflags will be used
451 # - targetdir: the directory to put the .o file and the .d file. By default
452 #   it is put in the same directory as the .m file
453 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
455 ifneq (%(basename),)
456 BD_NIXFLAG ?= -nix
457 ifeq (%(targetdir),)
458   TMP_TARGETBASE := %(basename)
459 else
460   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
461 endif
463 # Adjust compiler flags to suit ObjC
464 TMP_OBJCFLAGS := %(cflags)
465 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
466 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
467 ifeq (%(dflags),)
468   TMP_OBJCDFLAGS := %(cflags)
469 else
470   TMP_OBJCDFLAGS := %(dflags)
471 endif
473 # Define the use of cross compiler
474 ifeq ($(TARGET_OBJC),)
475   TMP_CC := $(TARGET_CC)
476 else
477   TMP_CC := $(TARGET_OBJC)
478 endif
480 ifeq ($(findstring %(compiler),host kernel target),)
481   $(error unknown compiler %(compiler))
482 endif
483 ifeq (%(compiler),target)
484 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
485 BD_STRIP ?= $(TARGET_STRIP)
486 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
487 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
488 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
489 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
490 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
491 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
492 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
493 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
494 endif
495 ifeq (%(compiler),host)
496 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
497 BD_STRIP ?= $(HOST_STRIP)
498 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
499 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
500 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
501 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
502 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
503 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
504 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
505 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
506 endif
507 ifeq (%(compiler),kernel)
508 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
509 BD_STRIP ?= $(ECHO) >/dev/null
510 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
511 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
512 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
513 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
514 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
515 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
516 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
517 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
518 endif
520 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
521 $(TMP_TARGETBASE).o : %(basename).m
522         %compile_q cmd=$(TMP_CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
524 ifeq (%(nix),yes)
525   $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
526 endif
527 $(TMP_TARGETBASE).d : %(basename).m
528         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_OBJCDFLAGS)
530 endif
532 %end
533 #------------------------------------------------------------------------------
536 #------------------------------------------------------------------------------
537 # Generate a rule to compile multiple C source files to an object file and
538 # generate the corresponding dependency files. The generated file will be put
539 # in the object directory without the directory part of the source file.
540 # options
541 # - basenames: the basenames of the files to compile. The names may include
542 #   relative or absolute path names. No wildcard is allowed
543 # - cflags (default $(CFLAGS)): the C flags to use for compilation
544 # - dflags: the flags used during creation of dependency file. If not specified
545 #   the same value as cflags will be used
546 # - targetdir: the directory to put the .o file and the .d file. By default
547 #   it is put in the same directory as the .c file. When targetdir is not
548 #   empty, path names will be stripped from the file names so that all files
549 #   are in that dir and not in subdirectories.
550 # - compiler (default target): compiler to use, target, kernel or host
551 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
552     compiler=target
554 ifeq (%(targetdir),)
555 TMP_TARGETS := $(addsuffix .o,%(basenames))
556 TMP_DTARGETS := $(addsuffix .d,%(basenames))
557 TMP_WILDCARD := %
558 else
559 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
560 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
561 TMP_WILDCARD := %(targetdir)/%
563 # Be sure that all .c files are generated
564 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
566 # Be sure that all .c files are found
567 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
568 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
569 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
570 ifneq ($(TMP_DIRS),)
571     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
572     vpath %.c $(TMP_DIRS)
573 endif
575 endif
577 TMP_CFLAGS := %(cflags)
578 ifeq (%(dflags),)
579   TMP_DFLAGS := %(cflags)
580 else
581   TMP_DFLAGS := %(dflags)
582 endif
584 ifeq ($(findstring %(compiler),host kernel target),)
585   $(error unknown compiler %(compiler))
586 endif
587 ifeq (%(compiler),target)
588 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
589 BD_STRIP ?= $(TARGET_STRIP)
590 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
591 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
592 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
593 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
594 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
595 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
596 endif
597 ifeq (%(compiler),host)
598 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
599 BD_STRIP ?= $(HOST_STRIP)
600 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
601 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
602 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
603 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
604 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
605 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
606 endif
607 ifeq (%(compiler),kernel)
608 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
609 BD_STRIP ?= $(ECHO) >/dev/null
610 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
611 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
612 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
613 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
614 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
615 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
616 endif
618 $(TMP_TARGETS) : CFLAGS := %(TMP_CFLAGS)
619 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
620         %compile_q cmd=$(CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
622 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
623         %mkdepend_q cc=$(CMD) flags=$(TMP_DFLAGS)
624 %end
625 #------------------------------------------------------------------------------
628 #------------------------------------------------------------------------------
629 # Generate a rule to compile multiple C++ source files to an object file and
630 # generate the corresponding dependency files. The generated file will be put
631 # in the object directory without the directory part of the source file.
632 # options
633 # - basenames: the basenames of the files to compile. The names may include
634 #   relative or absolute path names. No wildcard is allowed. basenames will be 
635 #   matched to supported AROS_CXXEXTS.
636 # - cflags (default $(CFLAGS)): the C flags to use for compilation
637 # - dflags: the flags used during creation of dependency file. If not specified
638 #   the same value as cflags will be used
639 # - targetdir: the directory to put the .o file and the .d file. By default
640 #   it is put in the same directory as the .c file. When targetdir is not
641 #   empty, path names will be stripped from the file names so that all files
642 #   are in that dir and not in subdirectories.
643 # - compiler (default target): compiler to use, target, kernel or host
644 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) dxxflags= \
645     targetdir= compiler=target
647 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
649 ifneq ($(TMP_CXXABSBASENAMES),)
651 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
653 # Identify the "real" c++ files from the passed in basenames
654 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
656 ifeq (%(targetdir),)
657   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
658   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
659   TMP_WILDCARD := %
660 else
661   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
662   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
663   TMP_WILDCARD := %(targetdir)/%
665   # Be sure that all source files are generated
666   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
667 endif
669 # Adjust compiler flags to suit C++
670 TMP_CXXFLAGS := %(cxxflags)
671 ifeq (%(dxxflags),)
672   TMP_DXXFLAGS := %(cxxflags)
673 else
674   TMP_DXXFLAGS := %(dxxflags)
675 endif
677 ifeq ($(findstring %(compiler),host kernel target),)
678   $(error unknown compiler %(compiler))
679 endif
680 ifeq (%(compiler),host)
681   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
682   BD_STRIP ?= $(HOST_STRIP)
683   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
684   TMP_CXXCMD:=$(HOST_CXX)
685   TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
686   TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
687   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
688   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
689 endif
690 ifeq (%(compiler),target)
691   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
692   BD_STRIP ?= $(TARGET_STRIP)
693   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
694   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
695   TMP_CXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
696   TMP_DXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
697   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
698   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
699 endif
700 ifeq (%(compiler),kernel)
701   KERNEL_CXX ?= $(KERNEL_CC)
702   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
703   BD_STRIP ?= $(ECHO) >/dev/null
704   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
705   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
706   TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
707   TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
708   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
709   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
710 endif
712 define cxx_multi_recipe_template
713  $(1).o : $(2)
714         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
716  $(1).d : $(2)
717         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
718 endef
719 ifeq (%(targetdir),)
720   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
721 else
722   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
723 endif
725 endif
727 %end
728 #------------------------------------------------------------------------------
731 #------------------------------------------------------------------------------
732 # Generate a rule to compile multiple ObjC source files to an object file and
733 # generate the corresponding dependency files. The generated file will be put
734 # in the object directory without the directory part of the source file.
735 # options
736 # - basenames: the basenames of the files to compile. The names may include
737 #   relative or absolute path names. No wildcard is allowed
738 # - cflags (default $(CFLAGS)): the C flags to use for compilation
739 # - dflags: the flags used during creation of dependency file. If not specified
740 #   the same value as cflags will be used
741 # - targetdir: the directory to put the .o file and the .d file. By default
742 #   it is put in the same directory as the .m file. When targetdir is not
743 #   empty, path names will be stripped from the file names so that all files
744 #   are in that dir and not in subdirectories.
745 # - compiler (default target): compiler to use, target, kernel or host
746 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
747     targetdir= compiler=target
749 ifneq (%(basenames),)
751 ifeq (%(targetdir),)
752   TMP_TARGETS := $(addsuffix .o,%(basenames))
753   TMP_DTARGETS := $(addsuffix .d,%(basenames))
754   TMP_WILDCARD := %
755 else
756   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
757   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
758   TMP_WILDCARD := %(targetdir)/%
760   # Be sure that all .m files are generated
761   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
763   # Be sure that all .m files are found
764   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
765   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
766   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
767   ifneq ($(TMP_DIRS),)
768     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
769     vpath %.m $(TMP_DIRS)
770   endif
771 endif
773 # Define the use of cross compiler
774 ifeq ($(TARGET_OBJC),)
775   TMP_CC := $(TARGET_CC)
776 else
777   TMP_CC := $(TARGET_OBJC)
778 endif
780 # Adjust compiler flags to suit ObjC
781 TMP_OBJCFLAGS := %(cflags)
782 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
783 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
784 ifeq (%(dflags),)
785   TMP_OBJCDFLAGS := %(cflags)
786 else
787   TMP_OBJCDFLAGS := %(dflags)
788 endif
790 ifeq ($(findstring %(compiler),host kernel target),)
791   $(error unknown compiler %(compiler))
792 endif
793 ifeq (%(compiler),target)
794   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
795   BD_STRIP ?= $(TARGET_STRIP)
796   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
797   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
798   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
799   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
800   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
801   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
802 endif
803 ifeq (%(compiler),host)
804   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
805   BD_STRIP ?= $(HOST_STRIP)
806   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
807   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
808   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
809   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
810   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
811   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
812 endif
813 ifeq (%(compiler),kernel)
814   KERNEL_OBJC ?= $(KERNEL_CC)
815   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
816   BD_STRIP ?= $(ECHO) >/dev/null
817   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
818   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
819   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
820   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
821   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
822   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
823 endif
825 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
826 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
827         %compile_q cmd=$(CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
829 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
830         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
832 endif
834 %end
835 #------------------------------------------------------------------------------
838 #------------------------------------------------------------------------------
839 # Make an alias from one arch specific build to another arch.
840 # arguments:
841 # - mainmmake: the mmake of the module in the main tree
842 # - arch: the current arch
843 # - alias: the alias to which this should point
844 %define rule_archalias mainmmake=\A arch=\A alias=\A
846 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
847 %end
848 #------------------------------------------------------------------------------
851 #------------------------------------------------------------------------------
852 # Generate a rule to assemble a source file to an object file. Basename may
853 # contain a directory part, then the source file has to be in that directory.
854 # The generated file will be put in the object directory without the directory.
855 # options
856 # - basename: the basename of the file to compile. Use % for a wildcard rule
857 # - flags (default $(AFLAGS)): the asm flags to use for assembling
858 # - targetdir: the directory to put the .o file in. By default it is put in the
859 #   same directory as the .s file
860 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
862 ifeq (%(targetdir),)
863 %(basename).o : AFLAGS := %(aflags)
864 %(basename).o : %(basename).s
865         %assemble_q
866 %(basename).o : %(basename).S
867         %assemble_q
869 else
870 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
871 %(targetdir)/$(notdir %(basename)).o : %(basename).s
872         %assemble_q
873 %(targetdir)/$(notdir %(basename)).o : %(basename).S
874         %assemble_q
876 endif
877 %end
878 #------------------------------------------------------------------------------
881 #------------------------------------------------------------------------------
882 # Generate a rule to assemble multiple source files to an object file. The
883 # generated file will be put in the object directory with the directory part
884 # of the source file stripped off.
885 # options
886 # - basenames: the basenames of the files to compile. The names may include
887 #   relative or absolute path names. No wildcard is allowed
888 # - aflags (default $(AFLAGS)): the flags to use for assembly
889 # - targetdir: the directory to put the .o file and the .d file. By default
890 #   it is put in the same directory as the .c file. When targetdir is not
891 #   empty, path names will be stripped from the file names so that all files
892 #   are in that dir and not in subdirectories.
893 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
895 ifeq (%(targetdir),)
896 TMP_TARGETS := $(addsuffix .o,%(basenames))
897 TMP_WILDCARD := %
898 else
899 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
900 TMP_WILDCARD := %(targetdir)/%
902 # Be sure that all .s files are generated
903 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
905 # Be sure that all .c files are found
906 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
907 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
908 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
909 ifneq ($(TMP_DIRS),)
910     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
911     vpath %%(suffix) $(TMP_DIRS)
912 endif
914 endif
916 BD_ASSEMBLER ?= %(cmd)
918 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
920 $(TMP_TARGETS) : AFLAGS := %(aflags)
921 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
922         %assemble_q cmd=$(TMP_CMD)
923 %end
924 #------------------------------------------------------------------------------
927 #------------------------------------------------------------------------------
928 # Link %(objs) to %(prog) using the libraries in %(uselibs)
929 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
930     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP) objdir=$(GENDIR)/$(CURDIR)
932 TMP_EXTRA_LDFLAGS := 
933 TMP_EXTRA_LIBS :=
934 ifeq (%(nix),yes)
935     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
936 endif
937 ifeq (%(usestartup),no)
938     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
939 endif
940 ifeq (%(detach),yes)
941     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
942 endif
944 # Make a list of the lib files this program depends on.
945 # In LDFLAGS remove white space between -L and directory
946 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
947 # Filter out only the libdirs and remove -L
948 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
949 # Add trailing /
950 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
951 # Add normal linklib path
952 TMP_DIRS += $(AROS_LIB)/
953 # add lib and .a to static linklib names
954 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
955 ifeq (%(usestartup),yes)
956     TMP_LIBS += startup.o
957 endif
958 ifeq (%(detach),yes)
959     TMP_LIBS += detach.o
960 endif
961 # search for the linklibs in the given path, ignore ones not found
962 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
963     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
966 %(prog) : OBJDIR := %(objdir)
967 %(prog) : OBJS := %(objs)
968 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
969 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
970 %(prog) : %(objs) $(TMP_DEPLIBS)
971         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
972 %end
973 #------------------------------------------------------------------------------
976 #------------------------------------------------------------------------------
977 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
978 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
979 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
980     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
981     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
983 TMP_EXTRA_LDFLAGS := 
984 TMP_EXTRA_LIBS :=
985 ifeq (%(nix),yes)
986     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
987 endif
988 ifeq (%(usestartup),no)
989     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
990 endif
991 ifeq (%(detach),yes)
992     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
993 endif
995 # Make a list of the lib files the programs depend on.
996 # In LDFLAGS remove white space between -L and directory
997 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
998 # Filter out only the libdirs and remove -L
999 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1000 # Add trailing /
1001 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1002 # Add normal linklib path
1003 TMP_DIRS += $(AROS_LIB)/
1004 # add lib and .a to static linklib names
1005 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1006 # search for the linklibs in the given path, ignore ones not found
1007 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1008     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1010 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1012 $(TMP_PROGS) : OBJDIR := %(objdir)
1013 $(TMP_PROGS) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
1014 $(TMP_PROGS) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1015 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1016         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
1017 %end
1018 #------------------------------------------------------------------------------
1021 #------------------------------------------------------------------------------
1022 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1023 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1025 ifeq (%(linker),target)
1026 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1027 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1028 endif
1029 ifeq (%(linker),host)
1030 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1031 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1032 endif
1033 ifeq (%(linker),kernel)
1034 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1035 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1036 endif
1038 %(libdir)/lib%(libname).a : %(objs)
1039         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1040 %end
1041 #------------------------------------------------------------------------------
1043 #------------------------------------------------------------------------------
1044 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1045 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1046 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1047     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1049 TMP_LDFLAGS  := %(ldflags)
1050 # Make a list of the lib files the programs depend on.
1051 # In LDFLAGS remove white space between -L and directory
1052 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1053 # Filter out only the libdirs and remove -L
1054 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1055 # Add trailing /
1056 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1057 # Add normal linklib path
1058 TMP_DIRS += $(AROS_LIB)/
1059 # add lib and .a to static linklib names
1060 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1061 # search for the linklibs in the given path, ignore ones not found
1062 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1063     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1066 %(module) : LIB_NAMES := %(uselibs)
1067 %(module) : OBJS := %(objs)
1068 %(module) : ENDTAG := %(endobj)
1069 %(module) : ERR := %(err)
1070 %(module) : OBJDIR := %(objdir)
1071 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1072 ifeq (%(usehostlibs),)
1073 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1074 else
1075 # Warning: the -L/usr/lib here can result in modules
1076 # linking against host libs instead of AROS libs (e.g stdc++) !!
1077 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1078                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1079 endif 
1080 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1081         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1083 %end
1084 #------------------------------------------------------------------------------
1087 #------------------------------------------------------------------------------
1088 # Generate the libdefs.h include file for a module.
1089 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1091 TMP_TARGET := %(modname)_libdefs.h
1092 TMP_DEPS := $(GENMODULE)
1093 TMP_OPTS := 
1094 ifneq (%(conffile),)
1095     ifeq ($(dir %(conffile)),./)
1096         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1097         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1098     else
1099         TMP_OPTS += -c %(conffile)
1100         TMP_DEPS += %(conffile)
1101     endif 
1102 else
1103     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1104     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1105 endif
1106 ifneq (%(modsuffix),)
1107     TMP_OPTS += -s %(modsuffix)
1108 endif
1109 ifneq (%(targetdir),)
1110     TMP_OPTS += -d %(targetdir)
1111     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1112 endif
1113 ifneq (%(version),)
1114     TMP_OPTS += -v %(version)
1115 endif
1117 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1118 $(TMP_TARGET) : MODNAME := %(modname)
1119 $(TMP_TARGET) : MODTYPE := %(modtype)
1120 $(TMP_TARGET) : $(TMP_DEPS)
1121         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1122         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1123 %end
1124 #------------------------------------------------------------------------------
1126 #------------------------------------------------------------------------------
1127 # Generate the _lib.fd file for a module.
1128 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1130 TMP_TARGET := %(modname)_lib.fd
1131 TMP_DEPS := $(GENMODULE)
1132 TMP_OPTS := 
1133 ifneq (%(conffile),)
1134     ifeq ($(dir %(conffile)),./)
1135         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1136         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1137     else
1138         TMP_OPTS += -c %(conffile)
1139         TMP_DEPS += %(conffile)
1140     endif 
1141 else
1142     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1143     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1144 endif
1145 ifneq (%(modsuffix),)
1146     TMP_OPTS += -s %(modsuffix)
1147 endif
1148 ifneq (%(targetdir),)
1149     TMP_OPTS += -d %(targetdir)
1150     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1151 endif
1153 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1154 $(TMP_TARGET) : MODNAME := %(modname)
1155 $(TMP_TARGET) : MODTYPE := %(modtype)
1156 $(TMP_TARGET) : $(TMP_DEPS)
1157         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1158         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1159 %end
1160 #------------------------------------------------------------------------------
1162 #------------------------------------------------------------------------------
1163 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1164 # generated file in this Makefile
1165 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1166     targetdir=
1168 TMP_TARGET := Makefile.%(modname)%(modtype)
1169 TMP_DEPS := $(GENMODULE)
1170 TMP_OPTS := 
1171 ifneq (%(conffile),)
1172     ifeq ($(dir %(conffile)),./)
1173         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1174         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1175     else
1176         TMP_OPTS += -c %(conffile)
1177         TMP_DEPS += %(conffile)
1178     endif 
1179 else
1180     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1181     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1182 endif
1183 ifneq (%(modsuffix),)
1184     TMP_OPTS += -s %(modsuffix)
1185 endif
1186 ifneq (%(targetdir),)
1187     TMP_OPTS += -d %(targetdir)
1188     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1189 endif
1191 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1192 $(TMP_TARGET) : MODNAME := %(modname)
1193 $(TMP_TARGET) : MODTYPE := %(modtype)
1194 $(TMP_TARGET) : $(TMP_DEPS)
1195         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1196 %end
1197 #------------------------------------------------------------------------------
1200 #------------------------------------------------------------------------------
1201 # Generate the support files for compiling a module. This includes include
1202 # files and source files. This rule has to be preceeded by
1203 # %rule_genmodule_makefile
1204 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= stubdir= \
1205     conffile=
1207 TMP_GENTARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES)
1208 TMP_STUBTARGETS := $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1209 TMP_GENTARGETS := $(addsuffix .c,$(TMP_GENTARGETS))
1210 TMP_STUBTARGETS := $(addsuffix .c,$(TMP_STUBTARGETS)) \
1211                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1214 TMP_DEPS := $(GENMODULE)
1215 TMP_OPTS :=
1217 ifneq (%(conffile),)
1218     ifeq ($(dir %(conffile)),./)
1219         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1220         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1221     else
1222         TMP_OPTS += -c %(conffile)
1223         TMP_DEPS += %(conffile)
1224     endif 
1225 else
1226     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1227     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1228 endif
1229 ifneq (%(modsuffix),)
1230     TMP_OPTS += -s %(modsuffix)
1231 endif
1232 ifneq (%(targetdir),)
1233     TMP_OPTS += -d %(targetdir)
1234     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1235     TMP_GENTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_GENTARGETS))
1236 endif
1237 ifneq (%(stubdir),)
1238     TMP_OPTS += -l %(stubdir)
1239     TMP_STUBTARGETDIR := $(shell echo %(stubdir) | sed 's/^\(.\):\//\/\1\//')
1240     TMP_STUBTARGETS := $(addprefix $(TMP_STUBTARGETDIR)/,$(TMP_STUBTARGETS))
1241     TMP_TARGETDIRS += %(stubdir)
1242 else
1243 ifneq (%(targetdir),)
1244     TMP_STUBTARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_STUBTARGETS))
1245 endif
1246 endif
1248 TMP_TARGETS := $(TMP_GENTARGETS) $(TMP_STUBTARGETS)
1249 ifneq ($(TMP_TARGETDIRS),)
1250 $(TMP_TARGETS) : | $(TMP_TARGETDIRS)
1251 endif
1253 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1254 $(TMP_TARGETS) : MODNAME := %(modname)
1255 $(TMP_TARGETS) : MODTYPE := %(modtype)
1256 $(TMP_TARGETS) : $(TMP_DEPS)
1257         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1258 ifneq (%(conffile),lib.conf)
1259         @$(IF) $(TEST) -f lib.conf; then \
1260           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1261         fi
1262 endif
1263         @$(IF) $(TEST) -f libdefs.h; then \
1264           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1265         fi
1266         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1267 %end
1268 #------------------------------------------------------------------------------
1271 #------------------------------------------------------------------------------
1272 # Generate the support files for compiling a module. This includes include
1273 # files and source files.
1274 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1275     targetdir= conffile=
1277 ifneq ($(%(modname)_INCLUDES),)
1278 TMP_TARGETS := $(%(modname)_INCLUDES)
1280 TMP_DEPS := $(GENMODULE)
1281 TMP_OPTS :=
1283 ifneq (%(conffile),)
1284     ifeq ($(dir %(conffile)),./)
1285         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1286         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1287     else
1288         TMP_OPTS += -c %(conffile)
1289         TMP_DEPS += %(conffile)
1290     endif 
1291 else
1292     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1293     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1294 endif
1295 ifneq (%(modsuffix),)
1296     TMP_OPTS += -s %(modsuffix)
1297 endif
1298 ifneq (%(targetdir),)
1299     TMP_OPTS += -d %(targetdir)
1300     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1301 endif
1303 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1304 $(TMP_TARGETS) : MODNAME := %(modname)
1305 $(TMP_TARGETS) : MODTYPE := %(modtype)
1306 $(TMP_TARGETS) : $(TMP_DEPS)
1307         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1308         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1309 endif
1310 %end
1311 #------------------------------------------------------------------------------
1313 #------------------------------------------------------------------------------
1314 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1315 # 'start' is an optional starting address
1316 # 'ldflags' is optional additional flags for the linker
1317 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1319 BD_OUTDIR := $(dir %(file))
1320 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1321 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1322 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1323 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1324 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1325 BD_OBJS += %(objs)
1327 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1329 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1330         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1331         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1332         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1334 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1335     GLOB_MKDIRS += $(BD_OUTDIR)
1336 endif
1338 %end
1340 #------------------------------------------------------------------------------
1341 # Common rules for all makefiles
1342 %define common
1343 # Delete generated makefiles
1345 clean ::
1346         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1348 include $(SRCDIR)/config/make.tail
1350 BDID := $(BDTARGETID)
1351 %end
1352 #------------------------------------------------------------------------------
1353       
1355 #############################################################################
1356 #############################################################################
1357 ##                                                                         ##
1358 ## Here are the mmakefile build macros. These are macros that takes care   ##
1359 ## of everything to go from the sources to the generated target. Also all  ##
1360 ## intermediate files and directories that are needed are created by these ##
1361 ## rules.                                                                  ##
1362 ##                                                                         ##
1363 #############################################################################
1364 #############################################################################
1366 #------------------------------------------------------------------------------
1367 # Build a program
1368 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1369     objcfiles= \
1370     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1371     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1372     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1373     includedir= libdir= \
1374     compiler=target linker= lto=$(TARGET_LTO)
1376 .PHONY : %(mmake)
1378 BD_PROGNAME  := %(progname)
1379 BD_OBJDIR    := %(objdir)
1380 BD_TARGETDIR := %(targetdir)
1381 BD_LINKER    := %(linker)
1383 # If not supplied, linker is equal to compiler
1384 ifeq ($(BD_LINKER),)
1385     BD_LINKER := %(compiler)
1386 endif
1388 BD_FILES     := %(files)
1389 BD_OBJCFILES := %(objcfiles)
1390 BD_ASMFILES  := %(asmfiles)
1391 BD_CXXFILES := %(cxxfiles)
1393 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1394 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1395 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1397 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1398 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1399 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1401 BD_CFLAGS    := %(cflags)
1402 BD_CXXFLAGS := %(cxxflags)
1403 ifeq (%(lto),yes)
1404 ifeq (%(compiler),target)
1405 BD_CFLAGS    := $(CFLAGS_LTO) $(BD_CFLAGS)
1406 BD_CXXFLAGS := $(CFLAGS_LTO) $(BD_CXXFLAGS)
1407 endif
1408 endif
1409 ifneq (%(includedir),)
1410 BD_CFLAGS    += -I%(includedir)
1411 BD_CXXFLAGS += -I%(includedir)
1412 endif
1413 BD_AFLAGS    := %(aflags)
1414 ifneq (%(includedir),)
1415 BD_AFLAGS    += -I%(includedir)
1416 endif
1417 BD_DFLAGS    := %(dflags)
1418 BD_DXXFLAGS := %(dxxflags)
1419 BD_LDFLAGS   := %(ldflags)
1420 ifneq (%(libdir),)
1421 BD_LDFLAGS   += -L%(libdir)
1422 endif
1425 %(mmake)-quick : %(mmake)
1427 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1428 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1430 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1431 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1432     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1433 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1434     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1435 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1436     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1437 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1438     aflags=$(BD_AFLAGS)
1440 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1441     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1442     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1443     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1444     cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1446 endif
1448 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1450 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1451 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1452 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1454 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1456 %(mmake)-clean ::
1457         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1458         @$(RM) $(FILES)
1460 %end
1461 #------------------------------------------------------------------------------
1464 #------------------------------------------------------------------------------
1465 # Build programs, for every C file an executable will be built with the same
1466 # name as the C file
1467 %define build_progs mmake=/A files=/A nix=no \
1468     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1469     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1470     includedir= libdir= \
1471     compiler=target \
1472     uselibs= usehostlibs= usestartup=yes detach=no lto=$(TARGET_LTO)
1474 .PHONY : %(mmake)
1476 BD_OBJDIR    := %(objdir)
1477 BD_TARGETDIR := %(targetdir)
1479 BD_FILES     := %(files)
1480 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1481 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1482 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1484 BD_CFLAGS    := %(cflags)
1485 ifeq (%(lto),yes)
1486 ifeq (%(compiler),target)
1487 BD_CFLAGS    := $(CFLAGS_LTO) $(BD_CFLAGS)
1488 endif
1489 endif
1490 ifneq (%(includedir),)
1491     BD_CFLAGS += -I%(includedir)
1492 endif
1493 BD_DFLAGS    := %(dflags)
1494 BD_LDFLAGS   := %(ldflags)
1495 ifneq (%(libdir),)
1496     BD_LDFLAGS += -L%(libdir)
1497 endif
1500 %(mmake)-quick : %(mmake)
1502 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1503 %(mmake) : $(BD_EXES)
1505 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1506 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1507     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1509 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1510     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1511     ldflags=$(BD_LDFLAGS) \
1512     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1513     usestartup="%(usestartup)" detach="%(detach)" \
1514      cmd=$(BD_LINK) strip=$(BD_STRIP) objdir=$(BD_OBJDIR)
1516 endif
1518 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1520 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1521 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1522 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1524 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1526 %(mmake)-clean ::
1527         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1528         @$(RM) $(FILES)
1530 %end
1531 #------------------------------------------------------------------------------
1534 #------------------------------------------------------------------------------
1535 # Build a module.
1536 # This is a bare version: It just compiles and links the given files. It is
1537 # assumed that all needed boiler plate code is in the files. This should only
1538 # be used for compiling external code. For AROS code use %build_module
1539 %define build_module_simple mmake=/A modname=/A modtype=/A \
1540     files="$(basename $(call WILDCARD, *.c))" \
1541     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1542     objdir=$(OBJDIR) moduledir= \
1543     uselibs= usehostlibs= compiler=target
1545 # Define metamake targets and their dependencies
1546 #MM %(mmake) : core-linklibs includes-generate-deps
1547 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1548 #MM %(mmake)-kobj-quick
1549 #MM %(mmake)-quick
1550 #MM %(mmake)-clean
1552 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1554 .PHONY : $(BD_ALLTARGETS)
1556 ifeq (%(modname),)
1557 $(error using %build_module_simple: modname may not be empty)
1558 endif
1559 ifeq (%(modtype),)
1560 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1561 endif
1563 # Default values for variables and arguments
1564 BD_DEFLINKLIBNAME := %(modname)
1565 BD_DEFDFLAGS := %(cflags)
1566 BD_DEFDXXFLAGS := %(dxxflags)
1567 OBJDIR ?= $(GENDIR)/$(CURDIR)
1568 BD_MODDIR := %(moduledir)
1569 ifeq ($(BD_MODDIR),)
1570   ifeq (%(modtype),library)
1571     BD_MODDIR  := $(AROS_LIBRARIES)
1572   endif
1573   ifeq (%(modtype),gadget)
1574     BD_MODDIR  := $(AROS_GADGETS)
1575   endif
1576   ifeq (%(modtype),datatype)
1577     BD_MODDIR  := $(AROS_DATATYPES)
1578   endif
1579   ifeq (%(modtype),handler)
1580     BD_MODDIR  := $(AROS_FS)
1581   endif
1582   ifeq (%(modtype),device)
1583     BD_MODDIR  := $(AROS_DEVS)
1584   endif
1585   ifeq (%(modtype),resource)
1586     BD_MODDIR  := $(AROS_RESOURCES)
1587   endif
1588   ifeq (%(modtype),hook)
1589     BD_MODDIR  := $(AROS_RESOURCES)
1590   endif
1591   ifeq (%(modtype),mui)
1592     BD_MODDIR  := $(AROS_CLASSES)/Zune
1593   endif
1594   ifeq (%(modtype),mcc)
1595     BD_MODDIR  := $(AROS_CLASSES)/Zune
1596   endif
1597   ifeq (%(modtype),mcp)
1598     BD_MODDIR  := $(AROS_CLASSES)/Zune
1599   endif
1600   ifeq (%(modtype),usbclass)
1601     BD_MODDIR  := $(AROS_CLASSES)/USB
1602   endif
1603   ifeq (%(modtype),hidd)
1604     BD_MODDIR  := $(AROS_DRIVERS)
1605   endif
1606   ifeq (%(modtype),printer)
1607     BD_MODDIR  := $(AROS_PRINTERS)
1608   endif
1609 endif
1610 ifeq ($(BD_MODDIR),)
1611   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1612 endif
1614 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1615 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1616 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1618 %rule_compile_multi \
1619     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1620     cflags="%(cflags)" dflags="%(dflags)" \
1621     compiler="%(compiler)"
1623 # Handlers use dash instead of dot in their names
1624 ifeq (%(modtype),handler)
1625 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1626 else
1627 ifeq (%(modtype),printer)
1628 BD_MODULE := $(BD_MODDIR)/%(modname)
1629 else
1630 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1631 endif
1632 endif
1633 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1635 %(mmake)-quick : %(mmake)
1636 %(mmake)-kobj-quick : $(BD_KOBJ)
1637 %(mmake)       : $(BD_MODULE)
1638 %(mmake)-kobj  : $(BD_KOBJ)
1640 # The module is linked from all the compiled .o files
1641 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1643 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1644 # This breaks con-handler build. Here we work around this
1645 ifeq (%(modname),con)
1646     BD_ERR := $(notdir $(BD_MODULE)).err
1647 else
1648     BD_ERR := %(modname).err
1649 endif
1651 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1652                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1653                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1654                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1656 # Link kernel object file
1657 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1659 # Make these symbols local
1660 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1661             UtilityBase ExpansionBase KeymapBase KernelBase
1663 BD_SYMBOLS := $(BD_KBASE)
1665 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1666 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1667 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1668 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1669 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1670 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1671         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1672         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1673         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1676 ## Dependency fine-tuning
1678 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1679 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1681 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1682 $(BD_MODULE) : | $(BD_MODDIR)
1683 $(BD_KOBJ) : | $(KOBJSDIR)
1684 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1686 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1687 %(mmake)-clean ::
1688         @$(ECHO) "Cleaning up for module %(modname)"
1689         @$(RM) $(FILES)
1690 %end
1691 #------------------------------------------------------------------------------
1694 #------------------------------------------------------------------------------
1695 # Build a module - core routine
1696 # Explanation of this macro is done in the developer's manual
1697 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1698   files="$(basename $(call WILDCARD, *.c))" \
1699   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1700   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1701   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1702   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1703   compiler=target nostartup=yes archspecific=no \
1704   includedir= libdir= \
1705   build_abi= build_library=
1707 # We will employ a terrifying, but unavoidable, hack here.
1708 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1709 # ignores GNU Make ifeq() statements, but will process any #MM
1710 # headed lines in the file.
1712 # So, to make the following #MM lines conditional on whether we want
1713 # to build the ABI, Library, or both, we define build_abi= and 
1714 # build_library as 'M' to enable, or '' to disable, which allows genmf
1715 # to do the following conversions:
1717 #  #%(build_abi)M includes-foo: foo-include
1718 #    becomes, when build_abi=M
1719 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1720 #    but, when build_abi= ...
1721 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1723 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1725 # Define metamake targets and their dependencies
1726 #MM %(mmake)
1727 #MM %(mmake)-quick
1728 #MM %(mmake)-makefile
1729 #MM %(mmake)-clean
1731 # ABI targets:
1732 #M%(build_abi)- includes-all : %(mmake)-includes
1733 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1734 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1735 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1736 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1737 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1738 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1739 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1740 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1741 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1742 #M%(build_abi) %(mmake)-includes-quick
1743 #M%(build_abi) %(mmake)-includes-dirs
1744 #M%(build_abi) %(mmake)-fd
1746 # Library targets
1747 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1748 #%(build_library)M %(mmake)-kobj-quick : 
1750 # Library with ABI targets:
1751 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1752 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1754 # All MetaMake targets defined by this macro
1755 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1757 ifeq (%(build_library),M)
1758 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1759 endif
1761 ifeq (%(build_abi),M)
1762 BD_ALLTARGETS += %(mmake)-includes \
1763                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1764                  %(mmake)-linklib %(mmake)-fd
1765 endif
1767 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1769 ifeq (%(modname),)
1770 $(error using %build_module: modname may not be empty)
1771 endif
1772 ifeq (%(modtype),)
1773 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1774 endif
1776 # Default values for variables and arguments
1777 BD_DEFLINKLIBNAME := %(modname)
1778 BD_DEFDFLAGS := %(cflags)
1779 BD_DEFDXXFLAGS := %(cxxflags)
1780 ifneq (%(includedir),)
1781     BD_DEFDFLAGS += -I%(includedir)
1782     BD_DEFDXXFLAGS += -I%(includedir)
1783 endif
1784 OBJDIR ?= $(GENDIR)/$(CURDIR)
1786 ## Create genmodule include Makefile for the module
1788 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1790 %rule_genmodule_makefile \
1791     modname="%(modname)" modtype="%(modtype)" \
1792     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1793     conffile="%(conffile)"
1795 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1797 GLOB_MKDIRS += %(objdir)
1799 # Do not parse these statements if metatarget is not appropriate
1800 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1802 include %(objdir)/Makefile.%(modname)%(modtype)
1804 BD_DEFMODDIR := $(%(modname)_MODDIR)
1805 ifeq (%(archspecific),yes)
1806 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1807 endif
1810 ## include files generation
1812 ifneq (%(includedir),)
1813 BD_INCDIR    := %(includedir)
1814 else
1815 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1816 endif
1817 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1818 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1820 ifeq (%(build_abi),M)
1821 %(mmake)-includes-quick : %(mmake)-includes
1822 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1823     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1824     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1826 ifneq ($(%(modname)_INCLUDES),)
1827 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1828                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1829                          conffile="%(conffile)"
1831 %rule_copy_diff_multi \
1832     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1833     stampfile="%(objdir)/%(modname)_geninc"
1835 %rule_copy_diff_multi \
1836     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1837     stampfile="%(objdir)/%(modname)_incs"
1839 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1841 TMP%(modname)_INCDIRS := \
1842     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1843     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1844     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1845 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1847 endif
1849 endif
1851 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1852                            modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1853                            conffile="%(conffile)" version="%(version)"
1855 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1856 $(BD_DEFLIBDEFSINC) :
1857         @$(ECHO) "Generating $@"
1858         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1860 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1861 GLOB_MKDIRS += %(objdir)/include
1863 ## Extra genmodule src files generation
1864 ## 
1865 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1866                       modsuffix="%(modsuffix)" targetdir="%(objdir)" stubdir="%(objdir)/linklib" \
1867                       conffile="%(conffile)"
1869 GLOB_MKDIRS += %(objdir)/linklib
1871 ifeq (%(build_abi),M)
1872 ## Create FD file
1873 ifeq (%(includedir),)
1874 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1875 else
1876 BD_FDDIR := %(includedir)/../fd
1877 endif
1878 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1880 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1881                    modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1883 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1885 GLOB_MKDIRS += $(BD_FDDIR)
1886 endif
1888 ## Compilation
1890 BD_FILES      := %(files)
1891 BD_CXXFILES := %(cxxfiles)
1893 BD_LIBFILES := %(linklibfiles)
1895 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1897 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1898 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1900 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1901 BD_LIBARCHOBJS   := $(wildcard %(objdir)/linklib/arch/*.o)
1902 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1903 BD_LIBARCHFILES  := $(basename $(notdir $(BD_LIBARCHOBJS)))
1904 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1905 BD_NLIBARCHFILES := $(filter-out $(BD_LIBARCHFILES),$(BD_LIBFILES))
1906 BD_ARCHNLIBFILES := $(filter-out $(BD_LIBFILES),$(BD_LIBARCHFILES))
1908 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1909 BD_CXXFLAGS := %(cxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CXXFLAGS)
1910 # ifeq (%(compiler),target)
1911 # BD_CFLAGS    := $(CFLAGS_LTO) $(BD_CFLAGS)
1912 # BD_CXXFLAGS := $(CFLAGS_LTO) $(BD_CXXFLAGS)
1913 # endif
1914 ifneq (%(includedir),)
1915 BD_CFLAGS     += -I%(includedir)
1916 BD_CXXFLAGS += -I%(includedir)
1917 endif
1918 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1919 BD_DXXFLAGS := %(dxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DXXFLAGS)
1921 ifeq (%(modtype),library)
1922     BD_LIBSUFFIX := 
1923 else
1924     BD_LIBSUFFIX := .%(modtype)
1925 endif
1927 ifeq (%(libdir),)
1928 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1929 else
1930 BD_LIBDIR := %(libdir)
1931 endif
1933 ifeq (%(build_abi),M)
1934 BD_LINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBFILES))
1935 BD_LINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_LINKLIBAFILES))
1936 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1937     BD_LINKLIB :=
1938 else
1939     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1940     ifneq (%(modname),%(linklibname))
1941         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1942     endif
1943 endif
1944 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1946 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBFILES))
1947 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/linklib/,$(%(modname)_RELLINKLIBAFILES))
1948 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles) $(BD_ARCHNLIBFILES)),)
1949     BD_RELLINKLIB :=
1950 else
1951     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1952     ifneq (%(modname),%(linklibname))
1953         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1954     endif
1955 endif
1956 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1957 endif
1959 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1960 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_LINKLIBFILES)) \
1961                  %(linklibobjs)
1962 BD_RELLINKLIBOBJS := $(addsuffix .o,$(addprefix %(objdir)/linklib/,$(notdir $(BD_NLIBARCHFILES))) $(addprefix %(objdir)/linklib/arch/,$(notdir $(BD_ARCHNLIBFILES))) $(BD_RELLINKLIBFILES)) \
1963                  %(linklibobjs)
1964 $(BD_LINKLIBFILES) $(BD_RELLINKLIBFILES) : | %(objdir)/linklib
1965 $(BD_LINKLIBOBJS) $(BD_RELLINKLIBOBJS) : | %(objdir)/linklib
1967 BD_CCFILES := $(BD_NARCHFILES)
1968 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES)
1969 BD_LINKLIBCCFILES := $(BD_NLIBARCHFILES) $(BD_LINKLIBCFILES) $(BD_RELLINKLIBCFILES)
1971 %rule_compile_cxx_multi \
1972     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1973     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
1974     compiler="%(compiler)"
1975 %rule_compile_multi \
1976     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1977     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1978     compiler="%(compiler)"
1979 %rule_compile_multi \
1980     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1981     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1982     compiler="%(compiler)"
1983 %rule_compile_multi \
1984     basenames=$(BD_LINKLIBCCFILES) targetdir="%(objdir)/linklib" \
1985     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1986     compiler="%(compiler)"
1988 ifneq ($(BD_LINKLIBAFILES),)
1989 %rule_assemble_multi \
1990     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)/linklib" suffix=.S
1991 endif
1993 ## Linking
1995 ifeq (%(modsuffix),)
1996 BD_SUFFIX := %(modtype)
1997 else
1998 BD_SUFFIX := %(modsuffix)
1999 endif
2001 ifeq (%(build_library),M)
2002 # Handlers use dash instead of dot in their names
2003 ifeq ($(BD_SUFFIX),handler)
2004 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
2005 else
2006 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
2007 endif
2008 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
2009 else
2010 BD_MODULE :=
2011 BD_KOBJ   :=
2012 endif
2014 %(mmake)-quick      : %(mmake)
2015 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
2016 ifeq (%(build_library),M)
2017 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2018 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
2019 endif
2020 ifeq (%(build_abi),M)
2021 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
2022 endif
2024 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
2025            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
2027 ifeq (%(nostartup),yes)
2028 # Handlers always have entry point
2029 ifneq (%(modtype),handler)
2030 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
2031 endif
2032 endif
2034 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
2035 # This breaks con-handler build. Here we work around this
2036 ifeq (%(modname),con)
2037     BD_ERR := $(notdir $(BD_MODULE)).err
2038 else
2039     BD_ERR := %(modname).err
2040 endif
2042 ifeq (%(build_library),M)
2043 # The module is linked from all the compiled .o files
2044 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
2045                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
2046                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
2047                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
2048 endif
2050 ifeq (%(build_abi),M)
2051 # Link static lib
2052 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2053 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2054 ifneq ($(BD_LINKLIB),)
2055 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2056 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2057 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2058 endif
2060 $(BD_LINKLIB) : | $(BD_LIBDIR)
2061 GLOB_MKDIRS += $(BD_LIBDIR)
2062 endif
2064 ifneq ($(BD_RELLINKLIB),)
2065 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2066 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2067 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2068 endif
2070 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2071 GLOB_MKDIRS += $(BD_LIBDIR)
2072 endif
2073 endif
2075 ifeq (%(build_library),M)
2076 # Link kernel object file
2077 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2079 # Make these symbols local
2080 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2081             UtilityBase ExpansionBase KeymapBase KernelBase
2083 BD_SYMBOLS := $(BD_KBASE)
2085 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2086 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2087 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2088 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2089 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2090 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2091         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2092         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2093         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2094 endif
2096 ## Dependency fine-tuning
2098 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d))) $(addprefix %(objdir)/linklib/,$(notdir $(BD_LINKLIBCCFILES:=.d)))
2100 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2102 $(BD_OBJS) $(BD_DEPS) : | %(objdir) %(objdir)/linklib
2103 $(BD_MODULE) : | %(prefix)/%(moduledir)
2104 $(BD_KOBJ)   : | $(KOBJSDIR)
2105 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2107 # Some include files need to be generated before the .c can be parsed.
2108 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2110 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2111     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2112 $(BD_DEPS) : $(BD_DFILE_DEPS)
2113 endif
2115 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2116     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2117     %(objdir)/Makefile.%(modname)%(modtype) \
2118     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2119     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2120     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2121     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2122     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2123     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2124     $(BD_ENDOBJS)
2125 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2126 %(mmake)-clean ::
2127         @$(ECHO) "Cleaning up for module %(modname)"
2128         @$(RM) $(FILES)
2130 endif # $(TARGET) in $(BD_ALLTARGETS)
2131 %end
2132 #------------------------------------------------------------------------------
2134 #------------------------------------------------------------------------------
2135 # Build a module - ABI and library
2136 # Explanation of this macro is done in the developer's manual
2137 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2138   files="$(basename $(call WILDCARD, *.c))" \
2139   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2140   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2141   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2142   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2143   compiler=target nostartup=yes archspecific=no \
2144   includedir= libdir=
2146 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2147    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2148    files="%(files)" cxxfiles="%(cxxfiles)" \
2149    linklibname="%(linklibname)" \
2150    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2151    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2152    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2153    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2154    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2155    includedir="%(includedir)" libdir="%(libdir)" \
2156    build_abi=M build_library=M
2158 %end
2159 #------------------------------------------------------------------------------
2162 #------------------------------------------------------------------------------
2163 # Build a module skeleton ABI
2164 # This is a stripped-down version of build_module, it only creates include
2165 # files and the linklibs.
2166 # This is used when for plugins or classes with the same API, but no actual
2167 # implementation here.
2168 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2169   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2170   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2171   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2172   compiler=target nostartup=yes archspecific=no \
2173   includedir= libdir=
2175 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2176   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2177   linklibname="%(linklibname)" \
2178   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2179   cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2180   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2181   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2182   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2183   includedir="%(includedir)" libdir="%(libdir)" \
2184   build_abi=M build_library=
2186 %end
2187 #------------------------------------------------------------------------------
2189 #------------------------------------------------------------------------------
2190 # Build a module library - no includes nor linklibs
2191 # Explanation of this macro is done in the developer's manual
2192 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2193   files="$(basename $(call WILDCARD, *.c))" \
2194   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2195   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2196   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2197   uselibs= usehostlibs= \
2198   compiler=target nostartup=yes archspecific=no \
2199   includedir= libdir=
2201 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2202    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2203    files="%(files)" cxxfiles="%(cxxfiles)" \
2204    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2205    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2206    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2207    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2208   includedir="%(includedir)" libdir="%(libdir)" \
2209    build_abi= build_library=M
2211 %end
2212 #------------------------------------------------------------------------------
2216 #------------------------------------------------------------------------------
2217 # Build a linklib.
2218 # - mmake is the mmaketarget
2219 # - libname is the baselibname e.g. lib%(libname).a will be created
2220 # - files are the C source files to include in the lib. The list of files
2221 #   has to be given without the .c suffix
2222 # - cxxfiles are C++ source files without suffix.
2223 #   NB: files will be matched in the order .cpp > .cxx > .cc
2224 # - asmfiles are the asm files to include in the lib. The list of files has to
2225 #   be given without the .s suffix
2226 # - objs additional object to link into the linklib. The objects have to be
2227 #   given with full absolute path and the .o suffix.
2228 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2229 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2230 # - cflags are the flags to compile the source (default $(CFLAGS))
2231 # - dflags are the flags used during makedepend (default equal to cflags)
2232 # - aflags are the flags used during assembling (default $(AFLAGS))
2233 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2234 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2235   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2236   includedir= \
2237   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2238   aflags=$(AFLAGS) compiler=target
2240 # assign and generate the local variables used in this macro
2241 BD_LIBNAME    := %(libname)
2242 BD_LINKLIB    := %(libdir)/lib%(libname).a
2244 BD_FILES      := %(files)
2245 BD_ASMFILES   := %(asmfiles)
2246 BD_CXXFILES := %(cxxfiles)
2248 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2249 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2250 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2252 BD_OBJS       := $(BD_ARCHOBJS) \
2253                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2254                  %(objs)
2255 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2257 BD_CFLAGS    := %(cflags)
2258 BD_CXXFLAGS := %(cxxflags)
2259 ifneq (%(includedir),)
2260 BD_CFLAGS    += -I%(includedir)
2261 BD_CXXFLAGS += -I%(includedir)
2262 endif
2263 BD_AFLAGS    := %(aflags)
2264 BD_DFLAGS    := %(dflags)
2265 BD_DXXFLAGS := %(dxxflags)
2267 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2270 %(mmake)-quick : %(mmake)
2272 #MM %(mmake) : includes-generate-deps
2273 %(mmake) : $(BD_LINKLIB)
2275 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2277 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2278     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2279 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2280     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2281 %rule_assemble basename=% targetdir="%(objdir)" \
2282     aflags=$(BD_AFLAGS)
2284 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2285 endif
2287 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2289 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2290 $(BD_LINKLIB) : | %(libdir)
2291 GLOB_MKDIRS += %(objdir) %(libdir)
2293 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2295 %(mmake)-clean ::
2296         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2297         @$(RM) $(FILES)
2299 %end
2300 #------------------------------------------------------------------------------
2303 #------------------------------------------------------------------------------
2304 # Build catalogs.
2305 # - mmake is the mmaketarget
2306 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2307 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2308 # - subdir is the destination subdirectory of the catalogs
2309 # - name is the name of the destination catalog, without the .catalog suffix
2310 # - source is the path to the generated source code file
2311 # - dir is the base destination directory (default $(AROS_CATALOGS))
2312 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2313 # - srcdir is the directory in which the *.cd and *.ct files are searched
2315 %define build_catalogs mmake=/A name=/A subdir=/A \
2316  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2317  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2319 ifeq (%(description),)
2320 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2321 else
2322 BD_DESC := %(description)
2323 endif
2325 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2327 ifeq (%(catalogs),)
2328 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2329 else
2330 BD_LNGS := %(catalogs)
2331 endif
2333 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2334 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2337 %(mmake) : $(BD_OBJS) %(source)
2339 $(BD_OBJS) : | $(BD_DIRS)
2340 GLOB_MKDIRS += $(BD_DIRS)
2342 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2343         @$(ECHO) "Creating   %(name) catalog for language $*."
2344         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2346 ifneq (%(source),)
2347 %(source) : BD_DESC := $(BD_DESC)
2348 %(source) : BD_SRC := $(BD_SRC)
2349 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2350         @$(ECHO) "Creating   %(name) catalog source file $@"
2351         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2352 endif
2354 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2356 %(mmake)-clean ::
2357         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2358         @$(RM) $(FILES)
2360 .PHONY: %(mmake) %(mmake)-clean
2362 %end
2363 #-----------------------------------------------------------------------------
2366 #-----------------------------------------------------------------------------
2367 # Build icons.
2368 # - mmake is the mmaketarget
2369 # - icons is a list of icon base names (ie. without the .info suffix)
2370 # - dir is the destination directory
2371 # - srcdir is where *.png and *.info.src are searched
2372 #-----------------------------------------------------------------------------
2374 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2376 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2379 %(mmake) : $(BD_OBJS)
2381 ifeq (%(image),)
2383 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2384         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2385         @$(ILBMTOICON) $+ $@
2387 else
2389 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2390         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2391         @$(ILBMTOICON) $+ $@
2393 endif
2395 $(BD_OBJS) : | %(dir)
2396 GLOB_MKDIRS += %(dir)
2398 %(mmake)-clean : FILES := $(BD_OBJS)
2400 %(mmake)-clean ::
2401         @$(RM) $(FILES)
2403 .PHONY: %(mmake) %(mmake)-clean
2405 %end
2406 #-----------------------------------------------------------------------------
2409 #------------------------------------------------------------------------------
2410 # Compile files for an arch-specific replacement of code for a module
2411 # - files: the basenames of the C files to compile.
2412 # - asmfiles: the basenames of the asm files to assemble.
2413 # - mainmmake: the mmake of the module in the main directory to compile these
2414 #   arch specific files for.
2415 # - maindir: the object directory for the main module
2416 # - arch: the arch for which to compile these files. It can have the form
2417 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2418 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2419 # - dflags: the flags used during creation of dependency file. If not specified
2420 #   the same value as cflags will be used
2421 # - aflags: the flags used during assembling
2422 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2423 #   the target compiler is used
2424 %define build_archspecific files= cxxfiles= asmfiles= linklibfiles= linklibobjs= mainmmake=/A maindir=/A arch=/A \
2425 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2427 ifeq (%(files) %(linklibfiles) %(linklibobjs) %(asmfiles),)
2428   $(error no files or asmfiles given)
2429 endif
2431 ifneq (%(cxxfiles),)
2432   $(error cxx support is TODO)
2433 endif
2435 %buildid targets="%(mainmmake)-%(arch)"
2437 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2438 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2439 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2440 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2441 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2442 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2443 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2444 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2445 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2446 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2447 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2448 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2449 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2450 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2451 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2453 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2455 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2456 BD_LIBOBJDIR$(BDID)  := $(GENDIR)/%(maindir)/linklib/arch
2457 BD_FILEOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(cxxfiles))))
2458 BD_LINKLIBOBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2459 BD_LINKLIBARCHOBJS$(BDID)   := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibobjs)))
2460 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2461 BD_OBJS$(BDID)    := $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2462 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files)))) $(addsuffix .d,$(addprefix $(BD_LIBOBJDIR$(BDID))/,$(notdir %(linklibfiles))))
2464 ifneq (%(modulename),)
2465 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2466 endif
2468 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2469     BD_TARGET := %(mainmmake)-%(arch)-quick
2470 else
2471     BD_TARGET := %(mainmmake)-%(arch)
2472 endif
2475 ifeq ($(TARGET),$(BD_TARGET))
2476 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2477 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2478 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(linklibfiles)))
2479 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2480 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2481 endif
2483 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2484 GLOB_MKDIRS += $(BD_OBJDIR$(BDID)) $(BD_LIBOBJDIR$(BDID))
2487 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2490 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2492 ifeq ($(findstring %(compiler),host kernel target),)
2493   $(error unknown compiler %(compiler))
2494 endif
2495 ifeq (%(compiler),target)
2496 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2497 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2498 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2499 endif
2500 ifeq (%(compiler),host)
2501 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
2502 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2503 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2504 endif
2505 ifeq (%(compiler),kernel)
2506 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2507 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2508 $(BD_FILEOBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2509 endif
2510 ifneq (%(modulename),)
2511 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2512 else
2513 $(BD_FILEOBJS$(BDID)) $(BD_LINKLIBOBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2514 endif
2515 ifeq ($(TARGET),$(BD_TARGET))
2516 $(BD_LIBOBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2517         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2518 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2519         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2520 endif
2522 ifeq (%(dflags),)
2523 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2524 else
2525 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2526 endif
2527 ifeq ($(TARGET),$(BD_TARGET))
2528 $(BD_LIBOBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2529         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2531 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2532         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2533 endif
2535 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2537 ifeq ($(TARGET),$(BD_TARGET))
2538 $(BD_OBJDIR$(BDID))/%.o : %.s
2539         %assemble_q
2540 $(BD_OBJDIR$(BDID))/%.o : %.S
2541         %assemble_q
2542 endif
2544 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2545 %end
2546 #------------------------------------------------------------------------------
2549 #------------------------------------------------------------------------------
2550 # generate asm files from c files (for debugging purposes)
2551 %define ctoasm_q
2552 %.s : %.c
2553         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2554         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2555 %end
2556 #------------------------------------------------------------------------------
2559 #------------------------------------------------------------------------------
2560 # Copy files from one directory to another.
2562 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2564 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2566 GLOB_MKDIRS += %(dst)
2568 .PHONY : %(mmake)
2571 %(mmake) : | %(dst) 
2572         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2574 %end
2575 #------------------------------------------------------------------------------
2578 #------------------------------------------------------------------------------
2579 # Copy a directory recursively to another place, preserving the original 
2580 # hierarchical structure
2582 # src: the source directory whose content will be copied.
2583 # dst: the directories where to copy src's content. If not existing, they will be made.
2584 # excludefiles: files which must not be copied. Path must be relative to src.
2586 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2588 .PHONY : %(mmake)
2591 %(mmake) :
2592         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2594 %end
2595 #------------------------------------------------------------------------------
2598 #------------------------------------------------------------------------------
2599 #   Copy include files into the includes directories. There are currently
2600 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2601 #   for building tools that need to run on the host system $(GENINCDIR). The
2602 #   $(GENINCDIR) path must not contain any references to the C runtime
2603 #   library header files.
2605 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2606     dir= compiler=target includedir=$(AROS_INCLUDES)
2608 ifeq ($(findstring %(compiler),host kernel target),)
2609 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2610 endif
2612 ifneq (%(dir),)
2613 TMP_DIR := %(dir)
2614 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2615 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2616 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2617 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2618 ifeq ($(TMP_DIRFIRST),/)
2619 BD_INC_PATH := %(dir)/
2620 else
2621 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2622 endif
2623 else
2624 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2625 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2626 endif
2628 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2629         @$(CP) $< $@
2632 ifeq (%(compiler),target)
2634 ifneq (%(dir),)
2635 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2636 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2637 else
2638 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2639 endif
2641 BD_INCL_FILES += $(BD_INCL_FILES2)
2643 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2644         @$(CP) $< $@
2645 endif
2648 %(mmake) : $(BD_INCL_FILES)
2650 .PHONY: %(mmake)
2652 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2653 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2654 %end
2655 #------------------------------------------------------------------------------
2658 #------------------------------------------------------------------------------
2659 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2660 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2661 STUBS_MEM := $(addsuffix .o,$(STUBS))
2662 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2663 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2664 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2666 #MM- linklibs : hidd-%(hidd)-stubs
2667 #MM- %(parenttarget): hidd-%(hidd)-stubs
2668 #MM hidd-%(hidd)-stubs : includes includes-copy
2669 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2671 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2672         %mklib_q from=$^
2674 $(STUBS_OBJ) : $(STUBS_SRC) 
2675         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2677 $(STUBS_DEP) : $(STUBS_SRC)
2678         %mkdepend_q flags="%(dflags)"
2680 setup ::
2681         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2684 clean ::
2685         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2687 DEPS := $(DEPS) $(STUBS_DEP)
2689 %end
2690 #------------------------------------------------------------------------------
2693 #------------------------------------------------------------------------------
2694 # Build an imported source tree which uses the configure script from the
2695 # autoconf package.  This rule will try to "integrate" the produced files as
2696 # much as possible in the AROS build, for example by putting libraries in the
2697 # standard library directory, includes in the standard include directory, and
2698 # so on. You can however override this behaviour.
2700 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2701 # be %(bindir) (or its deduced value) when running "make install", and
2702 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2703 # configure script some more parameters whose value depends upon the PROGDIR
2704 # env var, so that the program gets all its stuff installed in the proper place
2705 # when building it, but when running it from inside AROS it can also find that
2706 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2707 # the configuration parameters set when running ./configure
2709 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2710 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2711 # to the name which has to follow it.
2713 # Arguments:
2715 #     - mmake           = the meta make target.
2716 #     - package         = name of the package to be built.
2717 #     - srcdir          = the location of the unpacked source code. Defaults
2718 #                         to $(SRCDIR)/$(CURDIR).
2719 #     - prefix          = the target directory. Must be an absolute path of the
2720 #                         host system. Defaults to $(AROS_CONTRIB).
2721 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2722 #                         Defaults to the value of the prefix option.
2723 #     - extraoptions    = additional options for the configure script.
2724 #     - extracflags     = additional flags to use with the C compiler.
2725 #     - extracxxflags   = additional flags to use with the C++ compiler.
2726 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2727 #                         Defaults to the value of the nix argument.
2728 #     - nix             = enable u*nix path handling, i.e. a path like
2729 #                         /progdir//./file will be translated to
2730 #                         progdir:file during run-time. Defaults to no.
2731 #     - compiler        = target, host or kernel. Defaults to target.
2732 #     - install_target  = the command used for installing. Defaults to install. Leave
2733 #                         it empty if you want to suppress installing.
2734 #     - preconfigure    = a metatarget which is executed before configure is called.
2735 #     - postconfigure   = a metatarget which is executed after configure is called.
2736 #     - postinstall     = a metatarget which is executed after installing.
2737 #     - install_env     = set additional options for installing.
2738 #     - use_build_env   = if yes the configuration environment is used for
2739 #                         installing, too. Defaults to no.
2741 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2742 # like this:
2744 # if nix_dir_layout
2745 #    --prefix = $(aros_prefix)
2746 #    progdir = $(aros_prefix)/bin
2747 # else
2748 #    if nix
2749 #        --prefix = /PROGDIR
2750 #        --bindir = /PROGDIR
2751 #        --sbindir = /PROGDIR
2752 #        --libdir = /LIB
2753 #        --includedir = /INCLUDE
2754 #        --oldincludedir = /INCLUDE   
2755 #    else
2756 #        --prefix = $(aros_prefix)
2757 #    endif
2759 #    progdir = $(aros_prefix)
2761 #    # Install options
2762 #    bindir = $(prefix)
2763 #    sbindir = $(prefix)
2764 #    libdir = $(AROS_LIB)
2765 #    includedir = $(AROS_INCLUDES)
2766 #    oldincludedir = $(AROS_INCLUDES)
2767 # endif
2770 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2771     aros_prefix= extraoptions= extracflags= extracxxflags= nix_dir_layout= nix=no compiler=target \
2772     install_target=install preconfigure= postconfigure= postinstall= \
2773     config_env_extra= install_env= use_build_env=no gnuflags=yes
2775 ifneq (%(prefix),)
2776     %(mmake)-prefix := %(prefix)
2777 else
2778     %(mmake)-prefix := $(AROS_CONTRIB)
2779 endif
2781 ifneq (%(aros_prefix),)
2782     %(mmake)-aros_prefix := %(aros_prefix)
2783 else
2784     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2785 endif
2787 BD_NIXFLAG ?= -nix
2789 ifeq (%(nix),yes)
2790     %(mmake)-nix    := $(BD_NIXFLAG)
2791     %(mmake)-volpfx := /
2792     %(mmake)-volsfx := /
2793     
2794     ifeq (%(nix_dir_layout),)
2795         %(mmake)-nix_dir_layout := yes
2796     endif
2797 else
2798     %(mmake)-volsfx := :
2799     
2800     ifeq (%(nix_dir_layout),)
2801         %(mmake)-nix_dir_layout := no
2802     endif
2803 endif
2805 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2807 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2808         exec_prefix=$(%(mmake)-prefix) %(install_env)
2810 # Check if chosen compiler is valid
2811 ifeq ($(findstring %(compiler),host target kernel),)
2812   $(error unknown compiler %(compiler))
2813 endif
2815 # Set legacy 'host' variable based on chosen compiler
2816 ifeq (%(compiler),host)
2817     host := yes
2818     ifeq (%(package),)
2819         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2820     else
2821         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2822     endif
2823 else
2824     host := no
2825     ifeq (%(package),)
2826         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2827     else
2828         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2829     endif
2830 endif
2831 ifneq (%(gendir),)
2832     ifeq (%(package),)
2833         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2834     else
2835         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2836     endif
2837 endif
2839 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2840 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2842 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2843     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2844     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2845 else
2846     ifeq (%(nix),yes)
2847         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2848         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2849     else
2850         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2851     endif
2853     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2854     
2855     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2856         sbindir=$(%(mmake)-prefix) \
2857         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2858         oldincludedir=$(AROS_INCLUDES) %(install_env)
2859 endif
2861 ifneq ($(DEBUG),yes)
2862     %(mmake)-s_flag = -s
2863 endif
2865 # Set up build environment, and options for configure script
2866 ifeq (%(compiler),host)
2867     # NB: We need to pass in our crosstoolsdir, but cannot set CFLAGS since it
2868     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2869     # since that won't get picked up during configure.
2870     # We also cannot pass in the compiler including std flags so we need to use
2871     # the "plain" host compiler.
2872     CONFIG_ENV := %(config_env_extra) \
2873         CPP="$(HOST_CPP)" \
2874         CXXCPP="$(HOST_CPP)" \
2875         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2876         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2877         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2878         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2879         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2880         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2881         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2882         TARGET_AS="$(TARGET_AS)" \
2883         OBJCOPY="$(OBJCOPY)" \
2884         TARGET_RANLIB="$(RANLIB)" \
2885         TARGET_STRIP="$(STRIP_PLAIN)" \
2886         TARGET_NM="$(NM_PLAIN)" \
2887         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2888 endif
2889 ifeq (%(compiler),target)
2890     CONFIG_ENV := %(config_env_extra) \
2891         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2892         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2893         CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2894         CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2895         CC="$(TARGET_CC) $(TARGET_SYSROOT)" \
2896         CFLAGS=" $(TARGET_CFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2897         CXX="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2898         CXXFLAGS=" $(TARGET_CXXFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2899         LDFLAGS="-L$(AROS_DEVELOPMENT)/lib $(USER_LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2900         AS="$(TARGET_AS)" \
2901         CC_FOR_BUILD="$(HOST_DEF_CC)" \
2902         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2903         CXX_FOR_BUILD="$(HOST_CXX)" \
2904         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2905         RANLIB="$(RANLIB)" \
2906         AR="$(AR_PLAIN)" \
2907         STRIP="$(STRIP_PLAIN)" \
2908         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2909         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2910         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2911         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2912         TARGET_AS="$(TARGET_AS)" \
2913         OBJCOPY="$(OBJCOPY)" \
2914         TARGET_RANLIB="$(RANLIB)" \
2915         TARGET_STRIP="$(STRIP_PLAIN)" \
2916         TARGET_NM="$(NM_PLAIN)" \
2917         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_SYSROOT)" \
2918         CFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2919         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2920         CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2921 ifeq (%(gnuflags),yes)
2922     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2923         --host=$(AROS_TARGET_CPU)-aros\
2924         --target=$(AROS_TARGET_CPU)-aros\
2925         --disable-nls\
2926         --without-x --without-pic --disable-shared
2927 endif
2928 endif
2929 ifeq (%(compiler),kernel)
2930     CONFIG_ENV := %(config_env_extra) \
2931         CPP="$(KERNEL_CPP)" \
2932         CXXCPP="$(KERNEL_CPP)" \
2933         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2934         CFLAGS="$(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)" \
2935         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2936         CXXFLAGS="$(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag)" \
2937         AS="$(KERNEL_AS)" \
2938         CC_FOR_BUILD="$(HOST_DEF_CC)" \
2939         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2940         CXX_FOR_BUILD="$(HOST_CXX)" \
2941         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2942         RANLIB="$(RANLIB)" \
2943         TARGET_RANLIB="$(RANLIB)" \
2944         TARGET_STRIP="$(STRIP_PLAIN)" \
2945         TARGET_NM="$(NM_PLAIN)"
2946 ifeq (%(gnuflags),yes)
2947     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2948         --host=$(AROS_TARGET_CPU)-aros\
2949         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2950         --without-x --without-pic --disable-shared
2951 endif
2952 endif
2954 ifeq (%(use_build_env),yes)
2955     BUILD_ENV := $(CONFIG_ENV)
2956 endif
2958 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2960 # When building for the host, we don't need to build the
2961 # linklibs - this is especially true when building the
2962 # crosstool toolchain on 'foreign' architectures (such as
2963 # building PPC on x86)
2965 #MM- %(mmake)-host : setup includes %(mmake)-quick
2966 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2967 #MM- %(mmake): %(mmake)-%(compiler)
2969 # Using -j1 in install_command may result in a warning but finally
2970 # it does its job. make install for gcc does not work reliably for -jN
2971 # where N > 1.
2972 ifneq (%(install_target),)
2973     %(mmake)-install_command = \
2974         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2975         -C $(%(mmake)-pkgdir) %(install_target) -j1
2977     %(mmake)-uninstall_command = \
2978     $(RM) $(%(mmake)-installflag) && \
2979     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2980     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2981 else
2982     %(mmake)-install_command   := true
2983     %(mmake)-uninstall_command := true
2984 endif
2986 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2989 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2991 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2992         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2993             $(RM)  $(%(mmake)-installflag) && \
2994             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2995              -C $(%(mmake)-pkgdir) && \
2996             $(%(mmake)-install_command) && \
2997             $(TOUCH) $@ -r $^; \
2998         fi
3000 $(%(mmake)-pkgdir)/.files-touched:
3001         %mkdirs_q $(%(mmake)-pkgdir)
3002         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
3003         $(TOUCH) $@
3006 %(mmake)-uninstall :
3007         $(%(mmake)-uninstall_command)
3010 %(mmake)-configure : $(%(mmake)-configflag)
3012 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3013 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3014         $(RM) $@
3015         %mkdirs_q $(%(mmake)-pkgdir)
3016         cd $(%(mmake)-pkgdir) && \
3017         find . -name config.cache -exec $(RM) '{}' \; && \
3018         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
3019             %(extraoptions) && \
3020         $(TOUCH) $@
3023 %(mmake)-clean : %(mmake)-uninstall
3024         @$(RM) $(%(mmake)-pkgdir)
3025 %end
3026 #------------------------------------------------------------------------------
3029 #------------------------------------------------------------------------------
3030 # Build an imported source tree which uses cmake 
3032 # Arguments:
3034 #     - mmake           = the meta make target.
3035 #     - package         = name of the package to be built.
3036 #     - srcdir          = the location of the unpacked source code. Defaults
3037 #                         to $(SRCDIR)/$(CURDIR).
3038 #     - prefix          = the target directory. Must be an absolute path of the
3039 #                         host system. Defaults to $(AROS_CONTRIB).
3040 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
3041 #                         Defaults to the value of the prefix option.
3042 #     - extraoptions    = additional options for the cmake script.
3043 #     - installoptions    = additional options for the install step.
3046 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
3047     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
3048     cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
3050 ifneq (%(prefix),)
3051     %(mmake)-prefix := %(prefix)
3052 else
3053     %(mmake)-prefix := $(AROS_CONTRIB)
3054 endif
3056 ifneq (%(aros_prefix),)
3057     %(mmake)-aros_prefix := %(aros_prefix)
3058 else
3059     %(mmake)-aros_prefix := $(%(mmake)-prefix)
3060 endif
3062 ifeq (%(compiler),host)
3063     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
3064     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
3065     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
3066     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3067     ifeq (%(package),)
3068         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3069     else
3070         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3071     endif
3072 else
3073     BD_LDFLAGS   := %(ldflags)
3074     BD_CFLAGS := %(cflags)
3075     BD_CXXFLAGS := %(cxxflags)
3076     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(BD_LDFLAGS)"
3077     ifeq (%(package),)
3078         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3079     else
3080         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3081     endif
3082 endif
3083 ifneq (%(gendir),)
3084     ifeq (%(package),)
3085         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3086     else
3087         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3088     endif
3089 endif
3091 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3092 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3094 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3096 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3098 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3101 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3103 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3104         if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3105             $(RM)  $(%(mmake)-installflag) && \
3106             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3107             cd $(%(mmake)-pkgdir) && \
3108             cmake %(installoptions) -P cmake_install.cmake && \
3109             $(TOUCH) $@ -r $^; \
3110         fi
3112 $(%(mmake)-pkgdir)/.files-touched:
3113         %mkdirs_q $(%(mmake)-pkgdir)
3114         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3115         $(TOUCH) $@
3118 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3120 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3121 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3122         $(RM) $@
3123         %mkdirs_q $(%(mmake)-pkgdir)
3124         cd $(%(mmake)-pkgdir) && \
3125         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3126         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3127         $(TOUCH) $@
3130 %(mmake)-clean : %(mmake)-uninstall
3131         @$(RM) $(%(mmake)-pkgdir)
3132 %end
3133 #------------------------------------------------------------------------------
3136 #------------------------------------------------------------------------------
3137 # Given an archive name, patches names and locations where to find them, fetch
3138 # the archive and the patches from any of those locations, unpack the archive
3139 # and then apply the patches.
3141 # Locations currently supported are http and ftp sites, plus local filesystem
3142 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3143 # the fetch.sh script needs to be modified, since this macro relies on that script.
3145 # Arguments:
3147 #     - mmake           = mmaketarget
3148 #     - archive_origins = list of locations where to find the archive. They are tried
3149 #                         in sequence, until the archive is found and fetching it 
3150 #                         succeeded. If not specified, the current directory is assumed.
3151 #     - archive         = the archive name. Mandatory.
3152 #     - suffixes        = a list of suffixes to append to the the package name plus the
3153 #                         version. Each one of them is tried until a matching archive is
3154 #                         found. They are appended to patches and these are tried the
3155 #                         same way as packages are.
3156 #     - location        = the local directory where to put the fetched archive and patches.
3157 #                         If not specified, the directory specified by destination is used.
3158 #     - destination     = the directory to unpack the archive to.
3159 #                         If not specified, the current directory is assumed.
3160 #     - patches_origins = list of locations where to find the patches. They are tried
3161 #                         in sequence, until a patch is found and fetching it 
3162 #                         succeeded. If not specified, the current directory is assumed.
3163 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3164 #                         patch_name[:[patch_subdir][:patch_opt]].
3166 #                             - patch_name   = the name of the patch file
3167 #                             - patch_subdir = the directory within \destination\ where to
3168 #                                              apply the patch.
3169 #                             - patch_opt    = any options to pass to the `patch' command
3170 #                                              when applying the patch.
3171 #                         
3172 #                         The patch_subdir and patch_opt fields are optional.
3174 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3175     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3177 .PHONY: %(mmake)
3179 ifneq (%(location),)
3180     %(mmake)-location := %(location)
3181 else
3182     %(mmake)-location := %(destination)
3183 endif
3186 %(mmake) :
3187         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3188         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3189 %end
3190 #------------------------------------------------------------------------------
3193 #------------------------------------------------------------------------------
3194 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3195 # unpatched source tree and runs diff against this and a previously fetched and possibly
3196 # patched tree. Depending on what happens after patching during a normal build it might
3197 # give best results if the new patch is created directly after fetch.
3199 # Arguments:
3201 #     - mmake       = mmaketarget
3202 #     - archive     = archive base name
3203 #     - srcdir      = the top level directory the package is unpacked to, useful if
3204 #                     an archive unpacks to a directory other than its name suggests.
3205 #                     this should not be deeper than a single path element.
3206 #     - suffixes    = a list of suffixes to append to the the package name plus the
3207 #                     version. Each one of them is tried until a matching archive is
3208 #                     found.
3209 #     - destination = the directory to unpack the archive to.
3210 #     - excludes    = diff patterns to exclude files or directories from the patch
3212 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3214 .PHONY: %(mmake)
3216 ifneq (%(excludes),)
3217     %(mmake)-exclude := -X ./exclude.patterns
3218 endif
3220 ifneq (%(srcdir),)
3221     %(mmake)-srcdir := %(srcdir)
3222 else
3223     %(mmake)-srcdir := %(archive)
3224 endif
3226 #MM- %(mmake) : %(mmake)-diff
3227 #MM- %(mmake)-quick : %(mmake)-diff
3230 %(mmake)-diff:
3231         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3232         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3233         cd %(destination)/tmp ; \
3234         $(FOR) f in %(excludes) ; do \
3235             $(ECHO) $$f >> ./exclude.patterns ; \
3236         done ; \
3237         diff -ruN $(%(mmake)-exclude) \
3238             $(%(mmake)-srcdir) \
3239             $(%(mmake)-srcdir).aros \
3240             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3241         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3242         $(RM) %(destination)/tmp
3243 %end
3244 #------------------------------------------------------------------------------
3247 #------------------------------------------------------------------------------
3248 # Joins the features of %fetch and %build_with_configure.
3250 # If a patch is provided, it *must* be named the following way:
3252 #    <package name>-<version number>-aros.diff
3254 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3255 # CD'ing into the archive's extracted directory.
3257 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3258 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3259 # to make that patch fully comprehensive.
3261 # Arguments:
3263 #    - mmake            = the meta make target.
3264 #    - package          = the GNU package name, sans version and archive format suffixes.
3265 #    - subpackage       = ???
3266 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3267 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3268 #    - version          = the package's version number, or otherwise any other version string.
3269 #                         It gets appended to the package name to form the basename of the archive.
3270 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3271 #                         version. Each one of them is tried until a matching archive is found.
3272 #                         Defaults to "tar.bz2 tar.gz".
3273 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3274 #    - builddir         = override the location we expect to run configure/make in.
3275 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3276 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3277 #                         fetched or not. Default to no.
3278 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3279 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3280 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3281 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3282 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3283 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3284 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3285 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3286 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3287 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3288 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3289 #    - nix              = same meaning as the one for the %build_with_configure macro.
3290 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3291 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3293 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3294     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3295     prefix= aros_prefix= extraoptions= extracflags= extracxxflags= preconfigure= postconfigure= postinstall= \
3296     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no gnuflags=yes
3298 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3299 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3300 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3301 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3303 %(mmake)-archbase  := %(package)-%(version)
3305 ifeq (%(compiler),host)
3306     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3307 else
3308     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3309 endif
3311 ifeq (%(prefix),)
3312     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3313 else
3314     %(mmake)-prefix := %(prefix)
3315 endif
3317 ifneq (%(subpackage),)
3318     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3319 else
3320     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3321 endif
3323 ifneq (%(srcdir),)
3324     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3325 else
3326     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3327 endif
3329 ifneq (%(builddir),)
3330     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3331 else
3332     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3333 endif
3335 ifeq (%(patch),yes)
3336     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3337 else
3338     %(mmake)-%(subpackage)-patches_specs := ::
3339 endif
3341 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3342     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3343     archive_origins=". %(package_repo)" \
3344     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3346 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3347     archive=$(%(mmake)-%(subpackage)-archbase) \
3348     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3349     suffixes="%(suffixes)" \
3350     destination=$(%(mmake)-portdir)
3352 #MM- %(mmake) : %(mmake)-%(subpackage)
3354 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3356 %(mmake)-%(subpackage)-package-basename := \
3357     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3359 ifneq (%(create_pkg),no)
3360     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3361 endif
3363 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3364      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3365      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3366      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3367      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3368      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" gnuflags=%(gnuflags)
3370 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3371 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3374 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3376 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3377 #that $^ and $@ have exactly the same mtime, and in that case make tries
3378 #to rebuild $@ again, which would fail because the directory where
3379 #the package got installed would not exist anymore. 
3380 #We work this around by using an if statement to manually check the mtimes.
3381 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3382         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3383         $(RM) $@ ; \
3384         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3385         mkdir -p "$(DISTDIR)/Packages" ; \
3386         mkdir -p "$(%(mmake)-prefix)" ; \
3387         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3388         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3389         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3390     fi
3391 %end
3392 #------------------------------------------------------------------------------
3395 #------------------------------------------------------------------------------
3396 # Joins the features of %fetch and %build_with_configure, taking advantage of
3397 # the naming scheme of GNU packages. GNU packages names are in the form
3399 #     <package name>-<version number>.<archive format suffix>
3401 # If a patch is provided, it *must* be named the following way:
3403 #    <package name>-<version number>-aros.diff
3405 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3406 # CD'ing into the archive's extracted directory.
3408 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3409 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3410 # to make that patch fully comprehensive.
3412 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3414 # Arguments:
3416 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3418 #    - prefix           = defaults to $(GNUDIR).
3419 #    - aros_prefix      = defaults to /GNU.
3421 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3422     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3423     aros_prefix=/GNU extraoptions= extracflags= extracxxflags= config_env_extra= preconfigure= postconfigure= postinstall= 
3425 GNU_REPOSITORY := gnu://
3427 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3428     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3429     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3430     patch="%(patch)" patch_repo="%(patch_repo)" \
3431     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3432     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3434 %end
3435 #------------------------------------------------------------------------------
3438 #------------------------------------------------------------------------------
3439 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3440 # that the package is a "Development" package, and as such it needs to be placed
3441 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3443 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3444 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3445 # "mmake" argument, because the metatarget is implicitely defined as
3447 #     #MM- development-%(package)
3449 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3450     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3451     aros_prefix=/Development config_env_extra= preconfigure= postconfigure= postinstall=  extraoptions= extracflags= extracxxflags=
3453 #MM- development : development-%(package)
3456 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3457    version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3458    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3459    aros_prefix="%(aros_prefix)" config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3460    extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3463 postinstall-%(package)-delete-la-files:
3464         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3466 %end
3467 #------------------------------------------------------------------------------
3469 # Builds a kickstart package in PKG format
3471 # Arguments:
3473 #    - mmake   = target name
3474 #    - file    = destination file name with path
3476 # Other arguments are self-explanatory
3478 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3479     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3481 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3482 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3483 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3484 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3485 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3486 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3488 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3489 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3490 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3491 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3492 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3493 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3495 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3496     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3497 PKG_DIR   := $(dir %(file))
3500 %(mmake) : %(file)
3503 %(mmake)-quick : %(file)
3505 %(file): $(PKG_FILES) | $(PKG_DIR)
3506         @$(ECHO) Packaging $@...
3507         @$(SRCDIR)/tools/package/pkg c $@ $^
3509 %compress_file mmake="%(mmake)" file="%(file)"
3511 GLOB_MKDIRS += $(PKG_DIR)
3513 %end
3515 #------------------------------------------------------------------------------
3516 # Compresses %(file) with a gzip.
3517 # Good in conjunction with for example %build_prog
3519 %define compress_file mmake=/A file=/A
3521 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3524 %(mmake)-gz-quick : %(file).gz
3526 %(file).gz: %(file)
3527         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3528         @gzip -9 -f $^
3530 %end
3532 #------------------------------------------------------------------------------
3533 # Links a kickstart module in ELF format
3534 # Arguments are similar to make_package
3536 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3537     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3539 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3540 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3541 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3542 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3543 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3544 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3546 ifeq (%(startup),)
3547     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3548 else
3549     KOBJ_STARTUP := %(startup)
3550 endif
3552 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3554 TMP_LDFLAGS := %(ldflags)
3556 # Make a list of the lib files this program depends on.
3557 # In LDFLAGS remove white space between -L and directory
3558 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3559 # Filter out only the libdirs and remove -L
3560 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3561 # Add trailing /
3562 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3563 # Add normal linklib path
3564 TMP_DIRS += $(AROS_LIB)/
3565 # add lib and .a to static linklib names
3566 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3567 # search for the linklibs in the given path, ignore ones not found
3568 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3569     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3572 TMP_DIRS += $(dir %(file))
3573 ifneq (%(map),)
3574     TMP_LDFLAGS += $(GENMAP) %(map)
3575     TMP_DIRS    += $(dir %(map))
3576 endif
3578 #MM %(mmake) : %(deps)
3581 %(mmake) : %(file)
3584 %(mmake)-quick : %(file)
3586 %(file): KOBJS := $(KOBJS)
3587 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3588                     -static -nosysbase -Wl,-Ur
3589 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3590 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3591         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3592         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3593         @$(STRIP) $@
3595 %compress_file mmake="%(mmake)" file="%(file)"
3597 GLOB_MKDIRS += $(TMP_DIRS)
3599 %end