- Removed unused HandleEvent method.
[AROS.git] / config / make.tmpl
blobb3d34fc0d21b7adad45e31db1a23633a3f5f93e5
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 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
15 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
16         @$(ECHO) "Compiling  $(CURDIR)/$(notdir %(from))"
17         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
56         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         %(strip) %(to)
70 %end
71 #------------------------------------------------------------------------------
74 #-------------------------------------------------------------------------
75 # Link a module based upon a number of arguments and the standard $(LIBS)
76 # and $(DEPLIBS) make variables.
78 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
79         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
80         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
81             $(GENMAP) %(objdir)/%(module).map \
82             %(objs) %(libs) %(endtag) \
83             -o $@ 2>&1 > %(objdir)/%(err); \
84         then \
85             cat %(objdir)/%(err); \
86         else \
87             echo "$(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(endtag) -o $@"; \
88             cat %(objdir)/%(err); \
89             exit 1; \
90         fi
92         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
93         @$(STRIP) $@
94 %end
95 #------------------------------------------------------------------------------
98 #------------------------------------------------------------------------------
99 # Create the library
100 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
101         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
102         @%(ar) %(to) %(from)
103         @%(ranlib) %(to)
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the dependency file %(to) for %(from)
110 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
111         %mkdir_q dir="$(dir %(to))"
112         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
113         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create one directory without any output
120 %define mkdir_q dir=.
121         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
122 %end
123 #------------------------------------------------------------------------------
126 #------------------------------------------------------------------------------
127 # Create several directories without any output
128 %define mkdirs_q dirs=/M
129         @$(FOR) dir in %(dirs) ; do \
130             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
131         done
132 %end
133 #------------------------------------------------------------------------------
136 #############################################################################
137 #############################################################################
138 ##                                                                         ##
139 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
140 ## mmakefile. They consist of one or more full makefile rules.             ##
141 ## In general the files generated in these macros are also defined as      ##
142 ## make targets so that they can be used as a dependency in other rules    ##
143 ##                                                                         ##
144 #############################################################################
145 #############################################################################
147 #------------------------------------------------------------------------------
148 # Generate a unique id for each of the %build... rules
149 %define buildid targets=/A
150 BDID := $(BDID)_
151 ifneq ($(filter $(TARGET),%(targets)),)
152 BDTARGETID := $(BDID)
153 endif
154 %end
155 #------------------------------------------------------------------------------
158 #------------------------------------------------------------------------------
159 # Copy file %(from) to %(to) in a makefile rule
160 %define rule_copy from=/A to=/A
161 %(to) : %(from)
162         @$(CP) $< $@
163 %end
164 #------------------------------------------------------------------------------
167 #------------------------------------------------------------------------------
168 # Copy the files %(files) to %(targetdir). For each file in %(files),
169 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
170 # appropriate subdirs are not generated by this rule so they have to be
171 # present.
172 %define rule_copy_multi files=/A targetdir=/A srcdir=.
174 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
175         @$(CP) $< $@
176 %end
177 #------------------------------------------------------------------------------
180 #------------------------------------------------------------------------------
181 # Copy the files %(files) to %(targetdir). For each file in %(files),
182 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
183 # %(stampfile) is used to keep track of when the last time the comparison has
184 # been done. The targetdir and the appropriate subdirs are not generated by 
185 # this rule so they have to be present.
186 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
187     stampfile=$(TMP_SRCDIR)/.copy_stamp
189 TMP_SRCDIR := %(srcdir)
191 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
193 %(stampfile) : COPYSRCDIR := %(srcdir)
194 %(stampfile) : TGTDIR := %(targetdir)
195 %(stampfile) : FILES := %(files)
196 %(stampfile) : $(addprefix %(srcdir)/,%(files))
197         @for f in $(FILES); do \
198              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
199                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
200              fi ; \
201         done
202         @$(TOUCH) $@
203 %end
204 #------------------------------------------------------------------------------
207 #------------------------------------------------------------------------------
208 # Will join all the files in %(from) to %(to). When text is specified it will
209 # be displayed.
210 # Restriction: at the moment when using a non-empty target dir %(from) may
211 # not have 
212 %define rule_join to=/A from=/A text=
214 %(to) : %(from)
215 ifneq (%(text),)
216         @$(ECHO) %(text)
217 endif
218         @$(CAT) $^ >$@
219 %end
220 #------------------------------------------------------------------------------
223 #------------------------------------------------------------------------------
224 # Include the dependency files and add some internal rules
225 # When depstargets is provided the depencies will only be included when one of
226 # these targets is the $(TARGET). Otherwise the dependencies will only be
227 # included when the $(TARGET) is not for setup or clean 
228 %define include_deps deps=$(DEPS)/M  depstargets=
229 ifneq (%(deps),)
230   ifneq (%(depstargets),)
231     ifneq ($(findstring $(TARGET),%(depstargets)),)
232       -include %(deps)
233     endif
234   else
235     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
236       -include %(deps)
237     endif
238   endif
239 endif
240 %end
241 #------------------------------------------------------------------------------
244 #------------------------------------------------------------------------------
245 # Create the directories %(dirs). The creation will be done by adding rules to
246 # the %(setuptarget) make target with setup as the default. 
247 %define rule_makedirs dirs=/A setuptarget=setup
249 %(setuptarget) :: %(dirs)
251 GLOB_MKDIRS += %(dirs)
253 %end
254 #------------------------------------------------------------------------------
257 #------------------------------------------------------------------------------
258 # Generate a rule to compile a C source file to an object file and generate
259 # the dependency file. Basename may contain a directory part, then the source
260 # file has to be in that directory. The generated file will be put in the
261 # object directory without the directory.
262 # options
263 # - basename: the basename of the file to compile. Use % for a wildcard rule
264 # - cflags (default $(CFLAGS)): the C flags to use for compilation
265 # - dflags: the flags used during creation of dependency file. If not specified
266 #   the same value as cflags will be used
267 # - targetdir: the directory to put the .o file and the .d file. By default
268 #   it is put in the same directory as the .c file
269 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
271 ifeq (%(targetdir),)
272   TMP_TARGETBASE := %(basename)
273 else
274   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
275 endif
277 ifeq ($(findstring %(compiler),host kernel target),)
278   $(error unknown compiler %(compiler))
279 endif
280 ifeq (%(compiler),target)
281 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
283 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
285 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
287 endif
288 ifeq (%(compiler),host)
289 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
291 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
295 endif
296 ifeq (%(compiler),kernel)
297 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
299 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
303 endif
305 ifeq (%(nix),yes)
306   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
307 else
308   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
309 endif
310 $(TMP_TARGETBASE).o : %(basename).c
311         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
313 ifeq (%(dflags),)
314   ifeq (%(nix),yes)
315     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
316   else
317     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
318   endif
319 else
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
324   endif
325 endif
326 $(TMP_TARGETBASE).d : %(basename).c
327         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
328 %end
329 #------------------------------------------------------------------------------
332 #------------------------------------------------------------------------------
333 # Generate a rule to compile a C++ source file to an object file and generate
334 # the dependency file. Basename may contain a directory part, then the source
335 # file has to be in that directory. The generated file will be put in the
336 # object directory without the directory.
337 # options
338 # - basename: the basename of the file to compile. Use % for a wildcard rule
339 # - cflags (default $(CFLAGS)): the C flags to use for compilation
340 # - dflags: the flags used during creation of dependency file. If not specified
341 #   the same value as cflags will be used
342 # - targetdir: the directory to put the .o file and the .d file. By default
343 #   it is put in the same directory as the .c file
344 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
346 ifeq (%(targetdir),)
347   TMP_TARGETBASE := %(basename)
348 else
349   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
350 endif
352 # Adjust compiler flags to suit C++
353 TMP_CXXFLAGS := %(cflags)
354 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
355 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
357 ifeq ($(findstring %(compiler),host kernel target),)
358   $(error unknown compiler %(compiler))
359 endif
360 ifeq (%(compiler),target)
361 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
362 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
363 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
364 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
365 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
366 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
367 endif
368 ifeq (%(compiler),host)
369 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
370 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
373 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
374 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
375 endif
376 ifeq (%(compiler),kernel)
377 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
378 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
381 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
382 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
383 endif
385 ifeq (%(nix),yes)
386   $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_CXXFLAGS)
387 else
388   $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
389 endif
390 $(TMP_TARGETBASE).o : %(basename).cpp
391         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
393 ifeq (%(dflags),)
394   ifeq (%(nix),yes)
395     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
396   else
397     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
398   endif
399 else
400   ifeq (%(nix),yes)
401     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
402   else
403     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
404   endif
405 endif
406 $(TMP_TARGETBASE).d : %(basename).cpp
407         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
408 %end
409 #------------------------------------------------------------------------------
412 #------------------------------------------------------------------------------
413 # Generate a rule to compile multiple C source files to an object file and
414 # generate the corresponding dependency files. The generated file will be put
415 # in the object directory without the directory part of the source file.
416 # options
417 # - basenames: the basenames of the files to compile. The names may include
418 #   relative or absolute path names. No wildcard is allowed
419 # - cflags (default $(CFLAGS)): the C flags to use for compilation
420 # - dflags: the flags used during creation of dependency file. If not specified
421 #   the same value as cflags will be used
422 # - targetdir: the directory to put the .o file and the .d file. By default
423 #   it is put in the same directory as the .c file. When targetdir is not
424 #   empty, path names will be stripped from the file names so that all files
425 #   are in that dir and not in subdirectories.
426 # - compiler (default target): compiler to use, target, kernel or host
427 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
428     compiler=target
430 ifeq (%(targetdir),)
431 TMP_TARGETS := $(addsuffix .o,%(basenames))
432 TMP_DTARGETS := $(addsuffix .d,%(basenames))
433 TMP_WILDCARD := %
434 else
435 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
436 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
437 TMP_WILDCARD := %(targetdir)/%
439 # Be sure that all .c files are generated
440 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
442 # Be sure that all .c files are found
443 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
444 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
445 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
446 ifneq ($(TMP_DIRS),)
447     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
448     vpath %.c $(TMP_DIRS)
449 endif
451 endif
453 ifeq ($(findstring %(compiler),host kernel target),)
454   $(error unknown compiler %(compiler))
455 endif
456 ifeq (%(compiler),target)
457 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
458 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
460 endif
461 ifeq (%(compiler),host)
462 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
463 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
465 endif
466 ifeq (%(compiler),kernel)
467 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
470 endif
472 $(TMP_TARGETS) : CFLAGS := %(cflags)
473 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
474         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
476 ifeq (%(dflags),)
477 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
478 else
479 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
480 endif
481 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
482         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
483 %end
484 #------------------------------------------------------------------------------
487 #------------------------------------------------------------------------------
488 # Generate a rule to compile multiple C++ source files to an object file and
489 # generate the corresponding dependency files. The generated file will be put
490 # in the object directory without the directory part of the source file.
491 # options
492 # - basenames: the basenames of the files to compile. The names may include
493 #   relative or absolute path names. No wildcard is allowed
494 # - cflags (default $(CFLAGS)): the C flags to use for compilation
495 # - dflags: the flags used during creation of dependency file. If not specified
496 #   the same value as cflags will be used
497 # - targetdir: the directory to put the .o file and the .d file. By default
498 #   it is put in the same directory as the .c file. When targetdir is not
499 #   empty, path names will be stripped from the file names so that all files
500 #   are in that dir and not in subdirectories.
501 # - compiler (default target): compiler to use, target, kernel or host
502 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
503     targetdir= compiler=target
505 # Adjust compiler flags to suit C++
506 TMP_CXXFLAGS := %(cflags)
507 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
508 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
510 ifeq (%(targetdir),)
511 TMP_TARGETS := $(addsuffix .o,%(basenames))
512 TMP_DTARGETS := $(addsuffix .d,%(basenames))
513 TMP_WILDCARD := %
514 else
515 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
516 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
517 TMP_WILDCARD := %(targetdir)/%
519 # Be sure that all .cpp files are generated
520 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .cpp,%(basenames))
522 # Be sure that all .cpp files are found
523 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
524 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
525 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
526 ifneq ($(TMP_DIRS),)
527     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
528     vpath %.cpp $(TMP_DIRS)
529 endif
531 endif
533 # Define the use of cross compiler
534 ifeq ($(TARGET_CXX),)
535   TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-g++
536 else
537   TMP_CC := $(TARGET_CXX)
538 endif
540 ifeq ($(findstring %(compiler),host kernel target),)
541   $(error unknown compiler %(compiler))
542 endif
543 ifeq (%(compiler),target)
544 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
545 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
546 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
547 endif
548 ifeq (%(compiler),host)
549 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
550 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
551 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
552 endif
553 ifeq (%(compiler),kernel)
554 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
555 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
556 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
557 endif
559 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
560 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
561         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
563 ifeq (%(dflags),)
564 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
565 else
566 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
567 endif
568 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
569         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
570 %end
571 #------------------------------------------------------------------------------
574 #------------------------------------------------------------------------------
575 # Make an alias from one arch specific build to another arch.
576 # arguments:
577 # - mainmmake: the mmake of the module in the main tree
578 # - arch: the current arch
579 # - alias: the alias to which this should point
580 %define rule_archalias mainmmake=\A arch=\A alias=\A
582 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
583 %end
584 #------------------------------------------------------------------------------
587 #------------------------------------------------------------------------------
588 # Generate a rule to assemble a source file to an object file. Basename may
589 # contain a directory part, then the source file has to be in that directory.
590 # The generated file will be put in the object directory without the directory.
591 # options
592 # - basename: the basename of the file to compile. Use % for a wildcard rule
593 # - flags (default $(AFLAGS)): the asm flags to use for assembling
594 # - targetdir: the directory to put the .o file in. By default it is put in the
595 #   same directory as the .s file
596 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
598 ifeq (%(targetdir),)
599 %(basename).o : AFLAGS := %(aflags)
600 %(basename).o : %(basename).s
601         %assemble_q
602 %(basename).o : %(basename).S
603         %assemble_q
605 else
606 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
607 %(targetdir)/$(notdir %(basename)).o : %(basename).s
608         %assemble_q
609 %(targetdir)/$(notdir %(basename)).o : %(basename).S
610         %assemble_q
612 endif
613 %end
614 #------------------------------------------------------------------------------
617 #------------------------------------------------------------------------------
618 # Generate a rule to assemble multiple source files to an object file. The
619 # generated file will be put in the object directory with the directory part
620 # of the source file stripped off.
621 # options
622 # - basenames: the basenames of the files to compile. The names may include
623 #   relative or absolute path names. No wildcard is allowed
624 # - aflags (default $(AFLAGS)): the flags to use for assembly
625 # - targetdir: the directory to put the .o file and the .d file. By default
626 #   it is put in the same directory as the .c file. When targetdir is not
627 #   empty, path names will be stripped from the file names so that all files
628 #   are in that dir and not in subdirectories.
629 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
631 ifeq (%(targetdir),)
632 TMP_TARGETS := $(addsuffix .o,%(basenames))
633 TMP_WILDCARD := %
634 else
635 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
636 TMP_WILDCARD := %(targetdir)/%
638 # Be sure that all .s files are generated
639 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
641 # Be sure that all .c files are found
642 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
643 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
644 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
645 ifneq ($(TMP_DIRS),)
646     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
647     vpath %%(suffix) $(TMP_DIRS)
648 endif
650 endif
652 ifeq ($(findstring %(compiler),host kernel target),)
653   $(error unknown compiler %(compiler))
654 endif
655 ifeq (%(compiler),target)
656 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
657 endif
658 ifeq (%(compiler),host)
659 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
660 endif
661 ifeq (%(compiler),kernel)
662 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
663 endif
665 $(TMP_TARGETS) : AFLAGS := %(aflags)
666 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
667         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
668 %end
669 #------------------------------------------------------------------------------
672 #------------------------------------------------------------------------------
673 # Link %(objs) to %(prog) using the libraries in %(uselibs)
674 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
675     usehostlibs= usestartup=yes detach=no nix=no linker=target
677 TMP_EXTRA_LDFLAGS := 
678 TMP_EXTRA_LIBS :=
679 ifeq (%(nix),yes)
680     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
681 endif
682 ifeq (%(usestartup),no)
683     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
684     TMP_EXTRA_LIBS += arosc.static
685     ifeq (%(linker),target)
686         TMP_EXTRA_LIBS += libinit autoinit
687     endif
688 endif
689 ifeq (%(detach),yes)
690     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
691 endif
693 # Make a list of the lib files this program depends on.
694 # In LDFLAGS remove white space between -L and directory
695 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
696 # Filter out only the libdirs and remove -L
697 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
698 # Add trailing /
699 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
700 # Add normal linklib path
701 TMP_DIRS += $(LIBDIR)/
702 # add lib and .a to static linklib names
703 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
704 # search for the linklibs in the given path, ignore ones not found
705 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
706     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
709 ifeq (%(linker),target)
710 %(prog) : CMD:=$(TARGET_CC)
711 %(prog) : STRIPCMD:=$(TARGET_STRIP)
712 endif
713 ifeq (%(linker),host)
714 %(prog) : CMD:=$(HOST_CC)
715 %(prog) : STRIPCMD:=$(HOST_STRIP)
716 endif
717 ifeq (%(linker),kernel)
718 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
719 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
720 endif
722 %(prog) : OBJS := %(objs)
723 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
724 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
725 %(prog) : %(objs) $(TMP_DEPLIBS)
726         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
727 %end
728 #------------------------------------------------------------------------------
731 #------------------------------------------------------------------------------
732 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
733 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
734 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
735     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
736     usestartup=yes detach=no
738 TMP_EXTRA_LDFLAGS := 
739 TMP_EXTRA_LIBS :=
740 ifeq (%(nix),yes)
741     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
742 endif
743 ifeq (%(usestartup),no)
744     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
745     TMP_EXTRA_LIBS += arosc.static libinit autoinit
746 endif
747 ifeq (%(detach),yes)
748     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
749 endif
751 # Make a list of the lib files the programs depend on.
752 # In LDFLAGS remove white space between -L and directory
753 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
754 # Filter out only the libdirs and remove -L
755 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
756 # Add trailing /
757 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
758 # Add normal linklib path
759 TMP_DIRS += $(LIBDIR)/
760 # add lib and .a to static linklib names
761 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
762 # search for the linklibs in the given path, ignore ones not found
763 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
764     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
767 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
768 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
769 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
770         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
771 %end
772 #------------------------------------------------------------------------------
775 #------------------------------------------------------------------------------
776 # Link the %(objs) to the library %(libdir)/lib%(libname).a
777 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
779 ifeq (%(linker),target)
780 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
781 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
782 endif
783 ifeq (%(linker),host)
784 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
785 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
786 endif
787 ifeq (%(linker),kernel)
788 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
789 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
790 endif
792 %(libdir)/lib%(libname).a : %(objs)
793         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
794 %end
795 #------------------------------------------------------------------------------
797 #------------------------------------------------------------------------------
798 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
799 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
800 # The -noarosc flag is added so that modules are not linked with arosc.library
801 # (see /config/specs.in file)
802 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
803     ldflags=$(LDFLAGS) uselibs= usehostlibs=
805 TMP_LDFLAGS  := %(ldflags) $(%(module)_LDFLAGS)
806 # Make a list of the lib files the programs depend on.
807 # In LDFLAGS remove white space between -L and directory
808 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
809 # Filter out only the libdirs and remove -L
810 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
811 # Add trailing /
812 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
813 # Add normal linklib path
814 TMP_DIRS += $(LIBDIR)/
815 # add lib and .a to static linklib names
816 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
817 # search for the linklibs in the given path, ignore ones not found
818 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
819     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
822 %(module) : LIB_NAMES := %(uselibs)
823 %(module) : OBJS := %(objs)
824 %(module) : ENDTAG := %(endobj)
825 %(module) : ERR := %(err)
826 %(module) : OBJDIR := %(objdir)
827 %(module) : LDFLAGS := $(TMP_LDFLAGS)
828 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
829                     -L/usr/lib $(addprefix -l,%(usehostlibs))
830 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
831         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
833 %end
834 #------------------------------------------------------------------------------
837 #------------------------------------------------------------------------------
838 # Generate the libdefs.h include file for a module.
839 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
841 TMP_TARGET := %(modname)_libdefs.h
842 TMP_DEPS := $(GENMODULE)
843 TMP_OPTS := 
844 ifneq (%(conffile),)
845     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
846     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
847 else
848     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
849     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
850 endif
851 ifneq (%(modsuffix),)
852     TMP_OPTS += -s %(modsuffix)
853 endif
854 ifneq (%(targetdir),)
855     TMP_OPTS += -d %(targetdir)
856     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
857 endif
858 ifneq (%(version),)
859     TMP_OPTS += -v %(version)
860 endif
862 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
863 $(TMP_TARGET) : MODNAME := %(modname)
864 $(TMP_TARGET) : MODTYPE := %(modtype)
865 $(TMP_TARGET) : $(TMP_DEPS)
866         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
867         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
868 %end
869 #------------------------------------------------------------------------------
871 #------------------------------------------------------------------------------
872 # Generate the _lib.fd file for a module.
873 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
875 TMP_TARGET := %(modname)_lib.fd
876 TMP_DEPS := $(GENMODULE)
877 TMP_OPTS := 
878 ifneq (%(conffile),)
879     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
880     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
881 else
882     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
883     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
884 endif
885 ifneq (%(modsuffix),)
886     TMP_OPTS += -s %(modsuffix)
887 endif
888 ifneq (%(targetdir),)
889     TMP_OPTS += -d %(targetdir)
890     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
891 endif
893 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
894 $(TMP_TARGET) : MODNAME := %(modname)
895 $(TMP_TARGET) : MODTYPE := %(modtype)
896 $(TMP_TARGET) : $(TMP_DEPS)
897         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
898         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
899 %end
900 #------------------------------------------------------------------------------
902 #------------------------------------------------------------------------------
903 # Generate a Makefile.%(modname) with the genmodule program and include this
904 # generated file in this Makefile
905 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
906     targetdir=
908 TMP_TARGET := Makefile.%(modname)
909 TMP_DEPS := $(GENMODULE)
910 TMP_OPTS := 
911 ifneq (%(conffile),)
912     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
913     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
914 else
915     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
916     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
917 endif
918 ifneq (%(modsuffix),)
919     TMP_OPTS += -s %(modsuffix)
920 endif
921 ifneq (%(targetdir),)
922     TMP_OPTS += -d %(targetdir)
923     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
924 endif
926 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
927 $(TMP_TARGET) : MODNAME := %(modname)
928 $(TMP_TARGET) : MODTYPE := %(modtype)
929 $(TMP_TARGET) : $(TMP_DEPS)
930         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
931 %end
932 #------------------------------------------------------------------------------
935 #------------------------------------------------------------------------------
936 # Generate the support files for compiling a module. This includes include
937 # files and source files. This rule has to be preceeded by
938 # %rule_genmodule_makefile
939 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
940     conffile=
942 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
943                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
944 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
945                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
947 TMP_DEPS := $(GENMODULE)
948 TMP_OPTS :=
950 ifneq (%(conffile),)
951     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
952     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
953 else
954     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
955     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
956 endif
957 ifneq (%(modsuffix),)
958     TMP_OPTS += -s %(modsuffix)
959 endif
960 ifneq (%(targetdir),)
961     TMP_OPTS += -d %(targetdir)
962     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
963     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
964 endif
966 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
967 $(TMP_TARGETS) : MODNAME := %(modname)
968 $(TMP_TARGETS) : MODTYPE := %(modtype)
969 $(TMP_TARGETS) : $(TMP_DEPS)
970         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
971 ifneq (%(conffile),lib.conf)
972         @$(IF) $(TEST) -f lib.conf; then \
973           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
974         fi
975 endif
976         @$(IF) $(TEST) -f libdefs.h; then \
977           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
978         fi
979         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
980 %end
981 #------------------------------------------------------------------------------
984 #------------------------------------------------------------------------------
985 # Generate the support files for compiling a module. This includes include
986 # files and source files.
987 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
988     targetdir= conffile=
990 ifneq ($(%(modname)_INCLUDES),)
991 TMP_TARGETS := $(%(modname)_INCLUDES)
993 TMP_DEPS := $(GENMODULE)
994 TMP_OPTS :=
996 ifneq (%(conffile),)
997     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
998     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
999 else
1000     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1001     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1002 endif
1003 ifneq (%(modsuffix),)
1004     TMP_OPTS += -s %(modsuffix)
1005 endif
1006 ifneq (%(targetdir),)
1007     TMP_OPTS += -d %(targetdir)
1008     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1009 endif
1011 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1012 $(TMP_TARGETS) : MODNAME := %(modname)
1013 $(TMP_TARGETS) : MODTYPE := %(modtype)
1014 $(TMP_TARGETS) : $(TMP_DEPS)
1015         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1016         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1017 endif
1018 %end
1019 #------------------------------------------------------------------------------
1022 #------------------------------------------------------------------------------
1023 # Common rules for all makefiles
1024 %define common
1025 # Delete generated makefiles
1027 clean ::
1028         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1030 include $(SRCDIR)/config/make.tail
1032 BDID := $(BDTARGETID)
1033 %end
1034 #------------------------------------------------------------------------------
1035       
1037 #############################################################################
1038 #############################################################################
1039 ##                                                                         ##
1040 ## Here are the mmakefile build macros. These are macros that takes care   ##
1041 ## of everything to go from the sources to the generated target. Also all  ##
1042 ## intermediate files and directories that are needed are created by these ##
1043 ## rules.                                                                  ##
1044 ##                                                                         ##
1045 #############################################################################
1046 #############################################################################
1048 #------------------------------------------------------------------------------
1049 # Build a program
1050 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1051     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1052     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1053     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1054     compiler=target linker= srcdir=
1056 .PHONY : %(mmake)
1058 BD_PROGNAME  := %(progname)
1059 BD_OBJDIR    := %(objdir)
1060 BD_TARGETDIR := %(targetdir)
1061 BD_LINKER    := %(linker)
1063 # If not supplied, linker is equal to compiler
1064 ifeq ($(BD_LINKER),)
1065     BD_LINKER := %(compiler)
1066 endif
1068 BD_FILES     := %(files)
1069 BD_CXXFILES  := %(cxxfiles)
1070 BD_ASMFILES  := %(asmfiles)
1072 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1073 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1074 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1076 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))
1077 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES)))
1079 BD_CFLAGS    := %(cflags)
1080 BD_AFLAGS    := %(aflags)
1081 BD_DFLAGS    := %(dflags)
1082 BD_LDFLAGS   := %(ldflags)
1085 %(mmake)-quick : %(mmake)
1087 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1088 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1090 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1091 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1092     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1093 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1094     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1095 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1096     aflags=$(BD_AFLAGS) compiler=%(compiler)
1098 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1099     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1100     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1101     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1102     linker=$(BD_LINKER)
1104 endif
1106 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1108 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1109 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1110 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1112 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1114 %(mmake)-clean ::
1115         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1116         @$(RM) $(FILES)
1118 %end
1119 #------------------------------------------------------------------------------
1122 #------------------------------------------------------------------------------
1123 # Build programs, for every C file an executable will be built with the same
1124 # name as the C file
1125 %define build_progs mmake=/A files=/A nix=no \
1126     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1127     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1128     uselibs= usehostlibs= usestartup=yes detach=no
1130 .PHONY : %(mmake)
1132 BD_OBJDIR    := %(objdir)
1133 BD_TARGETDIR := %(targetdir)
1135 BD_FILES     := %(files)
1136 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1137 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1138 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1140 BD_CFLAGS    := %(cflags)
1141 BD_DFLAGS    := %(dflags)
1142 BD_LDFLAGS   := %(ldflags)
1145 %(mmake)-quick : %(mmake)
1147 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1148 %(mmake) : $(BD_EXES)
1150 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1151 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1152     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1154 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1155     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1156     ldflags=$(BD_LDFLAGS) \
1157     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1158     usestartup="%(usestartup)" detach="%(detach)"
1160 endif
1162 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1164 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1165 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1166 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1168 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1170 %(mmake)-clean ::
1171         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1172         @$(RM) $(FILES)
1174 %end
1175 #------------------------------------------------------------------------------
1178 #------------------------------------------------------------------------------
1179 # Build a module.
1180 # This is a bare version: It just compiles and links the given files. It is
1181 # assumed that all needed boiler plate code is in the files. This should only
1182 # be used for compiling external code. For AROS code use %build_module
1183 %define build_module_simple mmake=/A modname=/A modtype=/A \
1184     files="$(basename $(call WILDCARD, *.c))" \
1185     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1186     objdir=$(OBJDIR) moduledir= \
1187     uselibs= usehostlibs= compiler=target
1189 # Define metamake targets and their dependencies
1190 #MM %(mmake) : core-linklibs includes-generate-deps
1191 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1192 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1193 #MM %(mmake)-kobj-quick
1194 #MM %(mmake)-pkg-quick
1195 #MM %(mmake)-quick
1196 #MM %(mmake)-clean
1198 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1200 .PHONY : $(BD_ALLTARGETS)
1202 ifeq (%(modname),)
1203 $(error using %build_module_simple: modname may not be empty)
1204 endif
1205 ifeq (%(modtype),)
1206 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1207 endif
1209 # Default values for variables and arguments
1210 BD_DEFLINKLIBNAME := %(modname)
1211 BD_DEFDFLAGS := %(cflags)
1212 OBJDIR ?= $(GENDIR)/$(CURDIR)
1213 BD_MODDIR := %(moduledir)
1214 ifeq ($(BD_MODDIR),)
1215   ifeq (%(modtype),library)
1216     BD_MODDIR  := $(AROS_LIBS)
1217   endif
1218   ifeq (%(modtype),gadget)
1219     BD_MODDIR  := $(AROS_GADGETS)
1220   endif
1221   ifeq (%(modtype),datatype)
1222     BD_MODDIR  := $(AROS_DATATYPES)
1223   endif
1224   ifeq (%(modtype),handler)
1225     BD_MODDIR  := $(AROS_FS)
1226   endif
1227   ifeq (%(modtype),device)
1228     BD_MODDIR  := $(AROS_DEVS)
1229   endif
1230   ifeq (%(modtype),resource)
1231     BD_MODDIR  := $(AROS_RESOURCES)
1232   endif
1233   ifeq (%(modtype),hook)
1234     BD_MODDIR  := $(AROS_RESOURCES)
1235   endif
1236   ifeq (%(modtype),mui)
1237     BD_MODDIR  := $(AROS_CLASSES)/Zune
1238   endif
1239   ifeq (%(modtype),mcc)
1240     BD_MODDIR  := $(AROS_CLASSES)/Zune
1241   endif
1242   ifeq (%(modtype),mcp)
1243     BD_MODDIR  := $(AROS_CLASSES)/Zune
1244   endif
1245   ifeq (%(modtype),usbclass)
1246     BD_MODDIR  := $(AROS_CLASSES)/USB
1247   endif
1248   ifeq (%(modtype),hidd)
1249     BD_MODDIR  := $(AROS_DRIVERS)
1250   endif
1251   ifeq (%(modtype),printer)
1252     BD_MODDIR  := $(AROS_PRINTERS)
1253   endif
1254 endif
1255 ifeq ($(BD_MODDIR),)
1256   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1257 endif
1259 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1260 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1261 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1263 %rule_compile_multi \
1264     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1265     cflags="%(cflags)" dflags="%(dflags)" \
1266     compiler=%(compiler)
1268 # Handlers use dash instead of dot in their names
1269 ifeq (%(modtype),handler)
1270 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1271 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1272 else
1273 ifeq (%(modtype),printer)
1274 BD_MODULE := $(BD_MODDIR)/%(modname)
1275 BD_PKGMOD := $(PKGDIR)/%(modname)
1276 else
1277 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1278 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1279 endif
1280 endif
1281 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1283 %(mmake)-quick : %(mmake)
1284 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1285 %(mmake)-kobj-quick : $(BD_KOBJ)
1286 %(mmake)       : $(BD_MODULE)
1287 %(mmake)-pkg   : $(BD_PKGMOD)
1288 %(mmake)-kobj  : $(BD_KOBJ)
1290 # The module is linked from all the compiled .o files
1291 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1293 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1294 # This breaks con-handler build. Here we work around this
1295 ifeq (%(modname),con)
1296     BD_ERR := $(notdir $(BD_MODULE)).err
1297 else
1298     BD_ERR := %(modname).err
1299 endif
1301 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1302                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1303                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1305 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1306                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1307                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1309 # Link kernel object file
1310 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1312 # Make these symbols local
1313 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1314             UtilityBase ExpansionBase KeymapBase KernelBase
1316 BD_SYMBOLS := $(BD_KBASE)
1318 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1319 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1320 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1321 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1322 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1323 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1324         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1325         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1326         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1329 ## Dependency fine-tuning
1331 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1332 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1334 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1335 $(BD_MODULE) : | $(BD_MODDIR)
1336 $(BD_KOBJ) : | $(KOBJSDIR)
1337 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1339 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1340 %(mmake)-clean ::
1341         @$(ECHO) "Cleaning up for module %(modname)"
1342         @$(RM) $(FILES)
1343 %end
1344 #------------------------------------------------------------------------------
1347 #------------------------------------------------------------------------------
1348 # Build a module
1349 # Explanation of this macro is done in the developer's manual
1350 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1351   conffile= files="$(basename $(call WILDCARD, *.c))" \
1352   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1353   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1354   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1355   compiler=target nostartup=yes
1357 # Define metamake targets and their dependencies
1358 #MM- includes-all : %(mmake)-includes
1359 #MM- linklibs-%(modname): %(mmake)-linklib
1360 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1361 #MM- includes-%(modname): %(mmake)-includes
1362 #MM- includes-%(modname)_rel : %(mmake)-includes
1363 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1364 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1365 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1366 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1367 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1368 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1369 #MM %(mmake)-quick : %(mmake)-includes-quick
1370 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1371 #MM     includes-generate-deps %(mmake)-fd
1372 #MM %(mmake)-includes-quick
1373 #MM %(mmake)-includes-dirs
1374 #MM %(mmake)-fd
1375 #MM %(mmake)-makefile
1376 #MM %(mmake)-clean
1378 # All MetaMake targets defined by this macro
1379 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1380     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1381     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1382     %(mmake)-linklib %(mmake)-fd
1384 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1386 ifeq (%(modname),)
1387 $(error using %build_module: modname may not be empty)
1388 endif
1389 ifeq (%(modtype),)
1390 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1391 endif
1393 # Default values for variables and arguments
1394 BD_DEFLINKLIBNAME := %(modname)
1395 BD_DEFDFLAGS := %(cflags)
1396 OBJDIR ?= $(GENDIR)/$(CURDIR)
1398 ## Create genmodule include Makefile for the module
1400 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1402 %rule_genmodule_makefile \
1403     modname=%(modname) modtype=%(modtype) \
1404     modsuffix=%(modsuffix) targetdir=%(objdir) \
1405     conffile=%(conffile)
1407 %(objdir)/Makefile.%(modname) : | %(objdir)
1409 GLOB_MKDIRS += %(objdir)
1411 # Do not parse these statements if metatarget is not appropriate
1412 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1414 include %(objdir)/Makefile.%(modname)
1416 BD_DEFMODDIR := $(%(modname)_MODDIR)
1419 ## include files generation
1421 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1422 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1423 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1425 %(mmake)-includes-quick : %(mmake)-includes
1426 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1427     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1428     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1430 ifneq ($(%(modname)_INCLUDES),)
1431 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1432                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1433                          conffile=%(conffile)
1435 %rule_copy_diff_multi \
1436     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1437     stampfile=%(objdir)/%(modname)_geninc
1439 %rule_copy_diff_multi \
1440     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1441     stampfile=%(objdir)/%(modname)_incs
1443 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1445 TMP%(modname)_INCDIRS := \
1446     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1447     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1448     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1449 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1451 endif
1453 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1454                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1455                            conffile=%(conffile) version=%(version)
1457 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1458 $(BD_DEFLIBDEFSINC) :
1459         @$(ECHO) "generating $@"
1460         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1462 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1463 GLOB_MKDIRS += %(objdir)/include
1465 ## Extra genmodule src files generation
1466 ## 
1467 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1468                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1469                       conffile=%(conffile)
1472 ## Create FD file
1473 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1474 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1476 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1477                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1479 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1481 GLOB_MKDIRS += $(BD_FDDIR)
1484 ## Compilation
1486 BD_FILES      := %(files)
1487 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1488 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1489 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1491 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1492 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1493 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1495 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1496 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1498 ifeq (%(modtype),library)
1499     BD_LIBSUFFIX := 
1500 else
1501     BD_LIBSUFFIX := .%(modtype)
1502 endif
1504 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1505 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1506 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1507     BD_LINKLIB :=
1508 else
1509     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1510 endif
1511 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1513 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1514 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1515 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1516     BD_RELLINKLIB :=
1517 else
1518     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1519 endif
1520 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1522 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1523 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1524     $(BD_RELLINKLIBCFILES)
1526 %rule_compile_multi \
1527     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1528     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1529     compiler=%(compiler)
1530 %rule_compile_multi \
1531     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1532     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1533     compiler=%(compiler)
1535 ifneq ($(BD_LINKLIBAFILES),)
1536 %rule_assemble_multi \
1537     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1538 endif
1540 ## Linking
1542 ifeq (%(modsuffix),)
1543 BD_SUFFIX := %(modtype)
1544 else
1545 BD_SUFFIX := %(modsuffix)
1546 endif
1548 # Handlers use dash instead of dot in their names
1549 ifeq ($(BD_SUFFIX),handler)
1550 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1551 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1552 else
1553 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1554 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1555 endif
1556 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1558 %(mmake)-quick      : %(mmake)
1559 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1560 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1561 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1562 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1563 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1564 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1566 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1567                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1569 ifeq (%(nostartup),yes)
1570 # Handlers always have entry point
1571 ifneq (%(modtype),handler)
1572 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1573 endif
1574 endif
1576 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1577 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1578                  %(linklibobjs)
1579 BD_RELLINKLIBOBJS \
1580               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1581                  %(linklibobjs)
1583 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1584 # This breaks con-handler build. Here we work around this
1585 ifeq (%(modname),con)
1586     BD_ERR := $(notdir $(BD_MODULE)).err
1587 else
1588     BD_ERR := %(modname).err
1589 endif
1591 # The module is linked from all the compiled .o files
1592 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1593                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1594                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1596 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1597                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1598                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1600 # Link static lib
1601 ifneq ($(BD_LINKLIB),)
1602 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1604 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1605 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1606 endif
1608 ifneq ($(BD_RELLINKLIB),)
1609 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1611 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1612 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1613 endif
1615 # Link kernel object file
1616 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1618 # Make these symbols local
1619 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1620             UtilityBase ExpansionBase KeymapBase KernelBase
1622 BD_SYMBOLS := $(BD_KBASE)
1624 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1625 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1626 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1627 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1628 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1629 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1630         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1631         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1632         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1634 ## Dependency fine-tuning
1636 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1637 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1639 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1640 $(BD_MODULE) : | %(prefix)/%(moduledir)
1641 $(BD_PKGMOD) : | $(PKGDIR)
1642 $(BD_KOBJ)   : | $(KOBJSDIR)
1643 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1645 # Some include files need to be generated before the .c can be parsed.
1646 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
1648 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1649     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1650 $(BD_DEPS) : $(BD_DFILE_DEPS)
1651 endif
1653 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1654     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1655     %(objdir)/Makefile.%(modname) \
1656     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1657     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1658     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1659     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1660     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1661     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1662     $(BD_ENDOBJS)
1663 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1664 %(mmake)-clean ::
1665         @$(ECHO) "Cleaning up for module %(modname)"
1666         @$(RM) $(FILES)
1668 endif # $(TARGET) in $(BD_ALLTARGETS)
1669 %end
1670 #------------------------------------------------------------------------------
1673 #------------------------------------------------------------------------------
1674 # Build a module skeleton
1675 # This is a stripped-down version of build_module, it only creates include files,
1676 # but no actual object. This is used when for plugins or classes with the same
1677 # API, but no actual implementation here.
1678 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1679   conffile= \
1680   objdir=$(OBJDIR) prefix=$(AROSDIR)
1682 # Define metamake targets and their dependencies
1683 #MM- includes-all : %(mmake)-includes
1684 #MM %(mmake) : %(mmake)-includes core-linklibs
1685 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1686 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1687 #MM %(mmake)-linklib : %(mmake)-includes
1688 #MM %(mmake)-quick : %(mmake)-includes-quick
1689 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1690 #MM     includes-generate-deps
1691 #MM %(mmake)-includes-quick
1692 #MM %(mmake)-includes-dirs
1693 #MM %(mmake)-makefile
1694 #MM %(mmake)-clean
1696 # All MetaMake targets defined by this macro
1697 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1698     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1699     %(mmake)-kobj %(mmake)-pkg
1701 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1703 ifeq (%(modname),)
1704 $(error using %build_module_skeleton: modname may not be empty)
1705 endif
1706 ifeq (%(modtype),)
1707 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1708 endif
1710 # Default values for variables and arguments
1711 BD_DEFLINKLIBNAME := %(modname)
1712 BD_DEFDFLAGS := %(cflags)
1713 OBJDIR ?= $(GENDIR)/$(CURDIR)
1715 ## Create genmodule include Makefile for the module
1717 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1719 %rule_genmodule_makefile \
1720     modname=%(modname) modtype=%(modtype) \
1721     modsuffix=%(modsuffix) targetdir=%(objdir) \
1722     conffile=%(conffile)
1724 %(objdir)/Makefile.%(modname) : | %(objdir)
1726 GLOB_MKDIRS += %(objdir)
1728 # Do not parse these statements if metatarget is not appropriate
1729 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1731 include %(objdir)/Makefile.%(modname)
1733 BD_DEFMODDIR := $(%(modname)_MODDIR)
1736 ## include files generation
1738 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1739 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1740 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1742 %(mmake)-includes-quick : %(mmake)-includes
1743 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1744     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1745     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1747 ifneq ($(%(modname)_INCLUDES),)
1748 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1749                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1750                          conffile=%(conffile)
1752 %rule_copy_diff_multi \
1753     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1754     stampfile=%(objdir)/%(modname)_geninc
1756 %rule_copy_diff_multi \
1757     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1758     stampfile=%(objdir)/%(modname)_incs
1760 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1762 TMP%(modname)_INCDIRS := \
1763     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1764     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1765     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1766 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1768 endif
1770 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1771                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1772                            conffile=%(conffile)
1774 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1775 $(BD_DEFLIBDEFSINC) :
1776         @$(ECHO) "generating $@"
1777         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1779 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1780 GLOB_MKDIRS += %(objdir)/include
1782 ## Extra genmodule src files generation
1783 ## 
1784 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1785                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1786                       conffile=%(conffile)
1788 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1789     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1790     %(objdir)/Makefile.%(modname) \
1791     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1792     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1793     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1794     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1795     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1796     $(BD_DEFLIBDEFSINC)
1797 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1798 %(mmake)-clean ::
1799         @$(ECHO) "Cleaning up for module %(modname)"
1800         @$(RM) $(FILES)
1802 endif # $(TARGET) in $(BD_ALLTARGETS)
1803 %end
1804 #------------------------------------------------------------------------------
1807 #------------------------------------------------------------------------------
1808 # Build a linklib.
1809 # - mmake is the mmaketarget
1810 # - libname is the baselibname e.g. lib%(libname).a will be created
1811 # - files are the C source files to include in the lib. The list of files
1812 #   has to be given without the .c suffix
1813 # - asmfiles are the asm files to include in the lib. The list of files has to
1814 #   be given without the .s suffix
1815 # - objs additional object to link into the linklib. The objects have to be
1816 #   given with full absolute path and the .o suffix.
1817 # - cflags are the flags to compile the source (default $(CFLAGS))
1818 # - dflags are the flags use during makedepend (default equal to cflags)
1819 # - aflags are the flags use during assembling (default $(AFLAGS))
1820 # - objdir is where the .o are generated
1821 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1822 %define build_linklib mmake=/A libname=/A \
1823   files="$(basename $(call WILDCARD, *.c))" \
1824   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1825   asmfiles= objs= compiler=target \
1826   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1828 # assign and generate the local variables used in this macro
1829 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1831 BD_FILES      := %(files)
1832 BD_CXXFILES   := %(cxxfiles)
1833 BD_ASMFILES   := %(asmfiles)
1835 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1836 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1837 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1839 BD_OBJS       := $(BD_ARCHOBJS) \
1840                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
1841                  %(objs)
1842 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1844 BD_CFLAGS     := %(cflags)
1845 ifeq (%(dflags),)
1846 BD_DFLAGS     := $(BD_CFLAGS)
1847 else
1848 BD_DFLAGS     := %(dflags)
1849 endif
1850 BD_AFLAGS     := %(aflags)
1852 BD_LINKLIB    := %(libdir)/lib%(libname).a
1854 .PHONY : %(mmake) %(mmake)-clean
1856 #MM %(mmake) : includes-generate-deps
1857 %(mmake) : $(BD_LINKLIB)
1860 %(mmake)-clean ::
1861         @$(RM) $(BD_OBJS) $(BD_DEPS)
1863 ifeq ($(TARGET),%(mmake))
1864 ifneq ($(dir $(BD_FILES)),./)
1865 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1866 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1867 endif
1869 %rule_compile basename=% targetdir=%(objdir) \
1870     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1871 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1872     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1873 %rule_assemble basename=% targetdir=%(objdir) \
1874     aflags=$(BD_AFLAGS)
1876 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1877 endif
1879 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1881 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1882 $(BD_LINKLIB) : | %(libdir)
1883 GLOB_MKDIRS += %(objdir) %(libdir)
1885 %end
1886 #------------------------------------------------------------------------------
1889 #------------------------------------------------------------------------------
1890 # Build catalogs.
1891 # - mmake is the mmaketarget
1892 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1893 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1894 # - subdir is the destination subdirectory of the catalogs
1895 # - name is the name of the destination catalog, without the .catalog suffix
1896 # - source is the path to the generated source code file
1897 # - dir is the base destination directory (default $(AROS_CATALOGS))
1898 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1899 # - srcdir is the directory in which the *.cd and *.ct files are searched
1901 %define build_catalogs mmake=/A name=/A subdir=/A \
1902  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1903  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
1905 ifeq (%(description),)
1906 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1907 else
1908 BD_DESC := %(description)
1909 endif
1911 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1913 ifeq (%(catalogs),)
1914 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1915 else
1916 BD_LNGS := %(catalogs)
1917 endif
1919 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1920 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1923 %(mmake) : $(BD_OBJS) %(source)
1925 $(BD_OBJS) : | $(BD_DIRS)
1926 GLOB_MKDIRS += $(BD_DIRS)
1928 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1929         @$(ECHO) "Creating   %(name) catalog for language $*."
1930         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1932 ifneq (%(source),)
1933 %(source) : BD_DESC := $(BD_DESC)
1934 %(source) : BD_SRC := $(BD_SRC)
1935 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
1936         @$(ECHO) "Creating   %(name) catalog source file $@"
1937         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
1938 endif
1941 %(mmake)-clean ::
1942         $(RM) $(BD_OBJS) %(source)
1944 .PHONY: %(mmake) %(mmake)-clean
1946 %end
1947 #-----------------------------------------------------------------------------
1950 #-----------------------------------------------------------------------------
1951 # Build icons.
1952 # - mmake is the mmaketarget
1953 # - icons is a list of icon base names (ie. without the .info suffix)
1954 # - dir is the destination directory
1955 # - srcdir is where *.png and *.info.src are searched
1956 #-----------------------------------------------------------------------------
1958 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1960 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
1963 %(mmake) : $(BD_OBJS)
1965 ifeq (%(image),)
1967 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
1968         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1969         @$(ILBMTOICON) $+ $@
1971 else
1973 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
1974         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
1975         @$(ILBMTOICON) $+ $@
1977 endif
1979 $(BD_OBJS) : | %(dir)
1980 GLOB_MKDIRS += %(dir)
1982 %(mmake)-clean : FILES := $(BD_OBJS)
1984 %(mmake)-clean ::
1985         @$(RM) $(FILES)
1987 .PHONY: %(mmake) %(mmake)-clean
1989 %end
1990 #-----------------------------------------------------------------------------
1993 #------------------------------------------------------------------------------
1994 # Compile files for an arch-specific replacement of code for a module
1995 # - files: the basenames of the C files to compile.
1996 # - asmfiles: the basenames of the asm files to assemble.
1997 # - mainmmake: the mmake of the module in the main directory to compile these
1998 #   arch specific files for.
1999 # - maindir: the object directory for the main module
2000 # - arch: the arch for which to compile these files. It can have the form
2001 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2002 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2003 # - dflags: the flags used during creation of dependency file. If not specified
2004 #   the same value as cflags will be used
2005 # - aflags: the flags used during assembling
2006 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2007 #   the target compiler is used
2008 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2009 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2011 ifeq (%(files) %(asmfiles),)
2012   $(error no files or asmfiles given)
2013 endif
2015 %buildid targets="%(mainmmake)-%(arch)"
2017 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2018 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2019 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2020 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2021 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2022 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2023 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2024 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2025 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2026 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2027 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2028 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2029 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2030 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2031 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2032 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2033 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2034 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2035 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2036 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2037 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2039 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2041 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2042 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2043 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2044 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2045 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2047 ifneq (%(modulename),)
2048 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2049 endif
2051 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2052     BD_TARGET := %(mainmmake)-%(arch)-quick
2053 else
2054     BD_TARGET := %(mainmmake)-%(arch)
2055 endif
2058 ifeq ($(TARGET),$(BD_TARGET))
2059 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2060 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2061 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2062 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2063 endif
2065 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2066 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2069 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2072 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2074 ifeq ($(findstring %(compiler),host kernel target),)
2075   $(error unknown compiler %(compiler))
2076 endif
2077 ifeq (%(compiler),target)
2078 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2079 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2080 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2081 endif
2082 ifeq (%(compiler),host)
2083 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2084 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2085 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2086 endif
2087 ifeq (%(compiler),kernel)
2088 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2089 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2090 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2091 endif
2092 ifneq (%(modulename),)
2093 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2094 else
2095 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2096 endif
2097 ifeq ($(TARGET),$(BD_TARGET))
2098 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2099         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2100 endif
2102 ifeq (%(dflags),)
2103 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2104 else
2105 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2106 endif
2107 ifeq ($(TARGET),$(BD_TARGET))
2108 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2109         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2110 endif
2112 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2114 ifeq ($(TARGET),$(BD_TARGET))
2115 $(BD_OBJDIR$(BDID))/%.o : %.s
2116         %assemble_q opt=$(AFLAGS)
2117 $(BD_OBJDIR$(BDID))/%.o : %.S
2118         %assemble_q opt=$(AFLAGS)
2119 endif
2121 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2122 %end
2123 #------------------------------------------------------------------------------
2126 #------------------------------------------------------------------------------
2127 # generate asm files from c files (for debugging purposes)
2128 %define ctoasm_q
2129 %.s : %.c
2130         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2131         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2132 %end
2133 #------------------------------------------------------------------------------
2136 #------------------------------------------------------------------------------
2137 # Copy files from one directory to another.
2139 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2141 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2143 GLOB_MKDIRS += %(dst)
2145 .PHONY : %(mmake)
2148 %(mmake) : | %(dst) 
2149         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2151 %end
2152 #------------------------------------------------------------------------------
2155 #------------------------------------------------------------------------------
2156 # Copy a directory recursively to another place, preserving the original 
2157 # hierarchical structure
2159 # src: the source directory whose content will be copied
2160 # dst: the directory where to copy src's content. If not existing, it will be made.
2162 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2164 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2165 %(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)
2166 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2168 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2169 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2171 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2173 .PHONY : %(mmake)
2176 %(mmake): | $(GENDIR)/$(CURDIR)
2177         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2178         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2179         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2180         for d in $(%(mmake)_DIRS); do                      \
2181             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2182         done
2183         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2184         for f in $(%(mmake)_FILES); do                                            \
2185             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2186         done;  \
2187         for dst in %(dst); do \
2188             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2189         done
2191 %end
2192 #------------------------------------------------------------------------------
2195 #------------------------------------------------------------------------------
2196 #   Copy include files into the includes directories. There are currently
2197 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2198 #   for building tools that need to run on the host system $(GENINCDIR). The
2199 #   $(GENINCDIR) path must not contain any references to the C runtime
2200 #   library header files.
2202 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2203     dir= compiler=target
2205 ifeq ($(findstring %(compiler),host kernel target),)
2206 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2207 endif
2209 ifneq (%(dir),)
2210 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2211 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2212 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2213 else
2214 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2215 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2216 endif
2218 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2219         @$(CP) $< $@
2222 ifeq (%(compiler),target)
2224 ifneq (%(dir),)
2225 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2226 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2227 else
2228 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2229 endif
2231 BD_INCL_FILES += $(BD_INCL_FILES2)
2233 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2234         @$(CP) $< $@
2235 endif
2238 %(mmake) : $(BD_INCL_FILES)
2240 .PHONY: %(mmake)
2242 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2243 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2244 %end
2245 #------------------------------------------------------------------------------
2248 #------------------------------------------------------------------------------
2249 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2250 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2251 STUBS_MEM := $(addsuffix .o,$(STUBS))
2252 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2253 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2254 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2256 #MM- linklibs : hidd-%(hidd)-stubs
2257 #MM- %(parenttarget): hidd-%(hidd)-stubs
2258 #MM hidd-%(hidd)-stubs : includes includes-copy
2259 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2261 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2262         %mklib_q from=$^
2264 $(STUBS_OBJ) : $(STUBS_SRC) 
2265         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2267 $(STUBS_DEP) : $(STUBS_SRC)
2268         %mkdepend_q flags=%(dflags)
2270 setup ::
2271         %mkdirs_q $(OBJDIR) $(LIBDIR)
2274 clean ::
2275         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2277 DEPS := $(DEPS) $(STUBS_DEP)
2279 %end
2280 #------------------------------------------------------------------------------
2283 #------------------------------------------------------------------------------
2284 # Build an imported source tree which uses the configure script from the
2285 # autoconf package.  This rule will try to "integrate" the produced files as
2286 # much as possible in the AROS build, for example by putting libraries in the
2287 # standard library directory, includes in the standard include directory, and
2288 # so on. You can however override this behaviour.
2290 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2291 # be %(bindir) (or its deduced value) when running "make install", and
2292 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2293 # configure script some more parameters whose value depends upon the PROGDIR
2294 # env var, so that the program gets all its stuff installed in the proper place
2295 # when building it, but when running it from inside AROS it can also find that
2296 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2297 # the configuration parameters set when running ./configure
2299 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2300 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2301 # to the name which has to follow it.
2304 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2305     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2306     install_target=install preconfigure= postconfigure= postinstall= \
2307     install_env= use_build_env=no
2309 ifneq (%(prefix),)
2310     %(mmake)-prefix := %(prefix)
2311 else
2312     %(mmake)-prefix := $(AROS_CONTRIB)
2313 endif
2315 ifneq (%(aros_prefix),)
2316     %(mmake)-aros_prefix := %(aros_prefix)
2317 else
2318     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2319 endif
2321 ifeq (%(nix),yes)
2322     %(mmake)-nix    := -nix
2323     %(mmake)-volpfx := /
2324     %(mmake)-volsfx := /
2325     
2326     ifeq (%(nix_dir_layout),)
2327         %(mmake)-nix_dir_layout := yes
2328     endif
2329 else
2330     %(mmake)-volsfx := :
2331     
2332     ifeq (%(nix_dir_layout),)
2333         %(mmake)-nix_dir_layout := no
2334     endif
2335 endif
2337 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2339 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2340         exec_prefix=$(%(mmake)-prefix) %(install_env)
2342 # Check if chosen compiler is valid
2343 ifeq ($(findstring %(compiler),host target kernel),)
2344   $(error unknown compiler %(compiler))
2345 endif
2347 # Set legacy 'host' variable based on chosen compiler
2348 ifeq (%(compiler),host)
2349     host := yes
2350         ifeq (%(package),)
2351                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2352         else
2353                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2354         endif
2355 else
2356     host := no
2357         ifeq (%(package),)
2358                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2359         else
2360                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2361         endif
2362 endif
2364 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2365 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2367 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2368     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2369     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2370 else
2371     ifeq (%(nix),yes)
2372         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2373         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2374     else
2375         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2376     endif
2378     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2379     
2380     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2381         sbindir=$(%(mmake)-prefix) \
2382         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2383         oldincludedir=$(AROS_INCLUDES) %(install_env)
2384 endif
2386 ifneq ($(DEBUG),yes)
2387     %(mmake)-s_flag = -s
2388 endif
2390 # Set up build environment, and options for configure script
2391 ifeq (%(compiler),host)
2392     CONFIG_ENV := \
2393         CPP="$(HOST_CPP)" \
2394         CXXCPP="$(HOST_CPP)" \
2395         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2396         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2397         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2398         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2399         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2400         TARGET_NM="$(NM_PLAIN)"
2401 endif
2402 ifeq (%(compiler),target)
2403     CONFIG_ENV := \
2404         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2405         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2406         CPP="$(TARGET_CPP)" \
2407         CXXCPP="$(TARGET_CPP)" \
2408         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2409         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2410         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2411         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2412         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2413         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2414         TARGET_NM="$(NM_PLAIN)" \
2415         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2416         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2417     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2418         --host=$(AROS_TARGET_CPU)-aros\
2419         --target=$(AROS_TARGET_CPU)-aros\
2420         --disable-nls\
2421         --without-x --without-pic --disable-shared
2422 endif
2423 ifeq (%(compiler),kernel)
2424     CONFIG_ENV := \
2425         CPP="$(KERNEL_CPP)" \
2426         CXXCPP="$(KERNEL_CPP)" \
2427         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2428         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2429         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2430         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2431         TARGET_NM="$(NM_PLAIN)"
2432     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2433         --host=$(AROS_TARGET_CPU)-aros\
2434         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2435         --without-x --without-pic --disable-shared
2436 endif
2438 ifeq (%(use_build_env),yes)
2439     BUILD_ENV := $(CONFIG_ENV)
2440 endif
2443 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2445 # When building for the host, we don't need to build the
2446 # linklibs - this is especially true when building the
2447 # crosstool toolchain on 'foreign' architectures (such as
2448 # building PPC on x86)
2450 #MM- %(mmake)-host : setup includes %(mmake)-quick
2451 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2452 #MM- %(mmake): %(mmake)-%(compiler)
2454 # Using -j1 in install_command may result in a warning but finally
2455 # it does its job. make install for gcc does not work reliably for -jN
2456 # where N > 1.
2457 ifneq (%(install_target),)
2458     %(mmake)-install_command = \
2459         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2460         -C $(%(mmake)-pkgdir) %(install_target) -j1
2462     %(mmake)-uninstall_command = \
2463     $(RM) $(%(mmake)-installflag) && \
2464     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2465     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2466 else
2467     %(mmake)-install_command   := true
2468     %(mmake)-uninstall_command := true
2469 endif
2471 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2474 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2476 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2477         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2478             $(RM)  $(%(mmake)-installflag) && \
2479             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2480              -C $(%(mmake)-pkgdir) && \
2481             $(%(mmake)-install_command) && \
2482             $(TOUCH) $@ -r $^; \
2483         fi
2485 $(%(mmake)-pkgdir)/.files-touched:
2486         %mkdirs_q $(%(mmake)-pkgdir)
2487         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2488         $(TOUCH) $@
2491 %(mmake)-uninstall :
2492         $(%(mmake)-uninstall_command)
2495 %(mmake)-configure : $(%(mmake)-configflag)
2497 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2498 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2499         $(RM) $@
2500         %mkdirs_q $(%(mmake)-pkgdir)
2501         cd $(%(mmake)-pkgdir) && \
2502         find . -name config.cache -exec $(RM) '{}' \; && \
2503         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2504             %(extraoptions) && \
2505         $(TOUCH) $@
2508 %(mmake)-clean : %(mmake)-uninstall
2509         @$(RM) $(%(mmake)-pkgdir)
2510 %end
2511 #------------------------------------------------------------------------------
2514 #------------------------------------------------------------------------------
2515 # Given an archive name, patches names and locations where to find them, fetch
2516 # the archive and the patches from any of those locations, unpack the archive
2517 # and then apply the patches.
2519 # Locations currently supported are http and ftp sites, plus local filesystem
2520 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2521 # the fetch.sh script needs to be modified, since this macro relies on that script.
2523 # Arguments:
2525 #     - mmake           = mmaketarget
2526 #     - archive_origins = list of locations where to find the archive. They are tried
2527 #                         in sequence, until the archive is found and fetching it 
2528 #                         succeeded. If not specified, the current directory is assumed.
2529 #     - archive         = the archive name. Mandatory.
2530 #     - suffixes        = a list of suffixes to append to the the package name plus the
2531 #                         version. Each one of them is tried until a matching archive is
2532 #                         found. They are appended to patches and these are tried the
2533 #                         same way as packages are.
2534 #     - location        = the local directory where to put the fetched archive and patches.
2535 #                         If not specified, the directory specified by destination is used.
2536 #     - destination     = the directory to unpack the archive to.
2537 #                         If not specified, the current directory is assumed.
2538 #     - patches_origins = list of locations where to find the patches. They are tried
2539 #                         in sequence, until a patch is found and fetching it 
2540 #                         succeeded. If not specified, the current directory is assumed.
2541 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2542 #                         patch_name[:[patch_subdir][:patch_opt]].
2544 #                             - patch_name   = the name of the patch file
2545 #                             - patch_subdir = the directory within \destination\ where to
2546 #                                              apply the patch.
2547 #                             - patch_opt    = any options to pass to the `patch' command
2548 #                                              when applying the patch.
2549 #                         
2550 #                         The patch_subdir and patch_opt fields are optional.
2552 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2553     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2555 .PHONY: %(mmake)
2557 ifneq (%(location),)
2558     %(mmake)-location := %(location)
2559 else
2560     %(mmake)-location := %(destination)
2561 endif
2564 %(mmake) :
2565         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2566         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2567 %end
2568 #------------------------------------------------------------------------------
2571 #------------------------------------------------------------------------------
2572 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2573 # unpatched source tree and runs diff against this and a previously fetched and possibly
2574 # patched tree. Depending on what happens after patching during a normal build it might
2575 # give best results if the new patch is created directly after fetch.
2577 # Arguments:
2579 #     - mmake       = mmaketarget
2580 #     - archive     = archive base name
2581 #     - srcdir      = directory the package is unpacked to, useful if archive unpacks to
2582 #                     a directory other than its name suggests.
2583 #     - suffixes    = a list of suffixes to append to the the package name plus the
2584 #                     version. Each one of them is tried until a matching archive is
2585 #                     found.
2586 #     - destination = the directory to unpack the archive to.
2587 #     - excludes    = diff patterns to exclude files or directories from the patch
2589 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2591 .PHONY: %(mmake)
2593 ifneq (%(excludes),)
2594     %(mmake)-exclude := -X ./exclude.patterns
2595 endif
2597 ifneq (%srcdir),)
2598     %(mmake)-srcdir := %(srcdir)
2599 else
2600     %(mmake)-srcdir := %(archive)
2601 endif
2604 %(mmake):
2605         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2606         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2607         cd %(destination)/tmp ; \
2608         $(FOR) f in %(excludes) ; do \
2609             $(ECHO) $$f >> ./exclude.patterns ; \
2610         done ; \
2611         diff -ruN $(%(mmake)-exclude) \
2612             $(%(mmake)-srcdir) \
2613             $(%(mmake)-srcdir).aros \
2614             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2615         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2616         $(RM) %(destination)/tmp
2617 %end
2618 #------------------------------------------------------------------------------
2621 #------------------------------------------------------------------------------
2622 # Joins the features of %fetch and %build_with_configure, taking advantage of
2623 # the naming scheme of GNU packages. GNU packages names are in the form
2625 #     <package name>-<version number>.<archive format suffix>
2627 # If a patch is provided, it *must* be named the following way:
2629 #    <package name>-<version number>-aros.diff
2631 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2632 # CD'ing into the archive's extracted directory.
2634 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2635 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2636 # to make that patch fully comprehensive.
2638 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2640 # Arguments:
2642 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2643 #                     macro.
2644 #    - package      = the GNU package name, sans version and archive format suffixes.
2645 #    - version      = the package's version number, or otherwise any other version string.
2646 #                     It gets appended to the package name to form the basename of the archive.
2647 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2648 #                     version. Each one of them is tried until a matching archive is found.
2649 #                     Defaults to "tar.bz2 tar.gz".
2650 #    - destination  = same meaning as the one for the %fetch macro
2651 #    - location     = same meaning as the one for the %fetch macro
2652 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2653 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2654 #                     fetched or not
2655 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2656 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2657 #                     $(GNUDIR).
2658 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2659 #                     /GNU.
2660 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2661 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2662 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2663 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2665 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2666     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2667     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2669 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2670 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2671 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2672 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2674 %(mmake)-archbase  := %(package)-%(version)
2676 ifeq (%(compiler),host)
2677     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2678 else
2679     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2680 endif
2682 ifeq (%(prefix),)
2683     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2684 else
2685     %(mmake)-prefix := %(prefix)
2686 endif
2688 ifneq (%(subpackage),)
2689     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2690 else
2691     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2692 endif
2694 ifneq (%(srcdir),)
2695     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2696 else
2697     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2698 endif
2700 ifeq (%(patch),yes)
2701     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
2702 else
2703     %(mmake)-%(subpackage)-patches_specs := ::
2704 endif
2706 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2707     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2708     archive_origins=". %(package_repo)" \
2709     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2711 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2712     archive=$(%(mmake)-%(subpackage)-archbase) \
2713     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2714     suffixes="%(suffixes)" \
2715     destination=$(%(mmake)-portdir)
2717 #MM- %(mmake) : %(mmake)-%(subpackage)
2719 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2721 %(mmake)-%(subpackage)-package-basename := \
2722     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2724 ifneq (%(create_pkg),no)
2725     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2726 endif
2728 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2729      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2730      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2731      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2732      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2734 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2735 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2738 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2740 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2741 #that $^ and $@ have exactly the same mtime, and in that case make tries
2742 #to rebuild $@ again, which would fail because the directory where
2743 #the package got installed would not exist anymore. 
2744 #We work this around by using an if statement to manually check the mtimes.
2745 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2746         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2747         $(RM) $@ ; \
2748         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2749         mkdir -p "$(DISTDIR)/Packages" ; \
2750         mkdir -p "$(%(mmake)-prefix)" ; \
2751         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2752         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2753         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2754     fi
2755 %end
2756 #------------------------------------------------------------------------------
2759 #------------------------------------------------------------------------------
2760 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2761     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2762     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2764 GNU_REPOSITORY := gnu://
2766 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2767     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2768     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2769     patch="%(patch)" patch_repo="%(patch_repo)" \
2770     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2771     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2773 %end
2774 #------------------------------------------------------------------------------
2777 #------------------------------------------------------------------------------
2778 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2779 # that the package is a "Development" package, and as such it needs to be placed
2780 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2782 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2783 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2784 # "mmake" argument, because the metatarget is implicitely defined as
2786 #     #MM- development-%(package)
2788 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2789     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2790     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2792 #MM- development : development-%(package)
2795 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2796    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2797    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2798    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2799    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2802 postinstall-%(package)-delete-la-files:
2803         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2805 %end
2806 #------------------------------------------------------------------------------
2808 # Builds a kickstart package in PKG format
2809 # mmake   - target name
2810 # file    - Destination file name with path
2811 # startup - The file which will be put first
2812 # Other arguments are self-explanatory
2814 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2816 PKG_CLASSES   := $(addsuffix .class, %(classes))
2817 PKG_DEVICES   := $(addsuffix .device, %(devs))
2818 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2819 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2820 PKG_LIBS      := $(addsuffix .library, %(libs))
2821 PKG_RESOURCES := $(addsuffix .resource, %(res))
2823 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2824 PKG_DIR   := $(dir %(file))
2825 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2828 %(mmake) : %(file)
2831 %(mmake)-quick : %(file)
2833 %(file): PKG_FILES := $(PKG_FILES)
2834 %(file): $(PKG_DEPS) | $(PKG_DIR)
2835         @$(ECHO) Packaging $@...
2836         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2838 %compress_file mmake=%(mmake) file=%(file)
2840 GLOB_MKDIRS += $(PKG_DIR)
2842 %end
2844 #------------------------------------------------------------------------------
2845 # Compresses %(file) with a gzip.
2846 # Good in conjunction with for example %build_prog
2848 %define compress_file mmake=/A file=/A
2850 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2853 %(mmake)-gz-quick : %(file).gz
2855 %(file).gz: %(file)
2856         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2857         @gzip -9 -f $^
2859 %end
2861 #------------------------------------------------------------------------------
2862 # Links a kickstart module in ELF format
2863 # Arguments are similar to make_package
2865 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2866     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2868 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2869 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2870 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2871 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2872 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2873 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2875 ifeq (%(startup),)
2876     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2877 else
2878     KOBJ_STARTUP := %(startup)
2879 endif
2881 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2883 TMP_LDFLAGS := %(ldflags)
2885 # Make a list of the lib files this program depends on.
2886 # In LDFLAGS remove white space between -L and directory
2887 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2888 # Filter out only the libdirs and remove -L
2889 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2890 # Add trailing /
2891 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2892 # Add normal linklib path
2893 TMP_DIRS += $(LIBDIR)/
2894 # add lib and .a to static linklib names
2895 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2896 # search for the linklibs in the given path, ignore ones not found
2897 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2898     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2901 TMP_DIRS += $(dir %(file))
2902 ifneq (%(map),)
2903     TMP_LDFLAGS += $(GENMAP) %(map)
2904     TMP_DIRS    += $(dir %(map))
2905 endif
2907 #MM %(mmake) : %(deps)
2910 %(mmake) : %(file)
2913 %(mmake)-quick : %(file)
2915 %(file): KOBJS := $(KOBJS)
2916 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2917 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2918 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2919         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2920         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS) -noarosc
2921         @$(STRIP) $@
2923 %compress_file mmake=%(mmake) file=%(file)
2925 GLOB_MKDIRS += $(TMP_DIRS)
2927 %end
2929 #------------------------------------------------------------------------------
2930 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2931 # 'start' is an optional starting address
2932 # 'ldflags' is optional additional flags for the linker
2933 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2935 BD_OUTDIR := $(dir %(file))
2936 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2937 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2938 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2940 %(file) : %(objs) $(BD_OUTDIR)
2941         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2942         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2943         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2945 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2946     GLOB_MKDIRS += $(BD_OUTDIR)
2947 endif
2949 %end