prism2.device: Compiler delint
[AROS.git] / config / make.tmpl
blob7189ce07bc4fabac7d3114ae3cf83e0386d7bfca
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 $(TMP_CXXFLAGS)
396   else
397     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
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
530 endif
532 # Define the use of cross compiler
533 ifeq ($(TARGET_CXX),)
534   TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-g++
535 else
536   TMP_CC := $(TARGET_CXX)
537 endif
539 ifeq ($(findstring %(compiler),host kernel target),)
540   $(error unknown compiler %(compiler))
541 endif
542 ifeq (%(compiler),target)
543   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
544   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
545   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
546 endif
547 ifeq (%(compiler),host)
548   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
549   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
550   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
551 endif
552 ifeq (%(compiler),kernel)
553   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
554   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
555   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
556 endif
558 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
559 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
560         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
562 ifeq (%(dflags),)
563   $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
564 else
565   ifeq (%(dflags),%(cflags))
566     $(TMP_DTARGETS) : DFLAGS:=$(TMP_CXXFLAGS)
567   else
568     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
569   endif
570 endif
571 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
572         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
573 %end
574 #------------------------------------------------------------------------------
577 #------------------------------------------------------------------------------
578 # Make an alias from one arch specific build to another arch.
579 # arguments:
580 # - mainmmake: the mmake of the module in the main tree
581 # - arch: the current arch
582 # - alias: the alias to which this should point
583 %define rule_archalias mainmmake=\A arch=\A alias=\A
585 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
586 %end
587 #------------------------------------------------------------------------------
590 #------------------------------------------------------------------------------
591 # Generate a rule to assemble a source file to an object file. Basename may
592 # contain a directory part, then the source file has to be in that directory.
593 # The generated file will be put in the object directory without the directory.
594 # options
595 # - basename: the basename of the file to compile. Use % for a wildcard rule
596 # - flags (default $(AFLAGS)): the asm flags to use for assembling
597 # - targetdir: the directory to put the .o file in. By default it is put in the
598 #   same directory as the .s file
599 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
601 ifeq (%(targetdir),)
602 %(basename).o : AFLAGS := %(aflags)
603 %(basename).o : %(basename).s
604         %assemble_q
605 %(basename).o : %(basename).S
606         %assemble_q
608 else
609 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
610 %(targetdir)/$(notdir %(basename)).o : %(basename).s
611         %assemble_q
612 %(targetdir)/$(notdir %(basename)).o : %(basename).S
613         %assemble_q
615 endif
616 %end
617 #------------------------------------------------------------------------------
620 #------------------------------------------------------------------------------
621 # Generate a rule to assemble multiple source files to an object file. The
622 # generated file will be put in the object directory with the directory part
623 # of the source file stripped off.
624 # options
625 # - basenames: the basenames of the files to compile. The names may include
626 #   relative or absolute path names. No wildcard is allowed
627 # - aflags (default $(AFLAGS)): the flags to use for assembly
628 # - targetdir: the directory to put the .o file and the .d file. By default
629 #   it is put in the same directory as the .c file. When targetdir is not
630 #   empty, path names will be stripped from the file names so that all files
631 #   are in that dir and not in subdirectories.
632 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
634 ifeq (%(targetdir),)
635 TMP_TARGETS := $(addsuffix .o,%(basenames))
636 TMP_WILDCARD := %
637 else
638 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
639 TMP_WILDCARD := %(targetdir)/%
641 # Be sure that all .s files are generated
642 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
644 # Be sure that all .c files are found
645 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
646 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
647 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
648 ifneq ($(TMP_DIRS),)
649     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
650     vpath %%(suffix) $(TMP_DIRS)
651 endif
653 endif
655 ifeq ($(findstring %(compiler),host kernel target),)
656   $(error unknown compiler %(compiler))
657 endif
658 ifeq (%(compiler),target)
659 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
660 endif
661 ifeq (%(compiler),host)
662 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
663 endif
664 ifeq (%(compiler),kernel)
665 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
666 endif
668 $(TMP_TARGETS) : AFLAGS := %(aflags)
669 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
670         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
671 %end
672 #------------------------------------------------------------------------------
675 #------------------------------------------------------------------------------
676 # Link %(objs) to %(prog) using the libraries in %(uselibs)
677 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
678     usehostlibs= usestartup=yes detach=no nix=no linker=target
680 TMP_EXTRA_LDFLAGS := 
681 TMP_EXTRA_LIBS :=
682 ifeq (%(nix),yes)
683     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
684 endif
685 ifeq (%(usestartup),no)
686     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
687     TMP_EXTRA_LIBS += arosc.static
688     ifeq (%(linker),target)
689         TMP_EXTRA_LIBS += libinit autoinit
690     endif
691 endif
692 ifeq (%(detach),yes)
693     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
694 endif
696 # Make a list of the lib files this program depends on.
697 # In LDFLAGS remove white space between -L and directory
698 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
699 # Filter out only the libdirs and remove -L
700 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
701 # Add trailing /
702 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
703 # Add normal linklib path
704 TMP_DIRS += $(LIBDIR)/
705 # add lib and .a to static linklib names
706 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
707 ifeq (%(usestartup),yes)
708     TMP_LIBS += startup.o
709 endif
710 ifeq (%(detach),yes)
711     TMP_LIBS += detach.o
712 endif
713 # search for the linklibs in the given path, ignore ones not found
714 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
715     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
718 ifeq (%(linker),target)
719 %(prog) : CMD:=$(TARGET_CC)
720 %(prog) : STRIPCMD:=$(TARGET_STRIP)
721 endif
722 ifeq (%(linker),host)
723 %(prog) : CMD:=$(HOST_CC)
724 %(prog) : STRIPCMD:=$(HOST_STRIP)
725 endif
726 ifeq (%(linker),kernel)
727 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
728 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
729 endif
731 %(prog) : OBJS := %(objs)
732 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
733 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
734 %(prog) : %(objs) $(TMP_DEPLIBS)
735         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
736 %end
737 #------------------------------------------------------------------------------
740 #------------------------------------------------------------------------------
741 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
742 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
743 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
744     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
745     usestartup=yes detach=no
747 TMP_EXTRA_LDFLAGS := 
748 TMP_EXTRA_LIBS :=
749 ifeq (%(nix),yes)
750     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
751 endif
752 ifeq (%(usestartup),no)
753     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
754     TMP_EXTRA_LIBS += arosc.static libinit autoinit
755 endif
756 ifeq (%(detach),yes)
757     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
758 endif
760 # Make a list of the lib files the programs depend on.
761 # In LDFLAGS remove white space between -L and directory
762 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
763 # Filter out only the libdirs and remove -L
764 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
765 # Add trailing /
766 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
767 # Add normal linklib path
768 TMP_DIRS += $(LIBDIR)/
769 # add lib and .a to static linklib names
770 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
771 # search for the linklibs in the given path, ignore ones not found
772 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
773     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
776 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
777 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
778 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
779         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
780 %end
781 #------------------------------------------------------------------------------
784 #------------------------------------------------------------------------------
785 # Link the %(objs) to the library %(libdir)/lib%(libname).a
786 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
788 ifeq (%(linker),target)
789 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
790 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
791 endif
792 ifeq (%(linker),host)
793 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
794 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
795 endif
796 ifeq (%(linker),kernel)
797 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
798 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
799 endif
801 %(libdir)/lib%(libname).a : %(objs)
802         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
803 %end
804 #------------------------------------------------------------------------------
806 #------------------------------------------------------------------------------
807 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
808 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
809 # The -noarosc flag is added so that modules are not linked with arosc.library
810 # (see /config/specs.in file)
811 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
812     ldflags=$(LDFLAGS) uselibs= usehostlibs=
814 TMP_LDFLAGS  := %(ldflags)
815 # Make a list of the lib files the programs depend on.
816 # In LDFLAGS remove white space between -L and directory
817 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
818 # Filter out only the libdirs and remove -L
819 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
820 # Add trailing /
821 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
822 # Add normal linklib path
823 TMP_DIRS += $(LIBDIR)/
824 # add lib and .a to static linklib names
825 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
826 # search for the linklibs in the given path, ignore ones not found
827 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
828     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
831 %(module) : LIB_NAMES := %(uselibs)
832 %(module) : OBJS := %(objs)
833 %(module) : ENDTAG := %(endobj)
834 %(module) : ERR := %(err)
835 %(module) : OBJDIR := %(objdir)
836 %(module) : LDFLAGS := $(TMP_LDFLAGS)
837 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
838                     -L/usr/lib $(addprefix -l,%(usehostlibs))
839 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
840         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
842 %end
843 #------------------------------------------------------------------------------
846 #------------------------------------------------------------------------------
847 # Generate the libdefs.h include file for a module.
848 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
850 TMP_TARGET := %(modname)_libdefs.h
851 TMP_DEPS := $(GENMODULE)
852 TMP_OPTS := 
853 ifneq (%(conffile),)
854     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
855     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
856 else
857     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
858     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
859 endif
860 ifneq (%(modsuffix),)
861     TMP_OPTS += -s %(modsuffix)
862 endif
863 ifneq (%(targetdir),)
864     TMP_OPTS += -d %(targetdir)
865     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
866 endif
867 ifneq (%(version),)
868     TMP_OPTS += -v %(version)
869 endif
871 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
872 $(TMP_TARGET) : MODNAME := %(modname)
873 $(TMP_TARGET) : MODTYPE := %(modtype)
874 $(TMP_TARGET) : $(TMP_DEPS)
875         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
876         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
877 %end
878 #------------------------------------------------------------------------------
880 #------------------------------------------------------------------------------
881 # Generate the _lib.fd file for a module.
882 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
884 TMP_TARGET := %(modname)_lib.fd
885 TMP_DEPS := $(GENMODULE)
886 TMP_OPTS := 
887 ifneq (%(conffile),)
888     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
889     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
890 else
891     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
892     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
893 endif
894 ifneq (%(modsuffix),)
895     TMP_OPTS += -s %(modsuffix)
896 endif
897 ifneq (%(targetdir),)
898     TMP_OPTS += -d %(targetdir)
899     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
900 endif
902 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
903 $(TMP_TARGET) : MODNAME := %(modname)
904 $(TMP_TARGET) : MODTYPE := %(modtype)
905 $(TMP_TARGET) : $(TMP_DEPS)
906         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
907         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
908 %end
909 #------------------------------------------------------------------------------
911 #------------------------------------------------------------------------------
912 # Generate a Makefile.%(modname) with the genmodule program and include this
913 # generated file in this Makefile
914 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
915     targetdir=
917 TMP_TARGET := Makefile.%(modname)
918 TMP_DEPS := $(GENMODULE)
919 TMP_OPTS := 
920 ifneq (%(conffile),)
921     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
922     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
923 else
924     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
925     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
926 endif
927 ifneq (%(modsuffix),)
928     TMP_OPTS += -s %(modsuffix)
929 endif
930 ifneq (%(targetdir),)
931     TMP_OPTS += -d %(targetdir)
932     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
933 endif
935 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
936 $(TMP_TARGET) : MODNAME := %(modname)
937 $(TMP_TARGET) : MODTYPE := %(modtype)
938 $(TMP_TARGET) : $(TMP_DEPS)
939         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
940 %end
941 #------------------------------------------------------------------------------
944 #------------------------------------------------------------------------------
945 # Generate the support files for compiling a module. This includes include
946 # files and source files. This rule has to be preceeded by
947 # %rule_genmodule_makefile
948 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
949     conffile=
951 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
952                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
953 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
954                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
956 TMP_DEPS := $(GENMODULE)
957 TMP_OPTS :=
959 ifneq (%(conffile),)
960     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
961     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
962 else
963     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
964     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
965 endif
966 ifneq (%(modsuffix),)
967     TMP_OPTS += -s %(modsuffix)
968 endif
969 ifneq (%(targetdir),)
970     TMP_OPTS += -d %(targetdir)
971     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
972     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
973 endif
975 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
976 $(TMP_TARGETS) : MODNAME := %(modname)
977 $(TMP_TARGETS) : MODTYPE := %(modtype)
978 $(TMP_TARGETS) : $(TMP_DEPS)
979         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
980 ifneq (%(conffile),lib.conf)
981         @$(IF) $(TEST) -f lib.conf; then \
982           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
983         fi
984 endif
985         @$(IF) $(TEST) -f libdefs.h; then \
986           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
987         fi
988         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
989 %end
990 #------------------------------------------------------------------------------
993 #------------------------------------------------------------------------------
994 # Generate the support files for compiling a module. This includes include
995 # files and source files.
996 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
997     targetdir= conffile=
999 ifneq ($(%(modname)_INCLUDES),)
1000 TMP_TARGETS := $(%(modname)_INCLUDES)
1002 TMP_DEPS := $(GENMODULE)
1003 TMP_OPTS :=
1005 ifneq (%(conffile),)
1006     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1007     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1008 else
1009     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1010     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1011 endif
1012 ifneq (%(modsuffix),)
1013     TMP_OPTS += -s %(modsuffix)
1014 endif
1015 ifneq (%(targetdir),)
1016     TMP_OPTS += -d %(targetdir)
1017     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1018 endif
1020 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1021 $(TMP_TARGETS) : MODNAME := %(modname)
1022 $(TMP_TARGETS) : MODTYPE := %(modtype)
1023 $(TMP_TARGETS) : $(TMP_DEPS)
1024         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1025         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1026 endif
1027 %end
1028 #------------------------------------------------------------------------------
1030 #------------------------------------------------------------------------------
1031 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1032 # 'start' is an optional starting address
1033 # 'ldflags' is optional additional flags for the linker
1034 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
1036 BD_OUTDIR := $(dir %(file))
1037 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1038 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1039 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1041 %(file) : %(objs) $(BD_OUTDIR)
1042         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1043         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
1044         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1046 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1047     GLOB_MKDIRS += $(BD_OUTDIR)
1048 endif
1050 %end
1052 #------------------------------------------------------------------------------
1053 # Common rules for all makefiles
1054 %define common
1055 # Delete generated makefiles
1057 clean ::
1058         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1060 include $(SRCDIR)/config/make.tail
1062 BDID := $(BDTARGETID)
1063 %end
1064 #------------------------------------------------------------------------------
1065       
1067 #############################################################################
1068 #############################################################################
1069 ##                                                                         ##
1070 ## Here are the mmakefile build macros. These are macros that takes care   ##
1071 ## of everything to go from the sources to the generated target. Also all  ##
1072 ## intermediate files and directories that are needed are created by these ##
1073 ## rules.                                                                  ##
1074 ##                                                                         ##
1075 #############################################################################
1076 #############################################################################
1078 #------------------------------------------------------------------------------
1079 # Build a program
1080 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1081     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1082     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1083     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1084     compiler=target linker= srcdir=
1086 .PHONY : %(mmake)
1088 BD_PROGNAME  := %(progname)
1089 BD_OBJDIR    := %(objdir)
1090 BD_TARGETDIR := %(targetdir)
1091 BD_LINKER    := %(linker)
1093 # If not supplied, linker is equal to compiler
1094 ifeq ($(BD_LINKER),)
1095     BD_LINKER := %(compiler)
1096 endif
1098 BD_FILES     := %(files)
1099 BD_CXXFILES  := %(cxxfiles)
1100 BD_ASMFILES  := %(asmfiles)
1102 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1103 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1104 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1106 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))
1107 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES)))
1109 BD_CFLAGS    := %(cflags)
1110 BD_AFLAGS    := %(aflags)
1111 BD_DFLAGS    := %(dflags)
1112 BD_LDFLAGS   := %(ldflags)
1115 %(mmake)-quick : %(mmake)
1117 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1118 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1120 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1121 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1122     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1123 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1124     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1125 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1126     aflags=$(BD_AFLAGS) compiler=%(compiler)
1128 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1129     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1130     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1131     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1132     linker=$(BD_LINKER)
1134 endif
1136 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1138 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1139 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1140 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1142 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1144 %(mmake)-clean ::
1145         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1146         @$(RM) $(FILES)
1148 %end
1149 #------------------------------------------------------------------------------
1152 #------------------------------------------------------------------------------
1153 # Build programs, for every C file an executable will be built with the same
1154 # name as the C file
1155 %define build_progs mmake=/A files=/A nix=no \
1156     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1157     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1158     uselibs= usehostlibs= usestartup=yes detach=no
1160 .PHONY : %(mmake)
1162 BD_OBJDIR    := %(objdir)
1163 BD_TARGETDIR := %(targetdir)
1165 BD_FILES     := %(files)
1166 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1167 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1168 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1170 BD_CFLAGS    := %(cflags)
1171 BD_DFLAGS    := %(dflags)
1172 BD_LDFLAGS   := %(ldflags)
1175 %(mmake)-quick : %(mmake)
1177 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1178 %(mmake) : $(BD_EXES)
1180 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1181 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1182     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1184 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1185     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1186     ldflags=$(BD_LDFLAGS) \
1187     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1188     usestartup="%(usestartup)" detach="%(detach)"
1190 endif
1192 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1194 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1195 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1196 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1198 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1200 %(mmake)-clean ::
1201         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1202         @$(RM) $(FILES)
1204 %end
1205 #------------------------------------------------------------------------------
1208 #------------------------------------------------------------------------------
1209 # Build a module.
1210 # This is a bare version: It just compiles and links the given files. It is
1211 # assumed that all needed boiler plate code is in the files. This should only
1212 # be used for compiling external code. For AROS code use %build_module
1213 %define build_module_simple mmake=/A modname=/A modtype=/A \
1214     files="$(basename $(call WILDCARD, *.c))" \
1215     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1216     objdir=$(OBJDIR) moduledir= \
1217     uselibs= usehostlibs= compiler=target
1219 # Define metamake targets and their dependencies
1220 #MM %(mmake) : core-linklibs includes-generate-deps
1221 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1222 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1223 #MM %(mmake)-kobj-quick
1224 #MM %(mmake)-pkg-quick
1225 #MM %(mmake)-quick
1226 #MM %(mmake)-clean
1228 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1230 .PHONY : $(BD_ALLTARGETS)
1232 ifeq (%(modname),)
1233 $(error using %build_module_simple: modname may not be empty)
1234 endif
1235 ifeq (%(modtype),)
1236 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1237 endif
1239 # Default values for variables and arguments
1240 BD_DEFLINKLIBNAME := %(modname)
1241 BD_DEFDFLAGS := %(cflags)
1242 OBJDIR ?= $(GENDIR)/$(CURDIR)
1243 BD_MODDIR := %(moduledir)
1244 ifeq ($(BD_MODDIR),)
1245   ifeq (%(modtype),library)
1246     BD_MODDIR  := $(AROS_LIBS)
1247   endif
1248   ifeq (%(modtype),gadget)
1249     BD_MODDIR  := $(AROS_GADGETS)
1250   endif
1251   ifeq (%(modtype),datatype)
1252     BD_MODDIR  := $(AROS_DATATYPES)
1253   endif
1254   ifeq (%(modtype),handler)
1255     BD_MODDIR  := $(AROS_FS)
1256   endif
1257   ifeq (%(modtype),device)
1258     BD_MODDIR  := $(AROS_DEVS)
1259   endif
1260   ifeq (%(modtype),resource)
1261     BD_MODDIR  := $(AROS_RESOURCES)
1262   endif
1263   ifeq (%(modtype),hook)
1264     BD_MODDIR  := $(AROS_RESOURCES)
1265   endif
1266   ifeq (%(modtype),mui)
1267     BD_MODDIR  := $(AROS_CLASSES)/Zune
1268   endif
1269   ifeq (%(modtype),mcc)
1270     BD_MODDIR  := $(AROS_CLASSES)/Zune
1271   endif
1272   ifeq (%(modtype),mcp)
1273     BD_MODDIR  := $(AROS_CLASSES)/Zune
1274   endif
1275   ifeq (%(modtype),usbclass)
1276     BD_MODDIR  := $(AROS_CLASSES)/USB
1277   endif
1278   ifeq (%(modtype),hidd)
1279     BD_MODDIR  := $(AROS_DRIVERS)
1280   endif
1281   ifeq (%(modtype),printer)
1282     BD_MODDIR  := $(AROS_PRINTERS)
1283   endif
1284 endif
1285 ifeq ($(BD_MODDIR),)
1286   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1287 endif
1289 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1290 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1291 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1293 %rule_compile_multi \
1294     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1295     cflags="%(cflags)" dflags="%(dflags)" \
1296     compiler=%(compiler)
1298 # Handlers use dash instead of dot in their names
1299 ifeq (%(modtype),handler)
1300 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1301 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1302 else
1303 ifeq (%(modtype),printer)
1304 BD_MODULE := $(BD_MODDIR)/%(modname)
1305 BD_PKGMOD := $(PKGDIR)/%(modname)
1306 else
1307 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1308 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1309 endif
1310 endif
1311 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1313 %(mmake)-quick : %(mmake)
1314 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1315 %(mmake)-kobj-quick : $(BD_KOBJ)
1316 %(mmake)       : $(BD_MODULE)
1317 %(mmake)-pkg   : $(BD_PKGMOD)
1318 %(mmake)-kobj  : $(BD_KOBJ)
1320 # The module is linked from all the compiled .o files
1321 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1323 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1324 # This breaks con-handler build. Here we work around this
1325 ifeq (%(modname),con)
1326     BD_ERR := $(notdir $(BD_MODULE)).err
1327 else
1328     BD_ERR := %(modname).err
1329 endif
1331 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1332                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1333                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1334                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1336 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1337                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1338                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1339                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1341 # Link kernel object file
1342 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1344 # Make these symbols local
1345 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1346             UtilityBase ExpansionBase KeymapBase KernelBase
1348 BD_SYMBOLS := $(BD_KBASE)
1350 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1351 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1352 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1353 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1354 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1355 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1356         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1357         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1358         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1361 ## Dependency fine-tuning
1363 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1364 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1366 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1367 $(BD_MODULE) : | $(BD_MODDIR)
1368 $(BD_KOBJ) : | $(KOBJSDIR)
1369 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1371 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1372 %(mmake)-clean ::
1373         @$(ECHO) "Cleaning up for module %(modname)"
1374         @$(RM) $(FILES)
1375 %end
1376 #------------------------------------------------------------------------------
1379 #------------------------------------------------------------------------------
1380 # Build a module
1381 # Explanation of this macro is done in the developer's manual
1382 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1383   conffile= files="$(basename $(call WILDCARD, *.c))" \
1384   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1385   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1386   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1387   compiler=target nostartup=yes
1389 # Define metamake targets and their dependencies
1390 #MM- includes-all : %(mmake)-includes
1391 #MM- linklibs-%(modname): %(mmake)-linklib
1392 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1393 #MM- includes-%(modname): %(mmake)-includes
1394 #MM- includes-%(modname)_rel : %(mmake)-includes
1395 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1396 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1397 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1398 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1399 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1400 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1401 #MM %(mmake)-quick : %(mmake)-includes-quick
1402 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1403 #MM     includes-generate-deps %(mmake)-fd
1404 #MM %(mmake)-includes-quick
1405 #MM %(mmake)-includes-dirs
1406 #MM %(mmake)-fd
1407 #MM %(mmake)-makefile
1408 #MM %(mmake)-clean
1410 # All MetaMake targets defined by this macro
1411 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1412     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1413     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1414     %(mmake)-linklib %(mmake)-fd
1416 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1418 ifeq (%(modname),)
1419 $(error using %build_module: modname may not be empty)
1420 endif
1421 ifeq (%(modtype),)
1422 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1423 endif
1425 # Default values for variables and arguments
1426 BD_DEFLINKLIBNAME := %(modname)
1427 BD_DEFDFLAGS := %(cflags)
1428 OBJDIR ?= $(GENDIR)/$(CURDIR)
1430 ## Create genmodule include Makefile for the module
1432 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1434 %rule_genmodule_makefile \
1435     modname=%(modname) modtype=%(modtype) \
1436     modsuffix=%(modsuffix) targetdir=%(objdir) \
1437     conffile=%(conffile)
1439 %(objdir)/Makefile.%(modname) : | %(objdir)
1441 GLOB_MKDIRS += %(objdir)
1443 # Do not parse these statements if metatarget is not appropriate
1444 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1446 include %(objdir)/Makefile.%(modname)
1448 BD_DEFMODDIR := $(%(modname)_MODDIR)
1451 ## include files generation
1453 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1454 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1455 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1457 %(mmake)-includes-quick : %(mmake)-includes
1458 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1459     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1460     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1462 ifneq ($(%(modname)_INCLUDES),)
1463 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1464                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1465                          conffile=%(conffile)
1467 %rule_copy_diff_multi \
1468     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1469     stampfile=%(objdir)/%(modname)_geninc
1471 %rule_copy_diff_multi \
1472     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1473     stampfile=%(objdir)/%(modname)_incs
1475 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1477 TMP%(modname)_INCDIRS := \
1478     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1479     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1480     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1481 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1483 endif
1485 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1486                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1487                            conffile=%(conffile) version=%(version)
1489 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1490 $(BD_DEFLIBDEFSINC) :
1491         @$(ECHO) "generating $@"
1492         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1494 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1495 GLOB_MKDIRS += %(objdir)/include
1497 ## Extra genmodule src files generation
1498 ## 
1499 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1500                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1501                       conffile=%(conffile)
1504 ## Create FD file
1505 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1506 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1508 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1509                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1511 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1513 GLOB_MKDIRS += $(BD_FDDIR)
1516 ## Compilation
1518 BD_FILES      := %(files)
1519 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1520 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1521 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1523 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1524 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1525 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1527 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1528 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1530 ifeq (%(modtype),library)
1531     BD_LIBSUFFIX := 
1532 else
1533     BD_LIBSUFFIX := .%(modtype)
1534 endif
1536 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1537 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1538 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1539     BD_LINKLIB :=
1540 else
1541     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1542     ifneq (%(modname),%(linklibname))
1543         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1544     endif
1545 endif
1546 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1548 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1549 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1550 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1551     BD_RELLINKLIB :=
1552 else
1553     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1554     ifneq (%(modname),%(linklibname))
1555         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1556     endif
1557 endif
1558 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1560 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1561 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1562     $(BD_RELLINKLIBCFILES)
1564 %rule_compile_multi \
1565     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1566     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1567     compiler=%(compiler)
1568 %rule_compile_multi \
1569     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1570     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1571     compiler=%(compiler)
1573 ifneq ($(BD_LINKLIBAFILES),)
1574 %rule_assemble_multi \
1575     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1576 endif
1578 ## Linking
1580 ifeq (%(modsuffix),)
1581 BD_SUFFIX := %(modtype)
1582 else
1583 BD_SUFFIX := %(modsuffix)
1584 endif
1586 # Handlers use dash instead of dot in their names
1587 ifeq ($(BD_SUFFIX),handler)
1588 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1589 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1590 else
1591 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1592 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1593 endif
1594 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1596 %(mmake)-quick      : %(mmake)
1597 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1598 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1599 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1600 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1601 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1602 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1604 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1605                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1607 ifeq (%(nostartup),yes)
1608 # Handlers always have entry point
1609 ifneq (%(modtype),handler)
1610 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1611 endif
1612 endif
1614 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1615 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1616                  %(linklibobjs)
1617 BD_RELLINKLIBOBJS \
1618               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1619                  %(linklibobjs)
1621 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1622 # This breaks con-handler build. Here we work around this
1623 ifeq (%(modname),con)
1624     BD_ERR := $(notdir $(BD_MODULE)).err
1625 else
1626     BD_ERR := %(modname).err
1627 endif
1629 # The module is linked from all the compiled .o files
1630 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1631                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1632                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1633                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1635 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1636                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1637                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1638                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1640 # Link static lib
1641 ifneq ($(BD_LINKLIB),)
1642 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1644 ifneq (%(modname),%(linklibname))
1645 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1646 endif
1648 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1649 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1650 endif
1652 ifneq ($(BD_RELLINKLIB),)
1653 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1654 ifneq (%(modname),%(linklibname))
1655 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1656 endif
1658 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1659 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1660 endif
1662 # Link kernel object file
1663 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1665 # Make these symbols local
1666 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1667             UtilityBase ExpansionBase KeymapBase KernelBase
1669 BD_SYMBOLS := $(BD_KBASE)
1671 BD_KLIB := hiddstubs amiga arossupport arosc.static arosm autoinit libinit
1672 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1673 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1674 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1675 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1676 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1677         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1678         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1679         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1681 ## Dependency fine-tuning
1683 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1684 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1686 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1687 $(BD_MODULE) : | %(prefix)/%(moduledir)
1688 $(BD_PKGMOD) : | $(PKGDIR)
1689 $(BD_KOBJ)   : | $(KOBJSDIR)
1690 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1692 # Some include files need to be generated before the .c can be parsed.
1693 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
1695 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1696     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1697 $(BD_DEPS) : $(BD_DFILE_DEPS)
1698 endif
1700 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1701     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1702     %(objdir)/Makefile.%(modname) \
1703     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1704     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1705     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1706     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1707     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1708     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1709     $(BD_ENDOBJS)
1710 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1711 %(mmake)-clean ::
1712         @$(ECHO) "Cleaning up for module %(modname)"
1713         @$(RM) $(FILES)
1715 endif # $(TARGET) in $(BD_ALLTARGETS)
1716 %end
1717 #------------------------------------------------------------------------------
1720 #------------------------------------------------------------------------------
1721 # Build a module skeleton
1722 # This is a stripped-down version of build_module, it only creates include files,
1723 # but no actual object. This is used when for plugins or classes with the same
1724 # API, but no actual implementation here.
1725 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1726   conffile= \
1727   objdir=$(OBJDIR) prefix=$(AROSDIR)
1729 # Define metamake targets and their dependencies
1730 #MM- includes-all : %(mmake)-includes
1731 #MM %(mmake) : %(mmake)-includes core-linklibs
1732 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1733 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1734 #MM %(mmake)-linklib : %(mmake)-includes
1735 #MM %(mmake)-quick : %(mmake)-includes-quick
1736 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1737 #MM     includes-generate-deps
1738 #MM %(mmake)-includes-quick
1739 #MM %(mmake)-includes-dirs
1740 #MM %(mmake)-makefile
1741 #MM %(mmake)-clean
1743 # All MetaMake targets defined by this macro
1744 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1745     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1746     %(mmake)-kobj %(mmake)-pkg
1748 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1750 ifeq (%(modname),)
1751 $(error using %build_module_skeleton: modname may not be empty)
1752 endif
1753 ifeq (%(modtype),)
1754 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1755 endif
1757 # Default values for variables and arguments
1758 BD_DEFLINKLIBNAME := %(modname)
1759 BD_DEFDFLAGS := %(cflags)
1760 OBJDIR ?= $(GENDIR)/$(CURDIR)
1762 ## Create genmodule include Makefile for the module
1764 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1766 %rule_genmodule_makefile \
1767     modname=%(modname) modtype=%(modtype) \
1768     modsuffix=%(modsuffix) targetdir=%(objdir) \
1769     conffile=%(conffile)
1771 %(objdir)/Makefile.%(modname) : | %(objdir)
1773 GLOB_MKDIRS += %(objdir)
1775 # Do not parse these statements if metatarget is not appropriate
1776 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1778 include %(objdir)/Makefile.%(modname)
1780 BD_DEFMODDIR := $(%(modname)_MODDIR)
1783 ## include files generation
1785 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1786 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1787 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1789 %(mmake)-includes-quick : %(mmake)-includes
1790 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1791     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1792     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1794 ifneq ($(%(modname)_INCLUDES),)
1795 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1796                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1797                          conffile=%(conffile)
1799 %rule_copy_diff_multi \
1800     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1801     stampfile=%(objdir)/%(modname)_geninc
1803 %rule_copy_diff_multi \
1804     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1805     stampfile=%(objdir)/%(modname)_incs
1807 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1809 TMP%(modname)_INCDIRS := \
1810     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1811     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1812     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1813 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1815 endif
1817 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1818                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1819                            conffile=%(conffile)
1821 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1822 $(BD_DEFLIBDEFSINC) :
1823         @$(ECHO) "generating $@"
1824         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1826 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1827 GLOB_MKDIRS += %(objdir)/include
1829 ## Extra genmodule src files generation
1830 ## 
1831 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1832                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1833                       conffile=%(conffile)
1835 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1836     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1837     %(objdir)/Makefile.%(modname) \
1838     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1839     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1840     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1841     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1842     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1843     $(BD_DEFLIBDEFSINC)
1844 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1845 %(mmake)-clean ::
1846         @$(ECHO) "Cleaning up for module %(modname)"
1847         @$(RM) $(FILES)
1849 endif # $(TARGET) in $(BD_ALLTARGETS)
1850 %end
1851 #------------------------------------------------------------------------------
1854 #------------------------------------------------------------------------------
1855 # Build a linklib.
1856 # - mmake is the mmaketarget
1857 # - libname is the baselibname e.g. lib%(libname).a will be created
1858 # - files are the C source files to include in the lib. The list of files
1859 #   has to be given without the .c suffix
1860 # - asmfiles are the asm files to include in the lib. The list of files has to
1861 #   be given without the .s suffix
1862 # - objs additional object to link into the linklib. The objects have to be
1863 #   given with full absolute path and the .o suffix.
1864 # - cflags are the flags to compile the source (default $(CFLAGS))
1865 # - dflags are the flags use during makedepend (default equal to cflags)
1866 # - aflags are the flags use during assembling (default $(AFLAGS))
1867 # - objdir is where the .o are generated
1868 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1869 %define build_linklib mmake=/A libname=/A \
1870   files="$(basename $(call WILDCARD, *.c))" \
1871   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1872   asmfiles= objs= compiler=target \
1873   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1875 # assign and generate the local variables used in this macro
1876 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1878 BD_FILES      := %(files)
1879 BD_CXXFILES   := %(cxxfiles)
1880 BD_ASMFILES   := %(asmfiles)
1882 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1883 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1884 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1886 BD_OBJS       := $(BD_ARCHOBJS) \
1887                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
1888                  %(objs)
1889 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1891 BD_CFLAGS     := %(cflags)
1892 ifeq (%(dflags),)
1893 BD_DFLAGS     := $(BD_CFLAGS)
1894 else
1895 BD_DFLAGS     := %(dflags)
1896 endif
1897 BD_AFLAGS     := %(aflags)
1899 BD_LINKLIB    := %(libdir)/lib%(libname).a
1901 .PHONY : %(mmake) %(mmake)-clean
1903 #MM %(mmake) : includes-generate-deps
1904 %(mmake) : $(BD_LINKLIB)
1907 %(mmake)-clean ::
1908         @$(RM) $(BD_OBJS) $(BD_DEPS)
1910 ifeq ($(TARGET),%(mmake))
1911 ifneq ($(dir $(BD_FILES)),./)
1912 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1913 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1914 endif
1916 %rule_compile basename=% targetdir=%(objdir) \
1917     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1918 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1919     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1920 %rule_assemble basename=% targetdir=%(objdir) \
1921     aflags=$(BD_AFLAGS)
1923 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1924 endif
1926 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1928 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1929 $(BD_LINKLIB) : | %(libdir)
1930 GLOB_MKDIRS += %(objdir) %(libdir)
1932 %end
1933 #------------------------------------------------------------------------------
1936 #------------------------------------------------------------------------------
1937 # Build catalogs.
1938 # - mmake is the mmaketarget
1939 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1940 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1941 # - subdir is the destination subdirectory of the catalogs
1942 # - name is the name of the destination catalog, without the .catalog suffix
1943 # - source is the path to the generated source code file
1944 # - dir is the base destination directory (default $(AROS_CATALOGS))
1945 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1946 # - srcdir is the directory in which the *.cd and *.ct files are searched
1948 %define build_catalogs mmake=/A name=/A subdir=/A \
1949  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1950  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
1952 ifeq (%(description),)
1953 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1954 else
1955 BD_DESC := %(description)
1956 endif
1958 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1960 ifeq (%(catalogs),)
1961 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1962 else
1963 BD_LNGS := %(catalogs)
1964 endif
1966 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1967 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1970 %(mmake) : $(BD_OBJS) %(source)
1972 $(BD_OBJS) : | $(BD_DIRS)
1973 GLOB_MKDIRS += $(BD_DIRS)
1975 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1976         @$(ECHO) "Creating   %(name) catalog for language $*."
1977         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1979 ifneq (%(source),)
1980 %(source) : BD_DESC := $(BD_DESC)
1981 %(source) : BD_SRC := $(BD_SRC)
1982 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
1983         @$(ECHO) "Creating   %(name) catalog source file $@"
1984         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
1985 endif
1988 %(mmake)-clean ::
1989         $(RM) $(BD_OBJS) %(source)
1991 .PHONY: %(mmake) %(mmake)-clean
1993 %end
1994 #-----------------------------------------------------------------------------
1997 #-----------------------------------------------------------------------------
1998 # Build icons.
1999 # - mmake is the mmaketarget
2000 # - icons is a list of icon base names (ie. without the .info suffix)
2001 # - dir is the destination directory
2002 # - srcdir is where *.png and *.info.src are searched
2003 #-----------------------------------------------------------------------------
2005 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2007 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2010 %(mmake) : $(BD_OBJS)
2012 ifeq (%(image),)
2014 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2015         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2016         @$(ILBMTOICON) $+ $@
2018 else
2020 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2021         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2022         @$(ILBMTOICON) $+ $@
2024 endif
2026 $(BD_OBJS) : | %(dir)
2027 GLOB_MKDIRS += %(dir)
2029 %(mmake)-clean : FILES := $(BD_OBJS)
2031 %(mmake)-clean ::
2032         @$(RM) $(FILES)
2034 .PHONY: %(mmake) %(mmake)-clean
2036 %end
2037 #-----------------------------------------------------------------------------
2040 #------------------------------------------------------------------------------
2041 # Compile files for an arch-specific replacement of code for a module
2042 # - files: the basenames of the C files to compile.
2043 # - asmfiles: the basenames of the asm files to assemble.
2044 # - mainmmake: the mmake of the module in the main directory to compile these
2045 #   arch specific files for.
2046 # - maindir: the object directory for the main module
2047 # - arch: the arch for which to compile these files. It can have the form
2048 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2049 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2050 # - dflags: the flags used during creation of dependency file. If not specified
2051 #   the same value as cflags will be used
2052 # - aflags: the flags used during assembling
2053 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2054 #   the target compiler is used
2055 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2056 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2058 ifeq (%(files) %(asmfiles),)
2059   $(error no files or asmfiles given)
2060 endif
2062 %buildid targets="%(mainmmake)-%(arch)"
2064 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2065 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2066 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2067 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2068 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2069 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2070 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2071 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2072 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2073 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2074 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2075 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2076 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2077 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2078 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2079 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2080 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2081 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2082 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2083 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2084 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2086 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2088 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2089 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2090 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2091 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2092 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2094 ifneq (%(modulename),)
2095 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2096 endif
2098 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2099     BD_TARGET := %(mainmmake)-%(arch)-quick
2100 else
2101     BD_TARGET := %(mainmmake)-%(arch)
2102 endif
2105 ifeq ($(TARGET),$(BD_TARGET))
2106 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2107 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2108 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2109 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2110 endif
2112 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2113 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2116 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2119 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2121 ifeq ($(findstring %(compiler),host kernel target),)
2122   $(error unknown compiler %(compiler))
2123 endif
2124 ifeq (%(compiler),target)
2125 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2126 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2127 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2128 endif
2129 ifeq (%(compiler),host)
2130 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2131 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2132 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2133 endif
2134 ifeq (%(compiler),kernel)
2135 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2136 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2137 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2138 endif
2139 ifneq (%(modulename),)
2140 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2141 else
2142 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2143 endif
2144 ifeq ($(TARGET),$(BD_TARGET))
2145 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2146         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2147 endif
2149 ifeq (%(dflags),)
2150 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2151 else
2152 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2153 endif
2154 ifeq ($(TARGET),$(BD_TARGET))
2155 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2156         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2157 endif
2159 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2161 ifeq ($(TARGET),$(BD_TARGET))
2162 $(BD_OBJDIR$(BDID))/%.o : %.s
2163         %assemble_q opt=$(AFLAGS)
2164 $(BD_OBJDIR$(BDID))/%.o : %.S
2165         %assemble_q opt=$(AFLAGS)
2166 endif
2168 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2169 %end
2170 #------------------------------------------------------------------------------
2173 #------------------------------------------------------------------------------
2174 # generate asm files from c files (for debugging purposes)
2175 %define ctoasm_q
2176 %.s : %.c
2177         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2178         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2179 %end
2180 #------------------------------------------------------------------------------
2183 #------------------------------------------------------------------------------
2184 # Copy files from one directory to another.
2186 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2188 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2190 GLOB_MKDIRS += %(dst)
2192 .PHONY : %(mmake)
2195 %(mmake) : | %(dst) 
2196         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2198 %end
2199 #------------------------------------------------------------------------------
2202 #------------------------------------------------------------------------------
2203 # Copy a directory recursively to another place, preserving the original 
2204 # hierarchical structure
2206 # src: the source directory whose content will be copied
2207 # dst: the directory where to copy src's content. If not existing, it will be made.
2209 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2211 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2212 %(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)
2213 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2215 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2216 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2218 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2220 .PHONY : %(mmake)
2223 %(mmake): | $(GENDIR)/$(CURDIR)
2224         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2225         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2226         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2227         for d in $(%(mmake)_DIRS); do                      \
2228             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2229         done
2230         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2231         for f in $(%(mmake)_FILES); do                                            \
2232             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2233         done;  \
2234         for dst in %(dst); do \
2235             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2236         done
2238 %end
2239 #------------------------------------------------------------------------------
2242 #------------------------------------------------------------------------------
2243 #   Copy include files into the includes directories. There are currently
2244 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2245 #   for building tools that need to run on the host system $(GENINCDIR). The
2246 #   $(GENINCDIR) path must not contain any references to the C runtime
2247 #   library header files.
2249 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2250     dir= compiler=target
2252 ifeq ($(findstring %(compiler),host kernel target),)
2253 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2254 endif
2256 ifneq (%(dir),)
2257 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2258 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2259 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2260 else
2261 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2262 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2263 endif
2265 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2266         @$(CP) $< $@
2269 ifeq (%(compiler),target)
2271 ifneq (%(dir),)
2272 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2273 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2274 else
2275 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2276 endif
2278 BD_INCL_FILES += $(BD_INCL_FILES2)
2280 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2281         @$(CP) $< $@
2282 endif
2285 %(mmake) : $(BD_INCL_FILES)
2287 .PHONY: %(mmake)
2289 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2290 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2291 %end
2292 #------------------------------------------------------------------------------
2295 #------------------------------------------------------------------------------
2296 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2297 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2298 STUBS_MEM := $(addsuffix .o,$(STUBS))
2299 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2300 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2301 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2303 #MM- linklibs : hidd-%(hidd)-stubs
2304 #MM- %(parenttarget): hidd-%(hidd)-stubs
2305 #MM hidd-%(hidd)-stubs : includes includes-copy
2306 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2308 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2309         %mklib_q from=$^
2311 $(STUBS_OBJ) : $(STUBS_SRC) 
2312         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2314 $(STUBS_DEP) : $(STUBS_SRC)
2315         %mkdepend_q flags=%(dflags)
2317 setup ::
2318         %mkdirs_q $(OBJDIR) $(LIBDIR)
2321 clean ::
2322         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2324 DEPS := $(DEPS) $(STUBS_DEP)
2326 %end
2327 #------------------------------------------------------------------------------
2330 #------------------------------------------------------------------------------
2331 # Build an imported source tree which uses the configure script from the
2332 # autoconf package.  This rule will try to "integrate" the produced files as
2333 # much as possible in the AROS build, for example by putting libraries in the
2334 # standard library directory, includes in the standard include directory, and
2335 # so on. You can however override this behaviour.
2337 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2338 # be %(bindir) (or its deduced value) when running "make install", and
2339 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2340 # configure script some more parameters whose value depends upon the PROGDIR
2341 # env var, so that the program gets all its stuff installed in the proper place
2342 # when building it, but when running it from inside AROS it can also find that
2343 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2344 # the configuration parameters set when running ./configure
2346 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2347 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2348 # to the name which has to follow it.
2350 # Arguments:
2352 #     - mmake           = the meta make target.
2353 #     - package         = name of the package to be built.
2354 #     - srcdir          = the location of the unpacked source code. Defaults
2355 #                         to $(SRCDIR)/$(CURDIR).
2356 #     - prefix          = the target directory. Must be an absolute path of the
2357 #                         host system. Defaults to $(AROS_CONTRIB).
2358 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2359 #                         Defaults to the value of the prefix option.
2360 #     - extraoptions    = additional options for the configure script.
2361 #     - extracflags     = additional flags which are used for both C and C++.
2362 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2363 #                         Defaults to the value of the nix argument.
2364 #     - nix             = enable u*nix path handling, i.e. a path like
2365 #                         /progdir//./file will be translated to
2366 #                         progdir:file during run-time. Defaults to no.
2367 #     - compiler        = target, host or kernel. Defaults to target.
2368 #     - install_target  = the command used for installing. Defaults to install. Leave
2369 #                         it empty if you want to suppress installing.
2370 #     - preconfigure    = a metatarget which is executed before configure is called.
2371 #     - postconfigure   = a metatarget which is executed after configure is called.
2372 #     - postinstall     = a metatarget which is executed after installing.
2373 #     - install_env     = set additional options for installing.
2374 #     - use_build_env   = if yes the configuration environment is used for
2375 #                         installing, too. Defaults to no.
2377 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2378 # like this:
2380 # if nix_dir_layout
2381 #    --prefix = $(aros_prefix)
2382 #    progdir = $(aros_prefix)/bin
2383 # else
2384 #    if nix
2385 #        --prefix = /PROGDIR
2386 #        --bindir = /PROGDIR
2387 #        --sbindir = /PROGDIR
2388 #        --libdir = /LIB
2389 #        --includedir = /INCLUDE
2390 #        --oldincludedir = /INCLUDE   
2391 #    else
2392 #        --prefix = $(aros_prefix)
2393 #    endif
2395 #    progdir = $(aros_prefix)
2397 #    # Install options
2398 #    bindir = $(prefix)
2399 #    sbindir = $(prefix)
2400 #    libdir = $(AROS_LIB)
2401 #    includedir = $(AROS_INCLUDES)
2402 #    oldincludedir = $(AROS_INCLUDES)
2403 # endif
2406 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2407     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2408     install_target=install preconfigure= postconfigure= postinstall= \
2409     install_env= use_build_env=no
2411 ifneq (%(prefix),)
2412     %(mmake)-prefix := %(prefix)
2413 else
2414     %(mmake)-prefix := $(AROS_CONTRIB)
2415 endif
2417 ifneq (%(aros_prefix),)
2418     %(mmake)-aros_prefix := %(aros_prefix)
2419 else
2420     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2421 endif
2423 ifeq (%(nix),yes)
2424     %(mmake)-nix    := -nix
2425     %(mmake)-volpfx := /
2426     %(mmake)-volsfx := /
2427     
2428     ifeq (%(nix_dir_layout),)
2429         %(mmake)-nix_dir_layout := yes
2430     endif
2431 else
2432     %(mmake)-volsfx := :
2433     
2434     ifeq (%(nix_dir_layout),)
2435         %(mmake)-nix_dir_layout := no
2436     endif
2437 endif
2439 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2441 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2442         exec_prefix=$(%(mmake)-prefix) %(install_env)
2444 # Check if chosen compiler is valid
2445 ifeq ($(findstring %(compiler),host target kernel),)
2446   $(error unknown compiler %(compiler))
2447 endif
2449 # Set legacy 'host' variable based on chosen compiler
2450 ifeq (%(compiler),host)
2451     host := yes
2452         ifeq (%(package),)
2453                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2454         else
2455                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2456         endif
2457 else
2458     host := no
2459         ifeq (%(package),)
2460                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2461         else
2462                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2463         endif
2464 endif
2466 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2467 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2469 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2470     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2471     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2472 else
2473     ifeq (%(nix),yes)
2474         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2475         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2476     else
2477         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2478     endif
2480     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2481     
2482     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2483         sbindir=$(%(mmake)-prefix) \
2484         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2485         oldincludedir=$(AROS_INCLUDES) %(install_env)
2486 endif
2488 ifneq ($(DEBUG),yes)
2489     %(mmake)-s_flag = -s
2490 endif
2492 # Set up build environment, and options for configure script
2493 ifeq (%(compiler),host)
2494     CONFIG_ENV := \
2495         CPP="$(HOST_CPP)" \
2496         CXXCPP="$(HOST_CPP)" \
2497         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2498         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2499         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2500         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2501         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2502         TARGET_NM="$(NM_PLAIN)"
2503 endif
2504 ifeq (%(compiler),target)
2505     CONFIG_ENV := \
2506         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2507         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2508         CPP="$(TARGET_CPP)" \
2509         CXXCPP="$(TARGET_CPP)" \
2510         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2511         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2512         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2513         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2514         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2515         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2516         TARGET_NM="$(NM_PLAIN)" \
2517         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2518         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2519     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2520         --host=$(AROS_TARGET_CPU)-aros\
2521         --target=$(AROS_TARGET_CPU)-aros\
2522         --disable-nls\
2523         --without-x --without-pic --disable-shared
2524 endif
2525 ifeq (%(compiler),kernel)
2526     CONFIG_ENV := \
2527         CPP="$(KERNEL_CPP)" \
2528         CXXCPP="$(KERNEL_CPP)" \
2529         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2530         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2531         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2532         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2533         TARGET_NM="$(NM_PLAIN)"
2534     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2535         --host=$(AROS_TARGET_CPU)-aros\
2536         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2537         --without-x --without-pic --disable-shared
2538 endif
2540 ifeq (%(use_build_env),yes)
2541     BUILD_ENV := $(CONFIG_ENV)
2542 endif
2545 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2547 # When building for the host, we don't need to build the
2548 # linklibs - this is especially true when building the
2549 # crosstool toolchain on 'foreign' architectures (such as
2550 # building PPC on x86)
2552 #MM- %(mmake)-host : setup includes %(mmake)-quick
2553 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2554 #MM- %(mmake): %(mmake)-%(compiler)
2556 # Using -j1 in install_command may result in a warning but finally
2557 # it does its job. make install for gcc does not work reliably for -jN
2558 # where N > 1.
2559 ifneq (%(install_target),)
2560     %(mmake)-install_command = \
2561         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2562         -C $(%(mmake)-pkgdir) %(install_target) -j1
2564     %(mmake)-uninstall_command = \
2565     $(RM) $(%(mmake)-installflag) && \
2566     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2567     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2568 else
2569     %(mmake)-install_command   := true
2570     %(mmake)-uninstall_command := true
2571 endif
2573 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2576 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2578 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2579         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2580             $(RM)  $(%(mmake)-installflag) && \
2581             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2582              -C $(%(mmake)-pkgdir) && \
2583             $(%(mmake)-install_command) && \
2584             $(TOUCH) $@ -r $^; \
2585         fi
2587 $(%(mmake)-pkgdir)/.files-touched:
2588         %mkdirs_q $(%(mmake)-pkgdir)
2589         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2590         $(TOUCH) $@
2593 %(mmake)-uninstall :
2594         $(%(mmake)-uninstall_command)
2597 %(mmake)-configure : $(%(mmake)-configflag)
2599 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2600 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2601         $(RM) $@
2602         %mkdirs_q $(%(mmake)-pkgdir)
2603         cd $(%(mmake)-pkgdir) && \
2604         find . -name config.cache -exec $(RM) '{}' \; && \
2605         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2606             %(extraoptions) && \
2607         $(TOUCH) $@
2610 %(mmake)-clean : %(mmake)-uninstall
2611         @$(RM) $(%(mmake)-pkgdir)
2612 %end
2613 #------------------------------------------------------------------------------
2616 #------------------------------------------------------------------------------
2617 # Given an archive name, patches names and locations where to find them, fetch
2618 # the archive and the patches from any of those locations, unpack the archive
2619 # and then apply the patches.
2621 # Locations currently supported are http and ftp sites, plus local filesystem
2622 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2623 # the fetch.sh script needs to be modified, since this macro relies on that script.
2625 # Arguments:
2627 #     - mmake           = mmaketarget
2628 #     - archive_origins = list of locations where to find the archive. They are tried
2629 #                         in sequence, until the archive is found and fetching it 
2630 #                         succeeded. If not specified, the current directory is assumed.
2631 #     - archive         = the archive name. Mandatory.
2632 #     - suffixes        = a list of suffixes to append to the the package name plus the
2633 #                         version. Each one of them is tried until a matching archive is
2634 #                         found. They are appended to patches and these are tried the
2635 #                         same way as packages are.
2636 #     - location        = the local directory where to put the fetched archive and patches.
2637 #                         If not specified, the directory specified by destination is used.
2638 #     - destination     = the directory to unpack the archive to.
2639 #                         If not specified, the current directory is assumed.
2640 #     - patches_origins = list of locations where to find the patches. They are tried
2641 #                         in sequence, until a patch is found and fetching it 
2642 #                         succeeded. If not specified, the current directory is assumed.
2643 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2644 #                         patch_name[:[patch_subdir][:patch_opt]].
2646 #                             - patch_name   = the name of the patch file
2647 #                             - patch_subdir = the directory within \destination\ where to
2648 #                                              apply the patch.
2649 #                             - patch_opt    = any options to pass to the `patch' command
2650 #                                              when applying the patch.
2651 #                         
2652 #                         The patch_subdir and patch_opt fields are optional.
2654 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2655     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2657 .PHONY: %(mmake)
2659 ifneq (%(location),)
2660     %(mmake)-location := %(location)
2661 else
2662     %(mmake)-location := %(destination)
2663 endif
2666 %(mmake) :
2667         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2668         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2669 %end
2670 #------------------------------------------------------------------------------
2673 #------------------------------------------------------------------------------
2674 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2675 # unpatched source tree and runs diff against this and a previously fetched and possibly
2676 # patched tree. Depending on what happens after patching during a normal build it might
2677 # give best results if the new patch is created directly after fetch.
2679 # Arguments:
2681 #     - mmake       = mmaketarget
2682 #     - archive     = archive base name
2683 #     - srcdir      = directory the package is unpacked to, useful if archive unpacks to
2684 #                     a directory other than its name suggests.
2685 #     - suffixes    = a list of suffixes to append to the the package name plus the
2686 #                     version. Each one of them is tried until a matching archive is
2687 #                     found.
2688 #     - destination = the directory to unpack the archive to.
2689 #     - excludes    = diff patterns to exclude files or directories from the patch
2691 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2693 .PHONY: %(mmake)
2695 ifneq (%(excludes),)
2696     %(mmake)-exclude := -X ./exclude.patterns
2697 endif
2699 ifneq (%(srcdir),)
2700     %(mmake)-srcdir := %(srcdir)
2701 else
2702     %(mmake)-srcdir := %(archive)
2703 endif
2706 %(mmake):
2707         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2708         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2709         cd %(destination)/tmp ; \
2710         $(FOR) f in %(excludes) ; do \
2711             $(ECHO) $$f >> ./exclude.patterns ; \
2712         done ; \
2713         diff -ruN $(%(mmake)-exclude) \
2714             $(%(mmake)-srcdir) \
2715             $(%(mmake)-srcdir).aros \
2716             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2717         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2718         $(RM) %(destination)/tmp
2719 %end
2720 #------------------------------------------------------------------------------
2723 #------------------------------------------------------------------------------
2724 # Joins the features of %fetch and %build_with_configure.
2726 # If a patch is provided, it *must* be named the following way:
2728 #    <package name>-<version number>-aros.diff
2730 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2731 # CD'ing into the archive's extracted directory.
2733 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2734 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2735 # to make that patch fully comprehensive.
2737 # Arguments:
2739 #    - mmake            = the meta make target.
2740 #    - package          = the GNU package name, sans version and archive format suffixes.
2741 #    - subpackage       = ???
2742 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2743 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2744 #    - version          = the package's version number, or otherwise any other version string.
2745 #                         It gets appended to the package name to form the basename of the archive.
2746 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2747 #                         version. Each one of them is tried until a matching archive is found.
2748 #                         Defaults to "tar.bz2 tar.gz".
2749 #    - srcdir           = ???
2750 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2751 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2752 #                         fetched or not. Default to no.
2753 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2754 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2755 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2756 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2757 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2758 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2759 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2760 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2761 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2762 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2763 #    - nix              = same meaning as the one for the %build_with_configure macro.
2764 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
2765 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
2767 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2768     version=/A suffixes="tar.bz2 tar.gz" srcdir= package_repo= patch=no patch_repo= \
2769     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2770     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2772 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2773 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2774 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2775 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2777 %(mmake)-archbase  := %(package)-%(version)
2779 ifeq (%(compiler),host)
2780     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2781 else
2782     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2783 endif
2785 ifeq (%(prefix),)
2786     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2787 else
2788     %(mmake)-prefix := %(prefix)
2789 endif
2791 ifneq (%(subpackage),)
2792     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2793 else
2794     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2795 endif
2797 ifneq (%(srcdir),)
2798     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2799 else
2800     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2801 endif
2803 ifeq (%(patch),yes)
2804     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
2805 else
2806     %(mmake)-%(subpackage)-patches_specs := ::
2807 endif
2809 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2810     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2811     archive_origins=". %(package_repo)" \
2812     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2814 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2815     archive=$(%(mmake)-%(subpackage)-archbase) \
2816     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2817     suffixes="%(suffixes)" \
2818     destination=$(%(mmake)-portdir)
2820 #MM- %(mmake) : %(mmake)-%(subpackage)
2822 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2824 %(mmake)-%(subpackage)-package-basename := \
2825     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2827 ifneq (%(create_pkg),no)
2828     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2829 endif
2831 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
2832      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) install_env=%(install_env) use_build_env=%(use_build_env) \
2833      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2834      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2835      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2837 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2838 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2841 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2843 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2844 #that $^ and $@ have exactly the same mtime, and in that case make tries
2845 #to rebuild $@ again, which would fail because the directory where
2846 #the package got installed would not exist anymore. 
2847 #We work this around by using an if statement to manually check the mtimes.
2848 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2849         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2850         $(RM) $@ ; \
2851         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2852         mkdir -p "$(DISTDIR)/Packages" ; \
2853         mkdir -p "$(%(mmake)-prefix)" ; \
2854         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2855         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2856         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2857     fi
2858 %end
2859 #------------------------------------------------------------------------------
2862 #------------------------------------------------------------------------------
2863 # Joins the features of %fetch and %build_with_configure, taking advantage of
2864 # the naming scheme of GNU packages. GNU packages names are in the form
2866 #     <package name>-<version number>.<archive format suffix>
2868 # If a patch is provided, it *must* be named the following way:
2870 #    <package name>-<version number>-aros.diff
2872 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2873 # CD'ing into the archive's extracted directory.
2875 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2876 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2877 # to make that patch fully comprehensive.
2879 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2881 # Arguments:
2883 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
2885 #    - prefix           = defaults to $(GNUDIR).
2886 #    - aros_prefix      = defaults to /GNU.
2888 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2889     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2890     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2892 GNU_REPOSITORY := gnu://
2894 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2895     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2896     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2897     patch="%(patch)" patch_repo="%(patch_repo)" \
2898     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2899     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2901 %end
2902 #------------------------------------------------------------------------------
2905 #------------------------------------------------------------------------------
2906 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2907 # that the package is a "Development" package, and as such it needs to be placed
2908 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2910 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2911 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2912 # "mmake" argument, because the metatarget is implicitely defined as
2914 #     #MM- development-%(package)
2916 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2917     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2918     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2920 #MM- development : development-%(package)
2923 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2924    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2925    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2926    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2927    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2930 postinstall-%(package)-delete-la-files:
2931         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2933 %end
2934 #------------------------------------------------------------------------------
2936 # Builds a kickstart package in PKG format
2938 # Arguments:
2940 #    - mmake   = target name
2941 #    - file    = destination file name with path
2942 #    - startup = the file which will be put first
2944 # Other arguments are self-explanatory
2946 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2948 PKG_CLASSES   := $(addsuffix .class, %(classes))
2949 PKG_DEVICES   := $(addsuffix .device, %(devs))
2950 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2951 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2952 PKG_LIBS      := $(addsuffix .library, %(libs))
2953 PKG_RESOURCES := $(addsuffix .resource, %(res))
2955 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2956 PKG_DIR   := $(dir %(file))
2957 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2960 %(mmake) : %(file)
2963 %(mmake)-quick : %(file)
2965 %(file): PKG_FILES := $(PKG_FILES)
2966 %(file): $(PKG_DEPS) | $(PKG_DIR)
2967         @$(ECHO) Packaging $@...
2968         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2970 %compress_file mmake=%(mmake) file=%(file)
2972 GLOB_MKDIRS += $(PKG_DIR)
2974 %end
2976 #------------------------------------------------------------------------------
2977 # Compresses %(file) with a gzip.
2978 # Good in conjunction with for example %build_prog
2980 %define compress_file mmake=/A file=/A
2982 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2985 %(mmake)-gz-quick : %(file).gz
2987 %(file).gz: %(file)
2988         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2989         @gzip -9 -f $^
2991 %end
2993 #------------------------------------------------------------------------------
2994 # Links a kickstart module in ELF format
2995 # Arguments are similar to make_package
2997 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2998     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3000 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3001 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3002 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3003 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3004 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3005 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3007 ifeq (%(startup),)
3008     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3009 else
3010     KOBJ_STARTUP := %(startup)
3011 endif
3013 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3015 TMP_LDFLAGS := %(ldflags)
3017 # Make a list of the lib files this program depends on.
3018 # In LDFLAGS remove white space between -L and directory
3019 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3020 # Filter out only the libdirs and remove -L
3021 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3022 # Add trailing /
3023 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3024 # Add normal linklib path
3025 TMP_DIRS += $(LIBDIR)/
3026 # add lib and .a to static linklib names
3027 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3028 # search for the linklibs in the given path, ignore ones not found
3029 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3030     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3033 TMP_DIRS += $(dir %(file))
3034 ifneq (%(map),)
3035     TMP_LDFLAGS += $(GENMAP) %(map)
3036     TMP_DIRS    += $(dir %(map))
3037 endif
3039 #MM %(mmake) : %(deps)
3042 %(mmake) : %(file)
3045 %(mmake)-quick : %(file)
3047 %(file): KOBJS := $(KOBJS)
3048 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3049                     -noarosc -nosysbase -Wl,-Ur
3050 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3051 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3052         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3053         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3054         @$(STRIP) $@
3056 %compress_file mmake=%(mmake) file=%(file)
3058 GLOB_MKDIRS += $(TMP_DIRS)
3060 %end