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