workbench/network/stacks/AROSTCP/...: sys/signal.h -> signal.h
[AROS.git] / config / make.tmpl
blobc57a9e71c74d908e7a1c58c477ecee4eb4b53b20
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             cat %(objdir)/%(err); \
88             exit 1; \
89         fi
91         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
92         @$(STRIP) $@
93 %end
94 #------------------------------------------------------------------------------
97 #------------------------------------------------------------------------------
98 # Create the library
99 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
100         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
101         @%(ar) %(to) %(from)
102         @%(ranlib) %(to)
103 %end
104 #------------------------------------------------------------------------------
107 #------------------------------------------------------------------------------
108 # Create the dependency file %(to) for %(from)
109 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
110         %mkdir_q dir="$(dir %(to))"
111         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
112         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
113 %end
114 #------------------------------------------------------------------------------
117 #------------------------------------------------------------------------------
118 # Create one directory without any output
119 %define mkdir_q dir=.
120         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
121 %end
122 #------------------------------------------------------------------------------
125 #------------------------------------------------------------------------------
126 # Create several directories without any output
127 %define mkdirs_q dirs=/M
128         @$(FOR) dir in %(dirs) ; do \
129             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
130         done
131 %end
132 #------------------------------------------------------------------------------
135 #############################################################################
136 #############################################################################
137 ##                                                                         ##
138 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
139 ## mmakefile. They consist of one or more full makefile rules.             ##
140 ## In general the files generated in these macros are also defined as      ##
141 ## make targets so that they can be used as a dependency in other rules    ##
142 ##                                                                         ##
143 #############################################################################
144 #############################################################################
146 #------------------------------------------------------------------------------
147 # Generate a unique id for each of the %build... rules
148 %define buildid targets=/A
149 BDID := $(BDID)_
150 ifneq ($(filter $(TARGET),%(targets)),)
151 BDTARGETID := $(BDID)
152 endif
153 %end
154 #------------------------------------------------------------------------------
157 #------------------------------------------------------------------------------
158 # Copy file %(from) to %(to) in a makefile rule
159 %define rule_copy from=/A to=/A
160 %(to) : %(from)
161         @$(CP) $< $@
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy the files %(files) to %(targetdir). For each file in %(files),
168 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
169 # appropriate subdirs are not generated by this rule so they have to be
170 # present.
171 %define rule_copy_multi files=/A targetdir=/A srcdir=.
173 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
174         @$(CP) $< $@
175 %end
176 #------------------------------------------------------------------------------
179 #------------------------------------------------------------------------------
180 # Copy the files %(files) to %(targetdir). For each file in %(files),
181 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
182 # %(stampfile) is used to keep track of when the last time the comparison has
183 # been done. The targetdir and the appropriate subdirs are not generated by 
184 # this rule so they have to be present.
185 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
186     stampfile=$(TMP_SRCDIR)/.copy_stamp
188 TMP_SRCDIR := %(srcdir)
190 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
192 %(stampfile) : COPYSRCDIR := %(srcdir)
193 %(stampfile) : TGTDIR := %(targetdir)
194 %(stampfile) : FILES := %(files)
195 %(stampfile) : $(addprefix %(srcdir)/,%(files))
196         @for f in $(FILES); do \
197              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
198                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
199              fi ; \
200         done
201         @$(TOUCH) $@
202 %end
203 #------------------------------------------------------------------------------
206 #------------------------------------------------------------------------------
207 # Will join all the files in %(from) to %(to). When text is specified it will
208 # be displayed.
209 # Restriction: at the moment when using a non-empty target dir %(from) may
210 # not have 
211 %define rule_join to=/A from=/A text=
213 %(to) : %(from)
214 ifneq (%(text),)
215         @$(ECHO) %(text)
216 endif
217         @$(CAT) $^ >$@
218 %end
219 #------------------------------------------------------------------------------
222 #------------------------------------------------------------------------------
223 # Include the dependency files and add some internal rules
224 # When depstargets is provided the depencies will only be included when one of
225 # these targets is the $(TARGET). Otherwise the dependencies will only be
226 # included when the $(TARGET) is not for setup or clean 
227 %define include_deps deps=$(DEPS)/M  depstargets=
228 ifneq (%(deps),)
229   ifneq (%(depstargets),)
230     ifneq ($(findstring $(TARGET),%(depstargets)),)
231       -include %(deps)
232     endif
233   else
234     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
235       -include %(deps)
236     endif
237   endif
238 endif
239 %end
240 #------------------------------------------------------------------------------
243 #------------------------------------------------------------------------------
244 # Create the directories %(dirs). The creation will be done by adding rules to
245 # the %(setuptarget) make target with setup as the default. 
246 %define rule_makedirs dirs=/A setuptarget=setup
248 %(setuptarget) :: %(dirs)
250 GLOB_MKDIRS += %(dirs)
252 %end
253 #------------------------------------------------------------------------------
256 #------------------------------------------------------------------------------
257 # Generate a rule to compile a C source file to an object file and generate
258 # the dependency file. Basename may contain a directory part, then the source
259 # file has to be in that directory. The generated file will be put in the
260 # object directory without the directory.
261 # options
262 # - basename: the basename of the file to compile. Use % for a wildcard rule
263 # - cflags (default $(CFLAGS)): the C flags to use for compilation
264 # - dflags: the flags used during creation of dependency file. If not specified
265 #   the same value as cflags will be used
266 # - targetdir: the directory to put the .o file and the .d file. By default
267 #   it is put in the same directory as the .c file
268 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
270 ifeq (%(targetdir),)
271   TMP_TARGETBASE := %(basename)
272 else
273   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
274 endif
276 ifeq ($(findstring %(compiler),host kernel target),)
277   $(error unknown compiler %(compiler))
278 endif
279 ifeq (%(compiler),target)
280 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
281 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
282 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
283 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
284 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
285 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
286 endif
287 ifeq (%(compiler),host)
288 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
289 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
290 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
291 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
292 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
293 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
294 endif
295 ifeq (%(compiler),kernel)
296 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
297 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
298 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
299 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
300 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
301 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
302 endif
304 ifeq (%(nix),yes)
305   $(TMP_TARGETBASE).o : CFLAGS := -nix %(cflags)
306 else
307   $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
308 endif
309 $(TMP_TARGETBASE).o : %(basename).c
310         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
312 ifeq (%(dflags),)
313   ifeq (%(nix),yes)
314     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
315   else
316     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
317   endif
318 else
319   ifeq (%(nix),yes)
320     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
321   else
322     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
323   endif
324 endif
325 $(TMP_TARGETBASE).d : %(basename).c
326         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
327 %end
328 #------------------------------------------------------------------------------
331 #------------------------------------------------------------------------------
332 # Generate a rule to compile a C++ source file to an object file and generate
333 # the dependency file. Basename may contain a directory part, then the source
334 # file has to be in that directory. The generated file will be put in the
335 # object directory without the directory.
336 # options
337 # - basename: the basename of the file to compile. Use % for a wildcard rule
338 # - cflags (default $(CFLAGS)): the C flags to use for compilation
339 # - dflags: the flags used during creation of dependency file. If not specified
340 #   the same value as cflags will be used
341 # - targetdir: the directory to put the .o file and the .d file. By default
342 #   it is put in the same directory as the .c file
343 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target nix=no
345 ifeq (%(targetdir),)
346   TMP_TARGETBASE := %(basename)
347 else
348   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
349 endif
351 # Adjust compiler flags to suit C++
352 TMP_CXXFLAGS := %(cflags)
353 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
354 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
356 ifeq ($(findstring %(compiler),host kernel target),)
357   $(error unknown compiler %(compiler))
358 endif
359 ifeq (%(compiler),target)
360 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
361 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
362 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
363 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
364 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
365 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
366 endif
367 ifeq (%(compiler),host)
368 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
369 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
370 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
371 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
372 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
373 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
374 endif
375 ifeq (%(compiler),kernel)
376 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
377 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
378 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
379 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
380 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
381 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
382 endif
384 ifeq (%(nix),yes)
385   $(TMP_TARGETBASE).o : CFLAGS := -nix $(TMP_CXXFLAGS)
386 else
387   $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
388 endif
389 $(TMP_TARGETBASE).o : %(basename).cpp
390         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
392 ifeq (%(dflags),)
393   ifeq (%(nix),yes)
394     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
395   else
396     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
397   endif
398 else
399   ifeq (%(nix),yes)
400     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
401   else
402     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
403   endif
404 endif
405 $(TMP_TARGETBASE).d : %(basename).cpp
406         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
407 %end
408 #------------------------------------------------------------------------------
411 #------------------------------------------------------------------------------
412 # Generate a rule to compile multiple C source files to an object file and
413 # generate the corresponding dependency files. The generated file will be put
414 # in the object directory without the directory part of the source file.
415 # options
416 # - basenames: the basenames of the files to compile. The names may include
417 #   relative or absolute path names. No wildcard is allowed
418 # - cflags (default $(CFLAGS)): the C flags to use for compilation
419 # - dflags: the flags used during creation of dependency file. If not specified
420 #   the same value as cflags will be used
421 # - targetdir: the directory to put the .o file and the .d file. By default
422 #   it is put in the same directory as the .c file. When targetdir is not
423 #   empty, path names will be stripped from the file names so that all files
424 #   are in that dir and not in subdirectories.
425 # - compiler (default target): compiler to use, target, kernel or host
426 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
427     compiler=target
429 ifeq (%(targetdir),)
430 TMP_TARGETS := $(addsuffix .o,%(basenames))
431 TMP_DTARGETS := $(addsuffix .d,%(basenames))
432 TMP_WILDCARD := %
433 else
434 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
435 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
436 TMP_WILDCARD := %(targetdir)/%
438 # Be sure that all .c files are generated
439 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
441 # Be sure that all .c files are found
442 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
443 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
444 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
445 ifneq ($(TMP_DIRS),)
446     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
447     vpath %.c $(TMP_DIRS)
448 endif
450 endif
452 ifeq ($(findstring %(compiler),host kernel target),)
453   $(error unknown compiler %(compiler))
454 endif
455 ifeq (%(compiler),target)
456 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
457 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
458 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
459 endif
460 ifeq (%(compiler),host)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
462 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
463 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
464 endif
465 ifeq (%(compiler),kernel)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
467 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
468 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
469 endif
471 $(TMP_TARGETS) : CFLAGS := %(cflags)
472 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
473         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
475 ifeq (%(dflags),)
476 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
477 else
478 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
479 endif
480 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
481         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
482 %end
483 #------------------------------------------------------------------------------
486 #------------------------------------------------------------------------------
487 # Generate a rule to compile multiple C++ source files to an object file and
488 # generate the corresponding dependency files. The generated file will be put
489 # in the object directory without the directory part of the source file.
490 # options
491 # - basenames: the basenames of the files to compile. The names may include
492 #   relative or absolute path names. No wildcard is allowed
493 # - cflags (default $(CFLAGS)): the C flags to use for compilation
494 # - dflags: the flags used during creation of dependency file. If not specified
495 #   the same value as cflags will be used
496 # - targetdir: the directory to put the .o file and the .d file. By default
497 #   it is put in the same directory as the .c file. When targetdir is not
498 #   empty, path names will be stripped from the file names so that all files
499 #   are in that dir and not in subdirectories.
500 # - compiler (default target): compiler to use, target, kernel or host
501 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
502     targetdir= compiler=target
504 # Adjust compiler flags to suit C++
505 TMP_CXXFLAGS := %(cflags)
506 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
507 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
509 ifeq (%(targetdir),)
510 TMP_TARGETS := $(addsuffix .o,%(basenames))
511 TMP_DTARGETS := $(addsuffix .d,%(basenames))
512 TMP_WILDCARD := %
513 else
514 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
515 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
516 TMP_WILDCARD := %(targetdir)/%
518 # Be sure that all .cpp files are generated
519 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .cpp,%(basenames))
521 # Be sure that all .cpp files are found
522 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
523 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
524 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
525 ifneq ($(TMP_DIRS),)
526     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
527     vpath %.cpp $(TMP_DIRS)
528 endif
530 endif
532 # Define the use of cross compiler
533 ifeq ($(TARGET_CXX),)
534   TMP_CC := $(CROSSTOOLSDIR)/$(AROS_TARGET_CPU)-aros-g++
535 else
536   TMP_CC := $(TARGET_CXX)
537 endif
539 ifeq ($(findstring %(compiler),host kernel target),)
540   $(error unknown compiler %(compiler))
541 endif
542 ifeq (%(compiler),target)
543 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
544 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
545 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
546 endif
547 ifeq (%(compiler),host)
548 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CXX)
549 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
550 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
551 endif
552 ifeq (%(compiler),kernel)
553 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
554 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
555 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
556 endif
558 $(TMP_TARGETS) : CFLAGS := $(TMP_CXXFLAGS)
559 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.cpp
560         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
562 ifeq (%(dflags),)
563 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
564 else
565 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
566 endif
567 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.cpp
568         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
569 %end
570 #------------------------------------------------------------------------------
573 #------------------------------------------------------------------------------
574 # Make an alias from one arch specific build to another arch.
575 # arguments:
576 # - mainmmake: the mmake of the module in the main tree
577 # - arch: the current arch
578 # - alias: the alias to which this should point
579 %define rule_archalias mainmmake=\A arch=\A alias=\A
581 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
582 %end
583 #------------------------------------------------------------------------------
586 #------------------------------------------------------------------------------
587 # Generate a rule to compile a C source file to a shared object file with a
588 # .so suffix. Basename may contain a directory part, then the source
589 # file has to be in that directory. The generated file will be put in the
590 # object directory without the directory.
591 # options
592 # - basename: the basename of the file to compile. Use % for a wildcard rule
593 # - cflags (default $(CFLAGS)): the C flags to use for compilation
594 # - targetdir: the directory to put the .o file and the .d file. By default
595 #   it is put in the same directory as the .c file
596 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
598 ifeq (%(targetdir),)
599   TMP_TARGETBASE := %(basename)
600 else
601   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
602 endif
604 ifeq ($(findstring %(compiler),host kernel target),)
605   $(error unknown compiler %(compiler))
606 endif
607 ifeq (%(compiler),target)
608 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
609 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
610 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
611 endif
612 ifeq (%(compiler),host)
613 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
614 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(HOST_IQUOTE)
615 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
616 endif
617 ifeq (%(compiler),kernel)
618 $(TMP_TARGETBASE).so : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
619 $(TMP_TARGETBASE).so : TMP_IQUOTE:=$(KERNEL_IQUOTE)
620 $(TMP_TARGETBASE).so : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
621 endif
623 $(TMP_TARGETBASE).so : %(basename).c
624         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
625 %end
626 #------------------------------------------------------------------------------
629 #------------------------------------------------------------------------------
630 # Generate a rule to assemble a source file to an object file. Basename may
631 # contain a directory part, then the source file has to be in that directory.
632 # The generated file will be put in the object directory without the directory.
633 # options
634 # - basename: the basename of the file to compile. Use % for a wildcard rule
635 # - flags (default $(AFLAGS)): the asm flags to use for assembling
636 # - targetdir: the directory to put the .o file in. By default it is put in the
637 #   same directory as the .s file
638 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
640 ifeq (%(targetdir),)
641 %(basename).o : AFLAGS := %(aflags)
642 %(basename).o : %(basename).s
643         %assemble_q
644 %(basename).o : %(basename).S
645         %assemble_q
647 else
648 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
649 %(targetdir)/$(notdir %(basename)).o : %(basename).s
650         %assemble_q
651 %(targetdir)/$(notdir %(basename)).o : %(basename).S
652         %assemble_q
654 endif
655 %end
656 #------------------------------------------------------------------------------
659 #------------------------------------------------------------------------------
660 # Generate a rule to assemble multiple source files to an object file. The
661 # generated file will be put in the object directory with the directory part
662 # of the source file stripped off.
663 # options
664 # - basenames: the basenames of the files to compile. The names may include
665 #   relative or absolute path names. No wildcard is allowed
666 # - aflags (default $(AFLAGS)): the flags to use for assembly
667 # - targetdir: the directory to put the .o file and the .d file. By default
668 #   it is put in the same directory as the .c file. When targetdir is not
669 #   empty, path names will be stripped from the file names so that all files
670 #   are in that dir and not in subdirectories.
671 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
673 ifeq (%(targetdir),)
674 TMP_TARGETS := $(addsuffix .o,%(basenames))
675 TMP_WILDCARD := %
676 else
677 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
678 TMP_WILDCARD := %(targetdir)/%
680 # Be sure that all .s files are generated
681 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
683 # Be sure that all .c files are found
684 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
685 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
686 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
687 ifneq ($(TMP_DIRS),)
688     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
689     vpath %%(suffix) $(TMP_DIRS)
690 endif
692 endif
694 ifeq ($(findstring %(compiler),host kernel target),)
695   $(error unknown compiler %(compiler))
696 endif
697 ifeq (%(compiler),target)
698 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
699 endif
700 ifeq (%(compiler),host)
701 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
702 endif
703 ifeq (%(compiler),kernel)
704 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
705 endif
707 $(TMP_TARGETS) : AFLAGS := %(aflags)
708 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
709         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
710 %end
711 #------------------------------------------------------------------------------
714 #------------------------------------------------------------------------------
715 # Link %(objs) to %(prog) using the libraries in %(uselibs)
716 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
717     usehostlibs= usestartup=yes detach=no nix=no linker=target
719 TMP_EXTRA_LDFLAGS := 
720 ifeq (%(nix),yes)
721     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
722 endif
723 ifeq (%(usestartup),no)
724     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
725 endif
726 ifeq (%(detach),yes)
727     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
728 endif
730 # Make a list of the lib files this program depends on.
731 # In LDFLAGS remove white space between -L and directory
732 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
733 # Filter out only the libdirs and remove -L
734 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
735 # Add trailing /
736 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
737 # Add normal linklib path
738 TMP_DIRS += $(LIBDIR)/
739 # add lib and .a to static linklib names
740 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
741 # search for the linklibs in the given path, ignore ones not found
742 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
743     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
746 ifeq (%(linker),target)
747 %(prog) : CMD:=$(TARGET_CC)
748 %(prog) : STRIPCMD:=$(TARGET_STRIP)
749 endif
750 ifeq (%(linker),host)
751 %(prog) : CMD:=$(HOST_CC)
752 %(prog) : STRIPCMD:=$(HOST_STRIP)
753 endif
754 ifeq (%(linker),kernel)
755 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
756 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
757 endif
759 %(prog) : OBJS := %(objs)
760 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
761 %(prog) : LIBS := $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
762 %(prog) : %(objs) $(TMP_DEPLIBS)
763         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
764 %end
765 #------------------------------------------------------------------------------
768 #------------------------------------------------------------------------------
769 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
770 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
771 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
772     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
773     usestartup=yes detach=no
775 TMP_EXTRA_LDFLAGS := 
776 ifeq (%(nix),yes)
777     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
778 endif
779 ifeq (%(usestartup),no)
780     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
781 endif
782 ifeq (%(detach),yes)
783     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
784 endif
786 # Make a list of the lib files the programs depend on.
787 # In LDFLAGS remove white space between -L and directory
788 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
789 # Filter out only the libdirs and remove -L
790 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
791 # Add trailing /
792 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
793 # Add normal linklib path
794 TMP_DIRS += $(LIBDIR)/
795 # add lib and .a to static linklib names
796 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
797 # search for the linklibs in the given path, ignore ones not found
798 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
799     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
802 $(addprefix %(targetdir)/,%(progs)) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
803 $(addprefix %(targetdir)/,%(progs)) : LIBS:= $(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))
804 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
805         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
806 %end
807 #------------------------------------------------------------------------------
810 #------------------------------------------------------------------------------
811 # Link the %(objs) to the library %(libdir)/lib%(libname).a
812 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR) linker=target
814 ifeq (%(linker),target)
815 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
816 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
817 endif
818 ifeq (%(linker),host)
819 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
820 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
821 endif
822 ifeq (%(linker),kernel)
823 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
824 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
825 endif
827 %(libdir)/lib%(libname).a : %(objs)
828         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
829 %end
830 #------------------------------------------------------------------------------
833 #------------------------------------------------------------------------------
834 # Link the %(objs) to the library %(libdir)/lib%(libname).so
835 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
837 %(libdir)/lib%(libname).so : %(objs)
838         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
839 %end
840 #------------------------------------------------------------------------------
843 #------------------------------------------------------------------------------
844 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
845 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
846 # The -noarosc flag is added so that modules are not linked with arosc.library
847 # (see /config/specs.in file)
848 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
849     ldflags=$(LDFLAGS) uselibs= usehostlibs=
851 TMP_LDFLAGS  := %(ldflags)
852 # Make a list of the lib files the programs depend on.
853 # In LDFLAGS remove white space between -L and directory
854 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
855 # Filter out only the libdirs and remove -L
856 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
857 # Add trailing /
858 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
859 # Add normal linklib path
860 TMP_DIRS += $(LIBDIR)/
861 # add lib and .a to static linklib names
862 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
863 # search for the linklibs in the given path, ignore ones not found
864 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
865     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
868 %(module) : LIB_NAMES := %(uselibs)
869 %(module) : OBJS := %(objs)
870 %(module) : ENDTAG := %(endobj)
871 %(module) : ERR := %(err)
872 %(module) : OBJDIR := %(objdir)
873 %(module) : LDFLAGS := $(TMP_LDFLAGS)
874 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
875                     -L/usr/lib $(addprefix -l,%(usehostlibs))
876 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
877         %link_module_q err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -noarosc"
879 %end
880 #------------------------------------------------------------------------------
883 #------------------------------------------------------------------------------
884 # Generate the libdefs.h include file for a module.
885 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
887 TMP_TARGET := %(modname)_libdefs.h
888 TMP_DEPS := $(GENMODULE)
889 TMP_OPTS := 
890 ifneq (%(conffile),)
891     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
892     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
893 else
894     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
895     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
896 endif
897 ifneq (%(modsuffix),)
898     TMP_OPTS += -s %(modsuffix)
899 endif
900 ifneq (%(targetdir),)
901     TMP_OPTS += -d %(targetdir)
902     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
903 endif
904 ifneq (%(version),)
905     TMP_OPTS += -v %(version)
906 endif
908 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
909 $(TMP_TARGET) : MODNAME := %(modname)
910 $(TMP_TARGET) : MODTYPE := %(modtype)
911 $(TMP_TARGET) : $(TMP_DEPS)
912         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
913         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
914 %end
915 #------------------------------------------------------------------------------
917 #------------------------------------------------------------------------------
918 # Generate the _lib.fd file for a module.
919 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
921 TMP_TARGET := %(modname)_lib.fd
922 TMP_DEPS := $(GENMODULE)
923 TMP_OPTS := 
924 ifneq (%(conffile),)
925     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
926     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
927 else
928     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
929     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
930 endif
931 ifneq (%(modsuffix),)
932     TMP_OPTS += -s %(modsuffix)
933 endif
934 ifneq (%(targetdir),)
935     TMP_OPTS += -d %(targetdir)
936     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
937 endif
939 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
940 $(TMP_TARGET) : MODNAME := %(modname)
941 $(TMP_TARGET) : MODTYPE := %(modtype)
942 $(TMP_TARGET) : $(TMP_DEPS)
943         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
944         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
945 %end
946 #------------------------------------------------------------------------------
948 #------------------------------------------------------------------------------
949 # Generate a Makefile.%(modname) with the genmodule program and include this
950 # generated file in this Makefile
951 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
952     targetdir=
954 TMP_TARGET := Makefile.%(modname)
955 TMP_DEPS := $(GENMODULE)
956 TMP_OPTS := 
957 ifneq (%(conffile),)
958     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
959     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
960 else
961     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
962     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
963 endif
964 ifneq (%(modsuffix),)
965     TMP_OPTS += -s %(modsuffix)
966 endif
967 ifneq (%(targetdir),)
968     TMP_OPTS += -d %(targetdir)
969     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
970 endif
972 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
973 $(TMP_TARGET) : MODNAME := %(modname)
974 $(TMP_TARGET) : MODTYPE := %(modtype)
975 $(TMP_TARGET) : $(TMP_DEPS)
976         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
977 %end
978 #------------------------------------------------------------------------------
981 #------------------------------------------------------------------------------
982 # Generate the support files for compiling a module. This includes include
983 # files and source files. This rule has to be preceeded by
984 # %rule_genmodule_makefile
985 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
986     conffile=
988 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
989                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
990 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
991                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
993 TMP_DEPS := $(GENMODULE)
994 TMP_OPTS :=
996 ifneq (%(conffile),)
997     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
998     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
999 else
1000     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1001     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1002 endif
1003 ifneq (%(modsuffix),)
1004     TMP_OPTS += -s %(modsuffix)
1005 endif
1006 ifneq (%(targetdir),)
1007     TMP_OPTS += -d %(targetdir)
1008     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1009     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1010 endif
1012 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1013 $(TMP_TARGETS) : MODNAME := %(modname)
1014 $(TMP_TARGETS) : MODTYPE := %(modtype)
1015 $(TMP_TARGETS) : $(TMP_DEPS)
1016         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1017 ifneq (%(conffile),lib.conf)
1018         @$(IF) $(TEST) -f lib.conf; then \
1019           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1020         fi
1021 endif
1022         @$(IF) $(TEST) -f libdefs.h; then \
1023           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1024         fi
1025         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1026 %end
1027 #------------------------------------------------------------------------------
1030 #------------------------------------------------------------------------------
1031 # Generate the support files for compiling a module. This includes include
1032 # files and source files.
1033 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1034     targetdir= conffile=
1036 ifneq ($(%(modname)_INCLUDES),)
1037 TMP_TARGETS := $(%(modname)_INCLUDES)
1039 TMP_DEPS := $(GENMODULE)
1040 TMP_OPTS :=
1042 ifneq (%(conffile),)
1043     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1044     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1045 else
1046     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1047     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1048 endif
1049 ifneq (%(modsuffix),)
1050     TMP_OPTS += -s %(modsuffix)
1051 endif
1052 ifneq (%(targetdir),)
1053     TMP_OPTS += -d %(targetdir)
1054     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1055 endif
1057 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1058 $(TMP_TARGETS) : MODNAME := %(modname)
1059 $(TMP_TARGETS) : MODTYPE := %(modtype)
1060 $(TMP_TARGETS) : $(TMP_DEPS)
1061         @$(ECHO) "Generating include files"
1062         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1063 endif
1064 %end
1065 #------------------------------------------------------------------------------
1068 #------------------------------------------------------------------------------
1069 # Common rules for all makefiles
1070 %define common
1071 # Delete generated makefiles
1073 clean ::
1074         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1076 include $(SRCDIR)/config/make.tail
1078 BDID := $(BDTARGETID)
1079 %end
1080 #------------------------------------------------------------------------------
1081       
1083 #############################################################################
1084 #############################################################################
1085 ##                                                                         ##
1086 ## Here are the mmakefile build macros. These are macros that takes care   ##
1087 ## of everything to go from the sources to the generated target. Also all  ##
1088 ## intermediate files and directories that are needed are created by these ##
1089 ## rules.                                                                  ##
1090 ##                                                                         ##
1091 #############################################################################
1092 #############################################################################
1094 #------------------------------------------------------------------------------
1095 # Build a program
1096 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1097     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1098     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1099     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1100     compiler=target linker= srcdir=
1102 .PHONY : %(mmake)
1104 BD_PROGNAME  := %(progname)
1105 BD_OBJDIR    := %(objdir)
1106 BD_TARGETDIR := %(targetdir)
1107 BD_LINKER    := %(linker)
1109 # If not supplied, linker is equal to compiler
1110 ifeq ($(BD_LINKER),)
1111     BD_LINKER := %(compiler)
1112 endif
1114 BD_FILES     := %(files)
1115 BD_CXXFILES  := %(cxxfiles)
1116 BD_ASMFILES  := %(asmfiles)
1118 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1119 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1120 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1122 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))
1123 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_NARCHFILES) $(BD_CXXFILES)))
1125 BD_CFLAGS    := %(cflags)
1126 BD_AFLAGS    := %(aflags)
1127 BD_DFLAGS    := %(dflags)
1128 BD_LDFLAGS   := %(ldflags)
1131 %(mmake)-quick : %(mmake)
1133 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1134 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1136 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1137 %rule_compile basename=%(srcdir)% targetdir=$(BD_OBJDIR) \
1138     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1139 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1140     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1141 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1142     aflags=$(BD_AFLAGS) compiler=%(compiler)
1144 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1145     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1146     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1147     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1148     linker=$(BD_LINKER)
1150 endif
1152 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1154 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1155 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1156 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1158 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1160 %(mmake)-clean ::
1161         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1162         @$(RM) $(FILES)
1164 %end
1165 #------------------------------------------------------------------------------
1168 #------------------------------------------------------------------------------
1169 # Build programs, for every C file an executable will be built with the same
1170 # name as the C file
1171 %define build_progs mmake=/A files=/A nix=no \
1172     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1173     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1174     uselibs= usehostlibs= usestartup=yes detach=no
1176 .PHONY : %(mmake)
1178 BD_OBJDIR    := %(objdir)
1179 BD_TARGETDIR := %(targetdir)
1181 BD_FILES     := %(files)
1182 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1183 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1184 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1186 BD_CFLAGS    := %(cflags)
1187 BD_DFLAGS    := %(dflags)
1188 BD_LDFLAGS   := %(ldflags)
1191 %(mmake)-quick : %(mmake)
1193 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1194 %(mmake) : $(BD_EXES)
1196 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1197 %rule_compile basename=% targetdir=$(BD_OBJDIR) nix=%(nix) \
1198     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1200 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1201     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1202     ldflags=$(BD_LDFLAGS) \
1203     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1204     usestartup="%(usestartup)" detach="%(detach)"
1206 endif
1208 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1210 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1211 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1212 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1214 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1216 %(mmake)-clean ::
1217         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1218         @$(RM) $(FILES)
1220 %end
1221 #------------------------------------------------------------------------------
1224 #------------------------------------------------------------------------------
1225 # Build a module.
1226 # This is a bare version: It just compiles and links the given files. It is
1227 # assumed that all needed boiler plate code is in the files. This should only
1228 # be used for compiling external code. For AROS code use %build_module
1229 %define build_module_simple mmake=/A modname=/A modtype=/A \
1230     files="$(basename $(call WILDCARD, *.c))" \
1231     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1232     objdir=$(OBJDIR) moduledir= \
1233     uselibs= usehostlibs= compiler=target
1235 # Define metamake targets and their dependencies
1236 #MM %(mmake) : core-linklibs includes-generate-deps
1237 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1238 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1239 #MM %(mmake)-kobj-quick
1240 #MM %(mmake)-pkg-quick
1241 #MM %(mmake)-quick
1242 #MM %(mmake)-clean
1244 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1246 .PHONY : $(BD_ALLTARGETS)
1248 ifeq (%(modname),)
1249 $(error using %build_module_simple: modname may not be empty)
1250 endif
1251 ifeq (%(modtype),)
1252 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1253 endif
1255 # Default values for variables and arguments
1256 BD_DEFLINKLIBNAME := %(modname)
1257 BD_DEFDFLAGS := %(cflags)
1258 OBJDIR ?= $(GENDIR)/$(CURDIR)
1259 BD_MODDIR := %(moduledir)
1260 ifeq ($(BD_MODDIR),)
1261   ifeq (%(modtype),library)
1262     BD_MODDIR  := $(AROS_LIBS)
1263   endif
1264   ifeq (%(modtype),gadget)
1265     BD_MODDIR  := $(AROS_GADGETS)
1266   endif
1267   ifeq (%(modtype),datatype)
1268     BD_MODDIR  := $(AROS_DATATYPES)
1269   endif
1270   ifeq (%(modtype),handler)
1271     BD_MODDIR  := $(AROS_FS)
1272   endif
1273   ifeq (%(modtype),device)
1274     BD_MODDIR  := $(AROS_DEVS)
1275   endif
1276   ifeq (%(modtype),resource)
1277     BD_MODDIR  := $(AROS_RESOURCES)
1278   endif
1279   ifeq (%(modtype),hook)
1280     BD_MODDIR  := $(AROS_RESOURCES)
1281   endif
1282   ifeq (%(modtype),mui)
1283     BD_MODDIR  := $(AROS_CLASSES)/Zune
1284   endif
1285   ifeq (%(modtype),mcc)
1286     BD_MODDIR  := $(AROS_CLASSES)/Zune
1287   endif
1288   ifeq (%(modtype),mcp)
1289     BD_MODDIR  := $(AROS_CLASSES)/Zune
1290   endif
1291   ifeq (%(modtype),usbclass)
1292     BD_MODDIR  := $(AROS_CLASSES)/USB
1293   endif
1294   ifeq (%(modtype),hidd)
1295     BD_MODDIR  := $(AROS_DRIVERS)
1296   endif
1297   ifeq (%(modtype),printer)
1298     BD_MODDIR  := $(AROS_PRINTERS)
1299   endif
1300 endif
1301 ifeq ($(BD_MODDIR),)
1302   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1303 endif
1305 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1306 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1307 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1309 %rule_compile_multi \
1310     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1311     cflags="%(cflags)" dflags="%(dflags)" \
1312     compiler=%(compiler)
1314 # Handlers use dash instead of dot in their names
1315 ifeq (%(modtype),handler)
1316 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1317 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1318 else
1319 ifeq (%(modtype),printer)
1320 BD_MODULE := $(BD_MODDIR)/%(modname)
1321 BD_PKGMOD := $(PKGDIR)/%(modname)
1322 else
1323 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1324 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1325 endif
1326 endif
1327 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1329 %(mmake)-quick : %(mmake)
1330 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1331 %(mmake)-kobj-quick : $(BD_KOBJ)
1332 %(mmake)       : $(BD_MODULE)
1333 %(mmake)-pkg   : $(BD_PKGMOD)
1334 %(mmake)-kobj  : $(BD_KOBJ)
1336 # The module is linked from all the compiled .o files
1337 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1339 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1340 # This breaks con-handler build. Here we work around this
1341 ifeq (%(modname),con)
1342     BD_ERR := $(notdir $(BD_MODULE)).err
1343 else
1344     BD_ERR := %(modname).err
1345 endif
1347 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1348                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1349                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1351 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1352                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1353                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1355 # Link kernel object file
1356 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1358 # Make these symbols local
1359 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1360             UtilityBase ExpansionBase KeymapBase KernelBase
1362 BD_SYMBOLS := $(BD_KBASE)
1364 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1365 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1366 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1367 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1368 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1369 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1370         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1371         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1372         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1375 ## Dependency fine-tuning
1377 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1378 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1380 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1381 $(BD_MODULE) : | $(BD_MODDIR)
1382 $(BD_KOBJ) : | $(KOBJSDIR)
1383 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1385 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1386 %(mmake)-clean ::
1387         @$(ECHO) "Cleaning up for module %(modname)"
1388         @$(RM) $(FILES)
1389 %end
1390 #------------------------------------------------------------------------------
1393 #------------------------------------------------------------------------------
1394 # Build a module
1395 # Explanation of this macro is done in the developer's manual
1396 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= \
1397   conffile= files="$(basename $(call WILDCARD, *.c))" \
1398   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1399   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1400   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1401   compiler=target nostartup=yes
1403 # Define metamake targets and their dependencies
1404 #MM- includes-all : %(mmake)-includes
1405 #MM- linklibs-%(modname): %(mmake)-linklib
1406 #MM- includes-%(modname): %(mmake)-includes
1407 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1408 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1409 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1410 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1411 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1412 #MM %(mmake)-linklib : %(mmake)-includes
1413 #MM %(mmake)-quick : %(mmake)-includes-quick
1414 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1415 #MM     includes-generate-deps %(mmake)-fd
1416 #MM %(mmake)-includes-quick
1417 #MM %(mmake)-includes-dirs
1418 #MM %(mmake)-fd
1419 #MM %(mmake)-makefile
1420 #MM %(mmake)-clean
1422 # All MetaMake targets defined by this macro
1423 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1424     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1425     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1426     %(mmake)-linklib %(mmake)-fd
1428 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1430 ifeq (%(modname),)
1431 $(error using %build_module: modname may not be empty)
1432 endif
1433 ifeq (%(modtype),)
1434 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1435 endif
1437 # Default values for variables and arguments
1438 BD_DEFLINKLIBNAME := %(modname)
1439 BD_DEFDFLAGS := %(cflags)
1440 OBJDIR ?= $(GENDIR)/$(CURDIR)
1442 ## Create genmodule include Makefile for the module
1444 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1446 %rule_genmodule_makefile \
1447     modname=%(modname) modtype=%(modtype) \
1448     modsuffix=%(modsuffix) targetdir=%(objdir) \
1449     conffile=%(conffile)
1451 %(objdir)/Makefile.%(modname) : | %(objdir)
1453 GLOB_MKDIRS += %(objdir)
1455 # Do not parse these statements if metatarget is not appropriate
1456 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1458 include %(objdir)/Makefile.%(modname)
1460 BD_DEFMODDIR := $(%(modname)_MODDIR)
1463 ## include files generation
1465 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1466 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1467 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1469 %(mmake)-includes-quick : %(mmake)-includes
1470 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1471     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1472     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1474 ifneq ($(%(modname)_INCLUDES),)
1475 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1476                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1477                          conffile=%(conffile)
1479 %rule_copy_diff_multi \
1480     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1481     stampfile=%(objdir)/%(modname)_geninc
1483 %rule_copy_diff_multi \
1484     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1485     stampfile=%(objdir)/%(modname)_incs
1487 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1489 TMP%(modname)_INCDIRS := \
1490     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1491     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1492     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1493 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1495 endif
1497 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1498                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1499                            conffile=%(conffile) version=%(version)
1501 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1502 $(BD_DEFLIBDEFSINC) :
1503         @$(ECHO) "generating $@"
1504         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1506 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1507 GLOB_MKDIRS += %(objdir)/include
1509 ## Extra genmodule src files generation
1510 ## 
1511 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1512                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1513                       conffile=%(conffile)
1516 ## Create FD file
1517 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1518 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1520 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1521                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1523 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1525 GLOB_MKDIRS += $(BD_FDDIR)
1528 ## Compilation
1530 BD_FILES      := %(files)
1531 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1532 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1533 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1535 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1536 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1537 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1539 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1540 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC)
1542 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1543 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1544 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1545     BD_LINKLIB :=
1546 else
1547     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname).a
1548 endif
1549 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1551 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1552 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1553 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1554     BD_RELLINKLIB :=
1555 else
1556     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel.a
1557 endif
1558 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1560 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1561 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1562     $(BD_RELLINKLIBCFILES)
1564 %rule_compile_multi \
1565     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1566     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1567     compiler=%(compiler)
1568 %rule_compile_multi \
1569     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1570     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1571     compiler=%(compiler)
1573 ifneq ($(BD_LINKLIBAFILES),)
1574 %rule_assemble_multi \
1575     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1576 endif
1578 ## Linking
1580 ifeq (%(modsuffix),)
1581 BD_SUFFIX := %(modtype)
1582 else
1583 BD_SUFFIX := %(modsuffix)
1584 endif
1586 # Handlers use dash instead of dot in their names
1587 ifeq ($(BD_SUFFIX),handler)
1588 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1589 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1590 else
1591 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1592 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1593 endif
1594 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1596 %(mmake)-quick      : %(mmake)
1597 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1598 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1599 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1600 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1601 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1602 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1604 BD_OBJS       := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1605                  $(addsuffix .o, $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES))))
1607 ifeq (%(nostartup),yes)
1608 # Handlers always have entry point
1609 ifneq (%(modtype),handler)
1610 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1611 endif
1612 endif
1614 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1615 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1616                  %(linklibobjs)
1617 BD_RELLINKLIBOBJS \
1618               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1619                  %(linklibobjs)
1621 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1622 # This breaks con-handler build. Here we work around this
1623 ifeq (%(modname),con)
1624     BD_ERR := $(notdir $(BD_MODULE)).err
1625 else
1626     BD_ERR := %(modname).err
1627 endif
1629 # The module is linked from all the compiled .o files
1630 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1631                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1632                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1634 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1635                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1636                  uselibs="%(uselibs)" usehostlibs="%(usehostlibs)"
1638 # Link static lib
1639 ifneq ($(BD_LINKLIB),)
1640 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1642 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1643 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1644 endif
1646 ifneq ($(BD_RELLINKLIB),)
1647 %rule_link_linklib libname=%(linklibname)_rel objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1649 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1650 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1651 endif
1653 # Link kernel object file
1654 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1656 # Make these symbols local
1657 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1658             UtilityBase ExpansionBase KeymapBase KernelBase
1660 BD_SYMBOLS := $(BD_KBASE)
1662 BD_KLIB := hiddstubs amiga arossupport debug rom arosm autoinit libinit
1663 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1664 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1665 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1666 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1667 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1668         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1669         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1670         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1672 ## Dependency fine-tuning
1674 BD_DEPS := $(addsuffix .d,$(addprefix %(objdir)/,$(notdir $(BD_CCFILES) $(BD_TARGETCCFILES))))
1675 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1677 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1678 $(BD_MODULE) : | %(prefix)/%(moduledir)
1679 $(BD_PKGMOD) : | $(PKGDIR)
1680 $(BD_KOBJ)   : | $(KOBJSDIR)
1681 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1683 # Some include files need to be generated before the .c can be parsed.
1684 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
1686 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1687     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1688 $(BD_DEPS) : $(BD_DFILE_DEPS)
1689 endif
1691 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1692     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1693     %(objdir)/Makefile.%(modname) \
1694     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1695     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1696     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1697     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1698     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1699     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1700     $(BD_ENDOBJS)
1701 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1702 %(mmake)-clean ::
1703         @$(ECHO) "Cleaning up for module %(modname)"
1704         @$(RM) $(FILES)
1706 endif # $(TARGET) in $(BD_ALLTARGETS)
1707 %end
1708 #------------------------------------------------------------------------------
1711 #------------------------------------------------------------------------------
1712 # Build a module skeleton
1713 # This is a stripped-down version of build_module, it only creates include files,
1714 # but no actual object. This is used when for plugins or classes with the same
1715 # API, but no actual implementation here.
1716 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1717   conffile= \
1718   objdir=$(OBJDIR) prefix=$(AROSDIR)
1720 # Define metamake targets and their dependencies
1721 #MM- includes-all : %(mmake)-includes
1722 #MM %(mmake) : %(mmake)-includes core-linklibs
1723 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1724 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1725 #MM %(mmake)-linklib : %(mmake)-includes
1726 #MM %(mmake)-quick : %(mmake)-includes-quick
1727 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1728 #MM     includes-generate-deps
1729 #MM %(mmake)-includes-quick
1730 #MM %(mmake)-includes-dirs
1731 #MM %(mmake)-makefile
1732 #MM %(mmake)-clean
1734 # All MetaMake targets defined by this macro
1735 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1736     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1737     %(mmake)-kobj %(mmake)-pkg
1739 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1741 ifeq (%(modname),)
1742 $(error using %build_module_skeleton: modname may not be empty)
1743 endif
1744 ifeq (%(modtype),)
1745 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1746 endif
1748 # Default values for variables and arguments
1749 BD_DEFLINKLIBNAME := %(modname)
1750 BD_DEFDFLAGS := %(cflags)
1751 OBJDIR ?= $(GENDIR)/$(CURDIR)
1753 ## Create genmodule include Makefile for the module
1755 %(mmake)-makefile : %(objdir)/Makefile.%(modname)
1757 %rule_genmodule_makefile \
1758     modname=%(modname) modtype=%(modtype) \
1759     modsuffix=%(modsuffix) targetdir=%(objdir) \
1760     conffile=%(conffile)
1762 %(objdir)/Makefile.%(modname) : | %(objdir)
1764 GLOB_MKDIRS += %(objdir)
1766 # Do not parse these statements if metatarget is not appropriate
1767 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1769 include %(objdir)/Makefile.%(modname)
1771 BD_DEFMODDIR := $(%(modname)_MODDIR)
1774 ## include files generation
1776 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1777 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1778 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1780 %(mmake)-includes-quick : %(mmake)-includes
1781 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1782     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1783     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1785 ifneq ($(%(modname)_INCLUDES),)
1786 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1787                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1788                          conffile=%(conffile)
1790 %rule_copy_diff_multi \
1791     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1792     stampfile=%(objdir)/%(modname)_geninc
1794 %rule_copy_diff_multi \
1795     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1796     stampfile=%(objdir)/%(modname)_incs
1798 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1800 TMP%(modname)_INCDIRS := \
1801     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1802     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1803     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1804 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1806 endif
1808 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1809                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1810                            conffile=%(conffile)
1812 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1813 $(BD_DEFLIBDEFSINC) :
1814         @$(ECHO) "generating $@"
1815         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1817 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1818 GLOB_MKDIRS += %(objdir)/include
1820 ## Extra genmodule src files generation
1821 ## 
1822 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1823                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1824                       conffile=%(conffile)
1826 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1827     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1828     %(objdir)/Makefile.%(modname) \
1829     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1830     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1831     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1832     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1833     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1834     $(BD_DEFLIBDEFSINC)
1835 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1836 %(mmake)-clean ::
1837         @$(ECHO) "Cleaning up for module %(modname)"
1838         @$(RM) $(FILES)
1840 endif # $(TARGET) in $(BD_ALLTARGETS)
1841 %end
1842 #------------------------------------------------------------------------------
1845 #------------------------------------------------------------------------------
1846 # Build a linklib.
1847 # - mmake is the mmaketarget
1848 # - libname is the baselibname e.g. lib%(libname).a will be created
1849 # - files are the C source files to include in the lib. The list of files
1850 #   has to be given without the .c suffix
1851 # - asmfiles are the asm files to include in the lib. The list of files has to
1852 #   be given without the .s suffix
1853 # - objs additional object to link into the linklib. The objects have to be
1854 #   given with full absolute path and the .o suffix.
1855 # - cflags are the flags to compile the source (default $(CFLAGS))
1856 # - dflags are the flags use during makedepend (default equal to cflags)
1857 # - aflags are the flags use during assembling (default $(AFLAGS))
1858 # - objdir is where the .o are generated
1859 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1860 %define build_linklib mmake=/A libname=/A \
1861   files="$(basename $(call WILDCARD, *.c))" \
1862   cxxfiles="$(basename $(call WILDCARD, *.cpp))" \
1863   asmfiles= objs= compiler=target \
1864   cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1866 # assign and generate the local variables used in this macro
1867 OBJDIR        ?= $(GENDIR)/$(CURDIR)
1869 BD_FILES      := %(files)
1870 BD_CXXFILES   := %(cxxfiles)
1871 BD_ASMFILES   := %(asmfiles)
1873 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1874 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1875 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1877 BD_OBJS       := $(BD_ARCHOBJS) \
1878                  $(addsuffix .o,$(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES)))) \
1879                  %(objs)
1880 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
1882 BD_CFLAGS     := %(cflags)
1883 ifeq (%(dflags),)
1884 BD_DFLAGS     := $(BD_CFLAGS)
1885 else
1886 BD_DFLAGS     := %(dflags)
1887 endif
1888 BD_AFLAGS     := %(aflags)
1890 BD_LINKLIB    := %(libdir)/lib%(libname).a
1892 .PHONY : %(mmake) %(mmake)-clean
1894 #MM %(mmake) : includes-generate-deps
1895 %(mmake) : $(BD_LINKLIB)
1898 %(mmake)-clean ::
1899         @$(RM) $(BD_OBJS) $(BD_DEPS)
1901 ifeq ($(TARGET),%(mmake))
1902 ifneq ($(dir $(BD_FILES)),./)
1903 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
1904 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
1905 endif
1907 %rule_compile basename=% targetdir=%(objdir) \
1908     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1909 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1910     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1911 %rule_assemble basename=% targetdir=%(objdir) \
1912     aflags=$(BD_AFLAGS)
1914 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
1915 endif
1917 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
1919 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1920 $(BD_LINKLIB) : | %(libdir)
1921 GLOB_MKDIRS += %(objdir) %(libdir)
1923 %end
1924 #------------------------------------------------------------------------------
1927 #------------------------------------------------------------------------------
1928 # Build catalogs.
1929 # - mmake is the mmaketarget
1930 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1931 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
1932 # - subdir is the destination subdirectory of the catalogs
1933 # - name is the name of the destination catalog, without the .catalog suffix
1934 # - source is the path to the generated source code file
1935 # - dir is the base destination directory (default $(AROS_CATALOGS))
1936 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1937 # - srcdir is the directory in which the *.cd and *.ct files are searched
1939 %define build_catalogs mmake=/A name=/A subdir=/A \
1940  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
1941  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
1943 ifeq (%(description),)
1944 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
1945 else
1946 BD_DESC := %(description)
1947 endif
1949 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
1951 ifeq (%(catalogs),)
1952 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
1953 else
1954 BD_LNGS := %(catalogs)
1955 endif
1957 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
1958 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
1961 %(mmake) : $(BD_OBJS) %(source)
1963 $(BD_OBJS) : | $(BD_DIRS)
1964 GLOB_MKDIRS += $(BD_DIRS)
1966 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
1967         @$(ECHO) "Creating   %(name) catalog for language $*."
1968         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1970 ifneq (%(source),)
1971 %(source) : BD_DESC := $(BD_DESC)
1972 %(source) : BD_SRC := $(BD_SRC)
1973 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
1974         @$(ECHO) "Creating   %(name) catalog source file $@"
1975         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
1976 endif
1979 %(mmake)-clean ::
1980         $(RM) $(BD_OBJS) %(source)
1982 .PHONY: %(mmake) %(mmake)-clean
1984 %end
1985 #-----------------------------------------------------------------------------
1988 #-----------------------------------------------------------------------------
1989 # Build icons.
1990 # - mmake is the mmaketarget
1991 # - icons is a list of icon base names (ie. without the .info suffix)
1992 # - dir is the destination directory
1993 # - srcdir is where *.png and *.info.src are searched
1994 #-----------------------------------------------------------------------------
1996 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
1998 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2001 %(mmake) : $(BD_OBJS)
2003 ifeq (%(image),)
2005 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2006         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2007         @$(ILBMTOICON) $+ $@
2009 else
2011 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2012         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2013         @$(ILBMTOICON) $+ $@
2015 endif
2017 $(BD_OBJS) : | %(dir)
2018 GLOB_MKDIRS += %(dir)
2020 %(mmake)-clean : FILES := $(BD_OBJS)
2022 %(mmake)-clean ::
2023         @$(RM) $(FILES)
2025 .PHONY: %(mmake) %(mmake)-clean
2027 %end
2028 #-----------------------------------------------------------------------------
2031 #------------------------------------------------------------------------------
2032 # Compile files for an arch-specific replacement of code for a module
2033 # - files: the basenames of the C files to compile.
2034 # - asmfiles: the basenames of the asm files to assemble.
2035 # - mainmmake: the mmake of the module in the main directory to compile these
2036 #   arch specific files for.
2037 # - maindir: the object directory for the main module
2038 # - arch: the arch for which to compile these files. It can have the form
2039 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2040 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2041 # - dflags: the flags used during creation of dependency file. If not specified
2042 #   the same value as cflags will be used
2043 # - aflags: the flags used during assembling
2044 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2045 #   the target compiler is used
2046 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2047 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2049 ifeq (%(files) %(asmfiles),)
2050   $(error no files or asmfiles given)
2051 endif
2053 %buildid targets="%(mainmmake)-%(arch)"
2055 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2056 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2057 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2058 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2059 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2060 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2061 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2062 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2063 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2064 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2065 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2066 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2067 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2068 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2069 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2070 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2071 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2072 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2073 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2074 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2075 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2077 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2079 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2080 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2081 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2082 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2083 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2085 ifneq (%(modulename),)
2086 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2087 endif
2089 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2090     BD_TARGET := %(mainmmake)-%(arch)-quick
2091 else
2092     BD_TARGET := %(mainmmake)-%(arch)
2093 endif
2096 ifeq ($(TARGET),$(BD_TARGET))
2097 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2098 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2099 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2100 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2101 endif
2103 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2104 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2107 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2110 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2112 ifeq ($(findstring %(compiler),host kernel target),)
2113   $(error unknown compiler %(compiler))
2114 endif
2115 ifeq (%(compiler),target)
2116 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2117 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2118 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2119 endif
2120 ifeq (%(compiler),host)
2121 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2122 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2123 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2124 endif
2125 ifeq (%(compiler),kernel)
2126 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2127 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2128 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2129 endif
2130 ifneq (%(modulename),)
2131 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2132 else
2133 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2134 endif
2135 ifeq ($(TARGET),$(BD_TARGET))
2136 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2137         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2138 endif
2140 ifeq (%(dflags),)
2141 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2142 else
2143 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2144 endif
2145 ifeq ($(TARGET),$(BD_TARGET))
2146 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2147         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2148 endif
2150 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2152 ifeq ($(TARGET),$(BD_TARGET))
2153 $(BD_OBJDIR$(BDID))/%.o : %.s
2154         %assemble_q opt=$(AFLAGS)
2155 $(BD_OBJDIR$(BDID))/%.o : %.S
2156         %assemble_q opt=$(AFLAGS)
2157 endif
2159 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2160 %end
2161 #------------------------------------------------------------------------------
2164 #------------------------------------------------------------------------------
2165 # generate asm files from c files (for debugging purposes)
2166 %define ctoasm_q
2167 %.s : %.c
2168         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2169         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2170 %end
2171 #------------------------------------------------------------------------------
2174 #------------------------------------------------------------------------------
2175 # Copy files from one directory to another.
2177 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2179 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2181 GLOB_MKDIRS += %(dst)
2183 .PHONY : %(mmake)
2186 %(mmake) : | %(dst) 
2187         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2189 %end
2190 #------------------------------------------------------------------------------
2193 #------------------------------------------------------------------------------
2194 # Copy a directory recursively to another place, preserving the original 
2195 # hierarchical structure
2197 # src: the source directory whose content will be copied
2198 # dst: the directory where to copy src's content. If not existing, it will be made.
2200 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2202 %(mmake)_SRC   := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2203 %(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)
2204 %(mmake)_DIRS  := $(sort $(dir $(%(mmake)_FILES)))
2206 %(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles))
2207 %(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES))
2209 GLOB_MKDIRS += $(GENDIR)/$(CURDIR)
2211 .PHONY : %(mmake)
2214 %(mmake): | $(GENDIR)/$(CURDIR)
2215         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
2216         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
2217         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
2218         for d in $(%(mmake)_DIRS); do                      \
2219             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
2220         done
2221         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
2222         for f in $(%(mmake)_FILES); do                                            \
2223             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \
2224         done;  \
2225         for dst in %(dst); do \
2226             $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \
2227         done
2229 %end
2230 #------------------------------------------------------------------------------
2233 #------------------------------------------------------------------------------
2234 #   Copy include files into the includes directories. There are currently
2235 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2236 #   for building tools that need to run on the host system $(GENINCDIR). The
2237 #   $(GENINCDIR) path must not contain any references to the C runtime
2238 #   library header files.
2240 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2241     dir= compiler=target
2243 ifeq ($(findstring %(compiler),host kernel target),)
2244 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2245 endif
2247 ifneq (%(dir),)
2248 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2249 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2250 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2251 else
2252 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2253 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2254 endif
2256 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2257         @$(CP) $< $@
2260 ifeq (%(compiler),target)
2262 ifneq (%(dir),)
2263 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2264 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2265 else
2266 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2267 endif
2269 BD_INCL_FILES += $(BD_INCL_FILES2)
2271 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2272         @$(CP) $< $@
2273 endif
2276 %(mmake) : $(BD_INCL_FILES)
2278 .PHONY: %(mmake)
2280 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2281 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2282 %end
2283 #------------------------------------------------------------------------------
2286 #------------------------------------------------------------------------------
2287 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2288 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2289 STUBS_MEM := $(addsuffix .o,$(STUBS))
2290 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2291 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2292 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2294 #MM- linklibs : hidd-%(hidd)-stubs
2295 #MM- %(parenttarget): hidd-%(hidd)-stubs
2296 #MM hidd-%(hidd)-stubs : includes includes-copy
2297 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2299 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2300         %mklib_q from=$^
2302 $(STUBS_OBJ) : $(STUBS_SRC) 
2303         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2305 $(STUBS_DEP) : $(STUBS_SRC)
2306         %mkdepend_q flags=%(dflags)
2308 setup ::
2309         %mkdirs_q $(OBJDIR) $(LIBDIR)
2312 clean ::
2313         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2315 DEPS := $(DEPS) $(STUBS_DEP)
2317 %end
2318 #------------------------------------------------------------------------------
2321 #------------------------------------------------------------------------------
2322 # Build an imported source tree which uses the configure script from the
2323 # autoconf package.  This rule will try to "integrate" the produced files as
2324 # much as possible in the AROS build, for example by putting libraries in the
2325 # standard library directory, includes in the standard include directory, and
2326 # so on. You can however override this behaviour.
2328 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2329 # be %(bindir) (or its deduced value) when running "make install", and
2330 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2331 # configure script some more parameters whose value depends upon the PROGDIR
2332 # env var, so that the program gets all its stuff installed in the proper place
2333 # when building it, but when running it from inside AROS it can also find that
2334 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2335 # the configuration parameters set when running ./configure
2337 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2338 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2339 # to the name which has to follow it.
2342 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) prefix= \
2343     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2344     install_target=install preconfigure= postconfigure= postinstall= \
2345     install_env= use_build_env=no
2347 ifneq (%(prefix),)
2348     %(mmake)-prefix := %(prefix)
2349 else
2350     %(mmake)-prefix := $(AROS_CONTRIB)
2351 endif
2353 ifneq (%(aros_prefix),)
2354     %(mmake)-aros_prefix := %(aros_prefix)
2355 else
2356     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2357 endif
2359 ifeq (%(nix),yes)
2360     %(mmake)-nix    := -nix
2361     %(mmake)-volpfx := /
2362     %(mmake)-volsfx := /
2363     
2364     ifeq (%(nix_dir_layout),)
2365         %(mmake)-nix_dir_layout := yes
2366     endif
2367 else
2368     %(mmake)-volsfx := :
2369     
2370     ifeq (%(nix_dir_layout),)
2371         %(mmake)-nix_dir_layout := no
2372     endif
2373 endif
2375 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2377 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2378         exec_prefix=$(%(mmake)-prefix) %(install_env)
2380 # Check if chosen compiler is valid
2381 ifeq ($(findstring %(compiler),host target kernel),)
2382   $(error unknown compiler %(compiler))
2383 endif
2385 # Set legacy 'host' variable based on chosen compiler
2386 ifeq (%(compiler),host)
2387     host := yes
2388         ifeq (%(package),)
2389                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2390         else
2391                 %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2392         endif
2393 else
2394     host := no
2395         ifeq (%(package),)
2396                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2397         else
2398                 %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2399         endif
2400 endif
2402 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2403 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2405 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2406     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2407     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2408 else
2409     ifeq (%(nix),yes)
2410         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2411         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2412     else
2413         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2414     endif
2416     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2417     
2418     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2419         sbindir=$(%(mmake)-prefix) \
2420         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2421         oldincludedir=$(AROS_INCLUDES) %(install_env)
2422 endif
2424 ifneq ($(DEBUG),yes)
2425     %(mmake)-s_flag = -s
2426 endif
2428 # Set up build environment, and options for configure script
2429 ifeq (%(compiler),host)
2430     CONFIG_ENV := \
2431         CPP="$(HOST_CPP)" \
2432         CXXCPP="$(HOST_CPP)" \
2433         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2434         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2435         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2436         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2437         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2438 endif
2439 ifeq (%(compiler),target)
2440     CONFIG_ENV := \
2441         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2442         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2443         CPP="$(TARGET_CPP)" \
2444         CXXCPP="$(TARGET_CPP)" \
2445         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2446         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2447         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2448         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2449         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2450         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2451         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2452         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2453     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2454         --host=$(AROS_TARGET_CPU)-aros\
2455         --target=$(AROS_TARGET_CPU)-aros\
2456         --disable-nls\
2457         --without-x --without-pic --disable-shared
2458 endif
2459 ifeq (%(compiler),kernel)
2460     CONFIG_ENV := \
2461         CPP="$(KERNEL_CPP)" \
2462         CXXCPP="$(KERNEL_CPP)" \
2463         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2464         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2465         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2466         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"
2467     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2468         --host=$(AROS_TARGET_CPU)-aros\
2469         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2470         --without-x --without-pic --disable-shared
2471 endif
2473 ifeq (%(use_build_env),yes)
2474     BUILD_ENV := $(CONFIG_ENV)
2475 endif
2478 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2480 # When building for the host, we don't need to build the
2481 # linklibs - this is especially true when building the
2482 # crosstool toolchain on 'foreign' architectures (such as
2483 # building PPC on x86)
2485 #MM- %(mmake)-host : setup includes %(mmake)-quick
2486 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2487 #MM- %(mmake): %(mmake)-%(compiler)
2489 # Using -j1 in install_command may result in a warning but finally
2490 # it does its job. make install for gcc does not work reliably for -jN
2491 # where N > 1.
2492 ifneq (%(install_target),)
2493     %(mmake)-install_command = \
2494         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2495         -C $(%(mmake)-pkgdir) %(install_target) -j1
2497     %(mmake)-uninstall_command = \
2498     $(RM) $(%(mmake)-installflag) && \
2499     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2500     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2501 else
2502     %(mmake)-install_command   := true
2503     %(mmake)-uninstall_command := true
2504 endif
2506 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2509 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2511 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2512         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2513             $(RM)  $(%(mmake)-installflag) && \
2514             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2515              -C $(%(mmake)-pkgdir) && \
2516             $(%(mmake)-install_command) && \
2517             $(TOUCH) $@ -r $^; \
2518         fi
2520 $(%(mmake)-pkgdir)/.files-touched:
2521         %mkdirs_q $(%(mmake)-pkgdir)
2522         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2523         $(TOUCH) $@
2526 %(mmake)-uninstall :
2527         $(%(mmake)-uninstall_command)
2530 %(mmake)-configure : $(%(mmake)-configflag)
2532 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2533 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2534         $(RM) $@
2535         %mkdirs_q $(%(mmake)-pkgdir)
2536         cd $(%(mmake)-pkgdir) && \
2537         find . -name config.cache -exec $(RM) '{}' \; && \
2538         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2539             %(extraoptions) && \
2540         $(TOUCH) $@
2543 %(mmake)-clean : %(mmake)-uninstall
2544         @$(RM) $(%(mmake)-pkgdir)
2545 %end
2546 #------------------------------------------------------------------------------
2549 #------------------------------------------------------------------------------
2550 # Given an archive name, patches names and locations where to find them, fetch
2551 # the archive and the patches from any of those locations, unpack the archive
2552 # and then apply the patches.
2554 # Locations currently supported are http and ftp sites, plus local filesystem
2555 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2556 # the fetch.sh script needs to be modified, since this macro relies on that script.
2558 # Arguments:
2560 #     - mmake           = mmaketarget
2561 #     - archive_origins = list of locations where to find the archive. They are tried
2562 #                         in sequence, until the archive is found and fetching it 
2563 #                         succeeded. If not specified, the current directory is assumed.
2564 #     - archive         = the archive name. Mandatory.
2565 #     - suffixes        = a list of suffixes to append to the the package name plus the
2566 #                         version. Each one of them is tried until a matching archive is
2567 #                         found. They are appended to patches and these are tried the
2568 #                         same way as packages are.
2569 #     - location        = the local directory where to put the fetched archive and patches.
2570 #                         If not specified, the directory specified by destination is used.
2571 #     - destination     = the directory to unpack the archive to.
2572 #                         If not specified, the current directory is assumed.
2573 #     - patches_origins = list of locations where to find the patches. They are tried
2574 #                         in sequence, until a patch is found and fetching it 
2575 #                         succeeded. If not specified, the current directory is assumed.
2576 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2577 #                         patch_name[:[patch_subdir][:patch_opt]].
2579 #                             - patch_name   = the name of the patch file
2580 #                             - patch_subdir = the directory within \destination\ where to
2581 #                                              apply the patch.
2582 #                             - patch_opt    = any options to pass to the `patch' command
2583 #                                              when applying the patch.
2584 #                         
2585 #                         The patch_subdir and patch_opt fields are optional.
2587 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2588     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2590 .PHONY: %(mmake)
2592 ifneq (%(location),)
2593     %(mmake)-location := %(location)
2594 else
2595     %(mmake)-location := %(destination)
2596 endif
2599 %(mmake) :
2600         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2601         -d %(destination) -po "%(patches_origins)" -p %(patches_specs)
2602 %end
2603 #------------------------------------------------------------------------------
2606 #------------------------------------------------------------------------------
2607 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2608 # unpatched source tree and runs diff against this and a previously fetched and possibly
2609 # patched tree. Depending on what happens after patching during a normal build it might
2610 # give best results if the new patch is created directly after fetch.
2612 # Arguments:
2614 #     - mmake       = mmaketarget
2615 #     - archive     = archive base name
2616 #     - srcdir      = directory the package is unpacked to, useful if archive unpacks to
2617 #                     a directory other than its name suggests.
2618 #     - suffixes    = a list of suffixes to append to the the package name plus the
2619 #                     version. Each one of them is tried until a matching archive is
2620 #                     found.
2621 #     - destination = the directory to unpack the archive to.
2622 #     - excludes    = diff patterns to exclude files or directories from the patch
2624 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2626 .PHONY: %(mmake)
2628 ifneq (%(excludes),)
2629     %(mmake)-exclude := -X ./exclude.patterns
2630 endif
2632 ifneq (%srcdir),)
2633     %(mmake)-srcdir := %(srcdir)
2634 else
2635     %(mmake)-srcdir := %(archive)
2636 endif
2639 %(mmake):
2640         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2641         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2642         cd %(destination)/tmp ; \
2643         $(FOR) f in %(excludes) ; do \
2644             $(ECHO) $$f >> ./exclude.patterns ; \
2645         done ; \
2646         diff -ruN $(%(mmake)-exclude) \
2647             $(%(mmake)-srcdir) \
2648             $(%(mmake)-srcdir).aros \
2649             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2650         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2651         $(RM) %(destination)/tmp
2652 %end
2653 #------------------------------------------------------------------------------
2656 #------------------------------------------------------------------------------
2657 # Joins the features of %fetch and %build_with_configure, taking advantage of
2658 # the naming scheme of GNU packages. GNU packages names are in the form
2660 #     <package name>-<version number>.<archive format suffix>
2662 # If a patch is provided, it *must* be named the following way:
2664 #    <package name>-<version number>-aros.diff
2666 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2667 # CD'ing into the archive's extracted directory.
2669 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2670 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2671 # to make that patch fully comprehensive.
2673 # NOTE: GNU packages are always compiled with *nix semantics turned on.
2675 # Arguments:
2677 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
2678 #                     macro.
2679 #    - package      = the GNU package name, sans version and archive format suffixes.
2680 #    - version      = the package's version number, or otherwise any other version string.
2681 #                     It gets appended to the package name to form the basename of the archive.
2682 #    - suffixes     = a list of suffixes to apped to the the package name plus the
2683 #                     version. Each one of them is tried until a matching archive is found.
2684 #                     Defaults to "tar.bz2 tar.gz".
2685 #    - destination  = same meaning as the one for the %fetch macro
2686 #    - location     = same meaning as the one for the %fetch macro
2687 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
2688 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
2689 #                     fetched or not
2690 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
2691 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
2692 #                     $(GNUDIR).
2693 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
2694 #                     /GNU.
2695 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
2696 #    - extracflags  = same meaning as the one for the %build_with_configure macro.
2697 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
2698 #    - create_pkg   = create a distributable package of the compiled sources, defaults to no
2700 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target version=/A suffixes="tar.bz2 tar.gz" \
2701     srcdir= package_repo= patch=no patch_repo= prefix= aros_prefix= extraoptions= extracflags= \
2702     preconfigure= postconfigure= postinstall= nix=no nix_dir_layout= create_pkg=no
2704 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2705 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2706 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2707 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2709 %(mmake)-archbase  := %(package)-%(version)
2711 ifeq (%(compiler),host)
2712     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2713 else
2714     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2715 endif
2717 ifeq (%(prefix),)
2718     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2719 else
2720     %(mmake)-prefix := %(prefix)
2721 endif
2723 ifneq (%(subpackage),)
2724     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
2725 else
2726     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
2727 endif
2729 ifneq (%(srcdir),)
2730     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
2731 else
2732     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
2733 endif
2735 ifeq (%(patch),yes)
2736     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1
2737 else
2738     %(mmake)-%(subpackage)-patches_specs := ::
2739 endif
2741 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
2742     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
2743     archive_origins=". %(package_repo)" \
2744     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
2746 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
2747     archive=$(%(mmake)-%(subpackage)-archbase) \
2748     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
2749     suffixes="%(suffixes)" \
2750     destination=$(%(mmake)-portdir)
2752 #MM- %(mmake) : %(mmake)-%(subpackage)
2754 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
2756 %(mmake)-%(subpackage)-package-basename := \
2757     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
2759 ifneq (%(create_pkg),no)
2760     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2761 endif
2763 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) \
2764      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-srcdir) \
2765      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
2766      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
2767      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2769 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
2770 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2773 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
2775 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2776 #that $^ and $@ have exactly the same mtime, and in that case make tries
2777 #to rebuild $@ again, which would fail because the directory where
2778 #the package got installed would not exist anymore. 
2779 #We work this around by using an if statement to manually check the mtimes.
2780 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2781         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
2782         $(RM) $@ ; \
2783         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
2784         mkdir -p "$(DISTDIR)/Packages" ; \
2785         mkdir -p "$(%(mmake)-prefix)" ; \
2786         cd $(%(mmake)-%(subpackage)-package-dir) ; \
2787         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
2788         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
2789     fi
2790 %end
2791 #------------------------------------------------------------------------------
2794 #------------------------------------------------------------------------------
2795 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2796     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2797     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
2799 GNU_REPOSITORY := gnu://
2801 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2802     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2803     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
2804     patch="%(patch)" patch_repo="%(patch_repo)" \
2805     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
2806     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2808 %end
2809 #------------------------------------------------------------------------------
2812 #------------------------------------------------------------------------------
2813 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2814 # that the package is a "Development" package, and as such it needs to be placed
2815 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2817 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2818 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2819 # "mmake" argument, because the metatarget is implicitely defined as
2821 #     #MM- development-%(package)
2823 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2824     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2825     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
2827 #MM- development : development-%(package)
2830 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2831    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2832    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2833    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
2834    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
2837 postinstall-%(package)-delete-la-files:
2838         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
2840 %end
2841 #------------------------------------------------------------------------------
2843 # Builds a kickstart package in PKG format
2844 # mmake   - target name
2845 # file    - Destination file name with path
2846 # startup - The file which will be put first
2847 # Other arguments are self-explanatory
2849 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= startup=
2851 PKG_CLASSES   := $(addsuffix .class, %(classes))
2852 PKG_DEVICES   := $(addsuffix .device, %(devs))
2853 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
2854 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
2855 PKG_LIBS      := $(addsuffix .library, %(libs))
2856 PKG_RESOURCES := $(addsuffix .resource, %(res))
2858 PKG_FILES := %(startup) $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
2859 PKG_DIR   := $(dir %(file))
2860 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
2863 %(mmake) : %(file)
2866 %(mmake)-quick : %(file)
2868 %(file): PKG_FILES := $(PKG_FILES)
2869 %(file): $(PKG_DEPS) | $(PKG_DIR)
2870         @$(ECHO) Packaging $@...
2871         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
2873 %compress_file mmake=%(mmake) file=%(file)
2875 GLOB_MKDIRS += $(PKG_DIR)
2877 %end
2879 #------------------------------------------------------------------------------
2880 # Compresses %(file) with a gzip.
2881 # Good in conjunction with for example %build_prog
2883 %define compress_file mmake=/A file=/A
2885 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
2888 %(mmake)-gz-quick : %(file).gz
2890 %(file).gz: %(file)
2891         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
2892         @gzip -9 -f $^
2894 %end
2896 #------------------------------------------------------------------------------
2897 # Links a kickstart module in ELF format
2898 # Arguments are similar to make_package
2900 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
2901     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
2903 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
2904 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
2905 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
2906 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
2907 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
2908 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
2910 ifeq (%(startup),)
2911     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
2912 else
2913     KOBJ_STARTUP := %(startup)
2914 endif
2916 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
2918 TMP_LDFLAGS := %(ldflags)
2920 # Make a list of the lib files this program depends on.
2921 # In LDFLAGS remove white space between -L and directory
2922 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
2923 # Filter out only the libdirs and remove -L
2924 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
2925 # Add trailing /
2926 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
2927 # Add normal linklib path
2928 TMP_DIRS += $(LIBDIR)/
2929 # add lib and .a to static linklib names
2930 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
2931 # search for the linklibs in the given path, ignore ones not found
2932 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
2933     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
2936 TMP_DIRS += $(dir %(file))
2937 ifneq (%(map),)
2938     TMP_LDFLAGS += $(GENMAP) %(map)
2939     TMP_DIRS    += $(dir %(map))
2940 endif
2942 #MM %(mmake) : %(deps)
2945 %(mmake) : %(file)
2948 %(mmake)-quick : %(file)
2950 %(file): KOBJS := $(KOBJS)
2951 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS)
2952 %(file): LDLIBS := $(addprefix -l, %(uselibs))
2953 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
2954         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2955         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS) -noarosc
2956         @$(STRIP) $@
2958 %compress_file mmake=%(mmake) file=%(file)
2960 GLOB_MKDIRS += $(TMP_DIRS)
2962 %end
2964 #------------------------------------------------------------------------------
2965 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
2966 # 'start' is an optional starting address
2967 # 'ldflags' is optional additional flags for the linker
2968 %define rule_link_binary file=/A name=/A objs=/A start=0 ldflags=
2970 BD_OUTDIR := $(dir %(file))
2971 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
2972 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
2973 BD_TMPDIR := $(GENDIR)/$(CURDIR)
2975 %(file) : %(objs) $(BD_OUTDIR)
2976         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
2977         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) %(objs)
2978         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
2980 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
2981     GLOB_MKDIRS += $(BD_OUTDIR)
2982 endif
2984 %end