Compositor: Compiler delint
[AROS.git] / config / make.tmpl
blob1e0450449c46695a7039cead56e16475d65a6b49
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macros that are used as commands in the body     ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefiles to different        ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16 %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
17 else
18 %(var) := %(string)
19 endif
20 %end
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         @$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31             else \
32                 $(NOP) ; \
33             fi ; \
34         else \
35             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37             exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51             else \
52                 $(NOP) ; \
53             fi ; \
54         else \
55             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57             exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(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) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(endtag) -o $@"; \
98             cat %(objdir)/%(err); \
99             exit 1; \
100         fi
102         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
103         @$(STRIP) $@
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the library
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
112         @%(ar) %(to) %(from)
113         @%(ranlib) %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121         %mkdir_q dir="$(dir %(to))"
122         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
124 %end
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
148 ##                                                                         ##
149 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
150 ## mmakefile. They consist of one or more full makefile rules.             ##
151 ## In general the files generated in these macros are also defined as      ##
152 ## make targets so that they can be used as a dependency in other rules    ##
153 ##                                                                         ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
160 BDID := $(BDID)_
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
163 endif
164 %end
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
171 %(to) : %(from)
172         @$(CP) $< $@
173 %end
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
181 # present.
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185         @$(CP) $< $@
186 %end
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by 
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197     stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207         @for f in $(FILES); do \
208              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
210              fi ; \
211         done
212         @$(TOUCH) $@
213 %end
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
219 # be displayed.
220 # Restriction: at the moment when using a non-empty target dir %(from) may
221 # not have 
222 %define rule_join to=/A from=/A text=
224 %(to) : %(from)
225 ifneq (%(text),)
226         @$(ECHO) %(text)
227 endif
228         @$(CAT) $^ >$@
229 %end
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean 
238 %define include_deps deps=$(DEPS)/M  depstargets=
239 ifneq (%(deps),)
240   ifneq (%(depstargets),)
241     ifneq ($(findstring $(TARGET),%(depstargets)),)
242       -include %(deps)
243     endif
244   else
245     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
246       -include %(deps)
247     endif
248   endif
249 endif
250 %end
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default. 
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
263 %end
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
272 # options
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 #   the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 #   it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
281 ifeq (%(targetdir),)
282   TMP_TARGETBASE := %(basename)
283 else
284   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
285 endif
287 ifeq ($(findstring %(compiler),host kernel target),)
288   $(error unknown compiler %(compiler))
289 endif
290 ifeq (%(compiler),target)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
297 endif
298 ifeq (%(compiler),host)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
305 endif
306 ifeq (%(compiler),kernel)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
313 endif
315 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
319 ifeq (%(dflags),)
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
324   endif
325 else
326   ifeq (%(nix),yes)
327     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
328   else
329     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
330   endif
331 endif
332 $(TMP_TARGETBASE).d : %(basename).c
333         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
334 %end
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile a C++ source file to an object file and generate
340 # the dependency file. Basename may contain a directory part, then the source
341 # file has to be in that directory. The generated file will be put in the
342 # object directory without the directory.
343 # options
344 # - basename: the basename of the file to compile. Use % for a wildcard rule
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 #   the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 #   it is put in the same directory as the .c file
350 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
352 ifeq (%(targetdir),)
353   TMP_TARGETBASE := %(basename)
354 else
355   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
356 endif
358 # Adjust compiler flags to suit C++
359 TMP_CXXFLAGS := %(cflags)
360 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
361 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
363 ifeq ($(findstring %(compiler),host kernel target),)
364   $(error unknown compiler %(compiler))
365 endif
366 ifeq (%(compiler),target)
367 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
368 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
369 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
370 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
373 endif
374 ifeq (%(compiler),host)
375 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
376 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
377 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
378 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
381 endif
382 ifeq (%(compiler),kernel)
383 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
384 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
387 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
388 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
392 $(TMP_TARGETBASE).o : %(basename).cpp
393         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396   ifeq (%(nix),yes)
397     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
398   else
399     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
400   endif
401 else
402   ifeq (%(nix),yes)
403     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
404   else
405     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
406   endif
407 endif
408 $(TMP_TARGETBASE).d : %(basename).cpp
409         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
410 %end
411 #------------------------------------------------------------------------------
414 #------------------------------------------------------------------------------
415 # Generate a rule to compile multiple C source files to an object file and
416 # generate the corresponding dependency files. The generated file will be put
417 # in the object directory without the directory part of the source file.
418 # options
419 # - basenames: the basenames of the files to compile. The names may include
420 #   relative or absolute path names. No wildcard is allowed
421 # - cflags (default $(CFLAGS)): the C flags to use for compilation
422 # - dflags: the flags used during creation of dependency file. If not specified
423 #   the same value as cflags will be used
424 # - targetdir: the directory to put the .o file and the .d file. By default
425 #   it is put in the same directory as the .c file. When targetdir is not
426 #   empty, path names will be stripped from the file names so that all files
427 #   are in that dir and not in subdirectories.
428 # - compiler (default target): compiler to use, target, kernel or host
429 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
430     compiler=target
432 ifeq (%(targetdir),)
433 TMP_TARGETS := $(addsuffix .o,%(basenames))
434 TMP_DTARGETS := $(addsuffix .d,%(basenames))
435 TMP_WILDCARD := %
436 else
437 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
438 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
439 TMP_WILDCARD := %(targetdir)/%
441 # Be sure that all .c files are generated
442 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
444 # Be sure that all .c files are found
445 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
446 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
447 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
448 ifneq ($(TMP_DIRS),)
449     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
450     vpath %.c $(TMP_DIRS)
451 endif
453 endif
455 ifeq ($(findstring %(compiler),host kernel target),)
456   $(error unknown compiler %(compiler))
457 endif
458 ifeq (%(compiler),target)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
460 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
462 endif
463 ifeq (%(compiler),host)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
467 endif
468 ifeq (%(compiler),kernel)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
471 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
472 endif
474 $(TMP_TARGETS) : CFLAGS := %(cflags)
475 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
476         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
478 ifeq (%(dflags),)
479 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
480 else
481 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
482 endif
483 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
484         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
485 %end
486 #------------------------------------------------------------------------------
489 #------------------------------------------------------------------------------
490 # Generate a rule to compile multiple C++ source files to an object file and
491 # generate the corresponding dependency files. The generated file will be put
492 # in the object directory without the directory part of the source file.
493 # options
494 # - basenames: the basenames of the files to compile. The names may include
495 #   relative or absolute path names. No wildcard is allowed
496 # - cflags (default $(CFLAGS)): the C flags to use for compilation
497 # - dflags: the flags used during creation of dependency file. If not specified
498 #   the same value as cflags will be used
499 # - targetdir: the directory to put the .o file and the .d file. By default
500 #   it is put in the same directory as the .c file. When targetdir is not
501 #   empty, path names will be stripped from the file names so that all files
502 #   are in that dir and not in subdirectories.
503 # - compiler (default target): compiler to use, target, kernel or host
504 # - suffix (default .cpp): suffix for source files to compile
505 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
506     targetdir= compiler=target suffix=.cpp
508 # Adjust compiler flags to suit C++
509 TMP_CXXFLAGS := %(cflags)
510 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
511 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
513 ifeq (%(targetdir),)
514   TMP_TARGETS := $(addsuffix .o,%(basenames))
515   TMP_DTARGETS := $(addsuffix .d,%(basenames))
516   TMP_WILDCARD := %
517 else
518   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
519   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
520   TMP_WILDCARD := %(targetdir)/%
522   # Be sure that all source files are generated
523   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix %(suffix),%(basenames))
525   # Be sure that all source files are found
526   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
527   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
528   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
529   ifneq ($(TMP_DIRS),)
530     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
531     vpath %%(suffix) $(TMP_DIRS)
532   endif
533 endif
535 ifeq ($(findstring %(compiler),host kernel target),)
536   $(error unknown compiler %(compiler))
537 endif
538 ifeq (%(compiler),target)
539   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
540   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
541   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
542 endif
543 ifeq (%(compiler),host)
544   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
545   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
546   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
547 endif
548 ifeq (%(compiler),kernel)
549   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
550   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
551   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
552 endif
554 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
555 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
556         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
558 ifeq (%(dflags),)
559   $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
560 else
561   ifeq (%(dflags),%(cflags))
562     $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
563   else
564     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
565   endif
566 endif
567 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %%(suffix)
568         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
569 %end
570 #------------------------------------------------------------------------------
573 #------------------------------------------------------------------------------
574 # Generate a rule to compile an ObjC source file to an object file and generate
575 # the dependency file. Basename may contain a directory part, then the source
576 # file has to be in that directory. The generated file will be put in the
577 # object directory without the directory.
578 # options
579 # - basename: the basename of the file to compile. Use % for a wildcard rule
580 # - cflags (default $(CFLAGS)): the C flags to use for compilation
581 # - dflags: the flags used during creation of dependency file. If not specified
582 #   the same value as cflags will be used
583 # - targetdir: the directory to put the .o file and the .d file. By default
584 #   it is put in the same directory as the .m file
585 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
587 ifeq (%(targetdir),)
588   TMP_TARGETBASE := %(basename)
589 else
590   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
591 endif
593 # Adjust compiler flags to suit ObjC
594 TMP_OBJCFLAGS := %(cflags)
595 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
596 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
598 ifeq ($(findstring %(compiler),host kernel target),)
599   $(error unknown compiler %(compiler))
600 endif
601 ifeq (%(compiler),target)
602 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
603 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
604 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
605 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
606 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
607 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
608 endif
609 ifeq (%(compiler),host)
610 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
611 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
612 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
613 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
614 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
615 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
616 endif
617 ifeq (%(compiler),kernel)
618 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
619 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
622 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
623 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
624 endif
626 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
627 $(TMP_TARGETBASE).o : %(basename).m
628         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
630 ifeq (%(dflags),)
631   ifeq (%(nix),yes)
632     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
633   else
634     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
635   endif
636 else
637   ifeq (%(nix),yes)
638     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
639   else
640     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
641   endif
642 endif
643 $(TMP_TARGETBASE).d : %(basename).m
644         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
645 %end
646 #------------------------------------------------------------------------------
648 #------------------------------------------------------------------------------
649 # Generate a rule to compile multiple ObjC source files to an object file and
650 # generate the corresponding dependency files. The generated file will be put
651 # in the object directory without the directory part of the source file.
652 # options
653 # - basenames: the basenames of the files to compile. The names may include
654 #   relative or absolute path names. No wildcard is allowed
655 # - cflags (default $(CFLAGS)): the C flags to use for compilation
656 # - dflags: the flags used during creation of dependency file. If not specified
657 #   the same value as cflags will be used
658 # - targetdir: the directory to put the .o file and the .d file. By default
659 #   it is put in the same directory as the .m file. When targetdir is not
660 #   empty, path names will be stripped from the file names so that all files
661 #   are in that dir and not in subdirectories.
662 # - compiler (default target): compiler to use, target, kernel or host
663 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
664     targetdir= compiler=target
666 # Adjust compiler flags to suit ObjC
667 TMP_OBJCFLAGS := %(cflags)
668 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
669 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
671 ifeq (%(targetdir),)
672   TMP_TARGETS := $(addsuffix .o,%(basenames))
673   TMP_DTARGETS := $(addsuffix .d,%(basenames))
674   TMP_WILDCARD := %
675 else
676   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
677   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
678   TMP_WILDCARD := %(targetdir)/%
680   # Be sure that all .m files are generated
681   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
683   # Be sure that all .m files are found
684   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
685   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
686   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
687   ifneq ($(TMP_DIRS),)
688     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
689     vpath %.m $(TMP_DIRS)
690   endif
691 endif
693 # Define the use of cross compiler
694 ifeq ($(TARGET_OBJC),)
695   TMP_CC := $(TARGET_CC)
696 else
697   TMP_CC := $(TARGET_OBJC)
698 endif
700 ifeq ($(findstring %(compiler),host kernel target),)
701   $(error unknown compiler %(compiler))
702 endif
703 ifeq (%(compiler),target)
704   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
705   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
706   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
707 endif
708 ifeq (%(compiler),host)
709   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
710   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
711   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
712 endif
713 ifeq (%(compiler),kernel)
714   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
715   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
716   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
717 endif
719 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
720 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
721         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
723 ifeq (%(dflags),)
724   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
725 else
726   ifeq (%(dflags),%(cflags))
727     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
728   else
729     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
730   endif
731 endif
732 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
733         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
734 %end
735 #------------------------------------------------------------------------------
738 #------------------------------------------------------------------------------
739 # Make an alias from one arch specific build to another arch.
740 # arguments:
741 # - mainmmake: the mmake of the module in the main tree
742 # - arch: the current arch
743 # - alias: the alias to which this should point
744 %define rule_archalias mainmmake=\A arch=\A alias=\A
746 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
747 %end
748 #------------------------------------------------------------------------------
751 #------------------------------------------------------------------------------
752 # Generate a rule to assemble a source file to an object file. Basename may
753 # contain a directory part, then the source file has to be in that directory.
754 # The generated file will be put in the object directory without the directory.
755 # options
756 # - basename: the basename of the file to compile. Use % for a wildcard rule
757 # - flags (default $(AFLAGS)): the asm flags to use for assembling
758 # - targetdir: the directory to put the .o file in. By default it is put in the
759 #   same directory as the .s file
760 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
762 ifeq (%(targetdir),)
763 %(basename).o : AFLAGS := %(aflags)
764 %(basename).o : %(basename).s
765         %assemble_q
766 %(basename).o : %(basename).S
767         %assemble_q
769 else
770 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
771 %(targetdir)/$(notdir %(basename)).o : %(basename).s
772         %assemble_q
773 %(targetdir)/$(notdir %(basename)).o : %(basename).S
774         %assemble_q
776 endif
777 %end
778 #------------------------------------------------------------------------------
781 #------------------------------------------------------------------------------
782 # Generate a rule to assemble multiple source files to an object file. The
783 # generated file will be put in the object directory with the directory part
784 # of the source file stripped off.
785 # options
786 # - basenames: the basenames of the files to compile. The names may include
787 #   relative or absolute path names. No wildcard is allowed
788 # - aflags (default $(AFLAGS)): the flags to use for assembly
789 # - targetdir: the directory to put the .o file and the .d file. By default
790 #   it is put in the same directory as the .c file. When targetdir is not
791 #   empty, path names will be stripped from the file names so that all files
792 #   are in that dir and not in subdirectories.
793 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
795 ifeq (%(targetdir),)
796 TMP_TARGETS := $(addsuffix .o,%(basenames))
797 TMP_WILDCARD := %
798 else
799 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
800 TMP_WILDCARD := %(targetdir)/%
802 # Be sure that all .s files are generated
803 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
805 # Be sure that all .c files are found
806 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
807 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
808 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
809 ifneq ($(TMP_DIRS),)
810     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
811     vpath %%(suffix) $(TMP_DIRS)
812 endif
814 endif
816 ifeq ($(findstring %(compiler),host kernel target),)
817   $(error unknown compiler %(compiler))
818 endif
819 ifeq (%(compiler),target)
820 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
821 endif
822 ifeq (%(compiler),host)
823 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
824 endif
825 ifeq (%(compiler),kernel)
826 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
827 endif
829 $(TMP_TARGETS) : AFLAGS := %(aflags)
830 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
831         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
832 %end
833 #------------------------------------------------------------------------------
836 #------------------------------------------------------------------------------
837 # Link %(objs) to %(prog) using the libraries in %(uselibs)
838 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
839     usehostlibs= usestartup=yes detach=no nix=no linker=target
841 TMP_EXTRA_LDFLAGS := 
842 TMP_EXTRA_LIBS :=
843 ifeq (%(nix),yes)
844     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
845 endif
846 ifeq (%(usestartup),no)
847     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
848     ifeq (%(linker),target)
849         TMP_EXTRA_LIBS += libinit autoinit
850     endif
851 endif
852 ifeq (%(detach),yes)
853     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
854 endif
856 # Make a list of the lib files this program depends on.
857 # In LDFLAGS remove white space between -L and directory
858 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
859 # Filter out only the libdirs and remove -L
860 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
861 # Add trailing /
862 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
863 # Add normal linklib path
864 TMP_DIRS += $(LIBDIR)/
865 # add lib and .a to static linklib names
866 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
867 ifeq (%(usestartup),yes)
868     TMP_LIBS += startup.o
869 endif
870 ifeq (%(detach),yes)
871     TMP_LIBS += detach.o
872 endif
873 # search for the linklibs in the given path, ignore ones not found
874 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
875     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
878 ifeq (%(linker),target)
879 %(prog) : CMD:=$(TARGET_CC)
880 %(prog) : STRIPCMD:=$(TARGET_STRIP)
881 endif
882 ifeq (%(linker),host)
883 %(prog) : CMD:=$(HOST_CC)
884 %(prog) : STRIPCMD:=$(HOST_STRIP)
885 endif
886 ifeq (%(linker),kernel)
887 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
888 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
889 endif
891 %(prog) : OBJS := %(objs)
892 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
893 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
894 %(prog) : %(objs) $(TMP_DEPLIBS)
895         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
896 %end
897 #------------------------------------------------------------------------------
900 #------------------------------------------------------------------------------
901 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
902 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
903 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
904     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
905     usestartup=yes detach=no
907 TMP_EXTRA_LDFLAGS := 
908 TMP_EXTRA_LIBS :=
909 ifeq (%(nix),yes)
910     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
911 endif
912 ifeq (%(usestartup),no)
913     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
914     TMP_EXTRA_LIBS += libinit autoinit
915 endif
916 ifeq (%(detach),yes)
917     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
918 endif
920 # Make a list of the lib files the programs depend on.
921 # In LDFLAGS remove white space between -L and directory
922 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
923 # Filter out only the libdirs and remove -L
924 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
925 # Add trailing /
926 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
927 # Add normal linklib path
928 TMP_DIRS += $(LIBDIR)/
929 # add lib and .a to static linklib names
930 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
931 # search for the linklibs in the given path, ignore ones not found
932 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
933     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
935 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
937 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
938 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
939 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
940         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
941 %end
942 #------------------------------------------------------------------------------
945 #------------------------------------------------------------------------------
946 # Link the %(objs) to the library %(libdir)/lib%(libname).a
947 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
949 ifeq (%(linker),target)
950 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
951 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
952 endif
953 ifeq (%(linker),host)
954 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
955 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
956 endif
957 ifeq (%(linker),kernel)
958 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
959 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
960 endif
962 %(libdir)/lib%(libname).a : %(objs)
963         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
964 %end
965 #------------------------------------------------------------------------------
967 #------------------------------------------------------------------------------
968 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
969 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
970 # The -nostdc flag is added so that modules are not linked with stdc.library,
971 # stdcio.library or posixc.library
972 # (see /config/specs.in file)
973 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
974     cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
976 TMP_LDFLAGS  := %(ldflags)
977 # Make a list of the lib files the programs depend on.
978 # In LDFLAGS remove white space between -L and directory
979 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
980 # Filter out only the libdirs and remove -L
981 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
982 # Add trailing /
983 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
984 # Add normal linklib path
985 TMP_DIRS += $(LIBDIR)/
986 # add lib and .a to static linklib names
987 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
988 # search for the linklibs in the given path, ignore ones not found
989 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
990     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
993 %(module) : LIB_NAMES := %(uselibs)
994 %(module) : OBJS := %(objs)
995 %(module) : ENDTAG := %(endobj)
996 %(module) : ERR := %(err)
997 %(module) : OBJDIR := %(objdir)
998 %(module) : LDFLAGS := $(TMP_LDFLAGS)
999 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1000                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1001 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1002         %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1004 %end
1005 #------------------------------------------------------------------------------
1008 #------------------------------------------------------------------------------
1009 # Generate the libdefs.h include file for a module.
1010 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1012 TMP_TARGET := %(modname)_libdefs.h
1013 TMP_DEPS := $(GENMODULE)
1014 TMP_OPTS := 
1015 ifneq (%(conffile),)
1016     ifeq ($(dir %(conffile)),./)
1017         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1018         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1019     else
1020         TMP_OPTS += -c %(conffile)
1021         TMP_DEPS += %(conffile)
1022     endif 
1023 else
1024     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1025     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1026 endif
1027 ifneq (%(modsuffix),)
1028     TMP_OPTS += -s %(modsuffix)
1029 endif
1030 ifneq (%(targetdir),)
1031     TMP_OPTS += -d %(targetdir)
1032     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1033 endif
1034 ifneq (%(version),)
1035     TMP_OPTS += -v %(version)
1036 endif
1038 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1039 $(TMP_TARGET) : MODNAME := %(modname)
1040 $(TMP_TARGET) : MODTYPE := %(modtype)
1041 $(TMP_TARGET) : $(TMP_DEPS)
1042         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1043         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1044 %end
1045 #------------------------------------------------------------------------------
1047 #------------------------------------------------------------------------------
1048 # Generate the _lib.fd file for a module.
1049 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1051 TMP_TARGET := %(modname)_lib.fd
1052 TMP_DEPS := $(GENMODULE)
1053 TMP_OPTS := 
1054 ifneq (%(conffile),)
1055     ifeq ($(dir %(conffile)),./)
1056         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1057         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1058     else
1059         TMP_OPTS += -c %(conffile)
1060         TMP_DEPS += %(conffile)
1061     endif 
1062 else
1063     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1064     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1065 endif
1066 ifneq (%(modsuffix),)
1067     TMP_OPTS += -s %(modsuffix)
1068 endif
1069 ifneq (%(targetdir),)
1070     TMP_OPTS += -d %(targetdir)
1071     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1072 endif
1074 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1075 $(TMP_TARGET) : MODNAME := %(modname)
1076 $(TMP_TARGET) : MODTYPE := %(modtype)
1077 $(TMP_TARGET) : $(TMP_DEPS)
1078         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1079         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1080 %end
1081 #------------------------------------------------------------------------------
1083 #------------------------------------------------------------------------------
1084 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1085 # generated file in this Makefile
1086 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1087     targetdir=
1089 TMP_TARGET := Makefile.%(modname)%(modtype)
1090 TMP_DEPS := $(GENMODULE)
1091 TMP_OPTS := 
1092 ifneq (%(conffile),)
1093     ifeq ($(dir %(conffile)),./)
1094         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1095         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1096     else
1097         TMP_OPTS += -c %(conffile)
1098         TMP_DEPS += %(conffile)
1099     endif 
1100 else
1101     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1102     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1103 endif
1104 ifneq (%(modsuffix),)
1105     TMP_OPTS += -s %(modsuffix)
1106 endif
1107 ifneq (%(targetdir),)
1108     TMP_OPTS += -d %(targetdir)
1109     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1110 endif
1112 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1113 $(TMP_TARGET) : MODNAME := %(modname)
1114 $(TMP_TARGET) : MODTYPE := %(modtype)
1115 $(TMP_TARGET) : $(TMP_DEPS)
1116         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1117 %end
1118 #------------------------------------------------------------------------------
1121 #------------------------------------------------------------------------------
1122 # Generate the support files for compiling a module. This includes include
1123 # files and source files. This rule has to be preceeded by
1124 # %rule_genmodule_makefile
1125 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1126     conffile=
1128 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1129                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1130 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1131                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1133 TMP_DEPS := $(GENMODULE)
1134 TMP_OPTS :=
1136 ifneq (%(conffile),)
1137     ifeq ($(dir %(conffile)),./)
1138         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1139         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1140     else
1141         TMP_OPTS += -c %(conffile)
1142         TMP_DEPS += %(conffile)
1143     endif 
1144 else
1145     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1146     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1147 endif
1148 ifneq (%(modsuffix),)
1149     TMP_OPTS += -s %(modsuffix)
1150 endif
1151 ifneq (%(targetdir),)
1152     TMP_OPTS += -d %(targetdir)
1153     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1154     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1155 endif
1157 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1158 $(TMP_TARGETS) : MODNAME := %(modname)
1159 $(TMP_TARGETS) : MODTYPE := %(modtype)
1160 $(TMP_TARGETS) : $(TMP_DEPS)
1161         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1162 ifneq (%(conffile),lib.conf)
1163         @$(IF) $(TEST) -f lib.conf; then \
1164           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1165         fi
1166 endif
1167         @$(IF) $(TEST) -f libdefs.h; then \
1168           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1169         fi
1170         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1171 %end
1172 #------------------------------------------------------------------------------
1175 #------------------------------------------------------------------------------
1176 # Generate the support files for compiling a module. This includes include
1177 # files and source files.
1178 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1179     targetdir= conffile=
1181 ifneq ($(%(modname)_INCLUDES),)
1182 TMP_TARGETS := $(%(modname)_INCLUDES)
1184 TMP_DEPS := $(GENMODULE)
1185 TMP_OPTS :=
1187 ifneq (%(conffile),)
1188     ifeq ($(dir %(conffile)),./)
1189         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1190         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1191     else
1192         TMP_OPTS += -c %(conffile)
1193         TMP_DEPS += %(conffile)
1194     endif 
1195 else
1196     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1197     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1198 endif
1199 ifneq (%(modsuffix),)
1200     TMP_OPTS += -s %(modsuffix)
1201 endif
1202 ifneq (%(targetdir),)
1203     TMP_OPTS += -d %(targetdir)
1204     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1205 endif
1207 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1208 $(TMP_TARGETS) : MODNAME := %(modname)
1209 $(TMP_TARGETS) : MODTYPE := %(modtype)
1210 $(TMP_TARGETS) : $(TMP_DEPS)
1211         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1212         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1213 endif
1214 %end
1215 #------------------------------------------------------------------------------
1217 #------------------------------------------------------------------------------
1218 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1219 # 'start' is an optional starting address
1220 # 'ldflags' is optional additional flags for the linker
1221 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1223 BD_OUTDIR := $(dir %(file))
1224 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1225 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1226 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1227 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1228 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1229 BD_OBJS += %(objs)
1231 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1233 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1234         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1235         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1236         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1238 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1239     GLOB_MKDIRS += $(BD_OUTDIR)
1240 endif
1242 %end
1244 #------------------------------------------------------------------------------
1245 # Common rules for all makefiles
1246 %define common
1247 # Delete generated makefiles
1249 clean ::
1250         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1252 include $(SRCDIR)/config/make.tail
1254 BDID := $(BDTARGETID)
1255 %end
1256 #------------------------------------------------------------------------------
1257       
1259 #############################################################################
1260 #############################################################################
1261 ##                                                                         ##
1262 ## Here are the mmakefile build macros. These are macros that takes care   ##
1263 ## of everything to go from the sources to the generated target. Also all  ##
1264 ## intermediate files and directories that are needed are created by these ##
1265 ## rules.                                                                  ##
1266 ##                                                                         ##
1267 #############################################################################
1268 #############################################################################
1270 #------------------------------------------------------------------------------
1271 # Build a program
1272 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1273     objcfiles= \
1274     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1275     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1276     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1277     compiler=target linker=
1279 .PHONY : %(mmake)
1281 BD_PROGNAME  := %(progname)
1282 BD_OBJDIR    := %(objdir)
1283 BD_TARGETDIR := %(targetdir)
1284 BD_LINKER    := %(linker)
1286 # If not supplied, linker is equal to compiler
1287 ifeq ($(BD_LINKER),)
1288     BD_LINKER := %(compiler)
1289 endif
1291 BD_FILES     := %(files)
1292 BD_CXXFILES  := %(cxxfiles)
1293 BD_OBJCFILES := %(objcfiles)
1294 BD_ASMFILES  := %(asmfiles)
1296 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1297 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1298 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1300 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1301 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1302 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1304 BD_CFLAGS    := %(cflags)
1305 BD_AFLAGS    := %(aflags)
1306 BD_DFLAGS    := %(dflags)
1307 BD_LDFLAGS   := %(ldflags)
1310 %(mmake)-quick : %(mmake)
1312 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1313 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1315 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1316 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1317     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1318 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1319     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1320 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1321     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1322 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1323     aflags=$(BD_AFLAGS) compiler=%(compiler)
1325 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1326     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1327     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1328     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1329     linker=$(BD_LINKER)
1331 endif
1333 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1335 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1336 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1337 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1339 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1341 %(mmake)-clean ::
1342         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1343         @$(RM) $(FILES)
1345 %end
1346 #------------------------------------------------------------------------------
1349 #------------------------------------------------------------------------------
1350 # Build programs, for every C file an executable will be built with the same
1351 # name as the C file
1352 %define build_progs mmake=/A files=/A nix=no \
1353     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1354     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1355     uselibs= usehostlibs= usestartup=yes detach=no
1357 .PHONY : %(mmake)
1359 BD_OBJDIR    := %(objdir)
1360 BD_TARGETDIR := %(targetdir)
1362 BD_FILES     := %(files)
1363 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1364 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1365 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1367 BD_CFLAGS    := %(cflags)
1368 BD_DFLAGS    := %(dflags)
1369 BD_LDFLAGS   := %(ldflags)
1372 %(mmake)-quick : %(mmake)
1374 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1375 %(mmake) : $(BD_EXES)
1377 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1378 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1379     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1381 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1382     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1383     ldflags=$(BD_LDFLAGS) \
1384     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1385     usestartup="%(usestartup)" detach="%(detach)"
1387 endif
1389 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1391 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1392 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1393 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1395 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1397 %(mmake)-clean ::
1398         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1399         @$(RM) $(FILES)
1401 %end
1402 #------------------------------------------------------------------------------
1405 #------------------------------------------------------------------------------
1406 # Build a module.
1407 # This is a bare version: It just compiles and links the given files. It is
1408 # assumed that all needed boiler plate code is in the files. This should only
1409 # be used for compiling external code. For AROS code use %build_module
1410 %define build_module_simple mmake=/A modname=/A modtype=/A \
1411     files="$(basename $(call WILDCARD, *.c))" \
1412     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1413     objdir=$(OBJDIR) moduledir= \
1414     uselibs= usehostlibs= compiler=target
1416 # Define metamake targets and their dependencies
1417 #MM %(mmake) : core-linklibs includes-generate-deps
1418 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1419 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1420 #MM %(mmake)-kobj-quick
1421 #MM %(mmake)-pkg-quick
1422 #MM %(mmake)-quick
1423 #MM %(mmake)-clean
1425 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1427 .PHONY : $(BD_ALLTARGETS)
1429 ifeq (%(modname),)
1430 $(error using %build_module_simple: modname may not be empty)
1431 endif
1432 ifeq (%(modtype),)
1433 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1434 endif
1436 # Default values for variables and arguments
1437 BD_DEFLINKLIBNAME := %(modname)
1438 BD_DEFDFLAGS := %(cflags)
1439 OBJDIR ?= $(GENDIR)/$(CURDIR)
1440 BD_MODDIR := %(moduledir)
1441 ifeq ($(BD_MODDIR),)
1442   ifeq (%(modtype),library)
1443     BD_MODDIR  := $(AROS_LIBS)
1444   endif
1445   ifeq (%(modtype),gadget)
1446     BD_MODDIR  := $(AROS_GADGETS)
1447   endif
1448   ifeq (%(modtype),datatype)
1449     BD_MODDIR  := $(AROS_DATATYPES)
1450   endif
1451   ifeq (%(modtype),handler)
1452     BD_MODDIR  := $(AROS_FS)
1453   endif
1454   ifeq (%(modtype),device)
1455     BD_MODDIR  := $(AROS_DEVS)
1456   endif
1457   ifeq (%(modtype),resource)
1458     BD_MODDIR  := $(AROS_RESOURCES)
1459   endif
1460   ifeq (%(modtype),hook)
1461     BD_MODDIR  := $(AROS_RESOURCES)
1462   endif
1463   ifeq (%(modtype),mui)
1464     BD_MODDIR  := $(AROS_CLASSES)/Zune
1465   endif
1466   ifeq (%(modtype),mcc)
1467     BD_MODDIR  := $(AROS_CLASSES)/Zune
1468   endif
1469   ifeq (%(modtype),mcp)
1470     BD_MODDIR  := $(AROS_CLASSES)/Zune
1471   endif
1472   ifeq (%(modtype),usbclass)
1473     BD_MODDIR  := $(AROS_CLASSES)/USB
1474   endif
1475   ifeq (%(modtype),hidd)
1476     BD_MODDIR  := $(AROS_DRIVERS)
1477   endif
1478   ifeq (%(modtype),printer)
1479     BD_MODDIR  := $(AROS_PRINTERS)
1480   endif
1481 endif
1482 ifeq ($(BD_MODDIR),)
1483   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1484 endif
1486 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1487 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1488 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1490 %rule_compile_multi \
1491     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1492     cflags="%(cflags)" dflags="%(dflags)" \
1493     compiler=%(compiler)
1495 # Handlers use dash instead of dot in their names
1496 ifeq (%(modtype),handler)
1497 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1498 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1499 else
1500 ifeq (%(modtype),printer)
1501 BD_MODULE := $(BD_MODDIR)/%(modname)
1502 BD_PKGMOD := $(PKGDIR)/%(modname)
1503 else
1504 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1505 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1506 endif
1507 endif
1508 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1510 %(mmake)-quick : %(mmake)
1511 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1512 %(mmake)-kobj-quick : $(BD_KOBJ)
1513 %(mmake)       : $(BD_MODULE)
1514 %(mmake)-pkg   : $(BD_PKGMOD)
1515 %(mmake)-kobj  : $(BD_KOBJ)
1517 # The module is linked from all the compiled .o files
1518 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1520 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1521 # This breaks con-handler build. Here we work around this
1522 ifeq (%(modname),con)
1523     BD_ERR := $(notdir $(BD_MODULE)).err
1524 else
1525     BD_ERR := %(modname).err
1526 endif
1528 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1529                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1530                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1531                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1533 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1534                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1535                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1536                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1538 # Link kernel object file
1539 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1541 # Make these symbols local
1542 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1543             UtilityBase ExpansionBase KeymapBase KernelBase
1545 BD_SYMBOLS := $(BD_KBASE)
1547 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1548 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1549 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1550 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1551 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1552 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1553         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1554         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1555         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1558 ## Dependency fine-tuning
1560 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1561 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1563 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1564 $(BD_MODULE) : | $(BD_MODDIR)
1565 $(BD_KOBJ) : | $(KOBJSDIR)
1566 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1568 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1569 %(mmake)-clean ::
1570         @$(ECHO) "Cleaning up for module %(modname)"
1571         @$(RM) $(FILES)
1572 %end
1573 #------------------------------------------------------------------------------
1576 #------------------------------------------------------------------------------
1577 # Build a module
1578 # Explanation of this macro is done in the developer's manual
1579 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1580   files="$(basename $(call WILDCARD, *.c))" \
1581   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1582   cxxxxfiles="$(basename $(call WILDCARD, *.cxx))" \
1583   cxxccfiles="$(basename $(call WILDCARD, *.cc))" \
1584   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1585   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1586   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1587   compiler=target nostartup=yes
1589 # Define metamake targets and their dependencies
1590 #MM- includes-all : %(mmake)-includes
1591 #MM- linklibs-%(modname): %(mmake)-linklib
1592 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1593 #MM- includes-%(modname): %(mmake)-includes
1594 #MM- includes-%(modname)_rel : %(mmake)-includes
1595 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1596 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1597 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1598 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1599 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1600 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1601 #MM %(mmake)-quick : %(mmake)-includes-quick
1602 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1603 #MM     includes-generate-deps %(mmake)-fd
1604 #MM %(mmake)-includes-quick
1605 #MM %(mmake)-includes-dirs
1606 #MM %(mmake)-fd
1607 #MM %(mmake)-makefile
1608 #MM %(mmake)-clean
1610 # All MetaMake targets defined by this macro
1611 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1612     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1613     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1614     %(mmake)-linklib %(mmake)-fd
1616 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1618 ifeq (%(modname),)
1619 $(error using %build_module: modname may not be empty)
1620 endif
1621 ifeq (%(modtype),)
1622 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1623 endif
1625 # Default values for variables and arguments
1626 BD_DEFLINKLIBNAME := %(modname)
1627 BD_DEFDFLAGS := %(cflags)
1628 OBJDIR ?= $(GENDIR)/$(CURDIR)
1630 ## Create genmodule include Makefile for the module
1632 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1634 %rule_genmodule_makefile \
1635     modname=%(modname) modtype=%(modtype) \
1636     modsuffix=%(modsuffix) targetdir=%(objdir) \
1637     conffile=%(conffile)
1639 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1641 GLOB_MKDIRS += %(objdir)
1643 # Do not parse these statements if metatarget is not appropriate
1644 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1646 include %(objdir)/Makefile.%(modname)%(modtype)
1648 BD_DEFMODDIR := $(%(modname)_MODDIR)
1651 ## include files generation
1653 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1654 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1655 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1657 %(mmake)-includes-quick : %(mmake)-includes
1658 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1659     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1660     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1662 ifneq ($(%(modname)_INCLUDES),)
1663 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1664                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1665                          conffile=%(conffile)
1667 %rule_copy_diff_multi \
1668     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1669     stampfile=%(objdir)/%(modname)_geninc
1671 %rule_copy_diff_multi \
1672     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1673     stampfile=%(objdir)/%(modname)_incs
1675 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1677 TMP%(modname)_INCDIRS := \
1678     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1679     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1680     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1681 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1683 endif
1685 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1686                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1687                            conffile=%(conffile) version=%(version)
1689 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1690 $(BD_DEFLIBDEFSINC) :
1691         @$(ECHO) "Generating $@"
1692         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1694 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1695 GLOB_MKDIRS += %(objdir)/include
1697 ## Extra genmodule src files generation
1698 ## 
1699 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1700                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1701                       conffile=%(conffile)
1704 ## Create FD file
1705 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1706 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1708 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1709                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1711 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1713 GLOB_MKDIRS += $(BD_FDDIR)
1716 ## Compilation
1718 BD_FILES      := %(files)
1719 BD_CXXFILES   := %(cxxfiles)
1720 BD_CXXXXFILES := %(cxxxxfiles)
1721 BD_CXXCCFILES := %(cxxccfiles)
1723 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1725 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1726 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1728 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1729 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1730 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1732 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1733 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1735 ifeq (%(modtype),library)
1736     BD_LIBSUFFIX := 
1737 else
1738     BD_LIBSUFFIX := .%(modtype)
1739 endif
1741 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1742 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1743 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1744     BD_LINKLIB :=
1745 else
1746     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1747     ifneq (%(modname),%(linklibname))
1748         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1749     endif
1750 endif
1751 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1753 ifneq ($(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES),)
1754 BD_LINKCMD=$(AROS_CXX)
1755 else
1756 BD_LINKCMD=$(AROS_CC)
1757 endif
1759 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1760 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1761 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1762     BD_RELLINKLIB :=
1763 else
1764     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1765     ifneq (%(modname),%(linklibname))
1766         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1767     endif
1768 endif
1769 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1771 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1772 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1773     $(BD_RELLINKLIBCFILES)
1775 %rule_compile_multi \
1776     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1777     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1778     compiler=%(compiler)
1779 %rule_compile_multi \
1780     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1781     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1782     compiler=%(compiler)
1783 %rule_compile_cxx_multi \
1784     basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1785     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1786     compiler=%(compiler)
1787 %rule_compile_cxx_multi \
1788     basenames=$(BD_CXXXXFILES) targetdir=%(objdir) suffix=.cxx \
1789     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1790     compiler=%(compiler)
1791 %rule_compile_cxx_multi \
1792     basenames=$(BD_CXXCCFILES) targetdir=%(objdir) suffix=.cc \
1793     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1794     compiler=%(compiler)
1796 ifneq ($(BD_LINKLIBAFILES),)
1797 %rule_assemble_multi \
1798     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1799 endif
1801 ## Linking
1803 ifeq (%(modsuffix),)
1804 BD_SUFFIX := %(modtype)
1805 else
1806 BD_SUFFIX := %(modsuffix)
1807 endif
1809 # Handlers use dash instead of dot in their names
1810 ifeq ($(BD_SUFFIX),handler)
1811 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1812 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1813 else
1814 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1815 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1816 endif
1817 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1819 %(mmake)-quick      : %(mmake)
1820 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1821 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1822 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1823 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1824 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1825 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1827 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1828            $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES)))) \
1829            $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES))))
1831 ifeq (%(nostartup),yes)
1832 # Handlers always have entry point
1833 ifneq (%(modtype),handler)
1834 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1835 endif
1836 endif
1838 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1839 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1840                  %(linklibobjs)
1841 BD_RELLINKLIBOBJS \
1842               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1843                  %(linklibobjs)
1845 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1846 # This breaks con-handler build. Here we work around this
1847 ifeq (%(modname),con)
1848     BD_ERR := $(notdir $(BD_MODULE)).err
1849 else
1850     BD_ERR := %(modname).err
1851 endif
1853 # The module is linked from all the compiled .o files
1854 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1855                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1856                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1857                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1859 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1860                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1861                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1862                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1864 # Link static lib
1865 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1866 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1867 ifneq ($(BD_LINKLIB),)
1868 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1869 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1870 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1871 endif
1873 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1874 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1875 endif
1877 ifneq ($(BD_RELLINKLIB),)
1878 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1879 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1880 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1881 endif
1883 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1884 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1885 endif
1887 # Link kernel object file
1888 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1890 # Make these symbols local
1891 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1892             UtilityBase ExpansionBase KeymapBase KernelBase
1894 BD_SYMBOLS := $(BD_KBASE)
1896 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1897 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1898 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1899 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1900 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1901 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1902         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1903         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1904         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1906 ## Dependency fine-tuning
1908 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES)))) \
1909            $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CXXFILES) $(BD_CXXXXFILES) $(BD_CXXCCFILES))))
1910 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1912 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1913 $(BD_MODULE) : | %(prefix)/%(moduledir)
1914 $(BD_PKGMOD) : | $(PKGDIR)
1915 $(BD_KOBJ)   : | $(KOBJSDIR)
1916 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1918 # Some include files need to be generated before the .c can be parsed.
1919 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick),) # Only for this target these deps are wanted
1921 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1922     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1923 $(BD_DEPS) : $(BD_DFILE_DEPS)
1924 endif
1926 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1927     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1928     %(objdir)/Makefile.%(modname)%(modtype) \
1929     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1930     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1931     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1932     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1933     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1934     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1935     $(BD_ENDOBJS)
1936 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1937 %(mmake)-clean ::
1938         @$(ECHO) "Cleaning up for module %(modname)"
1939         @$(RM) $(FILES)
1941 endif # $(TARGET) in $(BD_ALLTARGETS)
1942 %end
1943 #------------------------------------------------------------------------------
1946 #------------------------------------------------------------------------------
1947 # Build a module skeleton
1948 # This is a stripped-down version of build_module, it only creates include files,
1949 # but no actual object. This is used when for plugins or classes with the same
1950 # API, but no actual implementation here.
1951 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1952   conffile= \
1953   objdir=$(OBJDIR) prefix=$(AROSDIR)
1955 # Define metamake targets and their dependencies
1956 #MM- includes-all : %(mmake)-includes
1957 #MM %(mmake) : %(mmake)-includes core-linklibs
1958 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1959 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1960 #MM %(mmake)-linklib : %(mmake)-includes
1961 #MM %(mmake)-quick : %(mmake)-includes-quick
1962 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1963 #MM     includes-generate-deps
1964 #MM %(mmake)-includes-quick
1965 #MM %(mmake)-includes-dirs
1966 #MM %(mmake)-makefile
1967 #MM %(mmake)-clean
1969 # All MetaMake targets defined by this macro
1970 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1971     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1972     %(mmake)-kobj %(mmake)-pkg
1974 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1976 ifeq (%(modname),)
1977 $(error using %build_module_skeleton: modname may not be empty)
1978 endif
1979 ifeq (%(modtype),)
1980 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1981 endif
1983 # Default values for variables and arguments
1984 BD_DEFLINKLIBNAME := %(modname)
1985 BD_DEFDFLAGS := %(cflags)
1986 OBJDIR ?= $(GENDIR)/$(CURDIR)
1988 ## Create genmodule include Makefile for the module
1990 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1992 %rule_genmodule_makefile \
1993     modname=%(modname) modtype=%(modtype) \
1994     modsuffix=%(modsuffix) targetdir=%(objdir) \
1995     conffile=%(conffile)
1997 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1999 GLOB_MKDIRS += %(objdir)
2001 # Do not parse these statements if metatarget is not appropriate
2002 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
2004 include %(objdir)/Makefile.%(modname)%(modtype)
2006 BD_DEFMODDIR := $(%(modname)_MODDIR)
2009 ## include files generation
2011 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
2012 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2013 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2015 %(mmake)-includes-quick : %(mmake)-includes
2016 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2017     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2018     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2020 ifneq ($(%(modname)_INCLUDES),)
2021 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2022                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2023                          conffile=%(conffile)
2025 %rule_copy_diff_multi \
2026     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2027     stampfile=%(objdir)/%(modname)_geninc
2029 %rule_copy_diff_multi \
2030     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2031     stampfile=%(objdir)/%(modname)_incs
2033 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2035 TMP%(modname)_INCDIRS := \
2036     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2037     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2038     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2039 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2041 endif
2043 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2044                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2045                            conffile=%(conffile)
2047 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2048 $(BD_DEFLIBDEFSINC) :
2049         @$(ECHO) "generating $@"
2050         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2052 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2053 GLOB_MKDIRS += %(objdir)/include
2055 ## Extra genmodule src files generation
2056 ## 
2057 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2058                       modsuffix=%(modsuffix) targetdir=%(objdir) \
2059                       conffile=%(conffile)
2061 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2062     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2063     %(objdir)/Makefile.%(modname)%(modtype) \
2064     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2065     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2066     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2067     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2068     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2069     $(BD_DEFLIBDEFSINC)
2070 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2071 %(mmake)-clean ::
2072         @$(ECHO) "Cleaning up for module %(modname)"
2073         @$(RM) $(FILES)
2075 endif # $(TARGET) in $(BD_ALLTARGETS)
2076 %end
2077 #------------------------------------------------------------------------------
2080 #------------------------------------------------------------------------------
2081 # Build a linklib.
2082 # - mmake is the mmaketarget
2083 # - libname is the baselibname e.g. lib%(libname).a will be created
2084 # - files are the C source files to include in the lib. The list of files
2085 #   has to be given without the .c suffix
2086 # - asmfiles are the asm files to include in the lib. The list of files has to
2087 #   be given without the .s suffix
2088 # - objs additional object to link into the linklib. The objects have to be
2089 #   given with full absolute path and the .o suffix.
2090 # - cflags are the flags to compile the source (default $(CFLAGS))
2091 # - dflags are the flags use during makedepend (default equal to cflags)
2092 # - aflags are the flags use during assembling (default $(AFLAGS))
2093 # - objdir is where the .o are generated
2094 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
2095 %define build_linklib mmake=/A libname=/A \
2096   files="$(basename $(call WILDCARD, *.c))" \
2097   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
2098   asmfiles= objs= compiler=target \
2099   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
2101 # assign and generate the local variables used in this macro
2102 OBJDIR        ?= $(GENDIR)/$(CURDIR)
2104 BD_FILES      := %(files)
2105 BD_CXXFILES   := %(cxxfiles)
2106 BD_ASMFILES   := %(asmfiles)
2108 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2109 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2110 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2112 BD_OBJS       := $(BD_ARCHOBJS) \
2113                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
2114                  %(objs)
2115 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2117 BD_CFLAGS     := %(cflags)
2118 ifeq (%(dflags),)
2119 BD_DFLAGS     := $(BD_CFLAGS)
2120 else
2121 BD_DFLAGS     := %(dflags)
2122 endif
2123 BD_AFLAGS     := %(aflags)
2125 BD_LINKLIB    := %(libdir)/lib%(libname).a
2127 .PHONY : %(mmake) %(mmake)-clean
2129 #MM %(mmake) : includes-generate-deps
2130 %(mmake) : $(BD_LINKLIB)
2133 %(mmake)-clean ::
2134         @$(RM) $(BD_OBJS) $(BD_DEPS)
2136 ifeq ($(TARGET),%(mmake))
2137 ifneq ($(dir $(BD_FILES)),./)
2138 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2139 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
2140 endif
2142 %rule_compile basename=% targetdir=%(objdir) \
2143     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2144 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2145     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2146 %rule_assemble basename=% targetdir=%(objdir) \
2147     aflags=$(BD_AFLAGS)
2149 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2150 endif
2152 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2154 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2155 $(BD_LINKLIB) : | %(libdir)
2156 GLOB_MKDIRS += %(objdir) %(libdir)
2158 %end
2159 #------------------------------------------------------------------------------
2162 #------------------------------------------------------------------------------
2163 # Build catalogs.
2164 # - mmake is the mmaketarget
2165 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2166 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2167 # - subdir is the destination subdirectory of the catalogs
2168 # - name is the name of the destination catalog, without the .catalog suffix
2169 # - source is the path to the generated source code file
2170 # - dir is the base destination directory (default $(AROS_CATALOGS))
2171 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2172 # - srcdir is the directory in which the *.cd and *.ct files are searched
2174 %define build_catalogs mmake=/A name=/A subdir=/A \
2175  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2176  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2178 ifeq (%(description),)
2179 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2180 else
2181 BD_DESC := %(description)
2182 endif
2184 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2186 ifeq (%(catalogs),)
2187 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2188 else
2189 BD_LNGS := %(catalogs)
2190 endif
2192 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2193 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2196 %(mmake) : $(BD_OBJS) %(source)
2198 $(BD_OBJS) : | $(BD_DIRS)
2199 GLOB_MKDIRS += $(BD_DIRS)
2201 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2202         @$(ECHO) "Creating   %(name) catalog for language $*."
2203         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2205 ifneq (%(source),)
2206 %(source) : BD_DESC := $(BD_DESC)
2207 %(source) : BD_SRC := $(BD_SRC)
2208 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2209         @$(ECHO) "Creating   %(name) catalog source file $@"
2210         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2211 endif
2214 %(mmake)-clean ::
2215         $(RM) $(BD_OBJS) %(source)
2217 .PHONY: %(mmake) %(mmake)-clean
2219 %end
2220 #-----------------------------------------------------------------------------
2223 #-----------------------------------------------------------------------------
2224 # Build icons.
2225 # - mmake is the mmaketarget
2226 # - icons is a list of icon base names (ie. without the .info suffix)
2227 # - dir is the destination directory
2228 # - srcdir is where *.png and *.info.src are searched
2229 #-----------------------------------------------------------------------------
2231 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2233 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2236 %(mmake) : $(BD_OBJS)
2238 ifeq (%(image),)
2240 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2241         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2242         @$(ILBMTOICON) $+ $@
2244 else
2246 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2247         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2248         @$(ILBMTOICON) $+ $@
2250 endif
2252 $(BD_OBJS) : | %(dir)
2253 GLOB_MKDIRS += %(dir)
2255 %(mmake)-clean : FILES := $(BD_OBJS)
2257 %(mmake)-clean ::
2258         @$(RM) $(FILES)
2260 .PHONY: %(mmake) %(mmake)-clean
2262 %end
2263 #-----------------------------------------------------------------------------
2266 #------------------------------------------------------------------------------
2267 # Compile files for an arch-specific replacement of code for a module
2268 # - files: the basenames of the C files to compile.
2269 # - asmfiles: the basenames of the asm files to assemble.
2270 # - mainmmake: the mmake of the module in the main directory to compile these
2271 #   arch specific files for.
2272 # - maindir: the object directory for the main module
2273 # - arch: the arch for which to compile these files. It can have the form
2274 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2275 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2276 # - dflags: the flags used during creation of dependency file. If not specified
2277 #   the same value as cflags will be used
2278 # - aflags: the flags used during assembling
2279 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2280 #   the target compiler is used
2281 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2282 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2284 ifeq (%(files) %(asmfiles),)
2285   $(error no files or asmfiles given)
2286 endif
2288 %buildid targets="%(mainmmake)-%(arch)"
2290 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2291 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2292 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2293 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2294 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2295 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2296 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2297 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2298 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2299 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2300 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2301 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2302 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2303 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2304 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2305 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2306 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2307 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2308 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2309 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2310 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2312 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2314 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2315 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2316 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2317 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2318 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2320 ifneq (%(modulename),)
2321 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2322 endif
2324 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2325     BD_TARGET := %(mainmmake)-%(arch)-quick
2326 else
2327     BD_TARGET := %(mainmmake)-%(arch)
2328 endif
2331 ifeq ($(TARGET),$(BD_TARGET))
2332 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2333 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2334 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2335 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2336 endif
2338 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2339 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2342 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2345 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2347 ifeq ($(findstring %(compiler),host kernel target),)
2348   $(error unknown compiler %(compiler))
2349 endif
2350 ifeq (%(compiler),target)
2351 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2352 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2353 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2354 endif
2355 ifeq (%(compiler),host)
2356 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2357 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2358 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2359 endif
2360 ifeq (%(compiler),kernel)
2361 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2362 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2363 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2364 endif
2365 ifneq (%(modulename),)
2366 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2367 else
2368 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2369 endif
2370 ifeq ($(TARGET),$(BD_TARGET))
2371 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2372         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2373 endif
2375 ifeq (%(dflags),)
2376 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2377 else
2378 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2379 endif
2380 ifeq ($(TARGET),$(BD_TARGET))
2381 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2382         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2383 endif
2385 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2387 ifeq ($(TARGET),$(BD_TARGET))
2388 $(BD_OBJDIR$(BDID))/%.o : %.s
2389         %assemble_q opt=$(AFLAGS)
2390 $(BD_OBJDIR$(BDID))/%.o : %.S
2391         %assemble_q opt=$(AFLAGS)
2392 endif
2394 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2395 %end
2396 #------------------------------------------------------------------------------
2399 #------------------------------------------------------------------------------
2400 # generate asm files from c files (for debugging purposes)
2401 %define ctoasm_q
2402 %.s : %.c
2403         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2404         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2405 %end
2406 #------------------------------------------------------------------------------
2409 #------------------------------------------------------------------------------
2410 # Copy files from one directory to another.
2412 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2414 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2416 GLOB_MKDIRS += %(dst)
2418 .PHONY : %(mmake)
2421 %(mmake) : | %(dst) 
2422         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2424 %end
2425 #------------------------------------------------------------------------------
2428 #------------------------------------------------------------------------------
2429 # Copy a directory recursively to another place, preserving the original 
2430 # hierarchical structure
2432 # src: the source directory whose content will be copied
2433 # dst: the directory where to copy src's content. If not existing, it will be made.
2435 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2437 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2438 %(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print)
2439 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2441 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2442 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2444 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2446 .PHONY : %(mmake)
2449 %(mmake): | $(GENDIR)/$(CURDIR)
2450         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2451         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2452         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2453         for d in $(%(mmake)_DIRS); do                      \
2454             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2455         done
2456         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2457         for f in $(%(mmake)_FILES); do                                            \
2458             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2459         done;  \
2460         for dst in %(dst); do \
2461             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2462         done
2464 %end
2465 #------------------------------------------------------------------------------
2468 #------------------------------------------------------------------------------
2469 #   Copy include files into the includes directories. There are currently
2470 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2471 #   for building tools that need to run on the host system $(GENINCDIR). The
2472 #   $(GENINCDIR) path must not contain any references to the C runtime
2473 #   library header files.
2475 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2476     dir= compiler=target
2478 ifeq ($(findstring %(compiler),host kernel target),)
2479 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2480 endif
2482 ifneq (%(dir),)
2483 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2484 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2485 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2486 else
2487 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2488 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2489 endif
2491 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2492         @$(CP) $< $@
2495 ifeq (%(compiler),target)
2497 ifneq (%(dir),)
2498 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2499 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2500 else
2501 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2502 endif
2504 BD_INCL_FILES += $(BD_INCL_FILES2)
2506 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2507         @$(CP) $< $@
2508 endif
2511 %(mmake) : $(BD_INCL_FILES)
2513 .PHONY: %(mmake)
2515 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2516 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2517 %end
2518 #------------------------------------------------------------------------------
2521 #------------------------------------------------------------------------------
2522 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2523 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2524 STUBS_MEM := $(addsuffix .o,$(STUBS))
2525 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2526 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2527 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2529 #MM- linklibs : hidd-%(hidd)-stubs
2530 #MM- %(parenttarget): hidd-%(hidd)-stubs
2531 #MM hidd-%(hidd)-stubs : includes includes-copy
2532 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2534 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2535         %mklib_q from=$^
2537 $(STUBS_OBJ) : $(STUBS_SRC) 
2538         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2540 $(STUBS_DEP) : $(STUBS_SRC)
2541         %mkdepend_q flags=%(dflags)
2543 setup ::
2544         %mkdirs_q $(OBJDIR) $(LIBDIR)
2547 clean ::
2548         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2550 DEPS := $(DEPS) $(STUBS_DEP)
2552 %end
2553 #------------------------------------------------------------------------------
2556 #------------------------------------------------------------------------------
2557 # Build an imported source tree which uses the configure script from the
2558 # autoconf package.  This rule will try to "integrate" the produced files as
2559 # much as possible in the AROS build, for example by putting libraries in the
2560 # standard library directory, includes in the standard include directory, and
2561 # so on. You can however override this behaviour.
2563 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2564 # be %(bindir) (or its deduced value) when running "make install", and
2565 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2566 # configure script some more parameters whose value depends upon the PROGDIR
2567 # env var, so that the program gets all its stuff installed in the proper place
2568 # when building it, but when running it from inside AROS it can also find that
2569 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2570 # the configuration parameters set when running ./configure
2572 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2573 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2574 # to the name which has to follow it.
2576 # Arguments:
2578 #     - mmake           = the meta make target.
2579 #     - package         = name of the package to be built.
2580 #     - srcdir          = the location of the unpacked source code. Defaults
2581 #                         to $(SRCDIR)/$(CURDIR).
2582 #     - prefix          = the target directory. Must be an absolute path of the
2583 #                         host system. Defaults to $(AROS_CONTRIB).
2584 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2585 #                         Defaults to the value of the prefix option.
2586 #     - extraoptions    = additional options for the configure script.
2587 #     - extracflags     = additional flags which are used for both C and C++.
2588 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2589 #                         Defaults to the value of the nix argument.
2590 #     - nix             = enable u*nix path handling, i.e. a path like
2591 #                         /progdir//./file will be translated to
2592 #                         progdir:file during run-time. Defaults to no.
2593 #     - compiler        = target, host or kernel. Defaults to target.
2594 #     - install_target  = the command used for installing. Defaults to install. Leave
2595 #                         it empty if you want to suppress installing.
2596 #     - preconfigure    = a metatarget which is executed before configure is called.
2597 #     - postconfigure   = a metatarget which is executed after configure is called.
2598 #     - postinstall     = a metatarget which is executed after installing.
2599 #     - install_env     = set additional options for installing.
2600 #     - use_build_env   = if yes the configuration environment is used for
2601 #                         installing, too. Defaults to no.
2603 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2604 # like this:
2606 # if nix_dir_layout
2607 #    --prefix = $(aros_prefix)
2608 #    progdir = $(aros_prefix)/bin
2609 # else
2610 #    if nix
2611 #        --prefix = /PROGDIR
2612 #        --bindir = /PROGDIR
2613 #        --sbindir = /PROGDIR
2614 #        --libdir = /LIB
2615 #        --includedir = /INCLUDE
2616 #        --oldincludedir = /INCLUDE   
2617 #    else
2618 #        --prefix = $(aros_prefix)
2619 #    endif
2621 #    progdir = $(aros_prefix)
2623 #    # Install options
2624 #    bindir = $(prefix)
2625 #    sbindir = $(prefix)
2626 #    libdir = $(AROS_LIB)
2627 #    includedir = $(AROS_INCLUDES)
2628 #    oldincludedir = $(AROS_INCLUDES)
2629 # endif
2632 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2633     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2634     install_target=install preconfigure= postconfigure= postinstall= \
2635     install_env= use_build_env=no
2637 ifneq (%(prefix),)
2638     %(mmake)-prefix := %(prefix)
2639 else
2640     %(mmake)-prefix := $(AROS_CONTRIB)
2641 endif
2643 ifneq (%(aros_prefix),)
2644     %(mmake)-aros_prefix := %(aros_prefix)
2645 else
2646     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2647 endif
2649 ifeq (%(nix),yes)
2650     %(mmake)-nix    := -nix
2651     %(mmake)-volpfx := /
2652     %(mmake)-volsfx := /
2653     
2654     ifeq (%(nix_dir_layout),)
2655         %(mmake)-nix_dir_layout := yes
2656     endif
2657 else
2658     %(mmake)-volsfx := :
2659     
2660     ifeq (%(nix_dir_layout),)
2661         %(mmake)-nix_dir_layout := no
2662     endif
2663 endif
2665 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2667 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2668         exec_prefix=$(%(mmake)-prefix) %(install_env)
2670 # Check if chosen compiler is valid
2671 ifeq ($(findstring %(compiler),host target kernel),)
2672   $(error unknown compiler %(compiler))
2673 endif
2675 # Set legacy 'host' variable based on chosen compiler
2676 ifeq (%(compiler),host)
2677     host := yes
2678     ifeq (%(package),)
2679         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2680     else
2681         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2682     endif
2683 else
2684     host := no
2685     ifeq (%(package),)
2686         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2687     else
2688         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2689     endif
2690 endif
2691 ifneq (%(gendir),)
2692     ifeq (%(package),)
2693         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2694     else
2695         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2696     endif
2697 endif
2699 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2700 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2702 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2703     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2704     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2705 else
2706     ifeq (%(nix),yes)
2707         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2708         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2709     else
2710         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2711     endif
2713     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2714     
2715     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2716         sbindir=$(%(mmake)-prefix) \
2717         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2718         oldincludedir=$(AROS_INCLUDES) %(install_env)
2719 endif
2721 ifneq ($(DEBUG),yes)
2722     %(mmake)-s_flag = -s
2723 endif
2725 # Set up build environment, and options for configure script
2726 ifeq (%(compiler),host)
2727     CONFIG_ENV := \
2728         CPP="$(HOST_CPP)" \
2729         CXXCPP="$(HOST_CPP)" \
2730         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2731         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2732         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2733         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2734         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2735         TARGET_NM="$(NM_PLAIN)"
2736 endif
2737 ifeq (%(compiler),target)
2738     CONFIG_ENV := \
2739         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2740         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2741         CPP="$(TARGET_CPP)" \
2742         CXXCPP="$(TARGET_CPP)" \
2743         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2744         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2745         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2746         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2747         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2748         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2749         TARGET_NM="$(NM_PLAIN)" \
2750         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2751         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2752     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2753         --host=$(AROS_TARGET_CPU)-aros\
2754         --target=$(AROS_TARGET_CPU)-aros\
2755         --disable-nls\
2756         --without-x --without-pic --disable-shared
2757 endif
2758 ifeq (%(compiler),kernel)
2759     CONFIG_ENV := \
2760         CPP="$(KERNEL_CPP)" \
2761         CXXCPP="$(KERNEL_CPP)" \
2762         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2763         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2764         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2765         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2766         TARGET_NM="$(NM_PLAIN)"
2767     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2768         --host=$(AROS_TARGET_CPU)-aros\
2769         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2770         --without-x --without-pic --disable-shared
2771 endif
2773 ifeq (%(use_build_env),yes)
2774     BUILD_ENV := $(CONFIG_ENV)
2775 endif
2778 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2780 # When building for the host, we don't need to build the
2781 # linklibs - this is especially true when building the
2782 # crosstool toolchain on 'foreign' architectures (such as
2783 # building PPC on x86)
2785 #MM- %(mmake)-host : setup includes %(mmake)-quick
2786 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2787 #MM- %(mmake): %(mmake)-%(compiler)
2789 # Using -j1 in install_command may result in a warning but finally
2790 # it does its job. make install for gcc does not work reliably for -jN
2791 # where N > 1.
2792 ifneq (%(install_target),)
2793     %(mmake)-install_command = \
2794         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2795         -C $(%(mmake)-pkgdir) %(install_target) -j1
2797     %(mmake)-uninstall_command = \
2798     $(RM) $(%(mmake)-installflag) && \
2799     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2800     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2801 else
2802     %(mmake)-install_command   := true
2803     %(mmake)-uninstall_command := true
2804 endif
2806 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2809 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2811 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2812         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2813             $(RM)  $(%(mmake)-installflag) && \
2814             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2815              -C $(%(mmake)-pkgdir) && \
2816             $(%(mmake)-install_command) && \
2817             $(TOUCH) $@ -r $^; \
2818         fi
2820 $(%(mmake)-pkgdir)/.files-touched:
2821         %mkdirs_q $(%(mmake)-pkgdir)
2822         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2823         $(TOUCH) $@
2826 %(mmake)-uninstall :
2827         $(%(mmake)-uninstall_command)
2830 %(mmake)-configure : $(%(mmake)-configflag)
2832 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2833 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2834         $(RM) $@
2835         %mkdirs_q $(%(mmake)-pkgdir)
2836         cd $(%(mmake)-pkgdir) && \
2837         find . -name config.cache -exec $(RM) '{}' \; && \
2838         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2839             %(extraoptions) && \
2840         $(TOUCH) $@
2843 %(mmake)-clean : %(mmake)-uninstall
2844         @$(RM) $(%(mmake)-pkgdir)
2845 %end
2846 #------------------------------------------------------------------------------
2849 #------------------------------------------------------------------------------
2850 # Given an archive name, patches names and locations where to find them, fetch
2851 # the archive and the patches from any of those locations, unpack the archive
2852 # and then apply the patches.
2854 # Locations currently supported are http and ftp sites, plus local filesystem
2855 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2856 # the fetch.sh script needs to be modified, since this macro relies on that script.
2858 # Arguments:
2860 #     - mmake           = mmaketarget
2861 #     - archive_origins = list of locations where to find the archive. They are tried
2862 #                         in sequence, until the archive is found and fetching it 
2863 #                         succeeded. If not specified, the current directory is assumed.
2864 #     - archive         = the archive name. Mandatory.
2865 #     - suffixes        = a list of suffixes to append to the the package name plus the
2866 #                         version. Each one of them is tried until a matching archive is
2867 #                         found. They are appended to patches and these are tried the
2868 #                         same way as packages are.
2869 #     - location        = the local directory where to put the fetched archive and patches.
2870 #                         If not specified, the directory specified by destination is used.
2871 #     - destination     = the directory to unpack the archive to.
2872 #                         If not specified, the current directory is assumed.
2873 #     - patches_origins = list of locations where to find the patches. They are tried
2874 #                         in sequence, until a patch is found and fetching it 
2875 #                         succeeded. If not specified, the current directory is assumed.
2876 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2877 #                         patch_name[:[patch_subdir][:patch_opt]].
2879 #                             - patch_name   = the name of the patch file
2880 #                             - patch_subdir = the directory within \destination\ where to
2881 #                                              apply the patch.
2882 #                             - patch_opt    = any options to pass to the `patch' command
2883 #                                              when applying the patch.
2884 #                         
2885 #                         The patch_subdir and patch_opt fields are optional.
2887 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2888     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2890 .PHONY: %(mmake)
2892 ifneq (%(location),)
2893     %(mmake)-location := %(location)
2894 else
2895     %(mmake)-location := %(destination)
2896 endif
2899 %(mmake) :
2900         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2901         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2902 %end
2903 #------------------------------------------------------------------------------
2906 #------------------------------------------------------------------------------
2907 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2908 # unpatched source tree and runs diff against this and a previously fetched and possibly
2909 # patched tree. Depending on what happens after patching during a normal build it might
2910 # give best results if the new patch is created directly after fetch.
2912 # Arguments:
2914 #     - mmake       = mmaketarget
2915 #     - archive     = archive base name
2916 #     - srcdir      = the top level directory the package is unpacked to, useful if
2917 #                     an archive unpacks to a directory other than its name suggests.
2918 #                     this should not be deeper than a single path element.
2919 #     - suffixes    = a list of suffixes to append to the the package name plus the
2920 #                     version. Each one of them is tried until a matching archive is
2921 #                     found.
2922 #     - destination = the directory to unpack the archive to.
2923 #     - excludes    = diff patterns to exclude files or directories from the patch
2925 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2927 .PHONY: %(mmake)
2929 ifneq (%(excludes),)
2930     %(mmake)-exclude := -X ./exclude.patterns
2931 endif
2933 ifneq (%(srcdir),)
2934     %(mmake)-srcdir := %(srcdir)
2935 else
2936     %(mmake)-srcdir := %(archive)
2937 endif
2940 %(mmake):
2941         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2942         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2943         cd %(destination)/tmp ; \
2944         $(FOR) f in %(excludes) ; do \
2945             $(ECHO) $$f >> ./exclude.patterns ; \
2946         done ; \
2947         diff -ruN $(%(mmake)-exclude) \
2948             $(%(mmake)-srcdir) \
2949             $(%(mmake)-srcdir).aros \
2950             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2951         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2952         $(RM) %(destination)/tmp
2953 %end
2954 #------------------------------------------------------------------------------
2957 #------------------------------------------------------------------------------
2958 # Joins the features of %fetch and %build_with_configure.
2960 # If a patch is provided, it *must* be named the following way:
2962 #    <package name>-<version number>-aros.diff
2964 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2965 # CD'ing into the archive's extracted directory.
2967 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2968 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2969 # to make that patch fully comprehensive.
2971 # Arguments:
2973 #    - mmake            = the meta make target.
2974 #    - package          = the GNU package name, sans version and archive format suffixes.
2975 #    - subpackage       = ???
2976 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2977 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2978 #    - version          = the package's version number, or otherwise any other version string.
2979 #                         It gets appended to the package name to form the basename of the archive.
2980 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2981 #                         version. Each one of them is tried until a matching archive is found.
2982 #                         Defaults to "tar.bz2 tar.gz".
2983 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
2984 #    - builddir         = override the location we expect to run configure/make in.
2985 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2986 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2987 #                         fetched or not. Default to no.
2988 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2989 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2990 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2991 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2992 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2993 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2994 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2995 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2996 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2997 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2998 #    - nix              = same meaning as the one for the %build_with_configure macro.
2999 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3000 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3002 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3003     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3004     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
3005     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3007 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3008 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3009 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3010 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3012 %(mmake)-archbase  := %(package)-%(version)
3014 ifeq (%(compiler),host)
3015     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
3016 else
3017     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3018 endif
3020 ifeq (%(prefix),)
3021     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3022 else
3023     %(mmake)-prefix := %(prefix)
3024 endif
3026 ifneq (%(subpackage),)
3027     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3028 else
3029     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3030 endif
3032 ifneq (%(srcdir),)
3033     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3034 else
3035     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3036 endif
3038 ifneq (%(builddir),)
3039     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3040 else
3041     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3042 endif
3044 ifeq (%(patch),yes)
3045     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3046 else
3047     %(mmake)-%(subpackage)-patches_specs := ::
3048 endif
3050 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3051     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3052     archive_origins=". %(package_repo)" \
3053     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3055 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3056     archive=$(%(mmake)-%(subpackage)-archbase) \
3057     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3058     suffixes="%(suffixes)" \
3059     destination=$(%(mmake)-portdir)
3061 #MM- %(mmake) : %(mmake)-%(subpackage)
3063 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3065 %(mmake)-%(subpackage)-package-basename := \
3066     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3068 ifneq (%(create_pkg),no)
3069     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3070 endif
3072 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3073      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3074      install_env=%(install_env) use_build_env=%(use_build_env) \
3075      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3076      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3077      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3079 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3080 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3083 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3085 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3086 #that $^ and $@ have exactly the same mtime, and in that case make tries
3087 #to rebuild $@ again, which would fail because the directory where
3088 #the package got installed would not exist anymore. 
3089 #We work this around by using an if statement to manually check the mtimes.
3090 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3091         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3092         $(RM) $@ ; \
3093         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3094         mkdir -p "$(DISTDIR)/Packages" ; \
3095         mkdir -p "$(%(mmake)-prefix)" ; \
3096         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3097         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3098         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3099     fi
3100 %end
3101 #------------------------------------------------------------------------------
3104 #------------------------------------------------------------------------------
3105 # Joins the features of %fetch and %build_with_configure, taking advantage of
3106 # the naming scheme of GNU packages. GNU packages names are in the form
3108 #     <package name>-<version number>.<archive format suffix>
3110 # If a patch is provided, it *must* be named the following way:
3112 #    <package name>-<version number>-aros.diff
3114 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3115 # CD'ing into the archive's extracted directory.
3117 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3118 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3119 # to make that patch fully comprehensive.
3121 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3123 # Arguments:
3125 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3127 #    - prefix           = defaults to $(GNUDIR).
3128 #    - aros_prefix      = defaults to /GNU.
3130 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3131     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3132     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3134 GNU_REPOSITORY := gnu://
3136 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3137     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3138     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3139     patch="%(patch)" patch_repo="%(patch_repo)" \
3140     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3141     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3143 %end
3144 #------------------------------------------------------------------------------
3147 #------------------------------------------------------------------------------
3148 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3149 # that the package is a "Development" package, and as such it needs to be placed
3150 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3152 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3153 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3154 # "mmake" argument, because the metatarget is implicitely defined as
3156 #     #MM- development-%(package)
3158 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3159     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3160     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3162 #MM- development : development-%(package)
3165 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3166    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3167    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3168    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3169    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3172 postinstall-%(package)-delete-la-files:
3173         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3175 %end
3176 #------------------------------------------------------------------------------
3178 # Builds a kickstart package in PKG format
3180 # Arguments:
3182 #    - mmake   = target name
3183 #    - file    = destination file name with path
3184 #    - startup = the file which will be put first
3186 # Other arguments are self-explanatory
3188 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
3190 PKG_CLASSES   := $(addsuffix .class, %(classes))
3191 PKG_DEVICES   := $(addsuffix .device, %(devs))
3192 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
3193 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
3194 PKG_LIBS      := $(addsuffix .library, %(libs))
3195 PKG_RESOURCES := $(addsuffix .resource, %(res))
3197 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
3198 PKG_DIR   := $(dir %(file))
3199 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
3202 %(mmake) : %(file)
3205 %(mmake)-quick : %(file)
3207 %(file): PKG_FILES := $(PKG_FILES)
3208 %(file): $(PKG_DEPS) | $(PKG_DIR)
3209         @$(ECHO) Packaging $@...
3210         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
3212 %compress_file mmake=%(mmake) file=%(file)
3214 GLOB_MKDIRS += $(PKG_DIR)
3216 %end
3218 #------------------------------------------------------------------------------
3219 # Compresses %(file) with a gzip.
3220 # Good in conjunction with for example %build_prog
3222 %define compress_file mmake=/A file=/A
3224 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3227 %(mmake)-gz-quick : %(file).gz
3229 %(file).gz: %(file)
3230         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3231         @gzip -9 -f $^
3233 %end
3235 #------------------------------------------------------------------------------
3236 # Links a kickstart module in ELF format
3237 # Arguments are similar to make_package
3239 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3240     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3242 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3243 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3244 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3245 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3246 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3247 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3249 ifeq (%(startup),)
3250     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3251 else
3252     KOBJ_STARTUP := %(startup)
3253 endif
3255 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3257 TMP_LDFLAGS := %(ldflags)
3259 # Make a list of the lib files this program depends on.
3260 # In LDFLAGS remove white space between -L and directory
3261 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3262 # Filter out only the libdirs and remove -L
3263 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3264 # Add trailing /
3265 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3266 # Add normal linklib path
3267 TMP_DIRS += $(LIBDIR)/
3268 # add lib and .a to static linklib names
3269 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3270 # search for the linklibs in the given path, ignore ones not found
3271 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3272     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3275 TMP_DIRS += $(dir %(file))
3276 ifneq (%(map),)
3277     TMP_LDFLAGS += $(GENMAP) %(map)
3278     TMP_DIRS    += $(dir %(map))
3279 endif
3281 #MM %(mmake) : %(deps)
3284 %(mmake) : %(file)
3287 %(mmake)-quick : %(file)
3289 %(file): KOBJS := $(KOBJS)
3290 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3291                     -nostdc -nosysbase -Wl,-Ur
3292 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3293 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3294         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3295         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3296         @$(STRIP) $@
3298 %compress_file mmake=%(mmake) file=%(file)
3300 GLOB_MKDIRS += $(TMP_DIRS)
3302 %end