muimaster.library: update minor version
[AROS.git] / config / make.tmpl
blob93f98ecc30db67f8bff70dab5db2af6b884a646b
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) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         @$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31             else \
32                 $(NOP) ; \
33             fi ; \
34         else \
35             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37             exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd="$(CC) $(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)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(from) -o %(to) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(opt) %(libs)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(opt) %(libs)" 1>&2 ; \
76             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
77             exit 1 ; \
78         fi; \
79         %(strip) %(to)
80 %end
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd="$(AROS_CC) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(ldflags) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(endtag) -o $@"; \
98             cat %(objdir)/%(err); \
99             exit 1; \
100         fi
102         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
103         @$(STRIP) $@
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the library
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
112         @%(ar) %(to) %(from)
113         @%(ranlib) %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc="$(AROS_CC) $(TARGET_SYSROOT)"
121         %mkdir_q dir="$(dir %(to))"
122         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
124 %end
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
148 ##                                                                         ##
149 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
150 ## mmakefile. They consist of one or more full makefile rules.             ##
151 ## In general the files generated in these macros are also defined as      ##
152 ## make targets so that they can be used as a dependency in other rules    ##
153 ##                                                                         ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
160 BDID := $(BDID)_
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
163 endif
164 %end
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
171 %(to) : %(from)
172         @$(CP) $< $@
173 %end
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
181 # present.
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185         @$(CP) $< $@
186 %end
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by 
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197     stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207         @for f in $(FILES); do \
208              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
210              fi ; \
211         done
212         @$(TOUCH) $@
213 %end
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
219 # be displayed.
220 # Restriction: at the moment when using a non-empty target dir %(from) may
221 # not have 
222 %define rule_join to=/A from=/A text=
224 %(to) : %(from)
225 ifneq (%(text),)
226         @$(ECHO) %(text)
227 endif
228         @$(CAT) $^ >$@
229 %end
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean 
238 %define include_deps deps=$(DEPS)/M  depstargets=
239 ifneq (%(deps),)
240   ifneq (%(depstargets),)
241     ifneq ($(findstring $(TARGET),%(depstargets)),)
242       -include %(deps)
243     endif
244   else
245     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
246       -include %(deps)
247     endif
248   endif
249 endif
250 %end
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default. 
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
263 %end
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
272 # options
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 #   the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 #   it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
281 ifeq (%(targetdir),)
282   TMP_TARGETBASE := %(basename)
283 else
284   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
285 endif
287 # Adjust compiler flags to suit C
288 TMP_CFLAGS := %(cflags)
289 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
291 ifeq ($(findstring %(compiler),host kernel target),)
292   $(error unknown compiler %(compiler))
293 endif
294 ifeq (%(compiler),target)
295 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
296 BD_STRIP ?= $(TARGET_STRIP)
297 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
298 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
303 endif
304 ifeq (%(compiler),host)
305 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
306 BD_STRIP ?= $(HOST_STRIP)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
313 endif
314 ifeq (%(compiler),kernel)
315 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
316 BD_STRIP ?= $(ECHO) >/dev/null
317 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
318 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
319 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
320 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
321 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
322 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
323 endif
325 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
326 $(TMP_TARGETBASE).o : %(basename).c
327         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
329 ifeq (%(dflags),)
330   ifeq (%(nix),yes)
331     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
332   else
333     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
334   endif
335 else
336   ifeq (%(nix),yes)
337     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
338   else
339     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
340   endif
341 endif
342 $(TMP_TARGETBASE).d : %(basename).c
343         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
344 %end
345 #------------------------------------------------------------------------------
348 #------------------------------------------------------------------------------
349 # Generate a rule to compile a C++ source file to an object file and generate
350 # the dependency file. Basename may contain a directory part, then the source
351 # file has to be in that directory. The generated file will be put in the
352 # object directory without the directory.
353 # options
354 # - basename: the basename of the file to compile. Use % for a wildcard rule
355 # - cflags (default $(CFLAGS)): the C flags to use for compilation
356 # - dflags: the flags used during creation of dependency file. If not specified
357 #   the same value as cflags will be used
358 # - targetdir: the directory to put the .o file and the .d file. By default
359 #   it is put in the same directory as the .c file
360 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
362 ifneq (%(basename),)
364 ifeq (%(targetdir),)
365   TMP_TARGETBASE := %(basename)
366 else
367   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
368 endif
370 # Adjust compiler flags to suit C++
371 TMP_CXXFLAGS := %(cflags)
372 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include 
373 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
375 ifeq ($(findstring %(compiler),host kernel target),)
376   $(error unknown compiler %(compiler))
377 endif
378 ifeq (%(compiler),target)
379 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
380 BD_STRIP ?= $(TARGET_STRIP)
381 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
382 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
387 endif
388 ifeq (%(compiler),host)
389 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
390 BD_STRIP ?= $(HOST_STRIP)
391 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
392 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
393 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
394 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
395 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
396 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
397 endif
398 ifeq (%(compiler),kernel)
399 KERNEL_CXX ?= $(KERNEL_CC)
400 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
401 BD_STRIP ?= $(ECHO) >/dev/null
402 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
403 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
404 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
405 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
406 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
407 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
408 endif
410 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
411 $(TMP_TARGETBASE).o : %(basename).cpp
412         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
414 ifeq (%(dflags),)
415   ifeq (%(nix),yes)
416     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
417   else
418     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
419   endif
420 else
421   ifeq (%(nix),yes)
422     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
423   else
424     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
425   endif
426 endif
427 $(TMP_TARGETBASE).d : %(basename).cpp
428         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
430 endif
432 %end
433 #------------------------------------------------------------------------------
436 #------------------------------------------------------------------------------
437 # Generate a rule to compile an ObjC source file to an object file and generate
438 # the dependency file. Basename may contain a directory part, then the source
439 # file has to be in that directory. The generated file will be put in the
440 # object directory without the directory.
441 # options
442 # - basename: the basename of the file to compile. Use % for a wildcard rule
443 # - cflags (default $(CFLAGS)): the C flags to use for compilation
444 # - dflags: the flags used during creation of dependency file. If not specified
445 #   the same value as cflags will be used
446 # - targetdir: the directory to put the .o file and the .d file. By default
447 #   it is put in the same directory as the .m file
448 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
450 ifneq (%(basename),)
452 ifeq (%(targetdir),)
453   TMP_TARGETBASE := %(basename)
454 else
455   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
456 endif
458 # Adjust compiler flags to suit ObjC
459 TMP_OBJCFLAGS := %(cflags)
460 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
461 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
463 # Define the use of cross compiler
464 ifeq ($(TARGET_OBJC),)
465   TMP_CC := $(TARGET_CC)
466 else
467   TMP_CC := $(TARGET_OBJC)
468 endif
470 ifeq ($(findstring %(compiler),host kernel target),)
471   $(error unknown compiler %(compiler))
472 endif
473 ifeq (%(compiler),target)
474 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
475 BD_STRIP ?= $(TARGET_STRIP)
476 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
477 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
478 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
479 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
480 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
481 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
482 endif
483 ifeq (%(compiler),host)
484 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
485 BD_STRIP ?= $(HOST_STRIP)
486 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
487 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
488 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
489 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
490 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
491 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
492 endif
493 ifeq (%(compiler),kernel)
494 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
495 BD_STRIP ?= $(ECHO) >/dev/null
496 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
497 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
498 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
499 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
500 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
501 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
502 endif
504 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
505 $(TMP_TARGETBASE).o : %(basename).m
506         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
508 ifeq (%(dflags),)
509   ifeq (%(nix),yes)
510     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
511   else
512     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
513   endif
514 else
515   ifeq (%(nix),yes)
516     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
517   else
518     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
519   endif
520 endif
521 $(TMP_TARGETBASE).d : %(basename).m
522         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
524 endif
526 %end
527 #------------------------------------------------------------------------------
530 #------------------------------------------------------------------------------
531 # Generate a rule to compile multiple C source files to an object file and
532 # generate the corresponding dependency files. The generated file will be put
533 # in the object directory without the directory part of the source file.
534 # options
535 # - basenames: the basenames of the files to compile. The names may include
536 #   relative or absolute path names. No wildcard is allowed
537 # - cflags (default $(CFLAGS)): the C flags to use for compilation
538 # - dflags: the flags used during creation of dependency file. If not specified
539 #   the same value as cflags will be used
540 # - targetdir: the directory to put the .o file and the .d file. By default
541 #   it is put in the same directory as the .c file. When targetdir is not
542 #   empty, path names will be stripped from the file names so that all files
543 #   are in that dir and not in subdirectories.
544 # - compiler (default target): compiler to use, target, kernel or host
545 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
546     compiler=target
548 ifeq (%(targetdir),)
549 TMP_TARGETS := $(addsuffix .o,%(basenames))
550 TMP_DTARGETS := $(addsuffix .d,%(basenames))
551 TMP_WILDCARD := %
552 else
553 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
554 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
555 TMP_WILDCARD := %(targetdir)/%
557 # Be sure that all .c files are generated
558 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
560 # Be sure that all .c files are found
561 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
562 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
563 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
564 ifneq ($(TMP_DIRS),)
565     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
566     vpath %.c $(TMP_DIRS)
567 endif
569 endif
571 ifeq ($(findstring %(compiler),host kernel target),)
572   $(error unknown compiler %(compiler))
573 endif
574 ifeq (%(compiler),target)
575 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
576 BD_STRIP ?= $(TARGET_STRIP)
577 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
578 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
579 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
580 endif
581 ifeq (%(compiler),host)
582 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
583 BD_STRIP ?= $(HOST_STRIP)
584 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
585 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
586 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
587 endif
588 ifeq (%(compiler),kernel)
589 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
590 BD_STRIP ?= $(ECHO) >/dev/null
591 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
592 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
593 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
594 endif
596 $(TMP_TARGETS) : CFLAGS := %(cflags)
597 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
598         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
600 ifeq (%(dflags),)
601 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
602 else
603 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
604 endif
605 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
606         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
607 %end
608 #------------------------------------------------------------------------------
611 #------------------------------------------------------------------------------
612 # Generate a rule to compile multiple C++ source files to an object file and
613 # generate the corresponding dependency files. The generated file will be put
614 # in the object directory without the directory part of the source file.
615 # options
616 # - basenames: the basenames of the files to compile. The names may include
617 #   relative or absolute path names. No wildcard is allowed. basenames will be 
618 #   matched to supported AROS_CXXEXTS.
619 # - cflags (default $(CFLAGS)): the C flags to use for compilation
620 # - dflags: the flags used during creation of dependency file. If not specified
621 #   the same value as cflags will be used
622 # - targetdir: the directory to put the .o file and the .d file. By default
623 #   it is put in the same directory as the .c file. When targetdir is not
624 #   empty, path names will be stripped from the file names so that all files
625 #   are in that dir and not in subdirectories.
626 # - compiler (default target): compiler to use, target, kernel or host
627 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
628     targetdir= compiler=target
630 # Adjust compiler flags to suit C++
631 TMP_CXXFLAGS := %(cflags)
632 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
633 TMP_CXXFLAGS := -fno-rtti -fno-exceptions -fno-check-new $(TMP_CXXFLAGS) -isystem $(AROS_DEVELOPMENT)/include
635 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
637 ifneq ($(TMP_CXXABSBASENAMES),)
639 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
641 # Identify the "real" c++ files from the passed in basenames
642 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
644 ifeq (%(targetdir),)
645   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
646   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
647   TMP_WILDCARD := %
648 else
649   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
650   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
651   TMP_WILDCARD := %(targetdir)/%
653   # Be sure that all source files are generated
654   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
655 endif
657 ifeq ($(findstring %(compiler),host kernel target),)
658   $(error unknown compiler %(compiler))
659 endif
660 ifeq (%(compiler),target)
661   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
662   BD_STRIP ?= $(TARGET_STRIP)
663   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
664   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
665   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
666 endif
667 ifeq (%(compiler),host)
668   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
669   BD_STRIP ?= $(HOST_STRIP)
670   TMP_CXXCMD:=$(HOST_CXX)
671   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
672   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
673 endif
674 ifeq (%(compiler),kernel)
675   KERNEL_CXX ?= $(KERNEL_CC)
676   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
677   BD_STRIP ?= $(ECHO) >/dev/null
678   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
679   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
680   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
681 endif
683 ifeq (%(dflags),)
684   TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
685 else
686   ifeq (%(dflags),%(cflags))
687     TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
688   else
689     TMP_CXXDFLAGS:=%(dflags)
690   endif
691 endif
693 define cxx_multi_recipe_template
694  $(1).o : $(2)
695         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
697  $(1).d : $(2)
698         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
699 endef
700 ifeq (%(targetdir),)
701   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
702 else
703   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
704 endif
706 endif
708 %end
709 #------------------------------------------------------------------------------
712 #------------------------------------------------------------------------------
713 # Generate a rule to compile multiple ObjC source files to an object file and
714 # generate the corresponding dependency files. The generated file will be put
715 # in the object directory without the directory part of the source file.
716 # options
717 # - basenames: the basenames of the files to compile. The names may include
718 #   relative or absolute path names. No wildcard is allowed
719 # - cflags (default $(CFLAGS)): the C flags to use for compilation
720 # - dflags: the flags used during creation of dependency file. If not specified
721 #   the same value as cflags will be used
722 # - targetdir: the directory to put the .o file and the .d file. By default
723 #   it is put in the same directory as the .m file. When targetdir is not
724 #   empty, path names will be stripped from the file names so that all files
725 #   are in that dir and not in subdirectories.
726 # - compiler (default target): compiler to use, target, kernel or host
727 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
728     targetdir= compiler=target
730 ifneq (%(basenames),)
732 # Adjust compiler flags to suit ObjC
733 TMP_OBJCFLAGS := %(cflags)
734 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
735 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
737 ifeq (%(targetdir),)
738   TMP_TARGETS := $(addsuffix .o,%(basenames))
739   TMP_DTARGETS := $(addsuffix .d,%(basenames))
740   TMP_WILDCARD := %
741 else
742   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
743   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
744   TMP_WILDCARD := %(targetdir)/%
746   # Be sure that all .m files are generated
747   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
749   # Be sure that all .m files are found
750   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
751   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
752   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
753   ifneq ($(TMP_DIRS),)
754     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
755     vpath %.m $(TMP_DIRS)
756   endif
757 endif
759 # Define the use of cross compiler
760 ifeq ($(TARGET_OBJC),)
761   TMP_CC := $(TARGET_CC)
762 else
763   TMP_CC := $(TARGET_OBJC)
764 endif
766 ifeq ($(findstring %(compiler),host kernel target),)
767   $(error unknown compiler %(compiler))
768 endif
769 ifeq (%(compiler),target)
770   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
771   BD_STRIP ?= $(TARGET_STRIP)
772   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
773   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
774   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
775 endif
776 ifeq (%(compiler),host)
777   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
778   BD_STRIP ?= $(HOST_STRIP)
779   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
780   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
781   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
782 endif
783 ifeq (%(compiler),kernel)
784   KERNEL_OBJC ?= $(KERNEL_CC)
785   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
786   BD_STRIP ?= $(ECHO) >/dev/null
787   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
788   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
789   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
790 endif
792 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
793 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
794         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
796 ifeq (%(dflags),)
797   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
798 else
799   ifeq (%(dflags),%(cflags))
800     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
801   else
802     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
803   endif
804 endif
805 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
806         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
808 endif
810 %end
811 #------------------------------------------------------------------------------
814 #------------------------------------------------------------------------------
815 # Make an alias from one arch specific build to another arch.
816 # arguments:
817 # - mainmmake: the mmake of the module in the main tree
818 # - arch: the current arch
819 # - alias: the alias to which this should point
820 %define rule_archalias mainmmake=\A arch=\A alias=\A
822 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
823 %end
824 #------------------------------------------------------------------------------
827 #------------------------------------------------------------------------------
828 # Generate a rule to assemble a source file to an object file. Basename may
829 # contain a directory part, then the source file has to be in that directory.
830 # The generated file will be put in the object directory without the directory.
831 # options
832 # - basename: the basename of the file to compile. Use % for a wildcard rule
833 # - flags (default $(AFLAGS)): the asm flags to use for assembling
834 # - targetdir: the directory to put the .o file in. By default it is put in the
835 #   same directory as the .s file
836 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
838 ifeq (%(targetdir),)
839 %(basename).o : AFLAGS := %(aflags)
840 %(basename).o : %(basename).s
841         %assemble_q
842 %(basename).o : %(basename).S
843         %assemble_q
845 else
846 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
847 %(targetdir)/$(notdir %(basename)).o : %(basename).s
848         %assemble_q
849 %(targetdir)/$(notdir %(basename)).o : %(basename).S
850         %assemble_q
852 endif
853 %end
854 #------------------------------------------------------------------------------
857 #------------------------------------------------------------------------------
858 # Generate a rule to assemble multiple source files to an object file. The
859 # generated file will be put in the object directory with the directory part
860 # of the source file stripped off.
861 # options
862 # - basenames: the basenames of the files to compile. The names may include
863 #   relative or absolute path names. No wildcard is allowed
864 # - aflags (default $(AFLAGS)): the flags to use for assembly
865 # - targetdir: the directory to put the .o file and the .d file. By default
866 #   it is put in the same directory as the .c file. When targetdir is not
867 #   empty, path names will be stripped from the file names so that all files
868 #   are in that dir and not in subdirectories.
869 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
871 ifeq (%(targetdir),)
872 TMP_TARGETS := $(addsuffix .o,%(basenames))
873 TMP_WILDCARD := %
874 else
875 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
876 TMP_WILDCARD := %(targetdir)/%
878 # Be sure that all .s files are generated
879 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
881 # Be sure that all .c files are found
882 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
883 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
884 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
885 ifneq ($(TMP_DIRS),)
886     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
887     vpath %%(suffix) $(TMP_DIRS)
888 endif
890 endif
892 ifeq ($(findstring %(compiler),host kernel target),)
893   $(error unknown compiler %(compiler))
894 endif
895 ifeq (%(compiler),target)
896 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
897 endif
898 ifeq (%(compiler),host)
899 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
900 endif
901 ifeq (%(compiler),kernel)
902 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
903 endif
905 $(TMP_TARGETS) : AFLAGS := %(aflags)
906 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
907         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
908 %end
909 #------------------------------------------------------------------------------
912 #------------------------------------------------------------------------------
913 # Link %(objs) to %(prog) using the libraries in %(uselibs)
914 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
915     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
917 TMP_EXTRA_LDFLAGS := 
918 TMP_EXTRA_LIBS :=
919 ifeq (%(nix),yes)
920     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
921 endif
922 ifeq (%(usestartup),no)
923     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
924 endif
925 ifeq (%(detach),yes)
926     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
927 endif
929 # Make a list of the lib files this program depends on.
930 # In LDFLAGS remove white space between -L and directory
931 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
932 # Filter out only the libdirs and remove -L
933 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
934 # Add trailing /
935 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
936 # Add normal linklib path
937 TMP_DIRS += $(AROS_LIB)/
938 # add lib and .a to static linklib names
939 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
940 ifeq (%(usestartup),yes)
941     TMP_LIBS += startup.o
942 endif
943 ifeq (%(detach),yes)
944     TMP_LIBS += detach.o
945 endif
946 # search for the linklibs in the given path, ignore ones not found
947 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
948     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
951 %(prog) : OBJS := %(objs)
952 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
953 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
954 %(prog) : %(objs) $(TMP_DEPLIBS)
955         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
956 %end
957 #------------------------------------------------------------------------------
960 #------------------------------------------------------------------------------
961 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
962 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
963 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
964     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
965     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
967 TMP_EXTRA_LDFLAGS := 
968 TMP_EXTRA_LIBS :=
969 ifeq (%(nix),yes)
970     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
971 endif
972 ifeq (%(usestartup),no)
973     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
974 endif
975 ifeq (%(detach),yes)
976     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
977 endif
979 # Make a list of the lib files the programs depend on.
980 # In LDFLAGS remove white space between -L and directory
981 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
982 # Filter out only the libdirs and remove -L
983 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
984 # Add trailing /
985 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
986 # Add normal linklib path
987 TMP_DIRS += $(AROS_LIB)/
988 # add lib and .a to static linklib names
989 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
990 # search for the linklibs in the given path, ignore ones not found
991 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
992     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
994 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
996 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
997 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
998 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
999         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS)
1000 %end
1001 #------------------------------------------------------------------------------
1004 #------------------------------------------------------------------------------
1005 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1006 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1008 ifeq (%(linker),target)
1009 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1010 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1011 endif
1012 ifeq (%(linker),host)
1013 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1014 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1015 endif
1016 ifeq (%(linker),kernel)
1017 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1018 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1019 endif
1021 %(libdir)/lib%(libname).a : %(objs)
1022         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1023 %end
1024 #------------------------------------------------------------------------------
1026 #------------------------------------------------------------------------------
1027 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1028 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1029 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1030     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1032 TMP_LDFLAGS  := %(ldflags)
1033 # Make a list of the lib files the programs depend on.
1034 # In LDFLAGS remove white space between -L and directory
1035 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1036 # Filter out only the libdirs and remove -L
1037 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1038 # Add trailing /
1039 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1040 # Add normal linklib path
1041 TMP_DIRS += $(AROS_LIB)/
1042 # add lib and .a to static linklib names
1043 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1044 # search for the linklibs in the given path, ignore ones not found
1045 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1046     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1049 %(module) : LIB_NAMES := %(uselibs)
1050 %(module) : OBJS := %(objs)
1051 %(module) : ENDTAG := %(endobj)
1052 %(module) : ERR := %(err)
1053 %(module) : OBJDIR := %(objdir)
1054 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1055 ifeq (%(usehostlibs),)
1056 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1057 else
1058 # Warning: the -L/usr/lib here can result in modules
1059 # linking against host libs instead of AROS libs (e.g stdc++) !!
1060 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1061                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1062 endif 
1063 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1064         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1066 %end
1067 #------------------------------------------------------------------------------
1070 #------------------------------------------------------------------------------
1071 # Generate the libdefs.h include file for a module.
1072 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1074 TMP_TARGET := %(modname)_libdefs.h
1075 TMP_DEPS := $(GENMODULE)
1076 TMP_OPTS := 
1077 ifneq (%(conffile),)
1078     ifeq ($(dir %(conffile)),./)
1079         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1080         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1081     else
1082         TMP_OPTS += -c %(conffile)
1083         TMP_DEPS += %(conffile)
1084     endif 
1085 else
1086     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1087     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1088 endif
1089 ifneq (%(modsuffix),)
1090     TMP_OPTS += -s %(modsuffix)
1091 endif
1092 ifneq (%(targetdir),)
1093     TMP_OPTS += -d %(targetdir)
1094     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1095 endif
1096 ifneq (%(version),)
1097     TMP_OPTS += -v %(version)
1098 endif
1100 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1101 $(TMP_TARGET) : MODNAME := %(modname)
1102 $(TMP_TARGET) : MODTYPE := %(modtype)
1103 $(TMP_TARGET) : $(TMP_DEPS)
1104         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1105         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1106 %end
1107 #------------------------------------------------------------------------------
1109 #------------------------------------------------------------------------------
1110 # Generate the _lib.fd file for a module.
1111 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1113 TMP_TARGET := %(modname)_lib.fd
1114 TMP_DEPS := $(GENMODULE)
1115 TMP_OPTS := 
1116 ifneq (%(conffile),)
1117     ifeq ($(dir %(conffile)),./)
1118         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1119         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1120     else
1121         TMP_OPTS += -c %(conffile)
1122         TMP_DEPS += %(conffile)
1123     endif 
1124 else
1125     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1126     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1127 endif
1128 ifneq (%(modsuffix),)
1129     TMP_OPTS += -s %(modsuffix)
1130 endif
1131 ifneq (%(targetdir),)
1132     TMP_OPTS += -d %(targetdir)
1133     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1134 endif
1136 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1137 $(TMP_TARGET) : MODNAME := %(modname)
1138 $(TMP_TARGET) : MODTYPE := %(modtype)
1139 $(TMP_TARGET) : $(TMP_DEPS)
1140         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1141         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1142 %end
1143 #------------------------------------------------------------------------------
1145 #------------------------------------------------------------------------------
1146 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1147 # generated file in this Makefile
1148 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1149     targetdir=
1151 TMP_TARGET := Makefile.%(modname)%(modtype)
1152 TMP_DEPS := $(GENMODULE)
1153 TMP_OPTS := 
1154 ifneq (%(conffile),)
1155     ifeq ($(dir %(conffile)),./)
1156         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1157         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1158     else
1159         TMP_OPTS += -c %(conffile)
1160         TMP_DEPS += %(conffile)
1161     endif 
1162 else
1163     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1164     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1165 endif
1166 ifneq (%(modsuffix),)
1167     TMP_OPTS += -s %(modsuffix)
1168 endif
1169 ifneq (%(targetdir),)
1170     TMP_OPTS += -d %(targetdir)
1171     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1172 endif
1174 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1175 $(TMP_TARGET) : MODNAME := %(modname)
1176 $(TMP_TARGET) : MODTYPE := %(modtype)
1177 $(TMP_TARGET) : $(TMP_DEPS)
1178         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1179 %end
1180 #------------------------------------------------------------------------------
1183 #------------------------------------------------------------------------------
1184 # Generate the support files for compiling a module. This includes include
1185 # files and source files. This rule has to be preceeded by
1186 # %rule_genmodule_makefile
1187 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1188     conffile=
1190 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1191                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1192 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1193                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1195 TMP_DEPS := $(GENMODULE)
1196 TMP_OPTS :=
1198 ifneq (%(conffile),)
1199     ifeq ($(dir %(conffile)),./)
1200         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1201         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1202     else
1203         TMP_OPTS += -c %(conffile)
1204         TMP_DEPS += %(conffile)
1205     endif 
1206 else
1207     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1208     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1209 endif
1210 ifneq (%(modsuffix),)
1211     TMP_OPTS += -s %(modsuffix)
1212 endif
1213 ifneq (%(targetdir),)
1214     TMP_OPTS += -d %(targetdir)
1215     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1216     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1217 endif
1219 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1220 $(TMP_TARGETS) : MODNAME := %(modname)
1221 $(TMP_TARGETS) : MODTYPE := %(modtype)
1222 $(TMP_TARGETS) : $(TMP_DEPS)
1223         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1224 ifneq (%(conffile),lib.conf)
1225         @$(IF) $(TEST) -f lib.conf; then \
1226           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1227         fi
1228 endif
1229         @$(IF) $(TEST) -f libdefs.h; then \
1230           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1231         fi
1232         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1233 %end
1234 #------------------------------------------------------------------------------
1237 #------------------------------------------------------------------------------
1238 # Generate the support files for compiling a module. This includes include
1239 # files and source files.
1240 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1241     targetdir= conffile=
1243 ifneq ($(%(modname)_INCLUDES),)
1244 TMP_TARGETS := $(%(modname)_INCLUDES)
1246 TMP_DEPS := $(GENMODULE)
1247 TMP_OPTS :=
1249 ifneq (%(conffile),)
1250     ifeq ($(dir %(conffile)),./)
1251         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1252         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1253     else
1254         TMP_OPTS += -c %(conffile)
1255         TMP_DEPS += %(conffile)
1256     endif 
1257 else
1258     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1259     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1260 endif
1261 ifneq (%(modsuffix),)
1262     TMP_OPTS += -s %(modsuffix)
1263 endif
1264 ifneq (%(targetdir),)
1265     TMP_OPTS += -d %(targetdir)
1266     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1267 endif
1269 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1270 $(TMP_TARGETS) : MODNAME := %(modname)
1271 $(TMP_TARGETS) : MODTYPE := %(modtype)
1272 $(TMP_TARGETS) : $(TMP_DEPS)
1273         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1274         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1275 endif
1276 %end
1277 #------------------------------------------------------------------------------
1279 #------------------------------------------------------------------------------
1280 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1281 # 'start' is an optional starting address
1282 # 'ldflags' is optional additional flags for the linker
1283 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1285 BD_OUTDIR := $(dir %(file))
1286 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1287 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1288 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1289 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1290 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1291 BD_OBJS += %(objs)
1293 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1295 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1296         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1297         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1298         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1300 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1301     GLOB_MKDIRS += $(BD_OUTDIR)
1302 endif
1304 %end
1306 #------------------------------------------------------------------------------
1307 # Common rules for all makefiles
1308 %define common
1309 # Delete generated makefiles
1311 clean ::
1312         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1314 include $(SRCDIR)/config/make.tail
1316 BDID := $(BDTARGETID)
1317 %end
1318 #------------------------------------------------------------------------------
1319       
1321 #############################################################################
1322 #############################################################################
1323 ##                                                                         ##
1324 ## Here are the mmakefile build macros. These are macros that takes care   ##
1325 ## of everything to go from the sources to the generated target. Also all  ##
1326 ## intermediate files and directories that are needed are created by these ##
1327 ## rules.                                                                  ##
1328 ##                                                                         ##
1329 #############################################################################
1330 #############################################################################
1332 #------------------------------------------------------------------------------
1333 # Build a program
1334 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1335     objcfiles= \
1336     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1337     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1338     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1339     includedir= libdir= \
1340     compiler=target linker=
1342 .PHONY : %(mmake)
1344 BD_PROGNAME  := %(progname)
1345 BD_OBJDIR    := %(objdir)
1346 BD_TARGETDIR := %(targetdir)
1347 BD_LINKER    := %(linker)
1349 # If not supplied, linker is equal to compiler
1350 ifeq ($(BD_LINKER),)
1351     BD_LINKER := %(compiler)
1352 endif
1354 BD_FILES     := %(files)
1355 BD_OBJCFILES := %(objcfiles)
1356 BD_ASMFILES  := %(asmfiles)
1357 BD_CXXFILES := %(cxxfiles)
1359 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1360 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1361 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1363 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1364 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1365 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1367 BD_CFLAGS    := %(cflags)
1368 ifneq (%(includedir),)
1369 BD_CFLAGS    += -I%(includedir)
1370 endif
1371 BD_AFLAGS    := %(aflags)
1372 ifneq (%(includedir),)
1373 BD_AFLAGS    += -I%(includedir)
1374 endif
1375 BD_DFLAGS    := %(dflags)
1376 BD_LDFLAGS   := %(ldflags)
1377 ifneq (%(libdir),)
1378 BD_LDFLAGS   += -L%(libdir)
1379 endif
1382 %(mmake)-quick : %(mmake)
1384 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1385 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1387 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1388 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1389     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1390 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1391     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1392 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1393     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1394 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1395     aflags=$(BD_AFLAGS) compiler="%(compiler)"
1397 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1398     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1399     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1400     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1401     cmd=$(BD_LINK) strip=$(BD_STRIP)
1403 endif
1405 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1407 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1408 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1409 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1411 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1413 %(mmake)-clean ::
1414         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1415         @$(RM) $(FILES)
1417 %end
1418 #------------------------------------------------------------------------------
1421 #------------------------------------------------------------------------------
1422 # Build programs, for every C file an executable will be built with the same
1423 # name as the C file
1424 %define build_progs mmake=/A files=/A nix=no \
1425     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1426     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1427     includedir= libdir= \
1428     uselibs= usehostlibs= usestartup=yes detach=no
1430 .PHONY : %(mmake)
1432 BD_OBJDIR    := %(objdir)
1433 BD_TARGETDIR := %(targetdir)
1435 BD_FILES     := %(files)
1436 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1437 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1438 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1440 BD_CFLAGS    := %(cflags)
1441 ifneq (%(includedir),)
1442     BD_CFLAGS += -I%(includedir)
1443 endif
1444 BD_DFLAGS    := %(dflags)
1445 BD_LDFLAGS   := %(ldflags)
1446 ifneq (%(libdir),)
1447     BD_LDFLAGS += -L%(libdir)
1448 endif
1451 %(mmake)-quick : %(mmake)
1453 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1454 %(mmake) : $(BD_EXES)
1456 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1457 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1458     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1460 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1461     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1462     ldflags=$(BD_LDFLAGS) \
1463     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1464     usestartup="%(usestartup)" detach="%(detach)" \
1465      cmd=$(BD_LINK) strip=$(BD_STRIP)
1467 endif
1469 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1471 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1472 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1473 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1475 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1477 %(mmake)-clean ::
1478         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1479         @$(RM) $(FILES)
1481 %end
1482 #------------------------------------------------------------------------------
1485 #------------------------------------------------------------------------------
1486 # Build a module.
1487 # This is a bare version: It just compiles and links the given files. It is
1488 # assumed that all needed boiler plate code is in the files. This should only
1489 # be used for compiling external code. For AROS code use %build_module
1490 %define build_module_simple mmake=/A modname=/A modtype=/A \
1491     files="$(basename $(call WILDCARD, *.c))" \
1492     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1493     objdir=$(OBJDIR) moduledir= \
1494     uselibs= usehostlibs= compiler=target
1496 # Define metamake targets and their dependencies
1497 #MM %(mmake) : core-linklibs includes-generate-deps
1498 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1499 #MM %(mmake)-kobj-quick
1500 #MM %(mmake)-quick
1501 #MM %(mmake)-clean
1503 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1505 .PHONY : $(BD_ALLTARGETS)
1507 ifeq (%(modname),)
1508 $(error using %build_module_simple: modname may not be empty)
1509 endif
1510 ifeq (%(modtype),)
1511 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1512 endif
1514 # Default values for variables and arguments
1515 BD_DEFLINKLIBNAME := %(modname)
1516 BD_DEFDFLAGS := %(cflags)
1517 OBJDIR ?= $(GENDIR)/$(CURDIR)
1518 BD_MODDIR := %(moduledir)
1519 ifeq ($(BD_MODDIR),)
1520   ifeq (%(modtype),library)
1521     BD_MODDIR  := $(AROS_LIBRARIES)
1522   endif
1523   ifeq (%(modtype),gadget)
1524     BD_MODDIR  := $(AROS_GADGETS)
1525   endif
1526   ifeq (%(modtype),datatype)
1527     BD_MODDIR  := $(AROS_DATATYPES)
1528   endif
1529   ifeq (%(modtype),handler)
1530     BD_MODDIR  := $(AROS_FS)
1531   endif
1532   ifeq (%(modtype),device)
1533     BD_MODDIR  := $(AROS_DEVS)
1534   endif
1535   ifeq (%(modtype),resource)
1536     BD_MODDIR  := $(AROS_RESOURCES)
1537   endif
1538   ifeq (%(modtype),hook)
1539     BD_MODDIR  := $(AROS_RESOURCES)
1540   endif
1541   ifeq (%(modtype),mui)
1542     BD_MODDIR  := $(AROS_CLASSES)/Zune
1543   endif
1544   ifeq (%(modtype),mcc)
1545     BD_MODDIR  := $(AROS_CLASSES)/Zune
1546   endif
1547   ifeq (%(modtype),mcp)
1548     BD_MODDIR  := $(AROS_CLASSES)/Zune
1549   endif
1550   ifeq (%(modtype),usbclass)
1551     BD_MODDIR  := $(AROS_CLASSES)/USB
1552   endif
1553   ifeq (%(modtype),hidd)
1554     BD_MODDIR  := $(AROS_DRIVERS)
1555   endif
1556   ifeq (%(modtype),printer)
1557     BD_MODDIR  := $(AROS_PRINTERS)
1558   endif
1559 endif
1560 ifeq ($(BD_MODDIR),)
1561   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1562 endif
1564 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1565 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1566 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1568 %rule_compile_multi \
1569     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1570     cflags="%(cflags)" dflags="%(dflags)" \
1571     compiler="%(compiler)"
1573 # Handlers use dash instead of dot in their names
1574 ifeq (%(modtype),handler)
1575 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1576 else
1577 ifeq (%(modtype),printer)
1578 BD_MODULE := $(BD_MODDIR)/%(modname)
1579 else
1580 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1581 endif
1582 endif
1583 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1585 %(mmake)-quick : %(mmake)
1586 %(mmake)-kobj-quick : $(BD_KOBJ)
1587 %(mmake)       : $(BD_MODULE)
1588 %(mmake)-kobj  : $(BD_KOBJ)
1590 # The module is linked from all the compiled .o files
1591 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1593 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1594 # This breaks con-handler build. Here we work around this
1595 ifeq (%(modname),con)
1596     BD_ERR := $(notdir $(BD_MODULE)).err
1597 else
1598     BD_ERR := %(modname).err
1599 endif
1601 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1602                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1603                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1604                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1606 # Link kernel object file
1607 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1609 # Make these symbols local
1610 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1611             UtilityBase ExpansionBase KeymapBase KernelBase
1613 BD_SYMBOLS := $(BD_KBASE)
1615 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1616 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1617 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1618 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1619 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1620 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1621         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1622         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1623         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1626 ## Dependency fine-tuning
1628 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1629 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1631 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1632 $(BD_MODULE) : | $(BD_MODDIR)
1633 $(BD_KOBJ) : | $(KOBJSDIR)
1634 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1636 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1637 %(mmake)-clean ::
1638         @$(ECHO) "Cleaning up for module %(modname)"
1639         @$(RM) $(FILES)
1640 %end
1641 #------------------------------------------------------------------------------
1644 #------------------------------------------------------------------------------
1645 # Build a module - core routine
1646 # Explanation of this macro is done in the developer's manual
1647 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1648   files="$(basename $(call WILDCARD, *.c))" \
1649   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1650   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1651   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1652   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1653   compiler=target nostartup=yes archspecific=no \
1654   includedir= libdir= \
1655   build_abi= build_library=
1657 # We will employ a terrifying, but unavoidable, hack here.
1658 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1659 # ignores GNU Make ifeq() statements, but will process any #MM
1660 # headed lines in the file.
1662 # So, to make the following #MM lines conditional on whether we want
1663 # to build the ABI, Library, or both, we define build_abi= and 
1664 # build_library as 'M' to enable, or '' to disable, which allows genmf
1665 # to do the following conversions:
1667 #  #%(build_abi)M includes-foo: foo-include
1668 #    becomes, when build_abi=M
1669 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1670 #    but, when build_abi= ...
1671 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1673 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1675 # Define metamake targets and their dependencies
1676 #MM %(mmake)
1677 #MM %(mmake)-quick
1678 #MM %(mmake)-makefile
1679 #MM %(mmake)-clean
1681 # ABI targets:
1682 #M%(build_abi)- includes-all : %(mmake)-includes
1683 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1684 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1685 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1686 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1687 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1688 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1689 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1690 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1691 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1692 #M%(build_abi) %(mmake)-includes-quick
1693 #M%(build_abi) %(mmake)-includes-dirs
1694 #M%(build_abi) %(mmake)-fd
1696 # Library targets
1697 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1698 #%(build_library)M %(mmake)-kobj-quick : 
1700 # Library with ABI targets:
1701 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1702 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1704 # All MetaMake targets defined by this macro
1705 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1707 ifeq (%(build_library),M)
1708 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1709 endif
1711 ifeq (%(build_abi),M)
1712 BD_ALLTARGETS += %(mmake)-includes \
1713                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1714                  %(mmake)-linklib %(mmake)-fd
1715 endif
1717 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1719 ifeq (%(modname),)
1720 $(error using %build_module: modname may not be empty)
1721 endif
1722 ifeq (%(modtype),)
1723 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1724 endif
1726 # Default values for variables and arguments
1727 BD_DEFLINKLIBNAME := %(modname)
1728 BD_DEFDFLAGS := %(cflags)
1729 ifneq (%(includedir),)
1730     BD_DEFDFLAGS += -I%(includedir)
1731 endif
1732 OBJDIR ?= $(GENDIR)/$(CURDIR)
1734 ## Create genmodule include Makefile for the module
1736 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1738 %rule_genmodule_makefile \
1739     modname="%(modname)" modtype="%(modtype)" \
1740     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1741     conffile="%(conffile)"
1743 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1745 GLOB_MKDIRS += %(objdir)
1747 # Do not parse these statements if metatarget is not appropriate
1748 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1750 include %(objdir)/Makefile.%(modname)%(modtype)
1752 BD_DEFMODDIR := $(%(modname)_MODDIR)
1753 ifeq (%(archspecific),yes)
1754 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1755 endif
1758 ## include files generation
1760 ifneq (%(includedir),)
1761 BD_INCDIR    := %(includedir)
1762 else
1763 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1764 endif
1765 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1766 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1768 ifeq (%(build_abi),M)
1769 %(mmake)-includes-quick : %(mmake)-includes
1770 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1771     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1772     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1774 ifneq ($(%(modname)_INCLUDES),)
1775 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1776                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1777                          conffile="%(conffile)"
1779 %rule_copy_diff_multi \
1780     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1781     stampfile="%(objdir)/%(modname)_geninc"
1783 %rule_copy_diff_multi \
1784     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1785     stampfile="%(objdir)/%(modname)_incs"
1787 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1789 TMP%(modname)_INCDIRS := \
1790     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1791     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1792     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1793 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1795 endif
1797 endif
1799 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1800                            modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1801                            conffile="%(conffile)" version="%(version)"
1803 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1804 $(BD_DEFLIBDEFSINC) :
1805         @$(ECHO) "Generating $@"
1806         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1808 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1809 GLOB_MKDIRS += %(objdir)/include
1811 ## Extra genmodule src files generation
1812 ## 
1813 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1814                       modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1815                       conffile="%(conffile)"
1818 ifeq (%(build_abi),M)
1819 ## Create FD file
1820 ifeq (%(includedir),)
1821 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1822 else
1823 BD_FDDIR := %(includedir)/../fd
1824 endif
1825 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1827 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1828                    modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1830 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1832 GLOB_MKDIRS += $(BD_FDDIR)
1833 endif
1835 ## Compilation
1837 BD_FILES      := %(files)
1838 BD_CXXFILES := %(cxxfiles)
1840 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1842 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1843 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1845 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1846 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1847 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1849 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1850 ifneq (%(includedir),)
1851 BD_CFLAGS     += -I%(includedir)
1852 endif
1853 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1855 ifeq (%(modtype),library)
1856     BD_LIBSUFFIX := 
1857 else
1858     BD_LIBSUFFIX := .%(modtype)
1859 endif
1861 ifeq (%(libdir),)
1862 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1863 else
1864 BD_LIBDIR := %(libdir)
1865 endif
1867 ifeq (%(build_abi),M)
1868 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1869 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1870 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1871     BD_LINKLIB :=
1872 else
1873     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1874     ifneq (%(modname),%(linklibname))
1875         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1876     endif
1877 endif
1878 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1880 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1881 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1882 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1883     BD_RELLINKLIB :=
1884 else
1885     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1886     ifneq (%(modname),%(linklibname))
1887         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1888     endif
1889 endif
1890 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1891 endif
1893 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1894 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1895     $(BD_RELLINKLIBCFILES)
1897 %rule_compile_cxx_multi \
1898     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1899     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1900     compiler="%(compiler)"
1901 %rule_compile_multi \
1902     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1903     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1904     compiler="%(compiler)"
1905 %rule_compile_multi \
1906     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1907     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1908     compiler="%(compiler)"
1910 ifneq ($(BD_LINKLIBAFILES),)
1911 %rule_assemble_multi \
1912     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1913 endif
1915 ## Linking
1917 ifeq (%(modsuffix),)
1918 BD_SUFFIX := %(modtype)
1919 else
1920 BD_SUFFIX := %(modsuffix)
1921 endif
1923 ifeq (%(build_library),M)
1924 # Handlers use dash instead of dot in their names
1925 ifeq ($(BD_SUFFIX),handler)
1926 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1927 else
1928 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1929 endif
1930 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1931 else
1932 BD_MODULE :=
1933 BD_KOBJ   :=
1934 endif
1936 %(mmake)-quick      : %(mmake)
1937 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1938 ifeq (%(build_library),M)
1939 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1940 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1941 endif
1942 ifeq (%(build_abi),M)
1943 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1944 endif
1946 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1947            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1949 ifeq (%(nostartup),yes)
1950 # Handlers always have entry point
1951 ifneq (%(modtype),handler)
1952 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1953 endif
1954 endif
1956 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1957 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1958                  %(linklibobjs)
1959 BD_RELLINKLIBOBJS \
1960               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1961                  %(linklibobjs)
1963 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1964 # This breaks con-handler build. Here we work around this
1965 ifeq (%(modname),con)
1966     BD_ERR := $(notdir $(BD_MODULE)).err
1967 else
1968     BD_ERR := %(modname).err
1969 endif
1971 ifeq (%(build_library),M)
1972 # The module is linked from all the compiled .o files
1973 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1974                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
1975                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1976                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1977 endif
1979 ifeq (%(build_abi),M)
1980 # Link static lib
1981 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1982 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1983 ifneq ($(BD_LINKLIB),)
1984 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1985 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1986 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1987 endif
1989 $(BD_LINKLIB) : | $(BD_LIBDIR)
1990 GLOB_MKDIRS += $(BD_LIBDIR)
1991 endif
1993 ifneq ($(BD_RELLINKLIB),)
1994 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
1995 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1996 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
1997 endif
1999 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2000 GLOB_MKDIRS += $(BD_LIBDIR)
2001 endif
2002 endif
2004 ifeq (%(build_library),M)
2005 # Link kernel object file
2006 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2008 # Make these symbols local
2009 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2010             UtilityBase ExpansionBase KeymapBase KernelBase
2012 BD_SYMBOLS := $(BD_KBASE)
2014 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2015 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2016 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2017 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2018 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2019 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2020         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2021         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2022         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2023 endif
2025 ## Dependency fine-tuning
2027 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
2029 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2031 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2032 $(BD_MODULE) : | %(prefix)/%(moduledir)
2033 $(BD_KOBJ)   : | $(KOBJSDIR)
2034 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2036 # Some include files need to be generated before the .c can be parsed.
2037 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2039 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2040     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2041 $(BD_DEPS) : $(BD_DFILE_DEPS)
2042 endif
2044 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2045     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2046     %(objdir)/Makefile.%(modname)%(modtype) \
2047     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2048     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2049     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2050     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2051     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2052     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2053     $(BD_ENDOBJS)
2054 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2055 %(mmake)-clean ::
2056         @$(ECHO) "Cleaning up for module %(modname)"
2057         @$(RM) $(FILES)
2059 endif # $(TARGET) in $(BD_ALLTARGETS)
2060 %end
2061 #------------------------------------------------------------------------------
2063 #------------------------------------------------------------------------------
2064 # Build a module - ABI and library
2065 # Explanation of this macro is done in the developer's manual
2066 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2067   files="$(basename $(call WILDCARD, *.c))" \
2068   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2069   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2070   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2071   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2072   compiler=target nostartup=yes archspecific=no \
2073   includedir= libdir=
2075 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2076    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2077    files="%(files)" cxxfiles="%(cxxfiles)" \
2078    linklibname="%(linklibname)" \
2079    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2080    cflags="%(cflags)" dflags="%(dflags)" \
2081    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2082    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2083    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2084    includedir="%(includedir)" libdir="%(libdir)" \
2085    build_abi=M build_library=M
2087 %end
2088 #------------------------------------------------------------------------------
2091 #------------------------------------------------------------------------------
2092 # Build a module skeleton ABI
2093 # This is a stripped-down version of build_module, it only creates include
2094 # files and the linklibs.
2095 # This is used when for plugins or classes with the same API, but no actual
2096 # implementation here.
2097 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2098   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2099   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2100   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2101   compiler=target nostartup=yes archspecific=no \
2102   includedir= libdir=
2104 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2105   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2106   linklibname="%(linklibname)" \
2107   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2108   cflags="%(cflags)" dflags="%(dflags)" \
2109   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2110   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2111   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2112   includedir="%(includedir)" libdir="%(libdir)" \
2113   build_abi=M build_library=
2115 %end
2116 #------------------------------------------------------------------------------
2118 #------------------------------------------------------------------------------
2119 # Build a module library - no includes nor linklibs
2120 # Explanation of this macro is done in the developer's manual
2121 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2122   files="$(basename $(call WILDCARD, *.c))" \
2123   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2124   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
2125   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2126   uselibs= usehostlibs= \
2127   compiler=target nostartup=yes archspecific=no \
2128   includedir= libdir=
2130 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2131    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2132    files="%(files)" cxxfiles="%(cxxfiles)" \
2133    cflags="%(cflags)" dflags="%(dflags)" \
2134    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2135    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2136    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2137   includedir="%(includedir)" libdir="%(libdir)" \
2138    build_abi= build_library=M
2140 %end
2141 #------------------------------------------------------------------------------
2145 #------------------------------------------------------------------------------
2146 # Build a linklib.
2147 # - mmake is the mmaketarget
2148 # - libname is the baselibname e.g. lib%(libname).a will be created
2149 # - files are the C source files to include in the lib. The list of files
2150 #   has to be given without the .c suffix
2151 # - cxxfiles are C++ source files without suffix.
2152 #   NB: files will be matched in the order .cpp > .cxx > .cc
2153 # - asmfiles are the asm files to include in the lib. The list of files has to
2154 #   be given without the .s suffix
2155 # - objs additional object to link into the linklib. The objects have to be
2156 #   given with full absolute path and the .o suffix.
2157 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2158 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2159 # - cflags are the flags to compile the source (default $(CFLAGS))
2160 # - dflags are the flags use during makedepend (default equal to cflags)
2161 # - aflags are the flags use during assembling (default $(AFLAGS))
2162 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2163 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2164   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2165   includedir= \
2166   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2167   aflags=$(AFLAGS) compiler=target
2169 # assign and generate the local variables used in this macro
2170 BD_LIBNAME    := %(libname)
2171 BD_LINKLIB    := %(libdir)/lib%(libname).a
2173 BD_FILES      := %(files)
2174 BD_ASMFILES   := %(asmfiles)
2175 BD_CXXFILES := %(cxxfiles)
2177 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2178 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2179 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2181 BD_OBJS       := $(BD_ARCHOBJS) \
2182                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2183                  %(objs)
2184 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2186 BD_CFLAGS    := %(cflags)
2187 ifneq (%(includedir),)
2188 BD_CFLAGS    += -I%(includedir)
2189 endif
2190 BD_AFLAGS    := %(aflags)
2191 BD_DFLAGS    := %(dflags)
2193 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2196 %(mmake)-quick : %(mmake)
2198 #MM %(mmake) : includes-generate-deps
2199 %(mmake) : $(BD_LINKLIB)
2201 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2203 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2204     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2205 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2206     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2207 %rule_assemble basename=% targetdir="%(objdir)" \
2208     aflags=$(BD_AFLAGS)
2210 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2211 endif
2213 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2215 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2216 $(BD_LINKLIB) : | %(libdir)
2217 GLOB_MKDIRS += %(objdir) %(libdir)
2219 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2221 %(mmake)-clean ::
2222         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2223         @$(RM) $(FILES)
2225 %end
2226 #------------------------------------------------------------------------------
2229 #------------------------------------------------------------------------------
2230 # Build catalogs.
2231 # - mmake is the mmaketarget
2232 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2233 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2234 # - subdir is the destination subdirectory of the catalogs
2235 # - name is the name of the destination catalog, without the .catalog suffix
2236 # - source is the path to the generated source code file
2237 # - dir is the base destination directory (default $(AROS_CATALOGS))
2238 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2239 # - srcdir is the directory in which the *.cd and *.ct files are searched
2241 %define build_catalogs mmake=/A name=/A subdir=/A \
2242  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2243  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2245 ifeq (%(description),)
2246 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2247 else
2248 BD_DESC := %(description)
2249 endif
2251 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2253 ifeq (%(catalogs),)
2254 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2255 else
2256 BD_LNGS := %(catalogs)
2257 endif
2259 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2260 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2263 %(mmake) : $(BD_OBJS) %(source)
2265 $(BD_OBJS) : | $(BD_DIRS)
2266 GLOB_MKDIRS += $(BD_DIRS)
2268 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2269         @$(ECHO) "Creating   %(name) catalog for language $*."
2270         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2272 ifneq (%(source),)
2273 %(source) : BD_DESC := $(BD_DESC)
2274 %(source) : BD_SRC := $(BD_SRC)
2275 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2276         @$(ECHO) "Creating   %(name) catalog source file $@"
2277         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2278 endif
2280 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2282 %(mmake)-clean ::
2283         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2284         @$(RM) $(FILES)
2286 .PHONY: %(mmake) %(mmake)-clean
2288 %end
2289 #-----------------------------------------------------------------------------
2292 #-----------------------------------------------------------------------------
2293 # Build icons.
2294 # - mmake is the mmaketarget
2295 # - icons is a list of icon base names (ie. without the .info suffix)
2296 # - dir is the destination directory
2297 # - srcdir is where *.png and *.info.src are searched
2298 #-----------------------------------------------------------------------------
2300 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2302 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2305 %(mmake) : $(BD_OBJS)
2307 ifeq (%(image),)
2309 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2310         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2311         @$(ILBMTOICON) $+ $@
2313 else
2315 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2316         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2317         @$(ILBMTOICON) $+ $@
2319 endif
2321 $(BD_OBJS) : | %(dir)
2322 GLOB_MKDIRS += %(dir)
2324 %(mmake)-clean : FILES := $(BD_OBJS)
2326 %(mmake)-clean ::
2327         @$(RM) $(FILES)
2329 .PHONY: %(mmake) %(mmake)-clean
2331 %end
2332 #-----------------------------------------------------------------------------
2335 #------------------------------------------------------------------------------
2336 # Compile files for an arch-specific replacement of code for a module
2337 # - files: the basenames of the C files to compile.
2338 # - asmfiles: the basenames of the asm files to assemble.
2339 # - mainmmake: the mmake of the module in the main directory to compile these
2340 #   arch specific files for.
2341 # - maindir: the object directory for the main module
2342 # - arch: the arch for which to compile these files. It can have the form
2343 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2344 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2345 # - dflags: the flags used during creation of dependency file. If not specified
2346 #   the same value as cflags will be used
2347 # - aflags: the flags used during assembling
2348 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2349 #   the target compiler is used
2350 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2351 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2353 ifeq (%(files) %(asmfiles),)
2354   $(error no files or asmfiles given)
2355 endif
2357 %buildid targets="%(mainmmake)-%(arch)"
2359 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2360 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2361 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2362 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2363 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2364 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2365 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2366 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2367 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2368 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2369 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2370 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2371 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2372 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2373 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2375 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2377 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2378 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2379 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2380 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2381 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2383 ifneq (%(modulename),)
2384 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2385 endif
2387 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2388     BD_TARGET := %(mainmmake)-%(arch)-quick
2389 else
2390     BD_TARGET := %(mainmmake)-%(arch)
2391 endif
2394 ifeq ($(TARGET),$(BD_TARGET))
2395 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2396 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2397 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2398 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2399 endif
2401 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2402 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2405 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2408 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2410 ifeq ($(findstring %(compiler),host kernel target),)
2411   $(error unknown compiler %(compiler))
2412 endif
2413 ifeq (%(compiler),target)
2414 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2415 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2416 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2417 endif
2418 ifeq (%(compiler),host)
2419 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2420 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2421 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2422 endif
2423 ifeq (%(compiler),kernel)
2424 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2425 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2426 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2427 endif
2428 ifneq (%(modulename),)
2429 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2430 else
2431 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2432 endif
2433 ifeq ($(TARGET),$(BD_TARGET))
2434 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2435         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2436 endif
2438 ifeq (%(dflags),)
2439 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2440 else
2441 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2442 endif
2443 ifeq ($(TARGET),$(BD_TARGET))
2444 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2445         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2446 endif
2448 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2450 ifeq ($(TARGET),$(BD_TARGET))
2451 $(BD_OBJDIR$(BDID))/%.o : %.s
2452         %assemble_q opt=$(AFLAGS)
2453 $(BD_OBJDIR$(BDID))/%.o : %.S
2454         %assemble_q opt=$(AFLAGS)
2455 endif
2457 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2458 %end
2459 #------------------------------------------------------------------------------
2462 #------------------------------------------------------------------------------
2463 # generate asm files from c files (for debugging purposes)
2464 %define ctoasm_q
2465 %.s : %.c
2466         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2467         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2468 %end
2469 #------------------------------------------------------------------------------
2472 #------------------------------------------------------------------------------
2473 # Copy files from one directory to another.
2475 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2477 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2479 GLOB_MKDIRS += %(dst)
2481 .PHONY : %(mmake)
2484 %(mmake) : | %(dst) 
2485         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2487 %end
2488 #------------------------------------------------------------------------------
2491 #------------------------------------------------------------------------------
2492 # Copy a directory recursively to another place, preserving the original 
2493 # hierarchical structure
2495 # src: the source directory whose content will be copied.
2496 # dst: the directories where to copy src's content. If not existing, they will be made.
2497 # excludefiles: files which must not be copied. Path must be relative to src.
2499 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2501 .PHONY : %(mmake)
2504 %(mmake) :
2505         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2507 %end
2508 #------------------------------------------------------------------------------
2511 #------------------------------------------------------------------------------
2512 #   Copy include files into the includes directories. There are currently
2513 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2514 #   for building tools that need to run on the host system $(GENINCDIR). The
2515 #   $(GENINCDIR) path must not contain any references to the C runtime
2516 #   library header files.
2518 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2519     dir= compiler=target includedir=$(AROS_INCLUDES)
2521 ifeq ($(findstring %(compiler),host kernel target),)
2522 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2523 endif
2525 ifneq (%(dir),)
2526 TMP_DIR := %(dir)
2527 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2528 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2529 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2530 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2531 ifeq ($(TMP_DIRFIRST),/)
2532 BD_INC_PATH := %(dir)/
2533 else
2534 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2535 endif
2536 else
2537 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2538 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2539 endif
2541 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2542         @$(CP) $< $@
2545 ifeq (%(compiler),target)
2547 ifneq (%(dir),)
2548 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2549 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2550 else
2551 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2552 endif
2554 BD_INCL_FILES += $(BD_INCL_FILES2)
2556 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2557         @$(CP) $< $@
2558 endif
2561 %(mmake) : $(BD_INCL_FILES)
2563 .PHONY: %(mmake)
2565 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2566 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2567 %end
2568 #------------------------------------------------------------------------------
2571 #------------------------------------------------------------------------------
2572 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2573 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2574 STUBS_MEM := $(addsuffix .o,$(STUBS))
2575 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2576 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2577 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2579 #MM- linklibs : hidd-%(hidd)-stubs
2580 #MM- %(parenttarget): hidd-%(hidd)-stubs
2581 #MM hidd-%(hidd)-stubs : includes includes-copy
2582 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2584 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2585         %mklib_q from=$^
2587 $(STUBS_OBJ) : $(STUBS_SRC) 
2588         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2590 $(STUBS_DEP) : $(STUBS_SRC)
2591         %mkdepend_q flags="%(dflags)"
2593 setup ::
2594         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2597 clean ::
2598         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2600 DEPS := $(DEPS) $(STUBS_DEP)
2602 %end
2603 #------------------------------------------------------------------------------
2606 #------------------------------------------------------------------------------
2607 # Build an imported source tree which uses the configure script from the
2608 # autoconf package.  This rule will try to "integrate" the produced files as
2609 # much as possible in the AROS build, for example by putting libraries in the
2610 # standard library directory, includes in the standard include directory, and
2611 # so on. You can however override this behaviour.
2613 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2614 # be %(bindir) (or its deduced value) when running "make install", and
2615 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2616 # configure script some more parameters whose value depends upon the PROGDIR
2617 # env var, so that the program gets all its stuff installed in the proper place
2618 # when building it, but when running it from inside AROS it can also find that
2619 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2620 # the configuration parameters set when running ./configure
2622 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2623 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2624 # to the name which has to follow it.
2626 # Arguments:
2628 #     - mmake           = the meta make target.
2629 #     - package         = name of the package to be built.
2630 #     - srcdir          = the location of the unpacked source code. Defaults
2631 #                         to $(SRCDIR)/$(CURDIR).
2632 #     - prefix          = the target directory. Must be an absolute path of the
2633 #                         host system. Defaults to $(AROS_CONTRIB).
2634 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2635 #                         Defaults to the value of the prefix option.
2636 #     - extraoptions    = additional options for the configure script.
2637 #     - extracflags     = additional flags which are used for both C and C++.
2638 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2639 #                         Defaults to the value of the nix argument.
2640 #     - nix             = enable u*nix path handling, i.e. a path like
2641 #                         /progdir//./file will be translated to
2642 #                         progdir:file during run-time. Defaults to no.
2643 #     - compiler        = target, host or kernel. Defaults to target.
2644 #     - install_target  = the command used for installing. Defaults to install. Leave
2645 #                         it empty if you want to suppress installing.
2646 #     - preconfigure    = a metatarget which is executed before configure is called.
2647 #     - postconfigure   = a metatarget which is executed after configure is called.
2648 #     - postinstall     = a metatarget which is executed after installing.
2649 #     - install_env     = set additional options for installing.
2650 #     - use_build_env   = if yes the configuration environment is used for
2651 #                         installing, too. Defaults to no.
2653 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2654 # like this:
2656 # if nix_dir_layout
2657 #    --prefix = $(aros_prefix)
2658 #    progdir = $(aros_prefix)/bin
2659 # else
2660 #    if nix
2661 #        --prefix = /PROGDIR
2662 #        --bindir = /PROGDIR
2663 #        --sbindir = /PROGDIR
2664 #        --libdir = /LIB
2665 #        --includedir = /INCLUDE
2666 #        --oldincludedir = /INCLUDE   
2667 #    else
2668 #        --prefix = $(aros_prefix)
2669 #    endif
2671 #    progdir = $(aros_prefix)
2673 #    # Install options
2674 #    bindir = $(prefix)
2675 #    sbindir = $(prefix)
2676 #    libdir = $(AROS_LIB)
2677 #    includedir = $(AROS_INCLUDES)
2678 #    oldincludedir = $(AROS_INCLUDES)
2679 # endif
2682 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2683     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2684     install_target=install preconfigure= postconfigure= postinstall= \
2685     install_env= use_build_env=no
2687 ifneq (%(prefix),)
2688     %(mmake)-prefix := %(prefix)
2689 else
2690     %(mmake)-prefix := $(AROS_CONTRIB)
2691 endif
2693 ifneq (%(aros_prefix),)
2694     %(mmake)-aros_prefix := %(aros_prefix)
2695 else
2696     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2697 endif
2699 ifeq (%(nix),yes)
2700     %(mmake)-nix    := -nix
2701     %(mmake)-volpfx := /
2702     %(mmake)-volsfx := /
2703     
2704     ifeq (%(nix_dir_layout),)
2705         %(mmake)-nix_dir_layout := yes
2706     endif
2707 else
2708     %(mmake)-volsfx := :
2709     
2710     ifeq (%(nix_dir_layout),)
2711         %(mmake)-nix_dir_layout := no
2712     endif
2713 endif
2715 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2717 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2718         exec_prefix=$(%(mmake)-prefix) %(install_env)
2720 # Check if chosen compiler is valid
2721 ifeq ($(findstring %(compiler),host target kernel),)
2722   $(error unknown compiler %(compiler))
2723 endif
2725 # Set legacy 'host' variable based on chosen compiler
2726 ifeq (%(compiler),host)
2727     host := yes
2728     ifeq (%(package),)
2729         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2730     else
2731         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2732     endif
2733 else
2734     host := no
2735     ifeq (%(package),)
2736         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2737     else
2738         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2739     endif
2740 endif
2741 ifneq (%(gendir),)
2742     ifeq (%(package),)
2743         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2744     else
2745         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2746     endif
2747 endif
2749 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2750 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2752 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2753     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2754     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2755 else
2756     ifeq (%(nix),yes)
2757         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2758         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2759     else
2760         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2761     endif
2763     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2764     
2765     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2766         sbindir=$(%(mmake)-prefix) \
2767         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2768         oldincludedir=$(AROS_INCLUDES) %(install_env)
2769 endif
2771 ifneq ($(DEBUG),yes)
2772     %(mmake)-s_flag = -s
2773 endif
2775 # Set up build environment, and options for configure script
2776 ifeq (%(compiler),host)
2777     CONFIG_ENV := \
2778         CPP="$(HOST_CPP)" \
2779         CXXCPP="$(HOST_CPP)" \
2780         CC="$(HOST_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2781         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2782         LDFLAGS="-L$(CROSSTOOLSDIR)/lib" \
2783         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2784         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2785         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2786         TARGET_NM="$(NM_PLAIN)" TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2787 endif
2788 ifeq (%(compiler),target)
2789     CONFIG_ENV := \
2790         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2791         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2792         CFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2793         CXXFLAGS="$(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS)" \
2794         CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2795         CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2796         CC="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2797         CXX="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2798         LDFLAGS="-L$(AROS_DEVELOPMENT)/lib" \
2799         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2800         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2801         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2802         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2803         TARGET_NM="$(NM_PLAIN)" \
2804         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2805         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2806     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2807         --host=$(AROS_TARGET_CPU)-aros\
2808         --target=$(AROS_TARGET_CPU)-aros\
2809         --disable-nls\
2810         --without-x --without-pic --disable-shared
2811 endif
2812 ifeq (%(compiler),kernel)
2813     CONFIG_ENV := \
2814         CPP="$(KERNEL_CPP)" \
2815         CXXCPP="$(KERNEL_CPP)" \
2816         CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2817         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2818         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2819         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2820         TARGET_NM="$(NM_PLAIN)"
2821     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2822         --host=$(AROS_TARGET_CPU)-aros\
2823         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2824         --without-x --without-pic --disable-shared
2825 endif
2827 ifeq (%(use_build_env),yes)
2828     BUILD_ENV := $(CONFIG_ENV)
2829 endif
2831 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2833 # When building for the host, we don't need to build the
2834 # linklibs - this is especially true when building the
2835 # crosstool toolchain on 'foreign' architectures (such as
2836 # building PPC on x86)
2838 #MM- %(mmake)-host : setup includes %(mmake)-quick
2839 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2840 #MM- %(mmake): %(mmake)-%(compiler)
2842 # Using -j1 in install_command may result in a warning but finally
2843 # it does its job. make install for gcc does not work reliably for -jN
2844 # where N > 1.
2845 ifneq (%(install_target),)
2846     %(mmake)-install_command = \
2847         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2848         -C $(%(mmake)-pkgdir) %(install_target) -j1
2850     %(mmake)-uninstall_command = \
2851     $(RM) $(%(mmake)-installflag) && \
2852     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2853     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2854 else
2855     %(mmake)-install_command   := true
2856     %(mmake)-uninstall_command := true
2857 endif
2859 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2862 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2864 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2865         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2866             $(RM)  $(%(mmake)-installflag) && \
2867             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2868              -C $(%(mmake)-pkgdir) && \
2869             $(%(mmake)-install_command) && \
2870             $(TOUCH) $@ -r $^; \
2871         fi
2873 $(%(mmake)-pkgdir)/.files-touched:
2874         %mkdirs_q $(%(mmake)-pkgdir)
2875         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2876         $(TOUCH) $@
2879 %(mmake)-uninstall :
2880         $(%(mmake)-uninstall_command)
2883 %(mmake)-configure : $(%(mmake)-configflag)
2885 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2886 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2887         $(RM) $@
2888         %mkdirs_q $(%(mmake)-pkgdir)
2889         cd $(%(mmake)-pkgdir) && \
2890         find . -name config.cache -exec $(RM) '{}' \; && \
2891         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2892             %(extraoptions) && \
2893         $(TOUCH) $@
2896 %(mmake)-clean : %(mmake)-uninstall
2897         @$(RM) $(%(mmake)-pkgdir)
2898 %end
2899 #------------------------------------------------------------------------------
2902 #------------------------------------------------------------------------------
2903 # Build an imported source tree which uses cmake 
2905 # Arguments:
2907 #     - mmake           = the meta make target.
2908 #     - package         = name of the package to be built.
2909 #     - srcdir          = the location of the unpacked source code. Defaults
2910 #                         to $(SRCDIR)/$(CURDIR).
2911 #     - prefix          = the target directory. Must be an absolute path of the
2912 #                         host system. Defaults to $(AROS_CONTRIB).
2913 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2914 #                         Defaults to the value of the prefix option.
2915 #     - extraoptions    = additional options for the cmake script.
2916 #     - installoptions    = additional options for the install step.
2919 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2920     aros_prefix= extraoptions= installoptions= cflags=$(CFLAGS)
2922 ifneq (%(prefix),)
2923     %(mmake)-prefix := %(prefix)
2924 else
2925     %(mmake)-prefix := $(AROS_CONTRIB)
2926 endif
2928 ifneq (%(aros_prefix),)
2929     %(mmake)-aros_prefix := %(aros_prefix)
2930 else
2931     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2932 endif
2934 ifneq (%(gendir),)
2935     ifeq (%(package),)
2936         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2937     else
2938         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2939     endif
2940 else
2941     ifeq (%(package),)
2942         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2943     else
2944         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2945     endif
2946 endif
2948 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
2949 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2951 BD_CFLAGS := %(cflags)
2952 BD_CXXFLAGS := $(subst -Wno-pointer-sign,,$(BD_CFLAGS))
2954 %(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)"
2956 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2958 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
2960 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
2963 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2965 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
2966         if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
2967             $(RM)  $(%(mmake)-installflag) && \
2968             $(MAKE) -C $(%(mmake)-pkgdir) && \
2969             cd $(%(mmake)-pkgdir) && \
2970             cmake %(installoptions) -P cmake_install.cmake && \
2971             $(TOUCH) $@ -r $^; \
2972         fi
2974 $(%(mmake)-pkgdir)/.files-touched:
2975         %mkdirs_q $(%(mmake)-pkgdir)
2976         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
2977         $(TOUCH) $@
2980 %(mmake)-cmake : $(%(mmake)-cmakeflag)
2982 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2983 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2984         $(RM) $@
2985         %mkdirs_q $(%(mmake)-pkgdir)
2986         cd $(%(mmake)-pkgdir) && \
2987         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
2988         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
2989         $(TOUCH) $@
2992 %(mmake)-clean : %(mmake)-uninstall
2993         @$(RM) $(%(mmake)-pkgdir)
2994 %end
2995 #------------------------------------------------------------------------------
2998 #------------------------------------------------------------------------------
2999 # Given an archive name, patches names and locations where to find them, fetch
3000 # the archive and the patches from any of those locations, unpack the archive
3001 # and then apply the patches.
3003 # Locations currently supported are http and ftp sites, plus local filesystem
3004 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3005 # the fetch.sh script needs to be modified, since this macro relies on that script.
3007 # Arguments:
3009 #     - mmake           = mmaketarget
3010 #     - archive_origins = list of locations where to find the archive. They are tried
3011 #                         in sequence, until the archive is found and fetching it 
3012 #                         succeeded. If not specified, the current directory is assumed.
3013 #     - archive         = the archive name. Mandatory.
3014 #     - suffixes        = a list of suffixes to append to the the package name plus the
3015 #                         version. Each one of them is tried until a matching archive is
3016 #                         found. They are appended to patches and these are tried the
3017 #                         same way as packages are.
3018 #     - location        = the local directory where to put the fetched archive and patches.
3019 #                         If not specified, the directory specified by destination is used.
3020 #     - destination     = the directory to unpack the archive to.
3021 #                         If not specified, the current directory is assumed.
3022 #     - patches_origins = list of locations where to find the patches. They are tried
3023 #                         in sequence, until a patch is found and fetching it 
3024 #                         succeeded. If not specified, the current directory is assumed.
3025 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3026 #                         patch_name[:[patch_subdir][:patch_opt]].
3028 #                             - patch_name   = the name of the patch file
3029 #                             - patch_subdir = the directory within \destination\ where to
3030 #                                              apply the patch.
3031 #                             - patch_opt    = any options to pass to the `patch' command
3032 #                                              when applying the patch.
3033 #                         
3034 #                         The patch_subdir and patch_opt fields are optional.
3036 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3037     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3039 .PHONY: %(mmake)
3041 ifneq (%(location),)
3042     %(mmake)-location := %(location)
3043 else
3044     %(mmake)-location := %(destination)
3045 endif
3048 %(mmake) :
3049         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3050         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3051 %end
3052 #------------------------------------------------------------------------------
3055 #------------------------------------------------------------------------------
3056 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3057 # unpatched source tree and runs diff against this and a previously fetched and possibly
3058 # patched tree. Depending on what happens after patching during a normal build it might
3059 # give best results if the new patch is created directly after fetch.
3061 # Arguments:
3063 #     - mmake       = mmaketarget
3064 #     - archive     = archive base name
3065 #     - srcdir      = the top level directory the package is unpacked to, useful if
3066 #                     an archive unpacks to a directory other than its name suggests.
3067 #                     this should not be deeper than a single path element.
3068 #     - suffixes    = a list of suffixes to append to the the package name plus the
3069 #                     version. Each one of them is tried until a matching archive is
3070 #                     found.
3071 #     - destination = the directory to unpack the archive to.
3072 #     - excludes    = diff patterns to exclude files or directories from the patch
3074 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3076 .PHONY: %(mmake)
3078 ifneq (%(excludes),)
3079     %(mmake)-exclude := -X ./exclude.patterns
3080 endif
3082 ifneq (%(srcdir),)
3083     %(mmake)-srcdir := %(srcdir)
3084 else
3085     %(mmake)-srcdir := %(archive)
3086 endif
3089 %(mmake):
3090         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3091         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3092         cd %(destination)/tmp ; \
3093         $(FOR) f in %(excludes) ; do \
3094             $(ECHO) $$f >> ./exclude.patterns ; \
3095         done ; \
3096         diff -ruN $(%(mmake)-exclude) \
3097             $(%(mmake)-srcdir) \
3098             $(%(mmake)-srcdir).aros \
3099             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3100         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3101         $(RM) %(destination)/tmp
3102 %end
3103 #------------------------------------------------------------------------------
3106 #------------------------------------------------------------------------------
3107 # Joins the features of %fetch and %build_with_configure.
3109 # If a patch is provided, it *must* be named the following way:
3111 #    <package name>-<version number>-aros.diff
3113 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3114 # CD'ing into the archive's extracted directory.
3116 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3117 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3118 # to make that patch fully comprehensive.
3120 # Arguments:
3122 #    - mmake            = the meta make target.
3123 #    - package          = the GNU package name, sans version and archive format suffixes.
3124 #    - subpackage       = ???
3125 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3126 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3127 #    - version          = the package's version number, or otherwise any other version string.
3128 #                         It gets appended to the package name to form the basename of the archive.
3129 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3130 #                         version. Each one of them is tried until a matching archive is found.
3131 #                         Defaults to "tar.bz2 tar.gz".
3132 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3133 #    - builddir         = override the location we expect to run configure/make in.
3134 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3135 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3136 #                         fetched or not. Default to no.
3137 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3138 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3139 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3140 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3141 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3142 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3143 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3144 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3145 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3146 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3147 #    - nix              = same meaning as the one for the %build_with_configure macro.
3148 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3149 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3151 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3152     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3153     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
3154     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3156 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3157 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3158 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3159 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3161 %(mmake)-archbase  := %(package)-%(version)
3163 ifeq (%(compiler),host)
3164     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
3165 else
3166     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3167 endif
3169 ifeq (%(prefix),)
3170     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3171 else
3172     %(mmake)-prefix := %(prefix)
3173 endif
3175 ifneq (%(subpackage),)
3176     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3177 else
3178     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3179 endif
3181 ifneq (%(srcdir),)
3182     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3183 else
3184     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3185 endif
3187 ifneq (%(builddir),)
3188     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3189 else
3190     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3191 endif
3193 ifeq (%(patch),yes)
3194     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3195 else
3196     %(mmake)-%(subpackage)-patches_specs := ::
3197 endif
3199 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3200     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3201     archive_origins=". %(package_repo)" \
3202     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3204 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3205     archive=$(%(mmake)-%(subpackage)-archbase) \
3206     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3207     suffixes="%(suffixes)" \
3208     destination=$(%(mmake)-portdir)
3210 #MM- %(mmake) : %(mmake)-%(subpackage)
3212 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3214 %(mmake)-%(subpackage)-package-basename := \
3215     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3217 ifneq (%(create_pkg),no)
3218     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3219 endif
3221 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3222      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3223      install_env="%(install_env)" use_build_env="%(use_build_env)" \
3224      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3225      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3226      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3228 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3229 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3232 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3234 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3235 #that $^ and $@ have exactly the same mtime, and in that case make tries
3236 #to rebuild $@ again, which would fail because the directory where
3237 #the package got installed would not exist anymore. 
3238 #We work this around by using an if statement to manually check the mtimes.
3239 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3240         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3241         $(RM) $@ ; \
3242         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3243         mkdir -p "$(DISTDIR)/Packages" ; \
3244         mkdir -p "$(%(mmake)-prefix)" ; \
3245         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3246         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3247         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3248     fi
3249 %end
3250 #------------------------------------------------------------------------------
3253 #------------------------------------------------------------------------------
3254 # Joins the features of %fetch and %build_with_configure, taking advantage of
3255 # the naming scheme of GNU packages. GNU packages names are in the form
3257 #     <package name>-<version number>.<archive format suffix>
3259 # If a patch is provided, it *must* be named the following way:
3261 #    <package name>-<version number>-aros.diff
3263 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3264 # CD'ing into the archive's extracted directory.
3266 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3267 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3268 # to make that patch fully comprehensive.
3270 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3272 # Arguments:
3274 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3276 #    - prefix           = defaults to $(GNUDIR).
3277 #    - aros_prefix      = defaults to /GNU.
3279 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3280     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3281     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3283 GNU_REPOSITORY := gnu://
3285 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3286     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3287     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3288     patch="%(patch)" patch_repo="%(patch_repo)" \
3289     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3290     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3292 %end
3293 #------------------------------------------------------------------------------
3296 #------------------------------------------------------------------------------
3297 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3298 # that the package is a "Development" package, and as such it needs to be placed
3299 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3301 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3302 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3303 # "mmake" argument, because the metatarget is implicitely defined as
3305 #     #MM- development-%(package)
3307 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3308     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3309     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3311 #MM- development : development-%(package)
3314 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3315    version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3316    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3317    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3318    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3321 postinstall-%(package)-delete-la-files:
3322         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3324 %end
3325 #------------------------------------------------------------------------------
3327 # Builds a kickstart package in PKG format
3329 # Arguments:
3331 #    - mmake   = target name
3332 #    - file    = destination file name with path
3334 # Other arguments are self-explanatory
3336 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3337     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3339 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3340 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3341 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3342 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3343 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3344 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3346 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3347 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3348 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3349 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3350 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3351 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3353 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3354     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3355 PKG_DIR   := $(dir %(file))
3358 %(mmake) : %(file)
3361 %(mmake)-quick : %(file)
3363 %(file): $(PKG_FILES) | $(PKG_DIR)
3364         @$(ECHO) Packaging $@...
3365         @$(SRCDIR)/tools/package/pkg c $@ $^
3367 %compress_file mmake="%(mmake)" file="%(file)"
3369 GLOB_MKDIRS += $(PKG_DIR)
3371 %end
3373 #------------------------------------------------------------------------------
3374 # Compresses %(file) with a gzip.
3375 # Good in conjunction with for example %build_prog
3377 %define compress_file mmake=/A file=/A
3379 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3382 %(mmake)-gz-quick : %(file).gz
3384 %(file).gz: %(file)
3385         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3386         @gzip -9 -f $^
3388 %end
3390 #------------------------------------------------------------------------------
3391 # Links a kickstart module in ELF format
3392 # Arguments are similar to make_package
3394 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3395     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3397 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3398 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3399 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3400 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3401 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3402 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3404 ifeq (%(startup),)
3405     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3406 else
3407     KOBJ_STARTUP := %(startup)
3408 endif
3410 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3412 TMP_LDFLAGS := %(ldflags)
3414 # Make a list of the lib files this program depends on.
3415 # In LDFLAGS remove white space between -L and directory
3416 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3417 # Filter out only the libdirs and remove -L
3418 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3419 # Add trailing /
3420 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3421 # Add normal linklib path
3422 TMP_DIRS += $(AROS_LIB)/
3423 # add lib and .a to static linklib names
3424 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3425 # search for the linklibs in the given path, ignore ones not found
3426 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3427     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3430 TMP_DIRS += $(dir %(file))
3431 ifneq (%(map),)
3432     TMP_LDFLAGS += $(GENMAP) %(map)
3433     TMP_DIRS    += $(dir %(map))
3434 endif
3436 #MM %(mmake) : %(deps)
3439 %(mmake) : %(file)
3442 %(mmake)-quick : %(file)
3444 %(file): KOBJS := $(KOBJS)
3445 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3446                     -static -nosysbase -Wl,-Ur
3447 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3448 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3449         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3450         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3451         @$(STRIP) $@
3453 %compress_file mmake="%(mmake)" file="%(file)"
3455 GLOB_MKDIRS += $(TMP_DIRS)
3457 %end