use SRCDIR - not TMP_SRCDIR (foxes FryingPan build)
[AROS.git] / config / make.tmpl
blobc097bd887b7c1286e89cae3e8535fc17fee7fea0
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 # Convert the ISO-8859-1 string in %(string) to the host's locale (if necessary)
14 %define localisestr string= var=
15 ifeq (,$(findstring "ISO-8859-1",$(LOCALE)))
16 %(var) := $(shell echo %(string) | iconv -f iso-8859-1 )
17 else
18 %(var) := %(string)
19 endif
20 %end
22 #------------------------------------------------------------------------------
23 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
24 # and use the options in %(opt). Use %(iquote) and %(iquote_end) for supplying -iquote or -I- flags
25 %define compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=$(CFLAGS) from=$< to=$@ iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
26         @$(ECHO) "Compiling  $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))"
27         @$(IF) %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
28             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
29                 $(ECHO) "%(from): %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
30                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
31             else \
32                 $(NOP) ; \
33             fi ; \
34         else \
35             $(ECHO) "Compile failed: %(cmd) %(iquote) $(dir %(from)) %(iquote) $(SRCDIR)/$(CURDIR) %(iquote) . %(iquote_end) %(opt) -c %(from) -o %(to)" 1>&2 ; \
36             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
37             exit 1 ; \
38         fi
39 %end
40 #------------------------------------------------------------------------------
43 #------------------------------------------------------------------------------
44 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
45 %define assemble_q cmd=$(CC) opt=$(AFLAGS) from=$< to=$@
46         @$(ECHO) "Assembling $(notdir %(from))..."
47         @$(IF) %(cmd) %(opt) %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
48             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
49                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) %(from) -o %(to)" >> $(GENDIR)/errors ; \
50                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
51             else \
52                 $(NOP) ; \
53             fi ; \
54         else \
55             $(ECHO) "Assemble failed: %(cmd) %(opt) %(from) -o %(to)" 1>&2 ; \
56             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
57             exit 1 ; \
58         fi
59 %end
60 #-------------------------------------------------------------------------
63 #------------------------------------------------------------------------------
64 # Link a specified number of objects to an executable
65 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
76             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
77             exit 1 ; \
78         fi; \
79         %(strip) %(to)
80 %end
81 #------------------------------------------------------------------------------
84 #-------------------------------------------------------------------------
85 # Link a module based upon a number of arguments and the standard $(LIBS)
86 # and $(DEPLIBS) make variables.
88 %define link_module_q cmd=$(AROS_CC) err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) -nostdc %(ldflags) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(endtag) -o $@"; \
98             cat %(objdir)/%(err); \
99             exit 1; \
100         fi
102         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
103         @$(STRIP) $@
104 %end
105 #------------------------------------------------------------------------------
108 #------------------------------------------------------------------------------
109 # Create the library
110 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
111         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,%(to))..."
112         @%(ar) %(to) %(from)
113         @%(ranlib) %(to)
114 %end
115 #------------------------------------------------------------------------------
118 #------------------------------------------------------------------------------
119 # Create the dependency file %(to) for %(from)
120 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
121         %mkdir_q dir="$(dir %(to))"
122         @$(ECHO) "Makedepend $(if $(filter /%,%(from)),$(if $(filter $(SRCDIR)/%,$(abspath %(from))),$(patsubst $(SRCDIR)/%,%,$(abspath %(from))),$(patsubst $(TOP)/%,%,$(abspath %(from)))),$(patsubst $(SRCDIR)/%,%,$(abspath $(SRCDIR)/$(CURDIR)/%(from))))..."
123         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) -I$(TOP)/$(CURDIR) -I$(SRCDIR)/$(CURDIR) %(from) -o %(to)
124 %end
125 #------------------------------------------------------------------------------
128 #------------------------------------------------------------------------------
129 # Create one directory without any output
130 %define mkdir_q dir=.
131         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
132 %end
133 #------------------------------------------------------------------------------
136 #------------------------------------------------------------------------------
137 # Create several directories without any output
138 %define mkdirs_q dirs=/M
139         @$(FOR) dir in %(dirs) ; do \
140             $(IF) $(TEST) ! -d $$dir ; then $(MKDIR) $$dir ; else $(NOP) ; fi ; \
141         done
142 %end
143 #------------------------------------------------------------------------------
146 #############################################################################
147 #############################################################################
148 ##                                                                         ##
149 ## Here are the mmakefile macros that are used to do certain tasks in a    ##
150 ## mmakefile. They consist of one or more full makefile rules.             ##
151 ## In general the files generated in these macros are also defined as      ##
152 ## make targets so that they can be used as a dependency in other rules    ##
153 ##                                                                         ##
154 #############################################################################
155 #############################################################################
157 #------------------------------------------------------------------------------
158 # Generate a unique id for each of the %build... rules
159 %define buildid targets=/A
160 BDID := $(BDID)_
161 ifneq ($(filter $(TARGET),%(targets)),)
162 BDTARGETID := $(BDID)
163 endif
164 %end
165 #------------------------------------------------------------------------------
168 #------------------------------------------------------------------------------
169 # Copy file %(from) to %(to) in a makefile rule
170 %define rule_copy from=/A to=/A
171 %(to) : %(from)
172         @$(CP) $< $@
173 %end
174 #------------------------------------------------------------------------------
177 #------------------------------------------------------------------------------
178 # Copy the files %(files) to %(targetdir). For each file in %(files),
179 # %(srcdir)/file is copied to %(targetdir)/file. The targetdir and the
180 # appropriate subdirs are not generated by this rule so they have to be
181 # present.
182 %define rule_copy_multi files=/A targetdir=/A srcdir=.
184 $(addprefix %(targetdir)/,%(files)) : %(targetdir)/% : %(srcdir)/%
185         @$(CP) $< $@
186 %end
187 #------------------------------------------------------------------------------
190 #------------------------------------------------------------------------------
191 # Copy the files %(files) to %(targetdir). For each file in %(files),
192 # %(srcdir)/file is copied to %(targetdir)/file if these files are different.
193 # %(stampfile) is used to keep track of when the last time the comparison has
194 # been done. The targetdir and the appropriate subdirs are not generated by 
195 # this rule so they have to be present.
196 %define rule_copy_diff_multi files=/A targetdir=/A srcdir=. \
197     stampfile=$(TMP_SRCDIR)/.copy_stamp
199 TMP_SRCDIR := %(srcdir)
201 $(addprefix %(targetdir)/,%(files)) : | %(stampfile)
203 %(stampfile) : COPYSRCDIR := %(srcdir)
204 %(stampfile) : TGTDIR := %(targetdir)
205 %(stampfile) : FILES := %(files)
206 %(stampfile) : $(addprefix %(srcdir)/,%(files))
207         @for f in $(FILES); do \
208              $(IF) ! $(CMP) -s $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; then \
209                  $(CP) $(COPYSRCDIR)/$$f $(TGTDIR)/$$f ; \
210              fi ; \
211         done
212         @$(TOUCH) $@
213 %end
214 #------------------------------------------------------------------------------
217 #------------------------------------------------------------------------------
218 # Will join all the files in %(from) to %(to). When text is specified it will
219 # be displayed.
220 # Restriction: at the moment when using a non-empty target dir %(from) may
221 # not have 
222 %define rule_join to=/A from=/A text=
224 %(to) : %(from)
225 ifneq (%(text),)
226         @$(ECHO) %(text)
227 endif
228         @$(CAT) $^ >$@
229 %end
230 #------------------------------------------------------------------------------
233 #------------------------------------------------------------------------------
234 # Include the dependency files and add some internal rules
235 # When depstargets is provided the depencies will only be included when one of
236 # these targets is the $(TARGET). Otherwise the dependencies will only be
237 # included when the $(TARGET) is not for setup or clean 
238 %define include_deps deps=$(DEPS)/M  depstargets=
239 ifneq (%(deps),)
240   ifneq (%(depstargets),)
241     ifneq ($(findstring $(TARGET),%(depstargets)),)
242       -include %(deps)
243     endif
244   else
245     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
246       -include %(deps)
247     endif
248   endif
249 endif
250 %end
251 #------------------------------------------------------------------------------
254 #------------------------------------------------------------------------------
255 # Create the directories %(dirs). The creation will be done by adding rules to
256 # the %(setuptarget) make target with setup as the default. 
257 %define rule_makedirs dirs=/A setuptarget=setup
259 %(setuptarget) :: %(dirs)
261 GLOB_MKDIRS += %(dirs)
263 %end
264 #------------------------------------------------------------------------------
267 #------------------------------------------------------------------------------
268 # Generate a rule to compile a C source file to an object file and generate
269 # the dependency file. Basename may contain a directory part, then the source
270 # file has to be in that directory. The generated file will be put in the
271 # object directory without the directory.
272 # options
273 # - basename: the basename of the file to compile. Use % for a wildcard rule
274 # - cflags (default $(CFLAGS)): the C flags to use for compilation
275 # - dflags: the flags used during creation of dependency file. If not specified
276 #   the same value as cflags will be used
277 # - targetdir: the directory to put the .o file and the .d file. By default
278 #   it is put in the same directory as the .c file
279 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
281 ifeq (%(targetdir),)
282   TMP_TARGETBASE := %(basename)
283 else
284   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
285 endif
287 ifeq ($(findstring %(compiler),host kernel target),)
288   $(error unknown compiler %(compiler))
289 endif
290 ifeq (%(compiler),target)
291 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
292 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
293 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
294 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
295 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
296 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
297 endif
298 ifeq (%(compiler),host)
299 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
300 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
301 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
302 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
303 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
304 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
305 endif
306 ifeq (%(compiler),kernel)
307 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
308 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
309 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
310 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
311 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
312 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
313 endif
315 $(TMP_TARGETBASE).o : CFLAGS := %(cflags)
316 $(TMP_TARGETBASE).o : %(basename).c
317         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
319 ifeq (%(dflags),)
320   ifeq (%(nix),yes)
321     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(cflags)
322   else
323     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
324   endif
325 else
326   ifeq (%(nix),yes)
327     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
328   else
329     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
330   endif
331 endif
332 $(TMP_TARGETBASE).d : %(basename).c
333         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
334 %end
335 #------------------------------------------------------------------------------
338 #------------------------------------------------------------------------------
339 # Generate a rule to compile a C++ source file to an object file and generate
340 # the dependency file. Basename may contain a directory part, then the source
341 # file has to be in that directory. The generated file will be put in the
342 # object directory without the directory.
343 # options
344 # - basename: the basename of the file to compile. Use % for a wildcard rule
345 # - cflags (default $(CFLAGS)): the C flags to use for compilation
346 # - dflags: the flags used during creation of dependency file. If not specified
347 #   the same value as cflags will be used
348 # - targetdir: the directory to put the .o file and the .d file. By default
349 #   it is put in the same directory as the .c file
350 %define rule_compile_cxx basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
352 ifeq (%(targetdir),)
353   TMP_TARGETBASE := %(basename)
354 else
355   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
356 endif
358 # Adjust compiler flags to suit C++
359 TMP_CXXFLAGS := %(cflags)
360 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
361 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
363 ifeq ($(findstring %(compiler),host kernel target),)
364   $(error unknown compiler %(compiler))
365 endif
366 ifeq (%(compiler),target)
367 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
368 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_CFLAGS)
369 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
370 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
371 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
372 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
373 endif
374 ifeq (%(compiler),host)
375 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
376 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
377 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
378 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
379 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
380 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
381 endif
382 ifeq (%(compiler),kernel)
383 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
384 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
385 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
386 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
387 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
388 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
389 endif
391 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CXXFLAGS)
392 $(TMP_TARGETBASE).o : %(basename).cpp
393         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
395 ifeq (%(dflags),)
396   ifeq (%(nix),yes)
397     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_CXXFLAGS)
398   else
399     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_CXXFLAGS)
400   endif
401 else
402   ifeq (%(nix),yes)
403     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
404   else
405     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
406   endif
407 endif
408 $(TMP_TARGETBASE).d : %(basename).cpp
409         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
410 %end
411 #------------------------------------------------------------------------------
414 #------------------------------------------------------------------------------
415 # Generate a rule to compile multiple C source files to an object file and
416 # generate the corresponding dependency files. The generated file will be put
417 # in the object directory without the directory part of the source file.
418 # options
419 # - basenames: the basenames of the files to compile. The names may include
420 #   relative or absolute path names. No wildcard is allowed
421 # - cflags (default $(CFLAGS)): the C flags to use for compilation
422 # - dflags: the flags used during creation of dependency file. If not specified
423 #   the same value as cflags will be used
424 # - targetdir: the directory to put the .o file and the .d file. By default
425 #   it is put in the same directory as the .c file. When targetdir is not
426 #   empty, path names will be stripped from the file names so that all files
427 #   are in that dir and not in subdirectories.
428 # - compiler (default target): compiler to use, target, kernel or host
429 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
430     compiler=target
432 ifeq (%(targetdir),)
433 TMP_TARGETS := $(addsuffix .o,%(basenames))
434 TMP_DTARGETS := $(addsuffix .d,%(basenames))
435 TMP_WILDCARD := %
436 else
437 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
438 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
439 TMP_WILDCARD := %(targetdir)/%
441 # Be sure that all .c files are generated
442 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
444 # Be sure that all .c files are found
445 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
446 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
447 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
448 ifneq ($(TMP_DIRS),)
449     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
450     vpath %.c $(TMP_DIRS)
451 endif
453 endif
455 ifeq ($(findstring %(compiler),host kernel target),)
456   $(error unknown compiler %(compiler))
457 endif
458 ifeq (%(compiler),target)
459 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
460 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
461 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
462 endif
463 ifeq (%(compiler),host)
464 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
465 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
466 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
467 endif
468 ifeq (%(compiler),kernel)
469 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
470 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
471 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
472 endif
474 $(TMP_TARGETS) : CFLAGS := %(cflags)
475 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
476         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
478 ifeq (%(dflags),)
479 $(TMP_DTARGETS) : DFLAGS:=%(cflags)
480 else
481 $(TMP_DTARGETS) : DFLAGS:=%(dflags)
482 endif
483 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
484         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
485 %end
486 #------------------------------------------------------------------------------
489 #------------------------------------------------------------------------------
490 # Generate a rule to compile multiple C++ source files to an object file and
491 # generate the corresponding dependency files. The generated file will be put
492 # in the object directory without the directory part of the source file.
493 # options
494 # - basenames: the basenames of the files to compile. The names may include
495 #   relative or absolute path names. No wildcard is allowed. basenames will be 
496 #   matched to supported AROS_CXXEXTS.
497 # - cflags (default $(CFLAGS)): the C flags to use for compilation
498 # - dflags: the flags used during creation of dependency file. If not specified
499 #   the same value as cflags will be used
500 # - targetdir: the directory to put the .o file and the .d file. By default
501 #   it is put in the same directory as the .c file. When targetdir is not
502 #   empty, path names will be stripped from the file names so that all files
503 #   are in that dir and not in subdirectories.
504 # - compiler (default target): compiler to use, target, kernel or host
505 %define rule_compile_cxx_multi basenames=/A cflags=$(CFLAGS) dflags= \
506     targetdir= compiler=target
508 # Adjust compiler flags to suit C++
509 TMP_CXXFLAGS := %(cflags)
510 TMP_CXXFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_CXXFLAGS)))
511 TMP_CXXFLAGS := $(TMP_CXXFLAGS) -fno-rtti -fno-exceptions -fno-check-new -isystem $(AROS_DEVELOPMENT)/include
513 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
514 ifneq ($(TMP_CXXABSBASENAMES),)
515 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
517 # Identify the "real" c++ files from the passed in basenames
518 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
520 ifeq (%(targetdir),)
521   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
522   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
523   TMP_WILDCARD := %
524 else
525   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
526   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
527   TMP_WILDCARD := %(targetdir)/%
529   # Be sure that all source files are generated
530   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
531 endif
533 ifeq ($(findstring %(compiler),host kernel target),)
534   $(error unknown compiler %(compiler))
535 endif
536 ifeq (%(compiler),target)
537   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_CFLAGS)
538   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
539   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
540 endif
541 ifeq (%(compiler),host)
542   TMP_CXXCMD:=$(HOST_CXX)
543   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
544   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
545 endif
546 ifeq (%(compiler),kernel)
547   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_CFLAGS)
548   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
549   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
550 endif
552 ifeq (%(dflags),)
553   TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
554 else
555   ifeq (%(dflags),%(cflags))
556     TMP_CXXDFLAGS:=$(TMP_CXXFLAGS)
557   else
558     TMP_CXXDFLAGS:=%(dflags)
559   endif
560 endif
562 define cxx_multi_recipe_template
563  $(1).o : $(2)
564         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
566  $(1).d : $(2)
567         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_CXXDFLAGS) from=$(2) to=$(1).d
568 endef
569 ifeq (%(targetdir),)
570   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
571 else
572   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
573 endif
574 endif
575 %end
576 #------------------------------------------------------------------------------
579 #------------------------------------------------------------------------------
580 # Generate a rule to compile an ObjC source file to an object file and generate
581 # the dependency file. Basename may contain a directory part, then the source
582 # file has to be in that directory. The generated file will be put in the
583 # object directory without the directory.
584 # options
585 # - basename: the basename of the file to compile. Use % for a wildcard rule
586 # - cflags (default $(CFLAGS)): the C flags to use for compilation
587 # - dflags: the flags used during creation of dependency file. If not specified
588 #   the same value as cflags will be used
589 # - targetdir: the directory to put the .o file and the .d file. By default
590 #   it is put in the same directory as the .m file
591 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
593 ifeq (%(targetdir),)
594   TMP_TARGETBASE := %(basename)
595 else
596   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
597 endif
599 # Adjust compiler flags to suit ObjC
600 TMP_OBJCFLAGS := %(cflags)
601 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
602 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
604 ifeq ($(findstring %(compiler),host kernel target),)
605   $(error unknown compiler %(compiler))
606 endif
607 ifeq (%(compiler),target)
608 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
609 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
610 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
611 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
612 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
613 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
614 endif
615 ifeq (%(compiler),host)
616 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
617 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
618 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
619 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
620 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
621 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
622 endif
623 ifeq (%(compiler),kernel)
624 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
625 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
626 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
627 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
628 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
629 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
630 endif
632 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
633 $(TMP_TARGETBASE).o : %(basename).m
634         %compile_q cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
636 ifeq (%(dflags),)
637   ifeq (%(nix),yes)
638     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix $(TMP_OBJCFLAGS)
639   else
640     $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TMP_OBJCFLAGS)
641   endif
642 else
643   ifeq (%(nix),yes)
644     $(TMP_TARGETBASE).d : TMP_DFLAGS:=-nix %(dflags)
645   else
646     $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
647   endif
648 endif
649 $(TMP_TARGETBASE).d : %(basename).m
650         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
651 %end
652 #------------------------------------------------------------------------------
654 #------------------------------------------------------------------------------
655 # Generate a rule to compile multiple ObjC source files to an object file and
656 # generate the corresponding dependency files. The generated file will be put
657 # in the object directory without the directory part of the source file.
658 # options
659 # - basenames: the basenames of the files to compile. The names may include
660 #   relative or absolute path names. No wildcard is allowed
661 # - cflags (default $(CFLAGS)): the C flags to use for compilation
662 # - dflags: the flags used during creation of dependency file. If not specified
663 #   the same value as cflags will be used
664 # - targetdir: the directory to put the .o file and the .d file. By default
665 #   it is put in the same directory as the .m file. When targetdir is not
666 #   empty, path names will be stripped from the file names so that all files
667 #   are in that dir and not in subdirectories.
668 # - compiler (default target): compiler to use, target, kernel or host
669 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
670     targetdir= compiler=target
672 # Adjust compiler flags to suit ObjC
673 TMP_OBJCFLAGS := %(cflags)
674 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
675 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
677 ifeq (%(targetdir),)
678   TMP_TARGETS := $(addsuffix .o,%(basenames))
679   TMP_DTARGETS := $(addsuffix .d,%(basenames))
680   TMP_WILDCARD := %
681 else
682   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
683   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
684   TMP_WILDCARD := %(targetdir)/%
686   # Be sure that all .m files are generated
687   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
689   # Be sure that all .m files are found
690   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
691   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
692   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
693   ifneq ($(TMP_DIRS),)
694     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
695     vpath %.m $(TMP_DIRS)
696   endif
697 endif
699 # Define the use of cross compiler
700 ifeq ($(TARGET_OBJC),)
701   TMP_CC := $(TARGET_CC)
702 else
703   TMP_CC := $(TARGET_OBJC)
704 endif
706 ifeq ($(findstring %(compiler),host kernel target),)
707   $(error unknown compiler %(compiler))
708 endif
709 ifeq (%(compiler),target)
710   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_CFLAGS)
711   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
712   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
713 endif
714 ifeq (%(compiler),host)
715   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
716   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
717   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
718 endif
719 ifeq (%(compiler),kernel)
720   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_CFLAGS)
721   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
722   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
723 endif
725 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
726 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
727         %compile_q cmd=$(CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
729 ifeq (%(dflags),)
730   $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
731 else
732   ifeq (%(dflags),%(cflags))
733     $(TMP_DTARGETS) : DFLAGS:=$(TMP_OBJCFLAGS)
734   else
735     $(TMP_DTARGETS) : DFLAGS:=%(dflags)
736   endif
737 endif
738 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
739         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
740 %end
741 #------------------------------------------------------------------------------
744 #------------------------------------------------------------------------------
745 # Make an alias from one arch specific build to another arch.
746 # arguments:
747 # - mainmmake: the mmake of the module in the main tree
748 # - arch: the current arch
749 # - alias: the alias to which this should point
750 %define rule_archalias mainmmake=\A arch=\A alias=\A
752 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
753 %end
754 #------------------------------------------------------------------------------
757 #------------------------------------------------------------------------------
758 # Generate a rule to assemble a source file to an object file. Basename may
759 # contain a directory part, then the source file has to be in that directory.
760 # The generated file will be put in the object directory without the directory.
761 # options
762 # - basename: the basename of the file to compile. Use % for a wildcard rule
763 # - flags (default $(AFLAGS)): the asm flags to use for assembling
764 # - targetdir: the directory to put the .o file in. By default it is put in the
765 #   same directory as the .s file
766 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
768 ifeq (%(targetdir),)
769 %(basename).o : AFLAGS := %(aflags)
770 %(basename).o : %(basename).s
771         %assemble_q
772 %(basename).o : %(basename).S
773         %assemble_q
775 else
776 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
777 %(targetdir)/$(notdir %(basename)).o : %(basename).s
778         %assemble_q
779 %(targetdir)/$(notdir %(basename)).o : %(basename).S
780         %assemble_q
782 endif
783 %end
784 #------------------------------------------------------------------------------
787 #------------------------------------------------------------------------------
788 # Generate a rule to assemble multiple source files to an object file. The
789 # generated file will be put in the object directory with the directory part
790 # of the source file stripped off.
791 # options
792 # - basenames: the basenames of the files to compile. The names may include
793 #   relative or absolute path names. No wildcard is allowed
794 # - aflags (default $(AFLAGS)): the flags to use for assembly
795 # - targetdir: the directory to put the .o file and the .d file. By default
796 #   it is put in the same directory as the .c file. When targetdir is not
797 #   empty, path names will be stripped from the file names so that all files
798 #   are in that dir and not in subdirectories.
799 %define rule_assemble_multi basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s compiler=target
801 ifeq (%(targetdir),)
802 TMP_TARGETS := $(addsuffix .o,%(basenames))
803 TMP_WILDCARD := %
804 else
805 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
806 TMP_WILDCARD := %(targetdir)/%
808 # Be sure that all .s files are generated
809 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
811 # Be sure that all .c files are found
812 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
813 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
814 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
815 ifneq ($(TMP_DIRS),)
816     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
817     vpath %%(suffix) $(TMP_DIRS)
818 endif
820 endif
822 ifeq ($(findstring %(compiler),host kernel target),)
823   $(error unknown compiler %(compiler))
824 endif
825 ifeq (%(compiler),target)
826 $(TMP_TARGETS) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
827 endif
828 ifeq (%(compiler),host)
829 $(TMP_TARGETS) : TMP_CMD:=$(HOST_CC)
830 endif
831 ifeq (%(compiler),kernel)
832 $(TMP_TARGETS) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
833 endif
835 $(TMP_TARGETS) : AFLAGS := %(aflags)
836 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
837         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
838 %end
839 #------------------------------------------------------------------------------
842 #------------------------------------------------------------------------------
843 # Link %(objs) to %(prog) using the libraries in %(uselibs)
844 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
845     usehostlibs= usestartup=yes detach=no nix=no linker=target
847 TMP_EXTRA_LDFLAGS := 
848 TMP_EXTRA_LIBS :=
849 ifeq (%(nix),yes)
850     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
851 endif
852 ifeq (%(usestartup),no)
853     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
854     ifeq (%(linker),target)
855         TMP_EXTRA_LDFLAGS += -nostdc
856         TMP_EXTRA_LIBS += libinit autoinit
857     endif
858 endif
859 ifeq (%(detach),yes)
860     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
861 endif
863 # Make a list of the lib files this program depends on.
864 # In LDFLAGS remove white space between -L and directory
865 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
866 # Filter out only the libdirs and remove -L
867 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
868 # Add trailing /
869 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
870 # Add normal linklib path
871 TMP_DIRS += $(AROS_LIB)/
872 # add lib and .a to static linklib names
873 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
874 ifeq (%(usestartup),yes)
875     TMP_LIBS += startup.o
876 endif
877 ifeq (%(detach),yes)
878     TMP_LIBS += detach.o
879 endif
880 # search for the linklibs in the given path, ignore ones not found
881 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
882     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
885 ifeq (%(linker),target)
886 %(prog) : CMD:=$(TARGET_CC)
887 %(prog) : STRIPCMD:=$(TARGET_STRIP)
888 endif
889 ifeq (%(linker),host)
890 %(prog) : CMD:=$(HOST_CC)
891 %(prog) : STRIPCMD:=$(HOST_STRIP)
892 endif
893 ifeq (%(linker),kernel)
894 %(prog) : CMD:=$(KERNEL_CC) $(KERNEL_LDFLAGS)
895 %(prog) : STRIPCMD:=$(ECHO) >/dev/null
896 endif
898 %(prog) : OBJS := %(objs)
899 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
900 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
901 %(prog) : %(objs) $(TMP_DEPLIBS)
902         %link_q from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS) cmd=$(CMD) strip=$(STRIPCMD)
903 %end
904 #------------------------------------------------------------------------------
907 #------------------------------------------------------------------------------
908 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
909 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
910 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
911     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
912     usestartup=yes detach=no
914 TMP_EXTRA_LDFLAGS := 
915 TMP_EXTRA_LIBS :=
916 ifeq (%(nix),yes)
917     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
918 endif
919 ifeq (%(usestartup),no)
920     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS) -nostdc
921     TMP_EXTRA_LIBS += libinit autoinit
922 endif
923 ifeq (%(detach),yes)
924     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
925 endif
927 # Make a list of the lib files the programs depend on.
928 # In LDFLAGS remove white space between -L and directory
929 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
930 # Filter out only the libdirs and remove -L
931 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
932 # Add trailing /
933 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
934 # Add normal linklib path
935 TMP_DIRS += $(AROS_LIB)/
936 # add lib and .a to static linklib names
937 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
938 # search for the linklibs in the given path, ignore ones not found
939 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
940     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
942 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
944 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
945 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
946 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
947         %link_q from=$< opt=$(LDFLAGS) libs=$(LIBS)
948 %end
949 #------------------------------------------------------------------------------
952 #------------------------------------------------------------------------------
953 # Link the %(objs) to the library %(libdir)/lib%(libname).a
954 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
956 ifeq (%(linker),target)
957 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
958 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
959 endif
960 ifeq (%(linker),host)
961 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
962 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
963 endif
964 ifeq (%(linker),kernel)
965 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
966 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
967 endif
969 %(libdir)/lib%(libname).a : %(objs)
970         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
971 %end
972 #------------------------------------------------------------------------------
974 #------------------------------------------------------------------------------
975 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
976 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
977 # The -nostdc flag is added so that modules are not linked with stdc.library,
978 # stdcio.library or posixc.library
979 # (see /config/specs.in file)
980 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
981     cmd=$(AROS_CC) ldflags=$(LDFLAGS) uselibs= usehostlibs=
983 TMP_LDFLAGS  := %(ldflags)
984 # Make a list of the lib files the programs depend on.
985 # In LDFLAGS remove white space between -L and directory
986 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
987 # Filter out only the libdirs and remove -L
988 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
989 # Add trailing /
990 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
991 # Add normal linklib path
992 TMP_DIRS += $(AROS_LIB)/
993 # add lib and .a to static linklib names
994 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
995 # search for the linklibs in the given path, ignore ones not found
996 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
997     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1000 %(module) : LIB_NAMES := %(uselibs)
1001 %(module) : OBJS := %(objs)
1002 %(module) : ENDTAG := %(endobj)
1003 %(module) : ERR := %(err)
1004 %(module) : OBJDIR := %(objdir)
1005 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1006 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1007                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1008 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1009         %link_module_q cmd=%(cmd) err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags="$(LDFLAGS) -nostdc"
1011 %end
1012 #------------------------------------------------------------------------------
1015 #------------------------------------------------------------------------------
1016 # Generate the libdefs.h include file for a module.
1017 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1019 TMP_TARGET := %(modname)_libdefs.h
1020 TMP_DEPS := $(GENMODULE)
1021 TMP_OPTS := 
1022 ifneq (%(conffile),)
1023     ifeq ($(dir %(conffile)),./)
1024         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1025         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1026     else
1027         TMP_OPTS += -c %(conffile)
1028         TMP_DEPS += %(conffile)
1029     endif 
1030 else
1031     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1032     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1033 endif
1034 ifneq (%(modsuffix),)
1035     TMP_OPTS += -s %(modsuffix)
1036 endif
1037 ifneq (%(targetdir),)
1038     TMP_OPTS += -d %(targetdir)
1039     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1040 endif
1041 ifneq (%(version),)
1042     TMP_OPTS += -v %(version)
1043 endif
1045 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1046 $(TMP_TARGET) : MODNAME := %(modname)
1047 $(TMP_TARGET) : MODTYPE := %(modtype)
1048 $(TMP_TARGET) : $(TMP_DEPS)
1049         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1050         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1051 %end
1052 #------------------------------------------------------------------------------
1054 #------------------------------------------------------------------------------
1055 # Generate the _lib.fd file for a module.
1056 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1058 TMP_TARGET := %(modname)_lib.fd
1059 TMP_DEPS := $(GENMODULE)
1060 TMP_OPTS := 
1061 ifneq (%(conffile),)
1062     ifeq ($(dir %(conffile)),./)
1063         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1064         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1065     else
1066         TMP_OPTS += -c %(conffile)
1067         TMP_DEPS += %(conffile)
1068     endif 
1069 else
1070     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1071     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1072 endif
1073 ifneq (%(modsuffix),)
1074     TMP_OPTS += -s %(modsuffix)
1075 endif
1076 ifneq (%(targetdir),)
1077     TMP_OPTS += -d %(targetdir)
1078     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1079 endif
1081 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1082 $(TMP_TARGET) : MODNAME := %(modname)
1083 $(TMP_TARGET) : MODTYPE := %(modtype)
1084 $(TMP_TARGET) : $(TMP_DEPS)
1085         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1086         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1087 %end
1088 #------------------------------------------------------------------------------
1090 #------------------------------------------------------------------------------
1091 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1092 # generated file in this Makefile
1093 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1094     targetdir=
1096 TMP_TARGET := Makefile.%(modname)%(modtype)
1097 TMP_DEPS := $(GENMODULE)
1098 TMP_OPTS := 
1099 ifneq (%(conffile),)
1100     ifeq ($(dir %(conffile)),./)
1101         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1102         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1103     else
1104         TMP_OPTS += -c %(conffile)
1105         TMP_DEPS += %(conffile)
1106     endif 
1107 else
1108     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1109     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1110 endif
1111 ifneq (%(modsuffix),)
1112     TMP_OPTS += -s %(modsuffix)
1113 endif
1114 ifneq (%(targetdir),)
1115     TMP_OPTS += -d %(targetdir)
1116     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1117 endif
1119 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1120 $(TMP_TARGET) : MODNAME := %(modname)
1121 $(TMP_TARGET) : MODTYPE := %(modtype)
1122 $(TMP_TARGET) : $(TMP_DEPS)
1123         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1124 %end
1125 #------------------------------------------------------------------------------
1128 #------------------------------------------------------------------------------
1129 # Generate the support files for compiling a module. This includes include
1130 # files and source files. This rule has to be preceeded by
1131 # %rule_genmodule_makefile
1132 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1133     conffile=
1135 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1136                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1137 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1138                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1140 TMP_DEPS := $(GENMODULE)
1141 TMP_OPTS :=
1143 ifneq (%(conffile),)
1144     ifeq ($(dir %(conffile)),./)
1145         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1146         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1147     else
1148         TMP_OPTS += -c %(conffile)
1149         TMP_DEPS += %(conffile)
1150     endif 
1151 else
1152     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1153     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1154 endif
1155 ifneq (%(modsuffix),)
1156     TMP_OPTS += -s %(modsuffix)
1157 endif
1158 ifneq (%(targetdir),)
1159     TMP_OPTS += -d %(targetdir)
1160     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1161     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1162 endif
1164 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1165 $(TMP_TARGETS) : MODNAME := %(modname)
1166 $(TMP_TARGETS) : MODTYPE := %(modtype)
1167 $(TMP_TARGETS) : $(TMP_DEPS)
1168         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1169 ifneq (%(conffile),lib.conf)
1170         @$(IF) $(TEST) -f lib.conf; then \
1171           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1172         fi
1173 endif
1174         @$(IF) $(TEST) -f libdefs.h; then \
1175           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1176         fi
1177         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1178 %end
1179 #------------------------------------------------------------------------------
1182 #------------------------------------------------------------------------------
1183 # Generate the support files for compiling a module. This includes include
1184 # files and source files.
1185 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1186     targetdir= conffile=
1188 ifneq ($(%(modname)_INCLUDES),)
1189 TMP_TARGETS := $(%(modname)_INCLUDES)
1191 TMP_DEPS := $(GENMODULE)
1192 TMP_OPTS :=
1194 ifneq (%(conffile),)
1195     ifeq ($(dir %(conffile)),./)
1196         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1197         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1198     else
1199         TMP_OPTS += -c %(conffile)
1200         TMP_DEPS += %(conffile)
1201     endif 
1202 else
1203     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1204     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1205 endif
1206 ifneq (%(modsuffix),)
1207     TMP_OPTS += -s %(modsuffix)
1208 endif
1209 ifneq (%(targetdir),)
1210     TMP_OPTS += -d %(targetdir)
1211     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1212 endif
1214 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1215 $(TMP_TARGETS) : MODNAME := %(modname)
1216 $(TMP_TARGETS) : MODTYPE := %(modtype)
1217 $(TMP_TARGETS) : $(TMP_DEPS)
1218         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1219         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1220 endif
1221 %end
1222 #------------------------------------------------------------------------------
1224 #------------------------------------------------------------------------------
1225 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1226 # 'start' is an optional starting address
1227 # 'ldflags' is optional additional flags for the linker
1228 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1230 BD_OUTDIR := $(dir %(file))
1231 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1232 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1233 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1234 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1235 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1236 BD_OBJS += %(objs)
1238 %rule_compile_multi basenames=%(files) targetdir=$(BD_OBJDIR)
1240 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1241         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1242         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1243         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1245 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1246     GLOB_MKDIRS += $(BD_OUTDIR)
1247 endif
1249 %end
1251 #------------------------------------------------------------------------------
1252 # Common rules for all makefiles
1253 %define common
1254 # Delete generated makefiles
1256 clean ::
1257         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1259 include $(SRCDIR)/config/make.tail
1261 BDID := $(BDTARGETID)
1262 %end
1263 #------------------------------------------------------------------------------
1264       
1266 #############################################################################
1267 #############################################################################
1268 ##                                                                         ##
1269 ## Here are the mmakefile build macros. These are macros that takes care   ##
1270 ## of everything to go from the sources to the generated target. Also all  ##
1271 ## intermediate files and directories that are needed are created by these ##
1272 ## rules.                                                                  ##
1273 ##                                                                         ##
1274 #############################################################################
1275 #############################################################################
1277 #------------------------------------------------------------------------------
1278 # Build a program
1279 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1280     objcfiles= \
1281     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1282     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1283     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1284     compiler=target linker=
1286 .PHONY : %(mmake)
1288 BD_PROGNAME  := %(progname)
1289 BD_OBJDIR    := %(objdir)
1290 BD_TARGETDIR := %(targetdir)
1291 BD_LINKER    := %(linker)
1293 # If not supplied, linker is equal to compiler
1294 ifeq ($(BD_LINKER),)
1295     BD_LINKER := %(compiler)
1296 endif
1298 BD_FILES     := %(files)
1299 BD_OBJCFILES := %(objcfiles)
1300 BD_ASMFILES  := %(asmfiles)
1301 BD_CXXFILES := %(cxxfiles)
1303 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1304 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1305 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1307 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1308 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1309 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1311 BD_CFLAGS    := %(cflags)
1312 BD_AFLAGS    := %(aflags)
1313 BD_DFLAGS    := %(dflags)
1314 BD_LDFLAGS   := %(ldflags)
1317 %(mmake)-quick : %(mmake)
1319 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1320 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1322 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1323 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1324     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1325 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1326     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1327 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1328     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler=%(compiler)
1329 %rule_assemble_multi basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1330     aflags=$(BD_AFLAGS) compiler=%(compiler)
1332 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1333     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1334     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1335     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1336     linker=$(BD_LINKER)
1338 endif
1340 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1342 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1343 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1344 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1346 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1348 %(mmake)-clean ::
1349         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1350         @$(RM) $(FILES)
1352 %end
1353 #------------------------------------------------------------------------------
1356 #------------------------------------------------------------------------------
1357 # Build programs, for every C file an executable will be built with the same
1358 # name as the C file
1359 %define build_progs mmake=/A files=/A nix=no \
1360     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1361     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1362     uselibs= usehostlibs= usestartup=yes detach=no
1364 .PHONY : %(mmake)
1366 BD_OBJDIR    := %(objdir)
1367 BD_TARGETDIR := %(targetdir)
1369 BD_FILES     := %(files)
1370 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1371 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1372 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1374 BD_CFLAGS    := %(cflags)
1375 BD_DFLAGS    := %(dflags)
1376 BD_LDFLAGS   := %(ldflags)
1379 %(mmake)-quick : %(mmake)
1381 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1382 %(mmake) : $(BD_EXES)
1384 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1385 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1386     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1388 %rule_link_progs progs=$(BD_FILES) nix=%(nix) \
1389     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1390     ldflags=$(BD_LDFLAGS) \
1391     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1392     usestartup="%(usestartup)" detach="%(detach)"
1394 endif
1396 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1398 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1399 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1400 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1402 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1404 %(mmake)-clean ::
1405         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1406         @$(RM) $(FILES)
1408 %end
1409 #------------------------------------------------------------------------------
1412 #------------------------------------------------------------------------------
1413 # Build a module.
1414 # This is a bare version: It just compiles and links the given files. It is
1415 # assumed that all needed boiler plate code is in the files. This should only
1416 # be used for compiling external code. For AROS code use %build_module
1417 %define build_module_simple mmake=/A modname=/A modtype=/A \
1418     files="$(basename $(call WILDCARD, *.c))" \
1419     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1420     objdir=$(OBJDIR) moduledir= \
1421     uselibs= usehostlibs= compiler=target
1423 # Define metamake targets and their dependencies
1424 #MM %(mmake) : core-linklibs includes-generate-deps
1425 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1426 #MM %(mmake)-pkg  : core-linklibs includes-generate-deps
1427 #MM %(mmake)-kobj-quick
1428 #MM %(mmake)-pkg-quick
1429 #MM %(mmake)-quick
1430 #MM %(mmake)-clean
1432 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj %(mmake)-pkg
1434 .PHONY : $(BD_ALLTARGETS)
1436 ifeq (%(modname),)
1437 $(error using %build_module_simple: modname may not be empty)
1438 endif
1439 ifeq (%(modtype),)
1440 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1441 endif
1443 # Default values for variables and arguments
1444 BD_DEFLINKLIBNAME := %(modname)
1445 BD_DEFDFLAGS := %(cflags)
1446 OBJDIR ?= $(GENDIR)/$(CURDIR)
1447 BD_MODDIR := %(moduledir)
1448 ifeq ($(BD_MODDIR),)
1449   ifeq (%(modtype),library)
1450     BD_MODDIR  := $(AROS_LIBRARIES)
1451   endif
1452   ifeq (%(modtype),gadget)
1453     BD_MODDIR  := $(AROS_GADGETS)
1454   endif
1455   ifeq (%(modtype),datatype)
1456     BD_MODDIR  := $(AROS_DATATYPES)
1457   endif
1458   ifeq (%(modtype),handler)
1459     BD_MODDIR  := $(AROS_FS)
1460   endif
1461   ifeq (%(modtype),device)
1462     BD_MODDIR  := $(AROS_DEVS)
1463   endif
1464   ifeq (%(modtype),resource)
1465     BD_MODDIR  := $(AROS_RESOURCES)
1466   endif
1467   ifeq (%(modtype),hook)
1468     BD_MODDIR  := $(AROS_RESOURCES)
1469   endif
1470   ifeq (%(modtype),mui)
1471     BD_MODDIR  := $(AROS_CLASSES)/Zune
1472   endif
1473   ifeq (%(modtype),mcc)
1474     BD_MODDIR  := $(AROS_CLASSES)/Zune
1475   endif
1476   ifeq (%(modtype),mcp)
1477     BD_MODDIR  := $(AROS_CLASSES)/Zune
1478   endif
1479   ifeq (%(modtype),usbclass)
1480     BD_MODDIR  := $(AROS_CLASSES)/USB
1481   endif
1482   ifeq (%(modtype),hidd)
1483     BD_MODDIR  := $(AROS_DRIVERS)
1484   endif
1485   ifeq (%(modtype),printer)
1486     BD_MODDIR  := $(AROS_PRINTERS)
1487   endif
1488 endif
1489 ifeq ($(BD_MODDIR),)
1490   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1491 endif
1493 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1494 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1495 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1497 %rule_compile_multi \
1498     basenames="$(BD_NARCHFILES)" targetdir="%(objdir)" \
1499     cflags="%(cflags)" dflags="%(dflags)" \
1500     compiler=%(compiler)
1502 # Handlers use dash instead of dot in their names
1503 ifeq (%(modtype),handler)
1504 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1505 BD_PKGMOD := $(PKGDIR)/%(modname)-%(modtype)
1506 else
1507 ifeq (%(modtype),printer)
1508 BD_MODULE := $(BD_MODDIR)/%(modname)
1509 BD_PKGMOD := $(PKGDIR)/%(modname)
1510 else
1511 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1512 BD_PKGMOD := $(PKGDIR)/%(modname).%(modtype)
1513 endif
1514 endif
1515 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1517 %(mmake)-quick : %(mmake)
1518 %(mmake)-pkg-quick  : $(BD_PKGMOD)
1519 %(mmake)-kobj-quick : $(BD_KOBJ)
1520 %(mmake)       : $(BD_MODULE)
1521 %(mmake)-pkg   : $(BD_PKGMOD)
1522 %(mmake)-kobj  : $(BD_KOBJ)
1524 # The module is linked from all the compiled .o files
1525 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1527 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1528 # This breaks con-handler build. Here we work around this
1529 ifeq (%(modname),con)
1530     BD_ERR := $(notdir $(BD_MODULE)).err
1531 else
1532     BD_ERR := %(modname).err
1533 endif
1535 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1536                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1537                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1538                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1540 %rule_linkmodule module=$(BD_PKGMOD) objs=$(BD_OBJS) \
1541                  endobj= err=$(BD_ERR) objdir=%(objdir) \
1542                  cmd=$(AROS_CC) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1543                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1545 # Link kernel object file
1546 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1548 # Make these symbols local
1549 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1550             UtilityBase ExpansionBase KeymapBase KernelBase
1552 BD_SYMBOLS := $(BD_KBASE)
1554 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1555 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1556 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1557 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1558 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1559 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1560         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1561         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1562         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1565 ## Dependency fine-tuning
1567 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1568 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-pkg" deps=$(BD_DEPS)
1570 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1571 $(BD_MODULE) : | $(BD_MODDIR)
1572 $(BD_KOBJ) : | $(KOBJSDIR)
1573 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1575 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1576 %(mmake)-clean ::
1577         @$(ECHO) "Cleaning up for module %(modname)"
1578         @$(RM) $(FILES)
1579 %end
1580 #------------------------------------------------------------------------------
1583 #------------------------------------------------------------------------------
1584 # Build a module
1585 # Explanation of this macro is done in the developer's manual
1586 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1587   files="$(basename $(call WILDCARD, *.c))" \
1588   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1589   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1590   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1591   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1592   compiler=target nostartup=yes
1594 # Define metamake targets and their dependencies
1595 #MM- includes-all : %(mmake)-includes
1596 #MM- linklibs-%(modname): %(mmake)-linklib
1597 #MM- linklibs-%(modname)_rel : %(mmake)-linklib
1598 #MM- includes-%(modname): %(mmake)-includes
1599 #MM- includes-%(modname)_rel : %(mmake)-includes
1600 #MM %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1601 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1602 #MM %(mmake)-kobj-quick : %(mmake)-includes-quick
1603 #MM %(mmake)-pkg : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1604 #MM %(mmake)-pkg-quick : %(mmake)-includes-quick
1605 #MM %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1606 #MM %(mmake)-quick : %(mmake)-includes-quick
1607 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1608 #MM     includes-generate-deps %(mmake)-fd
1609 #MM %(mmake)-includes-quick
1610 #MM %(mmake)-includes-dirs
1611 #MM %(mmake)-fd
1612 #MM %(mmake)-makefile
1613 #MM %(mmake)-clean
1615 # All MetaMake targets defined by this macro
1616 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1617     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1618     %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick \
1619     %(mmake)-linklib %(mmake)-fd
1621 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1623 ifeq (%(modname),)
1624 $(error using %build_module: modname may not be empty)
1625 endif
1626 ifeq (%(modtype),)
1627 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1628 endif
1630 # Default values for variables and arguments
1631 BD_DEFLINKLIBNAME := %(modname)
1632 BD_DEFDFLAGS := %(cflags)
1633 OBJDIR ?= $(GENDIR)/$(CURDIR)
1635 ## Create genmodule include Makefile for the module
1637 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1639 %rule_genmodule_makefile \
1640     modname=%(modname) modtype=%(modtype) \
1641     modsuffix=%(modsuffix) targetdir=%(objdir) \
1642     conffile=%(conffile)
1644 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1646 GLOB_MKDIRS += %(objdir)
1648 # Do not parse these statements if metatarget is not appropriate
1649 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1651 include %(objdir)/Makefile.%(modname)%(modtype)
1653 BD_DEFMODDIR := $(%(modname)_MODDIR)
1656 ## include files generation
1658 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1659 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1660 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1662 %(mmake)-includes-quick : %(mmake)-includes
1663 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1664     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1665     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1667 ifneq ($(%(modname)_INCLUDES),)
1668 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
1669                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1670                          conffile=%(conffile)
1672 %rule_copy_diff_multi \
1673     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
1674     stampfile=%(objdir)/%(modname)_geninc
1676 %rule_copy_diff_multi \
1677     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
1678     stampfile=%(objdir)/%(modname)_incs
1680 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1682 TMP%(modname)_INCDIRS := \
1683     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1684     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1685     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1686 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
1688 endif
1690 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
1691                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
1692                            conffile=%(conffile) version=%(version)
1694 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1695 $(BD_DEFLIBDEFSINC) :
1696         @$(ECHO) "Generating $@"
1697         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1699 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1700 GLOB_MKDIRS += %(objdir)/include
1702 ## Extra genmodule src files generation
1703 ## 
1704 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
1705                       modsuffix=%(modsuffix) targetdir=%(objdir) \
1706                       conffile=%(conffile)
1709 ## Create FD file
1710 BD_FDDIR := $(AROS_DEVELOPMENT)/fd
1711 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1713 %rule_genmodule_fd modname=%(modname) modtype=%(modtype) \
1714                    modsuffix=%(modsuffix) targetdir=$(BD_FDDIR) conffile=%(conffile)
1716 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1718 GLOB_MKDIRS += $(BD_FDDIR)
1721 ## Compilation
1723 BD_FILES      := %(files)
1724 BD_CXXFILES := %(cxxfiles)
1726 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1728 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1729 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1731 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1732 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1733 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1735 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1736 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1738 ifeq (%(modtype),library)
1739     BD_LIBSUFFIX := 
1740 else
1741     BD_LIBSUFFIX := .%(modtype)
1742 endif
1744 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1745 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1746 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1747     BD_LINKLIB :=
1748 else
1749     BD_LINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)$(BD_LIBSUFFIX).a
1750     ifneq (%(modname),%(linklibname))
1751         BD_LINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)$(BD_LIBSUFFIX).a
1752     endif
1753 endif
1754 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1756 ifneq ($(BD_CXXFILES),)
1757 BD_LINKCMD=$(AROS_CXX)
1758 else
1759 BD_LINKCMD=$(AROS_CC)
1760 endif
1762 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1763 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1764 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1765     BD_RELLINKLIB :=
1766 else
1767     BD_RELLINKLIB := %(prefix)/$(AROS_DIR_LIB)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1768     ifneq (%(modname),%(linklibname))
1769         BD_RELLINKLIB += %(prefix)/$(AROS_DIR_LIB)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1770     endif
1771 endif
1772 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1774 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1775 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1776     $(BD_RELLINKLIBCFILES)
1778 %rule_compile_multi \
1779     basenames=$(BD_CCFILES) targetdir=%(objdir) \
1780     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1781     compiler=%(compiler)
1782 %rule_compile_multi \
1783     basenames=$(BD_TARGETCCFILES) targetdir=%(objdir) \
1784     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1785     compiler=%(compiler)
1786 %rule_compile_cxx_multi \
1787     basenames=$(BD_CXXFILES) targetdir=%(objdir) \
1788     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1789     compiler=%(compiler)
1791 ifneq ($(BD_LINKLIBAFILES),)
1792 %rule_assemble_multi \
1793     basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir=%(objdir) suffix=.S
1794 endif
1796 ## Linking
1798 ifeq (%(modsuffix),)
1799 BD_SUFFIX := %(modtype)
1800 else
1801 BD_SUFFIX := %(modsuffix)
1802 endif
1804 # Handlers use dash instead of dot in their names
1805 ifeq ($(BD_SUFFIX),handler)
1806 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1807 BD_PKGMOD := $(PKGDIR)/%(modname)-$(BD_SUFFIX)
1808 else
1809 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1810 BD_PKGMOD := $(PKGDIR)/%(modname).$(BD_SUFFIX)
1811 endif
1812 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1814 %(mmake)-quick      : %(mmake)
1815 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1816 %(mmake)-pkg        : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1817 %(mmake)-pkg-quick  : $(BD_PKGMOD) $(BD_LINKLIB) $(BD_RELLINKLIB)
1818 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1819 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1820 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1822 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1823            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1825 ifeq (%(nostartup),yes)
1826 # Handlers always have entry point
1827 ifneq (%(modtype),handler)
1828 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1829 endif
1830 endif
1832 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1833 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1834                  %(linklibobjs)
1835 BD_RELLINKLIBOBJS \
1836               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1837                  %(linklibobjs)
1839 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1840 # This breaks con-handler build. Here we work around this
1841 ifeq (%(modname),con)
1842     BD_ERR := $(notdir $(BD_MODULE)).err
1843 else
1844     BD_ERR := %(modname).err
1845 endif
1847 # The module is linked from all the compiled .o files
1848 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1849                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1850                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1851                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1853 %rule_linkmodule module=$(BD_PKGMOD) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1854                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir=%(objdir) \
1855                  cmd=$(BD_LINKCMD) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1856                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1858 # Link static lib
1859 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
1860 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
1861 ifneq ($(BD_LINKLIB),)
1862 %rule_link_linklib libname=%(linklibname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1863 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1864 %rule_link_linklib libname=%(modname)$(BD_LIBSUFFIX) objs=$(BD_LINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1865 endif
1867 $(BD_LINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1868 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1869 endif
1871 ifneq ($(BD_RELLINKLIB),)
1872 %rule_link_linklib libname=%(linklibname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1873 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
1874 %rule_link_linklib libname=%(modname)_rel$(BD_LIBSUFFIX) objs=$(BD_RELLINKLIBOBJS) libdir=%(prefix)/$(AROS_DIR_LIB)
1875 endif
1877 $(BD_RELLINKLIB) : | %(prefix)/$(AROS_DIR_LIB)
1878 GLOB_MKDIRS += %(prefix)/$(AROS_DIR_LIB)
1879 endif
1881 # Link kernel object file
1882 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1884 # Make these symbols local
1885 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1886             UtilityBase ExpansionBase KeymapBase KernelBase
1888 BD_SYMBOLS := $(BD_KBASE)
1890 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1891 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1892 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
1893 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1894 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
1895 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
1896         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1897         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1898         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1900 ## Dependency fine-tuning
1902 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
1904 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick %(mmake)-pkg %(mmake)-pkg-quick" deps=$(BD_DEPS)
1906 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1907 $(BD_MODULE) : | %(prefix)/%(moduledir)
1908 $(BD_PKGMOD) : | $(PKGDIR)
1909 $(BD_KOBJ)   : | $(KOBJSDIR)
1910 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR) $(PKGDIR)
1912 # Some include files need to be generated before the .c can be parsed.
1913 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
1915 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
1916     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
1917 $(BD_DEPS) : $(BD_DFILE_DEPS)
1918 endif
1920 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
1921     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
1922     %(objdir)/Makefile.%(modname)%(modtype) \
1923     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
1924     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1925     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1926     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
1927     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
1928     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
1929     $(BD_ENDOBJS)
1930 %(mmake)-clean : FILES := $(BD_TOCLEAN)
1931 %(mmake)-clean ::
1932         @$(ECHO) "Cleaning up for module %(modname)"
1933         @$(RM) $(FILES)
1935 endif # $(TARGET) in $(BD_ALLTARGETS)
1936 %end
1937 #------------------------------------------------------------------------------
1940 #------------------------------------------------------------------------------
1941 # Build a module skeleton
1942 # This is a stripped-down version of build_module, it only creates include files,
1943 # but no actual object. This is used when for plugins or classes with the same
1944 # API, but no actual implementation here.
1945 %define build_module_skeleton mmake=/A modname=/A modtype=/A modsuffix= \
1946   conffile= \
1947   objdir=$(OBJDIR) prefix=$(AROSDIR)
1949 # Define metamake targets and their dependencies
1950 #MM- includes-all : %(mmake)-includes
1951 #MM %(mmake) : %(mmake)-includes core-linklibs
1952 #MM %(mmake)-kobj : %(mmake)-includes core-linklibs
1953 #MM %(mmake)-pkg  : %(mmake)-includes core-linklibs
1954 #MM %(mmake)-linklib : %(mmake)-includes
1955 #MM %(mmake)-quick : %(mmake)-includes-quick
1956 #MM %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1957 #MM     includes-generate-deps
1958 #MM %(mmake)-includes-quick
1959 #MM %(mmake)-includes-dirs
1960 #MM %(mmake)-makefile
1961 #MM %(mmake)-clean
1963 # All MetaMake targets defined by this macro
1964 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-includes \
1965     %(mmake)-includes-quick %(mmake)-includes-dirs %(mmake)-clean \
1966     %(mmake)-kobj %(mmake)-pkg
1968 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1970 ifeq (%(modname),)
1971 $(error using %build_module_skeleton: modname may not be empty)
1972 endif
1973 ifeq (%(modtype),)
1974 $(error using %build_module_skeleton: $(MODTYPE) has to be defined with the type of the module)
1975 endif
1977 # Default values for variables and arguments
1978 BD_DEFLINKLIBNAME := %(modname)
1979 BD_DEFDFLAGS := %(cflags)
1980 OBJDIR ?= $(GENDIR)/$(CURDIR)
1982 ## Create genmodule include Makefile for the module
1984 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1986 %rule_genmodule_makefile \
1987     modname=%(modname) modtype=%(modtype) \
1988     modsuffix=%(modsuffix) targetdir=%(objdir) \
1989     conffile=%(conffile)
1991 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1993 GLOB_MKDIRS += %(objdir)
1995 # Do not parse these statements if metatarget is not appropriate
1996 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1998 include %(objdir)/Makefile.%(modname)%(modtype)
2000 BD_DEFMODDIR := $(%(modname)_MODDIR)
2003 ## include files generation
2005 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
2006 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
2007 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
2009 %(mmake)-includes-quick : %(mmake)-includes
2010 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2011     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2012     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
2014 ifneq ($(%(modname)_INCLUDES),)
2015 %rule_genmodule_includes modname=%(modname) modtype=%(modtype) \
2016                          modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2017                          conffile=%(conffile)
2019 %rule_copy_diff_multi \
2020     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(GENINCDIR) \
2021     stampfile=%(objdir)/%(modname)_geninc
2023 %rule_copy_diff_multi \
2024     files=$(%(modname)_INCLUDES) srcdir=%(objdir)/include targetdir=$(BD_INCDIR) \
2025     stampfile=%(objdir)/%(modname)_incs
2027 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
2029 TMP%(modname)_INCDIRS := \
2030     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
2031     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
2032     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
2033 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget=%(mmake)-includes-dirs
2035 endif
2037 %rule_genmodule_genlibdefs modname=%(modname) modtype=%(modtype) \
2038                            modsuffix=%(modsuffix) targetdir=%(objdir)/include \
2039                            conffile=%(conffile)
2041 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
2042 $(BD_DEFLIBDEFSINC) :
2043         @$(ECHO) "generating $@"
2044         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
2046 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
2047 GLOB_MKDIRS += %(objdir)/include
2049 ## Extra genmodule src files generation
2050 ## 
2051 %rule_genmodule_files modname=%(modname) modtype=%(modtype) \
2052                       modsuffix=%(modsuffix) targetdir=%(objdir) \
2053                       conffile=%(conffile)
2055 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2056     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2057     %(objdir)/Makefile.%(modname)%(modtype) \
2058     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2059     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2060     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2061     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2062     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2063     $(BD_DEFLIBDEFSINC)
2064 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2065 %(mmake)-clean ::
2066         @$(ECHO) "Cleaning up for module %(modname)"
2067         @$(RM) $(FILES)
2069 endif # $(TARGET) in $(BD_ALLTARGETS)
2070 %end
2071 #------------------------------------------------------------------------------
2074 #------------------------------------------------------------------------------
2075 # Build a linklib.
2076 # - mmake is the mmaketarget
2077 # - libname is the baselibname e.g. lib%(libname).a will be created
2078 # - files are the C source files to include in the lib. The list of files
2079 #   has to be given without the .c suffix
2080 # - cxxfiles are C++ source files without suffix.
2081 #   NB: files will be matched in the order .cpp > .cxx > .cc
2082 # - asmfiles are the asm files to include in the lib. The list of files has to
2083 #   be given without the .s suffix
2084 # - objs additional object to link into the linklib. The objects have to be
2085 #   given with full absolute path and the .o suffix.
2086 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2087 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2088 # - cflags are the flags to compile the source (default $(CFLAGS))
2089 # - dflags are the flags use during makedepend (default equal to cflags)
2090 # - aflags are the flags use during assembling (default $(AFLAGS))
2091 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2092 %define build_linklib mmake=/A libname=/A files=$(BD_LIBNAME) cxxfiles= \
2093   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2094   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) \
2095   aflags=$(AFLAGS) compiler=target
2097 # assign and generate the local variables used in this macro
2098 BD_LIBNAME    := %(libname)
2099 BD_LINKLIB    := %(libdir)/lib%(libname).a
2101 BD_FILES      := %(files)
2102 BD_ASMFILES   := %(asmfiles)
2103 BD_CXXFILES := %(cxxfiles)
2105 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2106 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2107 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2109 BD_OBJS       := $(BD_ARCHOBJS) \
2110                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2111                  %(objs)
2112 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2114 BD_CFLAGS    := %(cflags)
2115 BD_AFLAGS    := %(aflags)
2116 BD_DFLAGS    := %(dflags)
2118 .PHONY : %(mmake) %(mmake)-clean
2120 #MM %(mmake) : includes-generate-deps
2121 %(mmake) : $(BD_LINKLIB)
2123 ifeq ($(TARGET),%(mmake))
2124 ifneq ($(dir $(BD_FILES)),./)
2125 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2126 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir $(BD_FILES)))
2127 endif
2129 %rule_compile basename=% targetdir=%(objdir) \
2130     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2131 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=%(objdir) \
2132     compiler=%(compiler) cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2133 %rule_assemble basename=% targetdir=%(objdir) \
2134     aflags=$(BD_AFLAGS)
2136 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS) libdir=%(libdir) linker=%(compiler)
2137 endif
2139 %include_deps depstargets=%(mmake) deps=$(BD_DEPS)
2141 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2142 $(BD_LINKLIB) : | %(libdir)
2143 GLOB_MKDIRS += %(objdir) %(libdir)
2145 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2147 %(mmake)-clean ::
2148         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2149         @$(RM) $(FILES)
2151 %end
2152 #------------------------------------------------------------------------------
2155 #------------------------------------------------------------------------------
2156 # Build catalogs.
2157 # - mmake is the mmaketarget
2158 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2159 # - description is the catalog description file (.cd), without the .ct suffix (default *.cd)
2160 # - subdir is the destination subdirectory of the catalogs
2161 # - name is the name of the destination catalog, without the .catalog suffix
2162 # - source is the path to the generated source code file
2163 # - dir is the base destination directory (default $(AROS_CATALOGS))
2164 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2165 # - srcdir is the directory in which the *.cd and *.ct files are searched
2167 %define build_catalogs mmake=/A name=/A subdir=/A \
2168  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2169  sourcedescription="$(TOOLDIR)/C_h_aros" srcdir="$(SRCDIR)/$(CURDIR)"
2171 ifeq (%(description),)
2172 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2173 else
2174 BD_DESC := %(description)
2175 endif
2177 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2179 ifeq (%(catalogs),)
2180 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2181 else
2182 BD_LNGS := %(catalogs)
2183 endif
2185 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2186 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2189 %(mmake) : $(BD_OBJS) %(source)
2191 $(BD_OBJS) : | $(BD_DIRS)
2192 GLOB_MKDIRS += $(BD_DIRS)
2194 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2195         @$(ECHO) "Creating   %(name) catalog for language $*."
2196         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
2198 ifneq (%(source),)
2199 %(source) : BD_DESC := $(BD_DESC)
2200 %(source) : BD_SRC := $(BD_SRC)
2201 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2202         @$(ECHO) "Creating   %(name) catalog source file $@"
2203         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2204 endif
2206 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2208 %(mmake)-clean ::
2209         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2210         @$(RM) $(FILES)
2212 .PHONY: %(mmake) %(mmake)-clean
2214 %end
2215 #-----------------------------------------------------------------------------
2218 #-----------------------------------------------------------------------------
2219 # Build icons.
2220 # - mmake is the mmaketarget
2221 # - icons is a list of icon base names (ie. without the .info suffix)
2222 # - dir is the destination directory
2223 # - srcdir is where *.png and *.info.src are searched
2224 #-----------------------------------------------------------------------------
2226 %define build_icons mmake=/A icons=/A dir=/A srcdir="$(SRCDIR)/$(CURDIR)" image=
2228 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2231 %(mmake) : $(BD_OBJS)
2233 ifeq (%(image),)
2235 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2236         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2237         @$(ILBMTOICON) $+ $@
2239 else
2241 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2242         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2243         @$(ILBMTOICON) $+ $@
2245 endif
2247 $(BD_OBJS) : | %(dir)
2248 GLOB_MKDIRS += %(dir)
2250 %(mmake)-clean : FILES := $(BD_OBJS)
2252 %(mmake)-clean ::
2253         @$(RM) $(FILES)
2255 .PHONY: %(mmake) %(mmake)-clean
2257 %end
2258 #-----------------------------------------------------------------------------
2261 #------------------------------------------------------------------------------
2262 # Compile files for an arch-specific replacement of code for a module
2263 # - files: the basenames of the C files to compile.
2264 # - asmfiles: the basenames of the asm files to assemble.
2265 # - mainmmake: the mmake of the module in the main directory to compile these
2266 #   arch specific files for.
2267 # - maindir: the object directory for the main module
2268 # - arch: the arch for which to compile these files. It can have the form
2269 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2270 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2271 # - dflags: the flags used during creation of dependency file. If not specified
2272 #   the same value as cflags will be used
2273 # - aflags: the flags used during assembling
2274 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2275 #   the target compiler is used
2276 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2277 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2279 ifeq (%(files) %(asmfiles),)
2280   $(error no files or asmfiles given)
2281 endif
2283 %buildid targets="%(mainmmake)-%(arch)"
2285 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2286 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2287 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2288 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2289 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2290 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2291 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2292 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2293 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2294 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2295 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2296 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2297 #MM- %(mainmmake)-pkg :     %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2298 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2299 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2300 #MM- %(mainmmake)-pkg-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2301 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2302 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2303 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2304 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2305 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2307 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2309 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2310 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2311 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2312 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2313 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2315 ifneq (%(modulename),)
2316 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2317 endif
2319 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2320     BD_TARGET := %(mainmmake)-%(arch)-quick
2321 else
2322     BD_TARGET := %(mainmmake)-%(arch)
2323 endif
2326 ifeq ($(TARGET),$(BD_TARGET))
2327 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2328 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2329 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2330 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2331 endif
2333 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2334 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2337 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2340 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2342 ifeq ($(findstring %(compiler),host kernel target),)
2343   $(error unknown compiler %(compiler))
2344 endif
2345 ifeq (%(compiler),target)
2346 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_CFLAGS)
2347 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2348 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2349 endif
2350 ifeq (%(compiler),host)
2351 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2352 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2353 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2354 endif
2355 ifeq (%(compiler),kernel)
2356 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_CFLAGS)
2357 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2358 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2359 endif
2360 ifneq (%(modulename),)
2361 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2362 else
2363 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2364 endif
2365 ifeq ($(TARGET),$(BD_TARGET))
2366 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2367         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2368 endif
2370 ifeq (%(dflags),)
2371 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2372 else
2373 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2374 endif
2375 ifeq ($(TARGET),$(BD_TARGET))
2376 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2377         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2378 endif
2380 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2382 ifeq ($(TARGET),$(BD_TARGET))
2383 $(BD_OBJDIR$(BDID))/%.o : %.s
2384         %assemble_q opt=$(AFLAGS)
2385 $(BD_OBJDIR$(BDID))/%.o : %.S
2386         %assemble_q opt=$(AFLAGS)
2387 endif
2389 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2390 %end
2391 #------------------------------------------------------------------------------
2394 #------------------------------------------------------------------------------
2395 # generate asm files from c files (for debugging purposes)
2396 %define ctoasm_q
2397 %.s : %.c
2398         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2399         @$(TARGET_CC) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2400 %end
2401 #------------------------------------------------------------------------------
2404 #------------------------------------------------------------------------------
2405 # Copy files from one directory to another.
2407 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2409 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2411 GLOB_MKDIRS += %(dst)
2413 .PHONY : %(mmake)
2416 %(mmake) : | %(dst) 
2417         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2419 %end
2420 #------------------------------------------------------------------------------
2423 #------------------------------------------------------------------------------
2424 # Copy a directory recursively to another place, preserving the original 
2425 # hierarchical structure
2427 # src: the source directory whose content will be copied.
2428 # dst: the directories where to copy src's content. If not existing, they will be made.
2429 # excludefiles: files which must not be copied. Path must be relative to src.
2431 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2433 .PHONY : %(mmake)
2436 %(mmake) :
2437         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2439 %end
2440 #------------------------------------------------------------------------------
2443 #------------------------------------------------------------------------------
2444 #   Copy include files into the includes directories. There are currently
2445 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2446 #   for building tools that need to run on the host system $(GENINCDIR). The
2447 #   $(GENINCDIR) path must not contain any references to the C runtime
2448 #   library header files.
2450 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2451     dir= compiler=target
2453 ifeq ($(findstring %(compiler),host kernel target),)
2454 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2455 endif
2457 ifneq (%(dir),)
2458 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2459 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2460 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2461 else
2462 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2463 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2464 endif
2466 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2467         @$(CP) $< $@
2470 ifeq (%(compiler),target)
2472 ifneq (%(dir),)
2473 BD_INCL_FILES2 := $(subst %(dir),$(AROS_INCLUDES)/%(path),$(dir %(includes)))
2474 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,$(notdir %(includes)))
2475 else
2476 BD_INCL_FILES2 := $(addprefix $(AROS_INCLUDES)/%(path)/,%(includes))
2477 endif
2479 BD_INCL_FILES += $(BD_INCL_FILES2)
2481 $(BD_INCL_FILES2) : $(AROS_INCLUDES)/%(path)/% : $(BD_INC_PATH)%
2482         @$(CP) $< $@
2483 endif
2486 %(mmake) : $(BD_INCL_FILES)
2488 .PHONY: %(mmake)
2490 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2491 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2492 %end
2493 #------------------------------------------------------------------------------
2496 #------------------------------------------------------------------------------
2497 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2498 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2499 STUBS_MEM := $(addsuffix .o,$(STUBS))
2500 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2501 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2502 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2504 #MM- linklibs : hidd-%(hidd)-stubs
2505 #MM- %(parenttarget): hidd-%(hidd)-stubs
2506 #MM hidd-%(hidd)-stubs : includes includes-copy
2507 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2509 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2510         %mklib_q from=$^
2512 $(STUBS_OBJ) : $(STUBS_SRC) 
2513         %compile_q cmd="$(TARGET_CC) $(TARGET_CFLAGS)" opt=%(cflags) iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2515 $(STUBS_DEP) : $(STUBS_SRC)
2516         %mkdepend_q flags=%(dflags)
2518 setup ::
2519         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2522 clean ::
2523         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2525 DEPS := $(DEPS) $(STUBS_DEP)
2527 %end
2528 #------------------------------------------------------------------------------
2531 #------------------------------------------------------------------------------
2532 # Build an imported source tree which uses the configure script from the
2533 # autoconf package.  This rule will try to "integrate" the produced files as
2534 # much as possible in the AROS build, for example by putting libraries in the
2535 # standard library directory, includes in the standard include directory, and
2536 # so on. You can however override this behaviour.
2538 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2539 # be %(bindir) (or its deduced value) when running "make install", and
2540 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2541 # configure script some more parameters whose value depends upon the PROGDIR
2542 # env var, so that the program gets all its stuff installed in the proper place
2543 # when building it, but when running it from inside AROS it can also find that
2544 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2545 # the configuration parameters set when running ./configure
2547 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2548 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2549 # to the name which has to follow it.
2551 # Arguments:
2553 #     - mmake           = the meta make target.
2554 #     - package         = name of the package to be built.
2555 #     - srcdir          = the location of the unpacked source code. Defaults
2556 #                         to $(SRCDIR)/$(CURDIR).
2557 #     - prefix          = the target directory. Must be an absolute path of the
2558 #                         host system. Defaults to $(AROS_CONTRIB).
2559 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2560 #                         Defaults to the value of the prefix option.
2561 #     - extraoptions    = additional options for the configure script.
2562 #     - extracflags     = additional flags which are used for both C and C++.
2563 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2564 #                         Defaults to the value of the nix argument.
2565 #     - nix             = enable u*nix path handling, i.e. a path like
2566 #                         /progdir//./file will be translated to
2567 #                         progdir:file during run-time. Defaults to no.
2568 #     - compiler        = target, host or kernel. Defaults to target.
2569 #     - install_target  = the command used for installing. Defaults to install. Leave
2570 #                         it empty if you want to suppress installing.
2571 #     - preconfigure    = a metatarget which is executed before configure is called.
2572 #     - postconfigure   = a metatarget which is executed after configure is called.
2573 #     - postinstall     = a metatarget which is executed after installing.
2574 #     - install_env     = set additional options for installing.
2575 #     - use_build_env   = if yes the configuration environment is used for
2576 #                         installing, too. Defaults to no.
2578 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2579 # like this:
2581 # if nix_dir_layout
2582 #    --prefix = $(aros_prefix)
2583 #    progdir = $(aros_prefix)/bin
2584 # else
2585 #    if nix
2586 #        --prefix = /PROGDIR
2587 #        --bindir = /PROGDIR
2588 #        --sbindir = /PROGDIR
2589 #        --libdir = /LIB
2590 #        --includedir = /INCLUDE
2591 #        --oldincludedir = /INCLUDE   
2592 #    else
2593 #        --prefix = $(aros_prefix)
2594 #    endif
2596 #    progdir = $(aros_prefix)
2598 #    # Install options
2599 #    bindir = $(prefix)
2600 #    sbindir = $(prefix)
2601 #    libdir = $(AROS_LIB)
2602 #    includedir = $(AROS_INCLUDES)
2603 #    oldincludedir = $(AROS_INCLUDES)
2604 # endif
2607 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2608     aros_prefix= extraoptions= extracflags= nix_dir_layout= nix=no compiler=target \
2609     install_target=install preconfigure= postconfigure= postinstall= \
2610     install_env= use_build_env=no
2612 ifneq (%(prefix),)
2613     %(mmake)-prefix := %(prefix)
2614 else
2615     %(mmake)-prefix := $(AROS_CONTRIB)
2616 endif
2618 ifneq (%(aros_prefix),)
2619     %(mmake)-aros_prefix := %(aros_prefix)
2620 else
2621     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2622 endif
2624 ifeq (%(nix),yes)
2625     %(mmake)-nix    := -nix
2626     %(mmake)-volpfx := /
2627     %(mmake)-volsfx := /
2628     
2629     ifeq (%(nix_dir_layout),)
2630         %(mmake)-nix_dir_layout := yes
2631     endif
2632 else
2633     %(mmake)-volsfx := :
2634     
2635     ifeq (%(nix_dir_layout),)
2636         %(mmake)-nix_dir_layout := no
2637     endif
2638 endif
2640 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2642 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2643         exec_prefix=$(%(mmake)-prefix) %(install_env)
2645 # Check if chosen compiler is valid
2646 ifeq ($(findstring %(compiler),host target kernel),)
2647   $(error unknown compiler %(compiler))
2648 endif
2650 # Set legacy 'host' variable based on chosen compiler
2651 ifeq (%(compiler),host)
2652     host := yes
2653     ifeq (%(package),)
2654         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2655     else
2656         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2657     endif
2658 else
2659     host := no
2660     ifeq (%(package),)
2661         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2662     else
2663         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2664     endif
2665 endif
2666 ifneq (%(gendir),)
2667     ifeq (%(package),)
2668         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2669     else
2670         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2671     endif
2672 endif
2674 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2675 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2677 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2678     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2679     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2680 else
2681     ifeq (%(nix),yes)
2682         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2683         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2684     else
2685         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2686     endif
2688     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2689     
2690     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2691         sbindir=$(%(mmake)-prefix) \
2692         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2693         oldincludedir=$(AROS_INCLUDES) %(install_env)
2694 endif
2696 ifneq ($(DEBUG),yes)
2697     %(mmake)-s_flag = -s
2698 endif
2700 # Set up build environment, and options for configure script
2701 ifeq (%(compiler),host)
2702     CONFIG_ENV := \
2703         CPP="$(HOST_CPP)" \
2704         CXXCPP="$(HOST_CPP)" \
2705         CC="$(HOST_CC) $(HOST_CFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2706         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -L$(CROSSTOOLSDIR)/lib -I$(CROSSTOOLSDIR)/include" \
2707         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2708         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)" \
2709         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2710         TARGET_NM="$(NM_PLAIN)"
2711 endif
2712 ifeq (%(compiler),target)
2713     CONFIG_ENV := \
2714         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2715         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2716         CPP="$(TARGET_CPP)" \
2717         CXXCPP="$(TARGET_CPP)" \
2718         CC="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2719         CXX="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2720         AS="$(TARGET_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)" AR="$(AR_PLAIN)" STRIP="$(STRIP_PLAIN)"\
2721         TARGET_CC="$(KERNEL_CC) $(KERNEL_CFLAGS) $(%(mmake)-s_flag)"\
2722         TARGET_AS="$(TARGET_AS)" OBJCOPY="$(OBJCOPY)"\
2723         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)"\
2724         TARGET_NM="$(NM_PLAIN)" \
2725         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"\
2726         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib -I$(AROS_DEVELOPMENT)/include %(extracflags) $(LDFLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2727     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2728         --host=$(AROS_TARGET_CPU)-aros\
2729         --target=$(AROS_TARGET_CPU)-aros\
2730         --disable-nls\
2731         --without-x --without-pic --disable-shared
2732 endif
2733 ifeq (%(compiler),kernel)
2734     CONFIG_ENV := \
2735         CPP="$(KERNEL_CPP)" \
2736         CXXCPP="$(KERNEL_CPP)" \
2737         CC="$(KERNEL_CC) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2738         CXX="$(KERNEL_CXX) $(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)"\
2739         AS="$(KERNEL_AS)" CC_FOR_BUILD="$(HOST_CC)" RANLIB="$(RANLIB)"\
2740         TARGET_RANLIB="$(RANLIB)" TARGET_STRIP="$(STRIP_PLAIN)" \
2741         TARGET_NM="$(NM_PLAIN)"
2742     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2743         --host=$(AROS_TARGET_CPU)-aros\
2744         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2745         --without-x --without-pic --disable-shared
2746 endif
2748 ifeq (%(use_build_env),yes)
2749     BUILD_ENV := $(CONFIG_ENV)
2750 endif
2753 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2755 # When building for the host, we don't need to build the
2756 # linklibs - this is especially true when building the
2757 # crosstool toolchain on 'foreign' architectures (such as
2758 # building PPC on x86)
2760 #MM- %(mmake)-host : setup includes %(mmake)-quick
2761 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2762 #MM- %(mmake): %(mmake)-%(compiler)
2764 # Using -j1 in install_command may result in a warning but finally
2765 # it does its job. make install for gcc does not work reliably for -jN
2766 # where N > 1.
2767 ifneq (%(install_target),)
2768     %(mmake)-install_command = \
2769         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2770         -C $(%(mmake)-pkgdir) %(install_target) -j1
2772     %(mmake)-uninstall_command = \
2773     $(RM) $(%(mmake)-installflag) && \
2774     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2775     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2776 else
2777     %(mmake)-install_command   := true
2778     %(mmake)-uninstall_command := true
2779 endif
2781 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2784 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2786 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2787         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2788             $(RM)  $(%(mmake)-installflag) && \
2789             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2790              -C $(%(mmake)-pkgdir) && \
2791             $(%(mmake)-install_command) && \
2792             $(TOUCH) $@ -r $^; \
2793         fi
2795 $(%(mmake)-pkgdir)/.files-touched:
2796         %mkdirs_q $(%(mmake)-pkgdir)
2797         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2798         $(TOUCH) $@
2801 %(mmake)-uninstall :
2802         $(%(mmake)-uninstall_command)
2805 %(mmake)-configure : $(%(mmake)-configflag)
2807 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2808 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2809         $(RM) $@
2810         %mkdirs_q $(%(mmake)-pkgdir)
2811         cd $(%(mmake)-pkgdir) && \
2812         find . -name config.cache -exec $(RM) '{}' \; && \
2813         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2814             %(extraoptions) && \
2815         $(TOUCH) $@
2818 %(mmake)-clean : %(mmake)-uninstall
2819         @$(RM) $(%(mmake)-pkgdir)
2820 %end
2821 #------------------------------------------------------------------------------
2824 #------------------------------------------------------------------------------
2825 # Given an archive name, patches names and locations where to find them, fetch
2826 # the archive and the patches from any of those locations, unpack the archive
2827 # and then apply the patches.
2829 # Locations currently supported are http and ftp sites, plus local filesystem
2830 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
2831 # the fetch.sh script needs to be modified, since this macro relies on that script.
2833 # Arguments:
2835 #     - mmake           = mmaketarget
2836 #     - archive_origins = list of locations where to find the archive. They are tried
2837 #                         in sequence, until the archive is found and fetching it 
2838 #                         succeeded. If not specified, the current directory is assumed.
2839 #     - archive         = the archive name. Mandatory.
2840 #     - suffixes        = a list of suffixes to append to the the package name plus the
2841 #                         version. Each one of them is tried until a matching archive is
2842 #                         found. They are appended to patches and these are tried the
2843 #                         same way as packages are.
2844 #     - location        = the local directory where to put the fetched archive and patches.
2845 #                         If not specified, the directory specified by destination is used.
2846 #     - destination     = the directory to unpack the archive to.
2847 #                         If not specified, the current directory is assumed.
2848 #     - patches_origins = list of locations where to find the patches. They are tried
2849 #                         in sequence, until a patch is found and fetching it 
2850 #                         succeeded. If not specified, the current directory is assumed.
2851 #     - patches_specs   = list of "patch specs". A patch spec is of the form
2852 #                         patch_name[:[patch_subdir][:patch_opt]].
2854 #                             - patch_name   = the name of the patch file
2855 #                             - patch_subdir = the directory within \destination\ where to
2856 #                                              apply the patch.
2857 #                             - patch_opt    = any options to pass to the `patch' command
2858 #                                              when applying the patch.
2859 #                         
2860 #                         The patch_subdir and patch_opt fields are optional.
2862 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
2863     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
2865 .PHONY: %(mmake)
2867 ifneq (%(location),)
2868     %(mmake)-location := %(location)
2869 else
2870     %(mmake)-location := %(destination)
2871 endif
2874 %(mmake) :
2875         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
2876         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
2877 %end
2878 #------------------------------------------------------------------------------
2881 #------------------------------------------------------------------------------
2882 # This macro can aid in patch creation for fetched ports. It temporarily creates another
2883 # unpatched source tree and runs diff against this and a previously fetched and possibly
2884 # patched tree. Depending on what happens after patching during a normal build it might
2885 # give best results if the new patch is created directly after fetch.
2887 # Arguments:
2889 #     - mmake       = mmaketarget
2890 #     - archive     = archive base name
2891 #     - srcdir      = the top level directory the package is unpacked to, useful if
2892 #                     an archive unpacks to a directory other than its name suggests.
2893 #                     this should not be deeper than a single path element.
2894 #     - suffixes    = a list of suffixes to append to the the package name plus the
2895 #                     version. Each one of them is tried until a matching archive is
2896 #                     found.
2897 #     - destination = the directory to unpack the archive to.
2898 #     - excludes    = diff patterns to exclude files or directories from the patch
2900 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
2902 .PHONY: %(mmake)
2904 ifneq (%(excludes),)
2905     %(mmake)-exclude := -X ./exclude.patterns
2906 endif
2908 ifneq (%(srcdir),)
2909     %(mmake)-srcdir := %(srcdir)
2910 else
2911     %(mmake)-srcdir := %(archive)
2912 endif
2915 %(mmake):
2916         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
2917         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
2918         cd %(destination)/tmp ; \
2919         $(FOR) f in %(excludes) ; do \
2920             $(ECHO) $$f >> ./exclude.patterns ; \
2921         done ; \
2922         diff -ruN $(%(mmake)-exclude) \
2923             $(%(mmake)-srcdir) \
2924             $(%(mmake)-srcdir).aros \
2925             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
2926         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
2927         $(RM) %(destination)/tmp
2928 %end
2929 #------------------------------------------------------------------------------
2932 #------------------------------------------------------------------------------
2933 # Joins the features of %fetch and %build_with_configure.
2935 # If a patch is provided, it *must* be named the following way:
2937 #    <package name>-<version number>-aros.diff
2939 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
2940 # CD'ing into the archive's extracted directory.
2942 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
2943 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
2944 # to make that patch fully comprehensive.
2946 # Arguments:
2948 #    - mmake            = the meta make target.
2949 #    - package          = the GNU package name, sans version and archive format suffixes.
2950 #    - subpackage       = ???
2951 #    - compiler         = same meaning as the one for the %build_with_configure macro.
2952 #    - install_target   = same meaning as the one for the %build_with_configure macro.
2953 #    - version          = the package's version number, or otherwise any other version string.
2954 #                         It gets appended to the package name to form the basename of the archive.
2955 #    - suffixes         = a list of suffixes to apped to the the package name plus the
2956 #                         version. Each one of them is tried until a matching archive is found.
2957 #                         Defaults to "tar.bz2 tar.gz".
2958 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
2959 #    - builddir         = override the location we expect to run configure/make in.
2960 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
2961 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
2962 #                         fetched or not. Default to no.
2963 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
2964 #    - prefix           = same meaning as the one for the %build_with_configure macro.
2965 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
2966 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
2967 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
2968 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
2969 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
2970 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
2971 #    - install_env      = same meaning as the one for the %build_with_configure macro.
2972 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
2973 #    - nix              = same meaning as the one for the %build_with_configure macro.
2974 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
2975 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
2977 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
2978     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
2979     prefix= aros_prefix= extraoptions= extracflags= preconfigure= postconfigure= postinstall= \
2980     install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
2982 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
2983 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
2984 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
2985 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
2987 %(mmake)-archbase  := %(package)-%(version)
2989 ifeq (%(compiler),host)
2990     %(mmake)-portdir  := $(HOSTDIR)/Ports/%(package)
2991 else
2992     %(mmake)-portdir  := $(PORTSDIR)/%(package)
2993 endif
2995 ifeq (%(prefix),)
2996     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
2997 else
2998     %(mmake)-prefix := %(prefix)
2999 endif
3001 ifneq (%(subpackage),)
3002     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3003 else
3004     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3005 endif
3007 ifneq (%(srcdir),)
3008     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3009 else
3010     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3011 endif
3013 ifneq (%(builddir),)
3014     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3015 else
3016     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3017 endif
3019 ifeq (%(patch),yes)
3020     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3021 else
3022     %(mmake)-%(subpackage)-patches_specs := ::
3023 endif
3025 %fetch mmake=%(mmake)-%(subpackage)-fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3026     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3027     archive_origins=". %(package_repo)" \
3028     patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3030 %create_patch mmake=%(mmake)-%(subpackage)-create-patch \
3031     archive=$(%(mmake)-%(subpackage)-archbase) \
3032     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3033     suffixes="%(suffixes)" \
3034     destination=$(%(mmake)-portdir)
3036 #MM- %(mmake) : %(mmake)-%(subpackage)
3038 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3040 %(mmake)-%(subpackage)-package-basename := \
3041     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3043 ifneq (%(create_pkg),no)
3044     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3045 endif
3047 %build_with_configure mmake=%(mmake)-%(subpackage) package=%(package) compiler=%(compiler) install_target=%(install_target) \
3048      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir=%(gendir) \
3049      install_env=%(install_env) use_build_env=%(use_build_env) \
3050      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-prefix)" \
3051      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3052      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3054 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3055 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3058 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3060 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3061 #that $^ and $@ have exactly the same mtime, and in that case make tries
3062 #to rebuild $@ again, which would fail because the directory where
3063 #the package got installed would not exist anymore. 
3064 #We work this around by using an if statement to manually check the mtimes.
3065 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3066         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3067         $(RM) $@ ; \
3068         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3069         mkdir -p "$(DISTDIR)/Packages" ; \
3070         mkdir -p "$(%(mmake)-prefix)" ; \
3071         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3072         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3073         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3074     fi
3075 %end
3076 #------------------------------------------------------------------------------
3079 #------------------------------------------------------------------------------
3080 # Joins the features of %fetch and %build_with_configure, taking advantage of
3081 # the naming scheme of GNU packages. GNU packages names are in the form
3083 #     <package name>-<version number>.<archive format suffix>
3085 # If a patch is provided, it *must* be named the following way:
3087 #    <package name>-<version number>-aros.diff
3089 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3090 # CD'ing into the archive's extracted directory.
3092 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3093 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3094 # to make that patch fully comprehensive.
3096 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3098 # Arguments:
3100 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3102 #    - prefix           = defaults to $(GNUDIR).
3103 #    - aros_prefix      = defaults to /GNU.
3105 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3106     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3107     aros_prefix=/GNU extraoptions= extracflags= preconfigure= postconfigure= postinstall= 
3109 GNU_REPOSITORY := gnu://
3111 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3112     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3113     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3114     patch="%(patch)" patch_repo="%(patch_repo)" \
3115     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" \
3116     preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3118 %end
3119 #------------------------------------------------------------------------------
3122 #------------------------------------------------------------------------------
3123 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3124 # that the package is a "Development" package, and as such it needs to be placed
3125 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3127 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3128 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3129 # "mmake" argument, because the metatarget is implicitely defined as
3131 #     #MM- development-%(package)
3133 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3134     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3135     aros_prefix=/Development preconfigure= postconfigure= postinstall=  extraoptions= extracflags=
3137 #MM- development : development-%(package)
3140 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
3141    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3142    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
3143    aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3144    extraoptions="%(extraoptions)" extracflags="%(extracflags)"
3147 postinstall-%(package)-delete-la-files:
3148         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3150 %end
3151 #------------------------------------------------------------------------------
3153 # Builds a kickstart package in PKG format
3155 # Arguments:
3157 #    - mmake   = target name
3158 #    - file    = destination file name with path
3160 # Other arguments are self-explanatory
3162 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res=
3164 PKG_CLASSES   := $(addsuffix .class, %(classes))
3165 PKG_DEVICES   := $(addsuffix .device, %(devs))
3166 PKG_HANDLERS  := $(addsuffix -handler, %(handlers))
3167 PKG_HIDD      := $(addsuffix .hidd, %(hidds))
3168 PKG_LIBS      := $(addsuffix .library, %(libs))
3169 PKG_RESOURCES := $(addsuffix .resource, %(res))
3171 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES)
3172 PKG_DIR   := $(dir %(file))
3173 PKG_DEPS  := $(addprefix $(PKGDIR)/, $(PKG_FILES))
3176 %(mmake) : %(file)
3179 %(mmake)-quick : %(file)
3181 %(file): PKG_FILES := $(PKG_FILES)
3182 %(file): $(PKG_DEPS) | $(PKG_DIR)
3183         @$(ECHO) Packaging $@...
3184         @$(SRCDIR)/tools/package/pkg c $@ $(PKGDIR) $(PKG_FILES)
3186 %compress_file mmake=%(mmake) file=%(file)
3188 GLOB_MKDIRS += $(PKG_DIR)
3190 %end
3192 #------------------------------------------------------------------------------
3193 # Compresses %(file) with a gzip.
3194 # Good in conjunction with for example %build_prog
3196 %define compress_file mmake=/A file=/A
3198 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3201 %(mmake)-gz-quick : %(file).gz
3203 %(file).gz: %(file)
3204         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3205         @gzip -9 -f $^
3207 %end
3209 #------------------------------------------------------------------------------
3210 # Links a kickstart module in ELF format
3211 # Arguments are similar to make_package
3213 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3214     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3216 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3217 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3218 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3219 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3220 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3221 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3223 ifeq (%(startup),)
3224     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3225 else
3226     KOBJ_STARTUP := %(startup)
3227 endif
3229 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3231 TMP_LDFLAGS := %(ldflags)
3233 # Make a list of the lib files this program depends on.
3234 # In LDFLAGS remove white space between -L and directory
3235 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3236 # Filter out only the libdirs and remove -L
3237 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3238 # Add trailing /
3239 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3240 # Add normal linklib path
3241 TMP_DIRS += $(AROS_LIB)/
3242 # add lib and .a to static linklib names
3243 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) libinit autoinit))
3244 # search for the linklibs in the given path, ignore ones not found
3245 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3246     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3249 TMP_DIRS += $(dir %(file))
3250 ifneq (%(map),)
3251     TMP_LDFLAGS += $(GENMAP) %(map)
3252     TMP_DIRS    += $(dir %(map))
3253 endif
3255 #MM %(mmake) : %(deps)
3258 %(mmake) : %(file)
3261 %(mmake)-quick : %(file)
3263 %(file): KOBJS := $(KOBJS)
3264 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3265                     -nostdc -nosysbase -Wl,-Ur
3266 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3267 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3268         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3269         @$(TARGET_CC) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3270         @$(STRIP) $@
3272 %compress_file mmake=%(mmake) file=%(file)
3274 GLOB_MKDIRS += $(TMP_DIRS)
3276 %end