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