compiler/pthread: implement pthread_detach and pthread_getschedparam
[AROS.git] / config / make.tmpl
blobba19fb0ac2e37e8070379357121113763025c825
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 cxxflags=$(CXXFLAGS) dxxflags= 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 := %(cxxflags)
373 ifeq ($(findstring %(compiler),host kernel target),)
374   $(error unknown compiler %(compiler))
375 endif
376 ifeq (%(compiler),target)
377 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
378 BD_STRIP ?= $(TARGET_STRIP)
379 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
380 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
383 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
384 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
385 endif
386 ifeq (%(compiler),host)
387 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
388 BD_STRIP ?= $(HOST_STRIP)
389 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
390 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
391 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
392 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
393 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
394 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
395 endif
396 ifeq (%(compiler),kernel)
397 KERNEL_CXX ?= $(KERNEL_CC)
398 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
399 BD_STRIP ?= $(ECHO) >/dev/null
400 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
401 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
402 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
403 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
404 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
405 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
406 endif
408 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
409 $(TMP_TARGETBASE).o : %(basename).cpp
410         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
412 ifeq (%(dflags),)
413   ifeq (%(nix),yes)
414     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
415   else
416     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
417   endif
418 else
419   ifeq (%(nix),yes)
420     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dxxflags)
421   else
422     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dxxflags)
423   endif
424 endif
425 $(TMP_TARGETBASE).d : %(basename).cpp
426         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
428 endif
430 %end
431 #------------------------------------------------------------------------------
434 #------------------------------------------------------------------------------
435 # Generate a rule to compile an ObjC source file to an object file and generate
436 # the dependency file. Basename may contain a directory part, then the source
437 # file has to be in that directory. The generated file will be put in the
438 # object directory without the directory.
439 # options
440 # - basename: the basename of the file to compile. Use % for a wildcard rule
441 # - cflags (default $(CFLAGS)): the C flags to use for compilation
442 # - dflags: the flags used during creation of dependency file. If not specified
443 #   the same value as cflags will be used
444 # - targetdir: the directory to put the .o file and the .d file. By default
445 #   it is put in the same directory as the .m file
446 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
448 ifneq (%(basename),)
450 ifeq (%(targetdir),)
451   TMP_TARGETBASE := %(basename)
452 else
453   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
454 endif
456 # Adjust compiler flags to suit ObjC
457 TMP_OBJCFLAGS := %(cflags)
458 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
459 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
461 # Define the use of cross compiler
462 ifeq ($(TARGET_OBJC),)
463   TMP_CC := $(TARGET_CC)
464 else
465   TMP_CC := $(TARGET_OBJC)
466 endif
468 ifeq ($(findstring %(compiler),host kernel target),)
469   $(error unknown compiler %(compiler))
470 endif
471 ifeq (%(compiler),target)
472 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
473 BD_STRIP ?= $(TARGET_STRIP)
474 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
475 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
476 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
477 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
478 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
479 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
480 endif
481 ifeq (%(compiler),host)
482 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
483 BD_STRIP ?= $(HOST_STRIP)
484 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
485 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
486 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
487 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
488 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
489 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
490 endif
491 ifeq (%(compiler),kernel)
492 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
493 BD_STRIP ?= $(ECHO) >/dev/null
494 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
495 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
496 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
497 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
498 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
499 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
500 endif
502 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
503 $(TMP_TARGETBASE).o : %(basename).m
504         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
506 ifeq (%(dflags),)
507   ifeq (%(nix),yes)
508     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
509   else
510     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
511   endif
512 else
513   ifeq (%(nix),yes)
514     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
515   else
516     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
517   endif
518 endif
519 $(TMP_TARGETBASE).d : %(basename).m
520         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
522 endif
524 %end
525 #------------------------------------------------------------------------------
528 #------------------------------------------------------------------------------
529 # Generate a rule to compile multiple C source files to an object file and
530 # generate the corresponding dependency files. The generated file will be put
531 # in the object directory without the directory part of the source file.
532 # options
533 # - basenames: the basenames of the files to compile. The names may include
534 #   relative or absolute path names. No wildcard is allowed
535 # - cflags (default $(CFLAGS)): the C flags to use for compilation
536 # - dflags: the flags used during creation of dependency file. If not specified
537 #   the same value as cflags will be used
538 # - targetdir: the directory to put the .o file and the .d file. By default
539 #   it is put in the same directory as the .c file. When targetdir is not
540 #   empty, path names will be stripped from the file names so that all files
541 #   are in that dir and not in subdirectories.
542 # - compiler (default target): compiler to use, target, kernel or host
543 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
544     compiler=target
546 ifeq (%(targetdir),)
547 TMP_TARGETS := $(addsuffix .o,%(basenames))
548 TMP_DTARGETS := $(addsuffix .d,%(basenames))
549 TMP_WILDCARD := %
550 else
551 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
552 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
553 TMP_WILDCARD := %(targetdir)/%
555 # Be sure that all .c files are generated
556 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
558 # Be sure that all .c files are found
559 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
560 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
561 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
562 ifneq ($(TMP_DIRS),)
563     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
564     vpath %.c $(TMP_DIRS)
565 endif
567 endif
569 ifeq ($(findstring %(compiler),host kernel target),)
570   $(error unknown compiler %(compiler))
571 endif
572 ifeq (%(compiler),target)
573 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
574 BD_STRIP ?= $(TARGET_STRIP)
575 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
576 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
577 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
578 endif
579 ifeq (%(compiler),host)
580 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
581 BD_STRIP ?= $(HOST_STRIP)
582 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
583 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
584 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
585 endif
586 ifeq (%(compiler),kernel)
587 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
588 BD_STRIP ?= $(ECHO) >/dev/null
589 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
590 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
591 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
592 endif
594 $(TMP_TARGETS) : CFLAGS := %(cflags)
595 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
596         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
598 ifeq (%(dflags),)
599 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
600 else
601 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
602 endif
603 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
604         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
605 %end
606 #------------------------------------------------------------------------------
609 #------------------------------------------------------------------------------
610 # Generate a rule to compile multiple C++ source files to an object file and
611 # generate the corresponding dependency files. The generated file will be put
612 # in the object directory without the directory part of the source file.
613 # options
614 # - basenames: the basenames of the files to compile. The names may include
615 #   relative or absolute path names. No wildcard is allowed. basenames will be 
616 #   matched to supported AROS_CXXEXTS.
617 # - cflags (default $(CFLAGS)): the C flags to use for compilation
618 # - dflags: the flags used during creation of dependency file. If not specified
619 #   the same value as cflags will be used
620 # - targetdir: the directory to put the .o file and the .d file. By default
621 #   it is put in the same directory as the .c file. When targetdir is not
622 #   empty, path names will be stripped from the file names so that all files
623 #   are in that dir and not in subdirectories.
624 # - compiler (default target): compiler to use, target, kernel or host
625 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) dxxflags= \
626     targetdir= compiler=target
628 # Adjust compiler flags to suit C++
629 TMP_CXXFLAGS := %(cxxflags)
631 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
633 ifneq ($(TMP_CXXABSBASENAMES),)
635 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
637 # Identify the "real" c++ files from the passed in basenames
638 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
640 ifeq (%(targetdir),)
641   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
642   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
643   TMP_WILDCARD := %
644 else
645   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
646   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
647   TMP_WILDCARD := %(targetdir)/%
649   # Be sure that all source files are generated
650   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
651 endif
653 ifeq ($(findstring %(compiler),host kernel target),)
654   $(error unknown compiler %(compiler))
655 endif
656 ifeq (%(compiler),host)
657   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
658   BD_STRIP ?= $(HOST_STRIP)
659   TMP_CXXCMD:=$(HOST_CXX)
660   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
661   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
662 endif
663 ifeq (%(compiler),target)
664   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
665   BD_STRIP ?= $(TARGET_STRIP)
666   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_CXXFLAGS)
667   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
668   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
669 endif
670 ifeq (%(compiler),kernel)
671   KERNEL_CXX ?= $(KERNEL_CC)
672   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
673   BD_STRIP ?= $(ECHO) >/dev/null
674   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CXXFLAGS)
675   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
676   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
677 endif
679 ifeq (%(dxxflags),)
680   TMP_DXXFLAGS:=$(TMP_CXXFLAGS)
681 else
682   ifeq (%(dxxflags),%(cxxflags))
683     TMP_DXXFLAGS:=$(TMP_CXXFLAGS)
684   else
685     TMP_DXXFLAGS:=%(dxxflags)
686   endif
687 endif
689 define cxx_multi_recipe_template
690  $(1).o : $(2)
691         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
693  $(1).d : $(2)
694         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
695 endef
696 ifeq (%(targetdir),)
697   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
698 else
699   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
700 endif
702 endif
704 %end
705 #------------------------------------------------------------------------------
708 #------------------------------------------------------------------------------
709 # Generate a rule to compile multiple ObjC source files to an object file and
710 # generate the corresponding dependency files. The generated file will be put
711 # in the object directory without the directory part of the source file.
712 # options
713 # - basenames: the basenames of the files to compile. The names may include
714 #   relative or absolute path names. No wildcard is allowed
715 # - cflags (default $(CFLAGS)): the C flags to use for compilation
716 # - dflags: the flags used during creation of dependency file. If not specified
717 #   the same value as cflags will be used
718 # - targetdir: the directory to put the .o file and the .d file. By default
719 #   it is put in the same directory as the .m file. When targetdir is not
720 #   empty, path names will be stripped from the file names so that all files
721 #   are in that dir and not in subdirectories.
722 # - compiler (default target): compiler to use, target, kernel or host
723 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
724     targetdir= compiler=target
726 ifneq (%(basenames),)
728 # Adjust compiler flags to suit ObjC
729 TMP_OBJCFLAGS := %(cflags)
730 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
731 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
733 ifeq (%(targetdir),)
734   TMP_TARGETS := $(addsuffix .o,%(basenames))
735   TMP_DTARGETS := $(addsuffix .d,%(basenames))
736   TMP_WILDCARD := %
737 else
738   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
739   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
740   TMP_WILDCARD := %(targetdir)/%
742   # Be sure that all .m files are generated
743   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
745   # Be sure that all .m files are found
746   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
747   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
748   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
749   ifneq ($(TMP_DIRS),)
750     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
751     vpath %.m $(TMP_DIRS)
752   endif
753 endif
755 # Define the use of cross compiler
756 ifeq ($(TARGET_OBJC),)
757   TMP_CC := $(TARGET_CC)
758 else
759   TMP_CC := $(TARGET_OBJC)
760 endif
762 ifeq ($(findstring %(compiler),host kernel target),)
763   $(error unknown compiler %(compiler))
764 endif
765 ifeq (%(compiler),target)
766   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
767   BD_STRIP ?= $(TARGET_STRIP)
768   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
769   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
770   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
771 endif
772 ifeq (%(compiler),host)
773   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
774   BD_STRIP ?= $(HOST_STRIP)
775   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
776   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
777   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
778 endif
779 ifeq (%(compiler),kernel)
780   KERNEL_OBJC ?= $(KERNEL_CC)
781   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
782   BD_STRIP ?= $(ECHO) >/dev/null
783   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
784   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
785   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
786 endif
788 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
789 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
790         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
792 ifeq (%(dflags),)
793   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
794 else
795   ifeq (%(dflags),%(cflags))
796     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
797   else
798     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
799   endif
800 endif
801 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
802         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
804 endif
806 %end
807 #------------------------------------------------------------------------------
810 #------------------------------------------------------------------------------
811 # Make an alias from one arch specific build to another arch.
812 # arguments:
813 # - mainmmake: the mmake of the module in the main tree
814 # - arch: the current arch
815 # - alias: the alias to which this should point
816 %define rule_archalias mainmmake=\A arch=\A alias=\A
818 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
819 %end
820 #------------------------------------------------------------------------------
823 #------------------------------------------------------------------------------
824 # Generate a rule to assemble a source file to an object file. Basename may
825 # contain a directory part, then the source file has to be in that directory.
826 # The generated file will be put in the object directory without the directory.
827 # options
828 # - basename: the basename of the file to compile. Use % for a wildcard rule
829 # - flags (default $(AFLAGS)): the asm flags to use for assembling
830 # - targetdir: the directory to put the .o file in. By default it is put in the
831 #   same directory as the .s file
832 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
834 ifeq (%(targetdir),)
835 %(basename).o : AFLAGS := %(aflags)
836 %(basename).o : %(basename).s
837         %assemble_q
838 %(basename).o : %(basename).S
839         %assemble_q
841 else
842 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
843 %(targetdir)/$(notdir %(basename)).o : %(basename).s
844         %assemble_q
845 %(targetdir)/$(notdir %(basename)).o : %(basename).S
846         %assemble_q
848 endif
849 %end
850 #------------------------------------------------------------------------------
853 #------------------------------------------------------------------------------
854 # Generate a rule to assemble multiple source files to an object file. The
855 # generated file will be put in the object directory with the directory part
856 # of the source file stripped off.
857 # options
858 # - basenames: the basenames of the files to compile. The names may include
859 #   relative or absolute path names. No wildcard is allowed
860 # - aflags (default $(AFLAGS)): the flags to use for assembly
861 # - targetdir: the directory to put the .o file and the .d file. By default
862 #   it is put in the same directory as the .c file. When targetdir is not
863 #   empty, path names will be stripped from the file names so that all files
864 #   are in that dir and not in subdirectories.
865 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
867 ifeq (%(targetdir),)
868 TMP_TARGETS := $(addsuffix .o,%(basenames))
869 TMP_WILDCARD := %
870 else
871 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
872 TMP_WILDCARD := %(targetdir)/%
874 # Be sure that all .s files are generated
875 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
877 # Be sure that all .c files are found
878 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
879 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
880 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
881 ifneq ($(TMP_DIRS),)
882     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
883     vpath %%(suffix) $(TMP_DIRS)
884 endif
886 endif
888 ifeq ($(findstring %(compiler),host kernel target),)
889   $(error unknown compiler %(compiler))
890 endif
891 ifeq (%(compiler),target)
892 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
893 endif
894 ifeq (%(compiler),host)
895 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
896 endif
897 ifeq (%(compiler),kernel)
898 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
899 endif
901 $(TMP_TARGETS) : AFLAGS := %(aflags)
902 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
903         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
904 %end
905 #------------------------------------------------------------------------------
908 #------------------------------------------------------------------------------
909 # Link %(objs) to %(prog) using the libraries in %(uselibs)
910 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
911     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
913 TMP_EXTRA_LDFLAGS := 
914 TMP_EXTRA_LIBS :=
915 ifeq (%(nix),yes)
916     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
917 endif
918 ifeq (%(usestartup),no)
919     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
920 endif
921 ifeq (%(detach),yes)
922     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
923 endif
925 # Make a list of the lib files this program depends on.
926 # In LDFLAGS remove white space between -L and directory
927 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
928 # Filter out only the libdirs and remove -L
929 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
930 # Add trailing /
931 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
932 # Add normal linklib path
933 TMP_DIRS += $(AROS_LIB)/
934 # add lib and .a to static linklib names
935 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
936 ifeq (%(usestartup),yes)
937     TMP_LIBS += startup.o
938 endif
939 ifeq (%(detach),yes)
940     TMP_LIBS += detach.o
941 endif
942 # search for the linklibs in the given path, ignore ones not found
943 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
944     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
947 %(prog) : OBJS := %(objs)
948 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
949 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
950 %(prog) : %(objs) $(TMP_DEPLIBS)
951         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
952 %end
953 #------------------------------------------------------------------------------
956 #------------------------------------------------------------------------------
957 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
958 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
959 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
960     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
961     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
963 TMP_EXTRA_LDFLAGS := 
964 TMP_EXTRA_LIBS :=
965 ifeq (%(nix),yes)
966     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
967 endif
968 ifeq (%(usestartup),no)
969     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
970 endif
971 ifeq (%(detach),yes)
972     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
973 endif
975 # Make a list of the lib files the programs depend on.
976 # In LDFLAGS remove white space between -L and directory
977 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
978 # Filter out only the libdirs and remove -L
979 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
980 # Add trailing /
981 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
982 # Add normal linklib path
983 TMP_DIRS += $(AROS_LIB)/
984 # add lib and .a to static linklib names
985 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
986 # search for the linklibs in the given path, ignore ones not found
987 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
988     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
990 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
992 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
993 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
994 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
995         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS)
996 %end
997 #------------------------------------------------------------------------------
1000 #------------------------------------------------------------------------------
1001 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1002 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1004 ifeq (%(linker),target)
1005 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1006 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1007 endif
1008 ifeq (%(linker),host)
1009 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1010 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1011 endif
1012 ifeq (%(linker),kernel)
1013 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1014 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1015 endif
1017 %(libdir)/lib%(libname).a : %(objs)
1018         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1019 %end
1020 #------------------------------------------------------------------------------
1022 #------------------------------------------------------------------------------
1023 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1024 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1025 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1026     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1028 TMP_LDFLAGS  := %(ldflags)
1029 # Make a list of the lib files the programs depend on.
1030 # In LDFLAGS remove white space between -L and directory
1031 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1032 # Filter out only the libdirs and remove -L
1033 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1034 # Add trailing /
1035 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1036 # Add normal linklib path
1037 TMP_DIRS += $(AROS_LIB)/
1038 # add lib and .a to static linklib names
1039 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1040 # search for the linklibs in the given path, ignore ones not found
1041 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1042     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1045 %(module) : LIB_NAMES := %(uselibs)
1046 %(module) : OBJS := %(objs)
1047 %(module) : ENDTAG := %(endobj)
1048 %(module) : ERR := %(err)
1049 %(module) : OBJDIR := %(objdir)
1050 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1051 ifeq (%(usehostlibs),)
1052 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1053 else
1054 # Warning: the -L/usr/lib here can result in modules
1055 # linking against host libs instead of AROS libs (e.g stdc++) !!
1056 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1057                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1058 endif 
1059 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1060         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1062 %end
1063 #------------------------------------------------------------------------------
1066 #------------------------------------------------------------------------------
1067 # Generate the libdefs.h include file for a module.
1068 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1070 TMP_TARGET := %(modname)_libdefs.h
1071 TMP_DEPS := $(GENMODULE)
1072 TMP_OPTS := 
1073 ifneq (%(conffile),)
1074     ifeq ($(dir %(conffile)),./)
1075         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1076         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1077     else
1078         TMP_OPTS += -c %(conffile)
1079         TMP_DEPS += %(conffile)
1080     endif 
1081 else
1082     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1083     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1084 endif
1085 ifneq (%(modsuffix),)
1086     TMP_OPTS += -s %(modsuffix)
1087 endif
1088 ifneq (%(targetdir),)
1089     TMP_OPTS += -d %(targetdir)
1090     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1091 endif
1092 ifneq (%(version),)
1093     TMP_OPTS += -v %(version)
1094 endif
1096 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1097 $(TMP_TARGET) : MODNAME := %(modname)
1098 $(TMP_TARGET) : MODTYPE := %(modtype)
1099 $(TMP_TARGET) : $(TMP_DEPS)
1100         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1101         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1102 %end
1103 #------------------------------------------------------------------------------
1105 #------------------------------------------------------------------------------
1106 # Generate the _lib.fd file for a module.
1107 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1109 TMP_TARGET := %(modname)_lib.fd
1110 TMP_DEPS := $(GENMODULE)
1111 TMP_OPTS := 
1112 ifneq (%(conffile),)
1113     ifeq ($(dir %(conffile)),./)
1114         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1115         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1116     else
1117         TMP_OPTS += -c %(conffile)
1118         TMP_DEPS += %(conffile)
1119     endif 
1120 else
1121     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1122     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1123 endif
1124 ifneq (%(modsuffix),)
1125     TMP_OPTS += -s %(modsuffix)
1126 endif
1127 ifneq (%(targetdir),)
1128     TMP_OPTS += -d %(targetdir)
1129     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1130 endif
1132 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1133 $(TMP_TARGET) : MODNAME := %(modname)
1134 $(TMP_TARGET) : MODTYPE := %(modtype)
1135 $(TMP_TARGET) : $(TMP_DEPS)
1136         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1137         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1138 %end
1139 #------------------------------------------------------------------------------
1141 #------------------------------------------------------------------------------
1142 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1143 # generated file in this Makefile
1144 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1145     targetdir=
1147 TMP_TARGET := Makefile.%(modname)%(modtype)
1148 TMP_DEPS := $(GENMODULE)
1149 TMP_OPTS := 
1150 ifneq (%(conffile),)
1151     ifeq ($(dir %(conffile)),./)
1152         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1153         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1154     else
1155         TMP_OPTS += -c %(conffile)
1156         TMP_DEPS += %(conffile)
1157     endif 
1158 else
1159     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1160     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1161 endif
1162 ifneq (%(modsuffix),)
1163     TMP_OPTS += -s %(modsuffix)
1164 endif
1165 ifneq (%(targetdir),)
1166     TMP_OPTS += -d %(targetdir)
1167     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1168 endif
1170 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1171 $(TMP_TARGET) : MODNAME := %(modname)
1172 $(TMP_TARGET) : MODTYPE := %(modtype)
1173 $(TMP_TARGET) : $(TMP_DEPS)
1174         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1175 %end
1176 #------------------------------------------------------------------------------
1179 #------------------------------------------------------------------------------
1180 # Generate the support files for compiling a module. This includes include
1181 # files and source files. This rule has to be preceeded by
1182 # %rule_genmodule_makefile
1183 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1184     conffile=
1186 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1187                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1188 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1189                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1191 TMP_DEPS := $(GENMODULE)
1192 TMP_OPTS :=
1194 ifneq (%(conffile),)
1195     ifeq ($(dir %(conffile)),./)
1196         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1197         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1198     else
1199         TMP_OPTS += -c %(conffile)
1200         TMP_DEPS += %(conffile)
1201     endif 
1202 else
1203     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1204     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1205 endif
1206 ifneq (%(modsuffix),)
1207     TMP_OPTS += -s %(modsuffix)
1208 endif
1209 ifneq (%(targetdir),)
1210     TMP_OPTS += -d %(targetdir)
1211     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1212     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1213 endif
1215 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1216 $(TMP_TARGETS) : MODNAME := %(modname)
1217 $(TMP_TARGETS) : MODTYPE := %(modtype)
1218 $(TMP_TARGETS) : $(TMP_DEPS)
1219         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1220 ifneq (%(conffile),lib.conf)
1221         @$(IF) $(TEST) -f lib.conf; then \
1222           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1223         fi
1224 endif
1225         @$(IF) $(TEST) -f libdefs.h; then \
1226           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1227         fi
1228         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1229 %end
1230 #------------------------------------------------------------------------------
1233 #------------------------------------------------------------------------------
1234 # Generate the support files for compiling a module. This includes include
1235 # files and source files.
1236 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1237     targetdir= conffile=
1239 ifneq ($(%(modname)_INCLUDES),)
1240 TMP_TARGETS := $(%(modname)_INCLUDES)
1242 TMP_DEPS := $(GENMODULE)
1243 TMP_OPTS :=
1245 ifneq (%(conffile),)
1246     ifeq ($(dir %(conffile)),./)
1247         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1248         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1249     else
1250         TMP_OPTS += -c %(conffile)
1251         TMP_DEPS += %(conffile)
1252     endif 
1253 else
1254     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1255     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1256 endif
1257 ifneq (%(modsuffix),)
1258     TMP_OPTS += -s %(modsuffix)
1259 endif
1260 ifneq (%(targetdir),)
1261     TMP_OPTS += -d %(targetdir)
1262     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1263 endif
1265 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1266 $(TMP_TARGETS) : MODNAME := %(modname)
1267 $(TMP_TARGETS) : MODTYPE := %(modtype)
1268 $(TMP_TARGETS) : $(TMP_DEPS)
1269         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1270         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1271 endif
1272 %end
1273 #------------------------------------------------------------------------------
1275 #------------------------------------------------------------------------------
1276 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1277 # 'start' is an optional starting address
1278 # 'ldflags' is optional additional flags for the linker
1279 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1281 BD_OUTDIR := $(dir %(file))
1282 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1283 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1284 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1285 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1286 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1287 BD_OBJS += %(objs)
1289 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1291 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1292         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1293         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1294         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1296 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1297     GLOB_MKDIRS += $(BD_OUTDIR)
1298 endif
1300 %end
1302 #------------------------------------------------------------------------------
1303 # Common rules for all makefiles
1304 %define common
1305 # Delete generated makefiles
1307 clean ::
1308         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1310 include $(SRCDIR)/config/make.tail
1312 BDID := $(BDTARGETID)
1313 %end
1314 #------------------------------------------------------------------------------
1315       
1317 #############################################################################
1318 #############################################################################
1319 ##                                                                         ##
1320 ## Here are the mmakefile build macros. These are macros that takes care   ##
1321 ## of everything to go from the sources to the generated target. Also all  ##
1322 ## intermediate files and directories that are needed are created by these ##
1323 ## rules.                                                                  ##
1324 ##                                                                         ##
1325 #############################################################################
1326 #############################################################################
1328 #------------------------------------------------------------------------------
1329 # Build a program
1330 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1331     objcfiles= \
1332     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1333     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1334     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1335     includedir= libdir= \
1336     compiler=target linker=
1338 .PHONY : %(mmake)
1340 BD_PROGNAME  := %(progname)
1341 BD_OBJDIR    := %(objdir)
1342 BD_TARGETDIR := %(targetdir)
1343 BD_LINKER    := %(linker)
1345 # If not supplied, linker is equal to compiler
1346 ifeq ($(BD_LINKER),)
1347     BD_LINKER := %(compiler)
1348 endif
1350 BD_FILES     := %(files)
1351 BD_OBJCFILES := %(objcfiles)
1352 BD_ASMFILES  := %(asmfiles)
1353 BD_CXXFILES := %(cxxfiles)
1355 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1356 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1357 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1359 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1360 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1361 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1363 BD_CFLAGS    := %(cflags)
1364 BD_CXXFLAGS := %(cxxflags)
1365 ifneq (%(includedir),)
1366 BD_CFLAGS    += -I%(includedir)
1367 BD_CXXFLAGS += -I%(includedir)
1368 endif
1369 BD_AFLAGS    := %(aflags)
1370 ifneq (%(includedir),)
1371 BD_AFLAGS    += -I%(includedir)
1372 endif
1373 BD_DFLAGS    := %(dflags)
1374 BD_DXXFLAGS := %(dxxflags)
1375 BD_LDFLAGS   := %(ldflags)
1376 ifneq (%(libdir),)
1377 BD_LDFLAGS   += -L%(libdir)
1378 endif
1381 %(mmake)-quick : %(mmake)
1383 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1384 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1386 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1387 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1388     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1389 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1390     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1391 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1392     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1393 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1394     aflags=$(BD_AFLAGS) compiler="%(compiler)"
1396 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1397     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1398     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1399     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1400     cmd=$(BD_LINK) strip=$(BD_STRIP)
1402 endif
1404 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1406 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1407 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1408 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1410 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1412 %(mmake)-clean ::
1413         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1414         @$(RM) $(FILES)
1416 %end
1417 #------------------------------------------------------------------------------
1420 #------------------------------------------------------------------------------
1421 # Build programs, for every C file an executable will be built with the same
1422 # name as the C file
1423 %define build_progs mmake=/A files=/A nix=no \
1424     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1425     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1426     includedir= libdir= \
1427     uselibs= usehostlibs= usestartup=yes detach=no
1429 .PHONY : %(mmake)
1431 BD_OBJDIR    := %(objdir)
1432 BD_TARGETDIR := %(targetdir)
1434 BD_FILES     := %(files)
1435 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1436 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1437 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1439 BD_CFLAGS    := %(cflags)
1440 ifneq (%(includedir),)
1441     BD_CFLAGS += -I%(includedir)
1442 endif
1443 BD_DFLAGS    := %(dflags)
1444 BD_LDFLAGS   := %(ldflags)
1445 ifneq (%(libdir),)
1446     BD_LDFLAGS += -L%(libdir)
1447 endif
1450 %(mmake)-quick : %(mmake)
1452 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1453 %(mmake) : $(BD_EXES)
1455 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1456 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1457     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1459 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1460     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1461     ldflags=$(BD_LDFLAGS) \
1462     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1463     usestartup="%(usestartup)" detach="%(detach)" \
1464      cmd=$(BD_LINK) strip=$(BD_STRIP)
1466 endif
1468 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1470 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1471 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1472 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1474 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1476 %(mmake)-clean ::
1477         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1478         @$(RM) $(FILES)
1480 %end
1481 #------------------------------------------------------------------------------
1484 #------------------------------------------------------------------------------
1485 # Build a module.
1486 # This is a bare version: It just compiles and links the given files. It is
1487 # assumed that all needed boiler plate code is in the files. This should only
1488 # be used for compiling external code. For AROS code use %build_module
1489 %define build_module_simple mmake=/A modname=/A modtype=/A \
1490     files="$(basename $(call WILDCARD, *.c))" \
1491     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1492     objdir=$(OBJDIR) moduledir= \
1493     uselibs= usehostlibs= compiler=target
1495 # Define metamake targets and their dependencies
1496 #MM %(mmake) : core-linklibs includes-generate-deps
1497 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1498 #MM %(mmake)-kobj-quick
1499 #MM %(mmake)-quick
1500 #MM %(mmake)-clean
1502 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1504 .PHONY : $(BD_ALLTARGETS)
1506 ifeq (%(modname),)
1507 $(error using %build_module_simple: modname may not be empty)
1508 endif
1509 ifeq (%(modtype),)
1510 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1511 endif
1513 # Default values for variables and arguments
1514 BD_DEFLINKLIBNAME := %(modname)
1515 BD_DEFDFLAGS := %(cflags)
1516 BD_DEFDXXFLAGS := %(dxxflags)
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) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
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 BD_DEFDXXFLAGS := %(cxxflags)
1730 ifneq (%(includedir),)
1731     BD_DEFDFLAGS += -I%(includedir)
1732     BD_DEFDXXFLAGS += -I%(includedir)
1733 endif
1734 OBJDIR ?= $(GENDIR)/$(CURDIR)
1736 ## Create genmodule include Makefile for the module
1738 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1740 %rule_genmodule_makefile \
1741     modname="%(modname)" modtype="%(modtype)" \
1742     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1743     conffile="%(conffile)"
1745 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1747 GLOB_MKDIRS += %(objdir)
1749 # Do not parse these statements if metatarget is not appropriate
1750 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1752 include %(objdir)/Makefile.%(modname)%(modtype)
1754 BD_DEFMODDIR := $(%(modname)_MODDIR)
1755 ifeq (%(archspecific),yes)
1756 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1757 endif
1760 ## include files generation
1762 ifneq (%(includedir),)
1763 BD_INCDIR    := %(includedir)
1764 else
1765 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1766 endif
1767 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1768 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1770 ifeq (%(build_abi),M)
1771 %(mmake)-includes-quick : %(mmake)-includes
1772 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1773     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1774     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1776 ifneq ($(%(modname)_INCLUDES),)
1777 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1778                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1779                          conffile="%(conffile)"
1781 %rule_copy_diff_multi \
1782     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1783     stampfile="%(objdir)/%(modname)_geninc"
1785 %rule_copy_diff_multi \
1786     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1787     stampfile="%(objdir)/%(modname)_incs"
1789 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1791 TMP%(modname)_INCDIRS := \
1792     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1793     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1794     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1795 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1797 endif
1799 endif
1801 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1802                            modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1803                            conffile="%(conffile)" version="%(version)"
1805 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1806 $(BD_DEFLIBDEFSINC) :
1807         @$(ECHO) "Generating $@"
1808         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1810 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1811 GLOB_MKDIRS += %(objdir)/include
1813 ## Extra genmodule src files generation
1814 ## 
1815 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1816                       modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1817                       conffile="%(conffile)"
1820 ifeq (%(build_abi),M)
1821 ## Create FD file
1822 ifeq (%(includedir),)
1823 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1824 else
1825 BD_FDDIR := %(includedir)/../fd
1826 endif
1827 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1829 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1830                    modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1832 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1834 GLOB_MKDIRS += $(BD_FDDIR)
1835 endif
1837 ## Compilation
1839 BD_FILES      := %(files)
1840 BD_CXXFILES := %(cxxfiles)
1842 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1844 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1845 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1847 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1848 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1849 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1851 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1852 BD_CXXFLAGS := %(cxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CXXFLAGS)
1853 ifneq (%(includedir),)
1854 BD_CFLAGS     += -I%(includedir)
1855 BD_CXXFLAGS += -I%(includedir)
1856 endif
1857 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1858 BD_DXXFLAGS := %(dxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DXXFLAGS)
1860 ifeq (%(modtype),library)
1861     BD_LIBSUFFIX := 
1862 else
1863     BD_LIBSUFFIX := .%(modtype)
1864 endif
1866 ifeq (%(libdir),)
1867 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1868 else
1869 BD_LIBDIR := %(libdir)
1870 endif
1872 ifeq (%(build_abi),M)
1873 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1874 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1875 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1876     BD_LINKLIB :=
1877 else
1878     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1879     ifneq (%(modname),%(linklibname))
1880         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1881     endif
1882 endif
1883 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1885 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1886 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1887 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1888     BD_RELLINKLIB :=
1889 else
1890     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1891     ifneq (%(modname),%(linklibname))
1892         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1893     endif
1894 endif
1895 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1896 endif
1898 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1899 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1900     $(BD_RELLINKLIBCFILES)
1902 %rule_compile_cxx_multi \
1903     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1904     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
1905     compiler="%(compiler)"
1906 %rule_compile_multi \
1907     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1908     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1909     compiler="%(compiler)"
1910 %rule_compile_multi \
1911     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1912     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1913     compiler="%(compiler)"
1915 ifneq ($(BD_LINKLIBAFILES),)
1916 %rule_assemble_multi \
1917     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1918 endif
1920 ## Linking
1922 ifeq (%(modsuffix),)
1923 BD_SUFFIX := %(modtype)
1924 else
1925 BD_SUFFIX := %(modsuffix)
1926 endif
1928 ifeq (%(build_library),M)
1929 # Handlers use dash instead of dot in their names
1930 ifeq ($(BD_SUFFIX),handler)
1931 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1932 else
1933 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1934 endif
1935 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1936 else
1937 BD_MODULE :=
1938 BD_KOBJ   :=
1939 endif
1941 %(mmake)-quick      : %(mmake)
1942 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1943 ifeq (%(build_library),M)
1944 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1945 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1946 endif
1947 ifeq (%(build_abi),M)
1948 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1949 endif
1951 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1952            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1954 ifeq (%(nostartup),yes)
1955 # Handlers always have entry point
1956 ifneq (%(modtype),handler)
1957 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1958 endif
1959 endif
1961 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1962 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1963                  %(linklibobjs)
1964 BD_RELLINKLIBOBJS \
1965               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1966                  %(linklibobjs)
1968 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1969 # This breaks con-handler build. Here we work around this
1970 ifeq (%(modname),con)
1971     BD_ERR := $(notdir $(BD_MODULE)).err
1972 else
1973     BD_ERR := %(modname).err
1974 endif
1976 ifeq (%(build_library),M)
1977 # The module is linked from all the compiled .o files
1978 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1979                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
1980                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1981                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1982 endif
1984 ifeq (%(build_abi),M)
1985 # Link static lib
1986 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1987 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1988 ifneq ($(BD_LINKLIB),)
1989 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1990 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1991 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
1992 endif
1994 $(BD_LINKLIB) : | $(BD_LIBDIR)
1995 GLOB_MKDIRS += $(BD_LIBDIR)
1996 endif
1998 ifneq ($(BD_RELLINKLIB),)
1999 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2000 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2001 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2002 endif
2004 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2005 GLOB_MKDIRS += $(BD_LIBDIR)
2006 endif
2007 endif
2009 ifeq (%(build_library),M)
2010 # Link kernel object file
2011 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2013 # Make these symbols local
2014 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2015             UtilityBase ExpansionBase KeymapBase KernelBase
2017 BD_SYMBOLS := $(BD_KBASE)
2019 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2020 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2021 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2022 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2023 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2024 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2025         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2026         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2027         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2028 endif
2030 ## Dependency fine-tuning
2032 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
2034 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2036 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2037 $(BD_MODULE) : | %(prefix)/%(moduledir)
2038 $(BD_KOBJ)   : | $(KOBJSDIR)
2039 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2041 # Some include files need to be generated before the .c can be parsed.
2042 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2044 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2045     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2046 $(BD_DEPS) : $(BD_DFILE_DEPS)
2047 endif
2049 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2050     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2051     %(objdir)/Makefile.%(modname)%(modtype) \
2052     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2053     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2054     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2055     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2056     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2057     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2058     $(BD_ENDOBJS)
2059 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2060 %(mmake)-clean ::
2061         @$(ECHO) "Cleaning up for module %(modname)"
2062         @$(RM) $(FILES)
2064 endif # $(TARGET) in $(BD_ALLTARGETS)
2065 %end
2066 #------------------------------------------------------------------------------
2068 #------------------------------------------------------------------------------
2069 # Build a module - ABI and library
2070 # Explanation of this macro is done in the developer's manual
2071 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2072   files="$(basename $(call WILDCARD, *.c))" \
2073   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2074   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2075   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2076   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2077   compiler=target nostartup=yes archspecific=no \
2078   includedir= libdir=
2080 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2081    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2082    files="%(files)" cxxfiles="%(cxxfiles)" \
2083    linklibname="%(linklibname)" \
2084    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2085    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2086    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2087    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2088    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2089    includedir="%(includedir)" libdir="%(libdir)" \
2090    build_abi=M build_library=M
2092 %end
2093 #------------------------------------------------------------------------------
2096 #------------------------------------------------------------------------------
2097 # Build a module skeleton ABI
2098 # This is a stripped-down version of build_module, it only creates include
2099 # files and the linklibs.
2100 # This is used when for plugins or classes with the same API, but no actual
2101 # implementation here.
2102 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2103   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2104   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2105   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2106   compiler=target nostartup=yes archspecific=no \
2107   includedir= libdir=
2109 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2110   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2111   linklibname="%(linklibname)" \
2112   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2113   cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2114   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2115   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2116   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2117   includedir="%(includedir)" libdir="%(libdir)" \
2118   build_abi=M build_library=
2120 %end
2121 #------------------------------------------------------------------------------
2123 #------------------------------------------------------------------------------
2124 # Build a module library - no includes nor linklibs
2125 # Explanation of this macro is done in the developer's manual
2126 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2127   files="$(basename $(call WILDCARD, *.c))" \
2128   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2129   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2130   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2131   uselibs= usehostlibs= \
2132   compiler=target nostartup=yes archspecific=no \
2133   includedir= libdir=
2135 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2136    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2137    files="%(files)" cxxfiles="%(cxxfiles)" \
2138    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2139    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2140    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2141    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2142   includedir="%(includedir)" libdir="%(libdir)" \
2143    build_abi= build_library=M
2145 %end
2146 #------------------------------------------------------------------------------
2150 #------------------------------------------------------------------------------
2151 # Build a linklib.
2152 # - mmake is the mmaketarget
2153 # - libname is the baselibname e.g. lib%(libname).a will be created
2154 # - files are the C source files to include in the lib. The list of files
2155 #   has to be given without the .c suffix
2156 # - cxxfiles are C++ source files without suffix.
2157 #   NB: files will be matched in the order .cpp > .cxx > .cc
2158 # - asmfiles are the asm files to include in the lib. The list of files has to
2159 #   be given without the .s suffix
2160 # - objs additional object to link into the linklib. The objects have to be
2161 #   given with full absolute path and the .o suffix.
2162 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2163 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2164 # - cflags are the flags to compile the source (default $(CFLAGS))
2165 # - dflags are the flags use during makedepend (default equal to cflags)
2166 # - aflags are the flags use during assembling (default $(AFLAGS))
2167 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2168 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2169   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2170   includedir= \
2171   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2172   aflags=$(AFLAGS) compiler=target
2174 # assign and generate the local variables used in this macro
2175 BD_LIBNAME    := %(libname)
2176 BD_LINKLIB    := %(libdir)/lib%(libname).a
2178 BD_FILES      := %(files)
2179 BD_ASMFILES   := %(asmfiles)
2180 BD_CXXFILES := %(cxxfiles)
2182 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2183 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2184 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2186 BD_OBJS       := $(BD_ARCHOBJS) \
2187                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2188                  %(objs)
2189 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2191 BD_CFLAGS    := %(cflags)
2192 BD_CXXFLAGS := %(cxxflags)
2193 ifneq (%(includedir),)
2194 BD_CFLAGS    += -I%(includedir)
2195 BD_CXXFLAGS += -I%(includedir)
2196 endif
2197 BD_AFLAGS    := %(aflags)
2198 BD_DFLAGS    := %(dflags)
2199 BD_DXXFLAGS := %(dxxflags)
2201 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2204 %(mmake)-quick : %(mmake)
2206 #MM %(mmake) : includes-generate-deps
2207 %(mmake) : $(BD_LINKLIB)
2209 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2211 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2212     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2213 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2214     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2215 %rule_assemble basename=% targetdir="%(objdir)" \
2216     aflags=$(BD_AFLAGS)
2218 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2219 endif
2221 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2223 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2224 $(BD_LINKLIB) : | %(libdir)
2225 GLOB_MKDIRS += %(objdir) %(libdir)
2227 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2229 %(mmake)-clean ::
2230         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2231         @$(RM) $(FILES)
2233 %end
2234 #------------------------------------------------------------------------------
2237 #------------------------------------------------------------------------------
2238 # Build catalogs.
2239 # - mmake is the mmaketarget
2240 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2241 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2242 # - subdir is the destination subdirectory of the catalogs
2243 # - name is the name of the destination catalog, without the .catalog suffix
2244 # - source is the path to the generated source code file
2245 # - dir is the base destination directory (default $(AROS_CATALOGS))
2246 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2247 # - srcdir is the directory in which the *.cd and *.ct files are searched
2249 %define build_catalogs mmake=/A name=/A subdir=/A \
2250  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2251  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2253 ifeq (%(description),)
2254 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2255 else
2256 BD_DESC := %(description)
2257 endif
2259 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2261 ifeq (%(catalogs),)
2262 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2263 else
2264 BD_LNGS := %(catalogs)
2265 endif
2267 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2268 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2271 %(mmake) : $(BD_OBJS) %(source)
2273 $(BD_OBJS) : | $(BD_DIRS)
2274 GLOB_MKDIRS += $(BD_DIRS)
2276 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2277         @$(ECHO) "Creating   %(name) catalog for language $*."
2278         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2280 ifneq (%(source),)
2281 %(source) : BD_DESC := $(BD_DESC)
2282 %(source) : BD_SRC := $(BD_SRC)
2283 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2284         @$(ECHO) "Creating   %(name) catalog source file $@"
2285         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2286 endif
2288 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2290 %(mmake)-clean ::
2291         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2292         @$(RM) $(FILES)
2294 .PHONY: %(mmake) %(mmake)-clean
2296 %end
2297 #-----------------------------------------------------------------------------
2300 #-----------------------------------------------------------------------------
2301 # Build icons.
2302 # - mmake is the mmaketarget
2303 # - icons is a list of icon base names (ie. without the .info suffix)
2304 # - dir is the destination directory
2305 # - srcdir is where *.png and *.info.src are searched
2306 #-----------------------------------------------------------------------------
2308 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2310 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2313 %(mmake) : $(BD_OBJS)
2315 ifeq (%(image),)
2317 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2318         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2319         @$(ILBMTOICON) $+ $@
2321 else
2323 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2324         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2325         @$(ILBMTOICON) $+ $@
2327 endif
2329 $(BD_OBJS) : | %(dir)
2330 GLOB_MKDIRS += %(dir)
2332 %(mmake)-clean : FILES := $(BD_OBJS)
2334 %(mmake)-clean ::
2335         @$(RM) $(FILES)
2337 .PHONY: %(mmake) %(mmake)-clean
2339 %end
2340 #-----------------------------------------------------------------------------
2343 #------------------------------------------------------------------------------
2344 # Compile files for an arch-specific replacement of code for a module
2345 # - files: the basenames of the C files to compile.
2346 # - asmfiles: the basenames of the asm files to assemble.
2347 # - mainmmake: the mmake of the module in the main directory to compile these
2348 #   arch specific files for.
2349 # - maindir: the object directory for the main module
2350 # - arch: the arch for which to compile these files. It can have the form
2351 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2352 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2353 # - dflags: the flags used during creation of dependency file. If not specified
2354 #   the same value as cflags will be used
2355 # - aflags: the flags used during assembling
2356 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2357 #   the target compiler is used
2358 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2359 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2361 ifeq (%(files) %(asmfiles),)
2362   $(error no files or asmfiles given)
2363 endif
2365 %buildid targets="%(mainmmake)-%(arch)"
2367 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2368 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2369 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2370 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2371 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2372 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2373 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2374 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2375 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2376 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2377 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2378 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2379 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2380 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2381 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2383 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2385 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2386 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2387 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2388 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2389 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2391 ifneq (%(modulename),)
2392 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2393 endif
2395 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2396     BD_TARGET := %(mainmmake)-%(arch)-quick
2397 else
2398     BD_TARGET := %(mainmmake)-%(arch)
2399 endif
2402 ifeq ($(TARGET),$(BD_TARGET))
2403 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2404 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2405 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2406 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2407 endif
2409 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2410 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2413 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2416 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2418 ifeq ($(findstring %(compiler),host kernel target),)
2419   $(error unknown compiler %(compiler))
2420 endif
2421 ifeq (%(compiler),target)
2422 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2423 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2424 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2425 endif
2426 ifeq (%(compiler),host)
2427 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2428 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2429 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2430 endif
2431 ifeq (%(compiler),kernel)
2432 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2433 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2434 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2435 endif
2436 ifneq (%(modulename),)
2437 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2438 else
2439 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2440 endif
2441 ifeq ($(TARGET),$(BD_TARGET))
2442 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2443         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2444 endif
2446 ifeq (%(dflags),)
2447 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2448 else
2449 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2450 endif
2451 ifeq ($(TARGET),$(BD_TARGET))
2452 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2453         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2454 endif
2456 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2458 ifeq ($(TARGET),$(BD_TARGET))
2459 $(BD_OBJDIR$(BDID))/%.o : %.s
2460         %assemble_q opt=$(AFLAGS)
2461 $(BD_OBJDIR$(BDID))/%.o : %.S
2462         %assemble_q opt=$(AFLAGS)
2463 endif
2465 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2466 %end
2467 #------------------------------------------------------------------------------
2470 #------------------------------------------------------------------------------
2471 # generate asm files from c files (for debugging purposes)
2472 %define ctoasm_q
2473 %.s : %.c
2474         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2475         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2476 %end
2477 #------------------------------------------------------------------------------
2480 #------------------------------------------------------------------------------
2481 # Copy files from one directory to another.
2483 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2485 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2487 GLOB_MKDIRS += %(dst)
2489 .PHONY : %(mmake)
2492 %(mmake) : | %(dst) 
2493         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2495 %end
2496 #------------------------------------------------------------------------------
2499 #------------------------------------------------------------------------------
2500 # Copy a directory recursively to another place, preserving the original 
2501 # hierarchical structure
2503 # src: the source directory whose content will be copied.
2504 # dst: the directories where to copy src's content. If not existing, they will be made.
2505 # excludefiles: files which must not be copied. Path must be relative to src.
2507 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2509 .PHONY : %(mmake)
2512 %(mmake) :
2513         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2515 %end
2516 #------------------------------------------------------------------------------
2519 #------------------------------------------------------------------------------
2520 #   Copy include files into the includes directories. There are currently
2521 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2522 #   for building tools that need to run on the host system $(GENINCDIR). The
2523 #   $(GENINCDIR) path must not contain any references to the C runtime
2524 #   library header files.
2526 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2527     dir= compiler=target includedir=$(AROS_INCLUDES)
2529 ifeq ($(findstring %(compiler),host kernel target),)
2530 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2531 endif
2533 ifneq (%(dir),)
2534 TMP_DIR := %(dir)
2535 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2536 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2537 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2538 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2539 ifeq ($(TMP_DIRFIRST),/)
2540 BD_INC_PATH := %(dir)/
2541 else
2542 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2543 endif
2544 else
2545 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2546 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2547 endif
2549 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2550         @$(CP) $< $@
2553 ifeq (%(compiler),target)
2555 ifneq (%(dir),)
2556 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2557 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2558 else
2559 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2560 endif
2562 BD_INCL_FILES += $(BD_INCL_FILES2)
2564 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2565         @$(CP) $< $@
2566 endif
2569 %(mmake) : $(BD_INCL_FILES)
2571 .PHONY: %(mmake)
2573 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2574 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2575 %end
2576 #------------------------------------------------------------------------------
2579 #------------------------------------------------------------------------------
2580 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2581 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2582 STUBS_MEM := $(addsuffix .o,$(STUBS))
2583 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2584 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2585 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2587 #MM- linklibs : hidd-%(hidd)-stubs
2588 #MM- %(parenttarget): hidd-%(hidd)-stubs
2589 #MM hidd-%(hidd)-stubs : includes includes-copy
2590 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2592 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2593         %mklib_q from=$^
2595 $(STUBS_OBJ) : $(STUBS_SRC) 
2596         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2598 $(STUBS_DEP) : $(STUBS_SRC)
2599         %mkdepend_q flags="%(dflags)"
2601 setup ::
2602         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2605 clean ::
2606         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2608 DEPS := $(DEPS) $(STUBS_DEP)
2610 %end
2611 #------------------------------------------------------------------------------
2614 #------------------------------------------------------------------------------
2615 # Build an imported source tree which uses the configure script from the
2616 # autoconf package.  This rule will try to "integrate" the produced files as
2617 # much as possible in the AROS build, for example by putting libraries in the
2618 # standard library directory, includes in the standard include directory, and
2619 # so on. You can however override this behaviour.
2621 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2622 # be %(bindir) (or its deduced value) when running "make install", and
2623 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2624 # configure script some more parameters whose value depends upon the PROGDIR
2625 # env var, so that the program gets all its stuff installed in the proper place
2626 # when building it, but when running it from inside AROS it can also find that
2627 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2628 # the configuration parameters set when running ./configure
2630 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2631 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2632 # to the name which has to follow it.
2634 # Arguments:
2636 #     - mmake           = the meta make target.
2637 #     - package         = name of the package to be built.
2638 #     - srcdir          = the location of the unpacked source code. Defaults
2639 #                         to $(SRCDIR)/$(CURDIR).
2640 #     - prefix          = the target directory. Must be an absolute path of the
2641 #                         host system. Defaults to $(AROS_CONTRIB).
2642 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2643 #                         Defaults to the value of the prefix option.
2644 #     - extraoptions    = additional options for the configure script.
2645 #     - extracflags     = additional flags to use with the C compiler.
2646 #     - extracxxflags   = additional flags to use with the C++ compiler.
2647 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2648 #                         Defaults to the value of the nix argument.
2649 #     - nix             = enable u*nix path handling, i.e. a path like
2650 #                         /progdir//./file will be translated to
2651 #                         progdir:file during run-time. Defaults to no.
2652 #     - compiler        = target, host or kernel. Defaults to target.
2653 #     - install_target  = the command used for installing. Defaults to install. Leave
2654 #                         it empty if you want to suppress installing.
2655 #     - preconfigure    = a metatarget which is executed before configure is called.
2656 #     - postconfigure   = a metatarget which is executed after configure is called.
2657 #     - postinstall     = a metatarget which is executed after installing.
2658 #     - install_env     = set additional options for installing.
2659 #     - use_build_env   = if yes the configuration environment is used for
2660 #                         installing, too. Defaults to no.
2662 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2663 # like this:
2665 # if nix_dir_layout
2666 #    --prefix = $(aros_prefix)
2667 #    progdir = $(aros_prefix)/bin
2668 # else
2669 #    if nix
2670 #        --prefix = /PROGDIR
2671 #        --bindir = /PROGDIR
2672 #        --sbindir = /PROGDIR
2673 #        --libdir = /LIB
2674 #        --includedir = /INCLUDE
2675 #        --oldincludedir = /INCLUDE   
2676 #    else
2677 #        --prefix = $(aros_prefix)
2678 #    endif
2680 #    progdir = $(aros_prefix)
2682 #    # Install options
2683 #    bindir = $(prefix)
2684 #    sbindir = $(prefix)
2685 #    libdir = $(AROS_LIB)
2686 #    includedir = $(AROS_INCLUDES)
2687 #    oldincludedir = $(AROS_INCLUDES)
2688 # endif
2691 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2692     aros_prefix= extraoptions= extracflags= extracxxflags= nix_dir_layout= nix=no compiler=target \
2693     install_target=install preconfigure= postconfigure= postinstall= \
2694     config_env_extra= install_env= use_build_env=no
2696 ifneq (%(prefix),)
2697     %(mmake)-prefix := %(prefix)
2698 else
2699     %(mmake)-prefix := $(AROS_CONTRIB)
2700 endif
2702 ifneq (%(aros_prefix),)
2703     %(mmake)-aros_prefix := %(aros_prefix)
2704 else
2705     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2706 endif
2708 ifeq (%(nix),yes)
2709     %(mmake)-nix    := -nix
2710     %(mmake)-volpfx := /
2711     %(mmake)-volsfx := /
2712     
2713     ifeq (%(nix_dir_layout),)
2714         %(mmake)-nix_dir_layout := yes
2715     endif
2716 else
2717     %(mmake)-volsfx := :
2718     
2719     ifeq (%(nix_dir_layout),)
2720         %(mmake)-nix_dir_layout := no
2721     endif
2722 endif
2724 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2726 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2727         exec_prefix=$(%(mmake)-prefix) %(install_env)
2729 # Check if chosen compiler is valid
2730 ifeq ($(findstring %(compiler),host target kernel),)
2731   $(error unknown compiler %(compiler))
2732 endif
2734 # Set legacy 'host' variable based on chosen compiler
2735 ifeq (%(compiler),host)
2736     host := yes
2737     ifeq (%(package),)
2738         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2739     else
2740         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2741     endif
2742 else
2743     host := no
2744     ifeq (%(package),)
2745         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2746     else
2747         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2748     endif
2749 endif
2750 ifneq (%(gendir),)
2751     ifeq (%(package),)
2752         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2753     else
2754         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2755     endif
2756 endif
2758 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2759 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2761 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2762     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2763     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2764 else
2765     ifeq (%(nix),yes)
2766         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2767         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2768     else
2769         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2770     endif
2772     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2773     
2774     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2775         sbindir=$(%(mmake)-prefix) \
2776         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2777         oldincludedir=$(AROS_INCLUDES) %(install_env)
2778 endif
2780 ifneq ($(DEBUG),yes)
2781     %(mmake)-s_flag = -s
2782 endif
2784 # Set up build environment, and options for configure script
2785 ifeq (%(compiler),host)
2786     CONFIG_ENV := %(config_env_extra) \
2787         CPP="$(HOST_CPP)" \
2788         CXXCPP="$(HOST_CPP)" \
2789         CC="$(HOST_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2790         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2791         LDFLAGS="-L$(CROSSTOOLSDIR)/lib" \
2792         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2793         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2794         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2795         TARGET_NM="$(NM_PLAIN)" TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2796 endif
2797 ifeq (%(compiler),target)
2798     CONFIG_ENV := %(config_env_extra) \
2799         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2800         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2801         CFLAGS=" $(TARGET_CFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2802         CXXFLAGS=" $(TARGET_CXXFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2803         CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2804         CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2805         CC="$(TARGET_CC) $(TARGET_SYSROOT) -I$(AROS_DEVELOPMENT)/include"\
2806         CXX="$(TARGET_CXX) $(TARGET_SYSROOT) -I$(AROS_DEVELOPMENT)/include"\
2807         LDFLAGS="-L$(AROS_DEVELOPMENT)/lib" \
2808         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2809         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2810         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2811         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2812         TARGET_NM="$(NM_PLAIN)" \
2813         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)" \
2814         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2815     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2816         --host=$(AROS_TARGET_CPU)-aros\
2817         --target=$(AROS_TARGET_CPU)-aros\
2818         --disable-nls\
2819         --without-x --without-pic --disable-shared
2820 endif
2821 ifeq (%(compiler),kernel)
2822     CONFIG_ENV := %(config_env_extra) \
2823         CPP="$(KERNEL_CPP)" \
2824         CXXCPP="$(KERNEL_CPP)" \
2825         CFLAGS="%(extracflags) $(%(mmake)-s_flag)" \
2826         CXXFLAGS="%(extracxxflags) $(%(mmake)-s_flag)" \
2827         CC="$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)"\
2828         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)"\
2829         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" RANLIB="$(RANLIB)"\
2830         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2831         TARGET_NM="$(NM_PLAIN)"
2832     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2833         --host=$(AROS_TARGET_CPU)-aros\
2834         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2835         --without-x --without-pic --disable-shared
2836 endif
2838 ifeq (%(use_build_env),yes)
2839     BUILD_ENV := $(CONFIG_ENV)
2840 endif
2842 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2844 # When building for the host, we don't need to build the
2845 # linklibs - this is especially true when building the
2846 # crosstool toolchain on 'foreign' architectures (such as
2847 # building PPC on x86)
2849 #MM- %(mmake)-host : setup includes %(mmake)-quick
2850 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2851 #MM- %(mmake): %(mmake)-%(compiler)
2853 # Using -j1 in install_command may result in a warning but finally
2854 # it does its job. make install for gcc does not work reliably for -jN
2855 # where N > 1.
2856 ifneq (%(install_target),)
2857     %(mmake)-install_command = \
2858         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2859         -C $(%(mmake)-pkgdir) %(install_target) -j1
2861     %(mmake)-uninstall_command = \
2862     $(RM) $(%(mmake)-installflag) && \
2863     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2864     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2865 else
2866     %(mmake)-install_command   := true
2867     %(mmake)-uninstall_command := true
2868 endif
2870 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2873 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2875 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2876         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2877             $(RM)  $(%(mmake)-installflag) && \
2878             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2879              -C $(%(mmake)-pkgdir) && \
2880             $(%(mmake)-install_command) && \
2881             $(TOUCH) $@ -r $^; \
2882         fi
2884 $(%(mmake)-pkgdir)/.files-touched:
2885         %mkdirs_q $(%(mmake)-pkgdir)
2886         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2887         $(TOUCH) $@
2890 %(mmake)-uninstall :
2891         $(%(mmake)-uninstall_command)
2894 %(mmake)-configure : $(%(mmake)-configflag)
2896 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2897 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2898         $(RM) $@
2899         %mkdirs_q $(%(mmake)-pkgdir)
2900         cd $(%(mmake)-pkgdir) && \
2901         find . -name config.cache -exec $(RM) '{}' \; && \
2902         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2903             %(extraoptions) && \
2904         $(TOUCH) $@
2907 %(mmake)-clean : %(mmake)-uninstall
2908         @$(RM) $(%(mmake)-pkgdir)
2909 %end
2910 #------------------------------------------------------------------------------
2913 #------------------------------------------------------------------------------
2914 # Build an imported source tree which uses cmake 
2916 # Arguments:
2918 #     - mmake           = the meta make target.
2919 #     - package         = name of the package to be built.
2920 #     - srcdir          = the location of the unpacked source code. Defaults
2921 #                         to $(SRCDIR)/$(CURDIR).
2922 #     - prefix          = the target directory. Must be an absolute path of the
2923 #                         host system. Defaults to $(AROS_CONTRIB).
2924 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2925 #                         Defaults to the value of the prefix option.
2926 #     - extraoptions    = additional options for the cmake script.
2927 #     - installoptions    = additional options for the install step.
2930 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2931     aros_prefix= extraoptions= installoptions= maketarget= cflags=$(CFLAGS) cxxflags=$(CXXFLAGS)
2933 ifneq (%(prefix),)
2934     %(mmake)-prefix := %(prefix)
2935 else
2936     %(mmake)-prefix := $(AROS_CONTRIB)
2937 endif
2939 ifneq (%(aros_prefix),)
2940     %(mmake)-aros_prefix := %(aros_prefix)
2941 else
2942     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2943 endif
2945 ifneq (%(gendir),)
2946     ifeq (%(package),)
2947         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2948     else
2949         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2950     endif
2951 else
2952     ifeq (%(package),)
2953         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2954     else
2955         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2956     endif
2957 endif
2959 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
2960 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2962 BD_CFLAGS := %(cflags)
2963 BD_CXXFLAGS := %(cxxflags)
2965 %(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)"
2967 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2969 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
2971 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
2974 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2976 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
2977         if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
2978             $(RM)  $(%(mmake)-installflag) && \
2979             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
2980             cd $(%(mmake)-pkgdir) && \
2981             cmake %(installoptions) -P cmake_install.cmake && \
2982             $(TOUCH) $@ -r $^; \
2983         fi
2985 $(%(mmake)-pkgdir)/.files-touched:
2986         %mkdirs_q $(%(mmake)-pkgdir)
2987         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
2988         $(TOUCH) $@
2991 %(mmake)-cmake : $(%(mmake)-cmakeflag)
2993 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2994 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2995         $(RM) $@
2996         %mkdirs_q $(%(mmake)-pkgdir)
2997         cd $(%(mmake)-pkgdir) && \
2998         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
2999         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3000         $(TOUCH) $@
3003 %(mmake)-clean : %(mmake)-uninstall
3004         @$(RM) $(%(mmake)-pkgdir)
3005 %end
3006 #------------------------------------------------------------------------------
3009 #------------------------------------------------------------------------------
3010 # Given an archive name, patches names and locations where to find them, fetch
3011 # the archive and the patches from any of those locations, unpack the archive
3012 # and then apply the patches.
3014 # Locations currently supported are http and ftp sites, plus local filesystem
3015 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3016 # the fetch.sh script needs to be modified, since this macro relies on that script.
3018 # Arguments:
3020 #     - mmake           = mmaketarget
3021 #     - archive_origins = list of locations where to find the archive. They are tried
3022 #                         in sequence, until the archive is found and fetching it 
3023 #                         succeeded. If not specified, the current directory is assumed.
3024 #     - archive         = the archive name. Mandatory.
3025 #     - suffixes        = a list of suffixes to append to the the package name plus the
3026 #                         version. Each one of them is tried until a matching archive is
3027 #                         found. They are appended to patches and these are tried the
3028 #                         same way as packages are.
3029 #     - location        = the local directory where to put the fetched archive and patches.
3030 #                         If not specified, the directory specified by destination is used.
3031 #     - destination     = the directory to unpack the archive to.
3032 #                         If not specified, the current directory is assumed.
3033 #     - patches_origins = list of locations where to find the patches. They are tried
3034 #                         in sequence, until a patch is found and fetching it 
3035 #                         succeeded. If not specified, the current directory is assumed.
3036 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3037 #                         patch_name[:[patch_subdir][:patch_opt]].
3039 #                             - patch_name   = the name of the patch file
3040 #                             - patch_subdir = the directory within \destination\ where to
3041 #                                              apply the patch.
3042 #                             - patch_opt    = any options to pass to the `patch' command
3043 #                                              when applying the patch.
3044 #                         
3045 #                         The patch_subdir and patch_opt fields are optional.
3047 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3048     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3050 .PHONY: %(mmake)
3052 ifneq (%(location),)
3053     %(mmake)-location := %(location)
3054 else
3055     %(mmake)-location := %(destination)
3056 endif
3059 %(mmake) :
3060         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3061         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3062 %end
3063 #------------------------------------------------------------------------------
3066 #------------------------------------------------------------------------------
3067 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3068 # unpatched source tree and runs diff against this and a previously fetched and possibly
3069 # patched tree. Depending on what happens after patching during a normal build it might
3070 # give best results if the new patch is created directly after fetch.
3072 # Arguments:
3074 #     - mmake       = mmaketarget
3075 #     - archive     = archive base name
3076 #     - srcdir      = the top level directory the package is unpacked to, useful if
3077 #                     an archive unpacks to a directory other than its name suggests.
3078 #                     this should not be deeper than a single path element.
3079 #     - suffixes    = a list of suffixes to append to the the package name plus the
3080 #                     version. Each one of them is tried until a matching archive is
3081 #                     found.
3082 #     - destination = the directory to unpack the archive to.
3083 #     - excludes    = diff patterns to exclude files or directories from the patch
3085 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3087 .PHONY: %(mmake)
3089 ifneq (%(excludes),)
3090     %(mmake)-exclude := -X ./exclude.patterns
3091 endif
3093 ifneq (%(srcdir),)
3094     %(mmake)-srcdir := %(srcdir)
3095 else
3096     %(mmake)-srcdir := %(archive)
3097 endif
3100 %(mmake):
3101         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3102         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3103         cd %(destination)/tmp ; \
3104         $(FOR) f in %(excludes) ; do \
3105             $(ECHO) $$f >> ./exclude.patterns ; \
3106         done ; \
3107         diff -ruN $(%(mmake)-exclude) \
3108             $(%(mmake)-srcdir) \
3109             $(%(mmake)-srcdir).aros \
3110             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3111         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3112         $(RM) %(destination)/tmp
3113 %end
3114 #------------------------------------------------------------------------------
3117 #------------------------------------------------------------------------------
3118 # Joins the features of %fetch and %build_with_configure.
3120 # If a patch is provided, it *must* be named the following way:
3122 #    <package name>-<version number>-aros.diff
3124 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3125 # CD'ing into the archive's extracted directory.
3127 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3128 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3129 # to make that patch fully comprehensive.
3131 # Arguments:
3133 #    - mmake            = the meta make target.
3134 #    - package          = the GNU package name, sans version and archive format suffixes.
3135 #    - subpackage       = ???
3136 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3137 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3138 #    - version          = the package's version number, or otherwise any other version string.
3139 #                         It gets appended to the package name to form the basename of the archive.
3140 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3141 #                         version. Each one of them is tried until a matching archive is found.
3142 #                         Defaults to "tar.bz2 tar.gz".
3143 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3144 #    - builddir         = override the location we expect to run configure/make in.
3145 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3146 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3147 #                         fetched or not. Default to no.
3148 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3149 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3150 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3151 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3152 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3153 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3154 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3155 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3156 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3157 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3158 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3159 #    - nix              = same meaning as the one for the %build_with_configure macro.
3160 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3161 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3163 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3164     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3165     prefix= aros_prefix= extraoptions= extracflags= extracxxflags= preconfigure= postconfigure= postinstall= \
3166     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3168 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3169 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3170 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3171 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3173 %(mmake)-archbase  := %(package)-%(version)
3175 ifeq (%(compiler),host)
3176     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
3177 else
3178     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3179 endif
3181 ifeq (%(prefix),)
3182     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3183 else
3184     %(mmake)-prefix := %(prefix)
3185 endif
3187 ifneq (%(subpackage),)
3188     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3189 else
3190     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3191 endif
3193 ifneq (%(srcdir),)
3194     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3195 else
3196     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3197 endif
3199 ifneq (%(builddir),)
3200     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3201 else
3202     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3203 endif
3205 ifeq (%(patch),yes)
3206     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3207 else
3208     %(mmake)-%(subpackage)-patches_specs := ::
3209 endif
3211 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3212     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3213     archive_origins=". %(package_repo)" \
3214     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3216 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3217     archive=$(%(mmake)-%(subpackage)-archbase) \
3218     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3219     suffixes="%(suffixes)" \
3220     destination=$(%(mmake)-portdir)
3222 #MM- %(mmake) : %(mmake)-%(subpackage)
3224 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3226 %(mmake)-%(subpackage)-package-basename := \
3227     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3229 ifneq (%(create_pkg),no)
3230     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3231 endif
3233 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3234      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3235      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3236      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3237      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3238      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3240 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3241 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3244 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3246 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3247 #that $^ and $@ have exactly the same mtime, and in that case make tries
3248 #to rebuild $@ again, which would fail because the directory where
3249 #the package got installed would not exist anymore. 
3250 #We work this around by using an if statement to manually check the mtimes.
3251 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3252         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3253         $(RM) $@ ; \
3254         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3255         mkdir -p "$(DISTDIR)/Packages" ; \
3256         mkdir -p "$(%(mmake)-prefix)" ; \
3257         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3258         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3259         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3260     fi
3261 %end
3262 #------------------------------------------------------------------------------
3265 #------------------------------------------------------------------------------
3266 # Joins the features of %fetch and %build_with_configure, taking advantage of
3267 # the naming scheme of GNU packages. GNU packages names are in the form
3269 #     <package name>-<version number>.<archive format suffix>
3271 # If a patch is provided, it *must* be named the following way:
3273 #    <package name>-<version number>-aros.diff
3275 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3276 # CD'ing into the archive's extracted directory.
3278 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3279 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3280 # to make that patch fully comprehensive.
3282 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3284 # Arguments:
3286 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3288 #    - prefix           = defaults to $(GNUDIR).
3289 #    - aros_prefix      = defaults to /GNU.
3291 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3292     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3293     aros_prefix=/GNU extraoptions= extracflags= extracxxflags= config_env_extra= preconfigure= postconfigure= postinstall= 
3295 GNU_REPOSITORY := gnu://
3297 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3298     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3299     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3300     patch="%(patch)" patch_repo="%(patch_repo)" \
3301     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3302     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3304 %end
3305 #------------------------------------------------------------------------------
3308 #------------------------------------------------------------------------------
3309 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3310 # that the package is a "Development" package, and as such it needs to be placed
3311 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3313 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3314 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3315 # "mmake" argument, because the metatarget is implicitely defined as
3317 #     #MM- development-%(package)
3319 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3320     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3321     aros_prefix=/Development config_env_extra= preconfigure= postconfigure= postinstall=  extraoptions= extracflags= extracxxflags=
3323 #MM- development : development-%(package)
3326 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3327    version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3328    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3329    aros_prefix="%(aros_prefix)" config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3330    extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3333 postinstall-%(package)-delete-la-files:
3334         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3336 %end
3337 #------------------------------------------------------------------------------
3339 # Builds a kickstart package in PKG format
3341 # Arguments:
3343 #    - mmake   = target name
3344 #    - file    = destination file name with path
3346 # Other arguments are self-explanatory
3348 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3349     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3351 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3352 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3353 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3354 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3355 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3356 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3358 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3359 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3360 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3361 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3362 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3363 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3365 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3366     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3367 PKG_DIR   := $(dir %(file))
3370 %(mmake) : %(file)
3373 %(mmake)-quick : %(file)
3375 %(file): $(PKG_FILES) | $(PKG_DIR)
3376         @$(ECHO) Packaging $@...
3377         @$(SRCDIR)/tools/package/pkg c $@ $^
3379 %compress_file mmake="%(mmake)" file="%(file)"
3381 GLOB_MKDIRS += $(PKG_DIR)
3383 %end
3385 #------------------------------------------------------------------------------
3386 # Compresses %(file) with a gzip.
3387 # Good in conjunction with for example %build_prog
3389 %define compress_file mmake=/A file=/A
3391 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3394 %(mmake)-gz-quick : %(file).gz
3396 %(file).gz: %(file)
3397         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3398         @gzip -9 -f $^
3400 %end
3402 #------------------------------------------------------------------------------
3403 # Links a kickstart module in ELF format
3404 # Arguments are similar to make_package
3406 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3407     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3409 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3410 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3411 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3412 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3413 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3414 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3416 ifeq (%(startup),)
3417     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3418 else
3419     KOBJ_STARTUP := %(startup)
3420 endif
3422 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3424 TMP_LDFLAGS := %(ldflags)
3426 # Make a list of the lib files this program depends on.
3427 # In LDFLAGS remove white space between -L and directory
3428 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3429 # Filter out only the libdirs and remove -L
3430 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3431 # Add trailing /
3432 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3433 # Add normal linklib path
3434 TMP_DIRS += $(AROS_LIB)/
3435 # add lib and .a to static linklib names
3436 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3437 # search for the linklibs in the given path, ignore ones not found
3438 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3439     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3442 TMP_DIRS += $(dir %(file))
3443 ifneq (%(map),)
3444     TMP_LDFLAGS += $(GENMAP) %(map)
3445     TMP_DIRS    += $(dir %(map))
3446 endif
3448 #MM %(mmake) : %(deps)
3451 %(mmake) : %(file)
3454 %(mmake)-quick : %(file)
3456 %(file): KOBJS := $(KOBJS)
3457 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3458                     -static -nosysbase -Wl,-Ur
3459 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3460 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3461         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3462         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3463         @$(STRIP) $@
3465 %compress_file mmake="%(mmake)" file="%(file)"
3467 GLOB_MKDIRS += $(TMP_DIRS)
3469 %end