store the lto/graphite flags
[AROS.git] / config / make.tmpl
blobd6b4259793f9ab304b37f4bacf8502292407419c
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_SYSROOT)" opt="$(TARGET_CFLAGS) $(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) $(TARGET_SYSROOT)" 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) $(TARGET_SYSROOT)" opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS) strip=$(STRIP)
66         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,%(to))..."
67         @$(IF) %(cmd) %(from) -o %(to) %(opt) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
68                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
69                                 $(ECHO) "%(to): %(cmd) %(from) -o %(to) %(opt) %(libs)" >> $(GENDIR)/errors ; \
70                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
71                 else \
72                         $(NOP) ; \
73                 fi ; \
74         else \
75             $(ECHO) "Link failed: %(cmd) %(from) -o %(to) %(opt) %(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) $(TARGET_SYSROOT)" err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
89         @$(ECHO) "Building   $(subst $(TARGETDIR)/,,$@) ..."
90         @if %(cmd) $(NOSTARTUP_LDFLAGS) \
91             $(GENMAP) %(objdir)/%(module).map \
92             %(objs) %(libs) %(ldflags) %(endtag) \
93             -o $@ 2>&1 > %(objdir)/%(err); \
94         then \
95             cat %(objdir)/%(err); \
96         else \
97             echo "%(cmd) $(NOSTARTUP_LDFLAGS) $(GENMAP) %(objdir)/%(module).map %(objs) %(libs) %(ldflags) %(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) $(TARGET_SYSROOT)"
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 BD_NIXFLAG ?= -nix
283 ifeq (%(targetdir),)
284   TMP_TARGETBASE := %(basename)
285 else
286   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
287 endif
289 # Adjust compiler flags to suit C
290 TMP_CFLAGS := %(cflags)
291 TMP_CFLAGS := $(subst -fpermissive,, $(TMP_CFLAGS))
292 ifeq (%(dflags),)
293   TMP_DFLAGS := %(cflags)
294 else
295   TMP_DFLAGS := %(dflags)
296 endif
298 ifeq ($(findstring %(compiler),host kernel target),)
299   $(error unknown compiler %(compiler))
300 endif
301 ifeq (%(compiler),target)
302 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
303 BD_STRIP ?= $(TARGET_STRIP)
304 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
305 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
306 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
307 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
308 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
309 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
310 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
311 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
312 endif
313 ifeq (%(compiler),host)
314 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
315 BD_STRIP ?= $(HOST_STRIP)
316 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
317 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
318 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
319 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
320 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
321 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
322 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
323 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
324 endif
325 ifeq (%(compiler),kernel)
326 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
327 BD_STRIP ?= $(ECHO) >/dev/null
328 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
329 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
330 $(TMP_TARGETBASE).o : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
331 $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
332 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
333 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
334 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
335 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
336 endif
338 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_CFLAGS)
339 $(TMP_TARGETBASE).o : %(basename).c
340         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
342 ifeq (%(nix),yes)
343   $(TMP_TARGETBASE).d : TMP_DFLAGS:=$(BD_NIXFLAG) $(TMP_DFLAGS)
344 endif
345 $(TMP_TARGETBASE).d : %(basename).c
346         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
347 %end
348 #------------------------------------------------------------------------------
351 #------------------------------------------------------------------------------
352 # Generate a rule to compile a C++ source file to an object file and generate
353 # the dependency file. Basename may contain a directory part, then the source
354 # file has to be in that directory. The generated file will be put in the
355 # object directory without the directory.
356 # options
357 # - basename: the basename of the file to compile. Use % for a wildcard rule
358 # - cflags (default $(CFLAGS)): the C flags to use for compilation
359 # - dflags: the flags used during creation of dependency file. If not specified
360 #   the same value as cflags will be used
361 # - targetdir: the directory to put the .o file and the .d file. By default
362 #   it is put in the same directory as the .c file
363 %define rule_compile_cxx basename=/A cxxflags=$(CXXFLAGS) dxxflags= targetdir= compiler=target
365 ifneq (%(basename),)
366 BD_NIXFLAG ?= -nix
367 ifeq (%(targetdir),)
368   TMP_TARGETBASE := %(basename)
369 else
370   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
371 endif
373 # Adjust compiler flags to suit C++
374 TMP_CXXFLAGS := %(cxxflags)
375 ifeq (%(dxxflags),)
376   TMP_DXXFLAGS := %(cxxflags)
377 else
378   TMP_DXXFLAGS := %(dxxflags)
379 endif
381 ifeq ($(findstring %(compiler),host kernel target),)
382   $(error unknown compiler %(compiler))
383 endif
384 ifeq (%(compiler),target)
385 BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
386 BD_STRIP ?= $(TARGET_STRIP)
387 $(TMP_TARGETBASE).o : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
388 $(TMP_TARGETBASE).d : TMP_CMD:=$(AROS_CXX) $(TARGET_SYSROOT)
389 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
390 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
391 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
392 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
393 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
394 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
395 endif
396 ifeq (%(compiler),host)
397 BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
398 BD_STRIP ?= $(HOST_STRIP)
399 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CXX)
400 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CXX)
401 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
402 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
403 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
404 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
405 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
406 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
407 endif
408 ifeq (%(compiler),kernel)
409 KERNEL_CXX ?= $(KERNEL_CC)
410 BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
411 BD_STRIP ?= $(ECHO) >/dev/null
412 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
413 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
414 $(TMP_TARGETBASE).o : TMP_CXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
415 $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
416 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
417 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
418 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
419 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
420 endif
422 $(TMP_TARGETBASE).o : CXXFLAGS := $(TMP_CXXFLAGS)
423 $(TMP_TARGETBASE).o : %(basename).cpp
424         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
426 ifeq (%(nix),yes)
427   $(TMP_TARGETBASE).d : TMP_DXXFLAGS:=$(BD_NIXFLAG) $(TMP_DXXFLAGS)
428 endif
429 $(TMP_TARGETBASE).d : %(basename).cpp
430         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DXXFLAGS)
432 endif
434 %end
435 #------------------------------------------------------------------------------
438 #------------------------------------------------------------------------------
439 # Generate a rule to compile an ObjC source file to an object file and generate
440 # the dependency file. Basename may contain a directory part, then the source
441 # file has to be in that directory. The generated file will be put in the
442 # object directory without the directory.
443 # options
444 # - basename: the basename of the file to compile. Use % for a wildcard rule
445 # - cflags (default $(CFLAGS)): the C flags to use for compilation
446 # - dflags: the flags used during creation of dependency file. If not specified
447 #   the same value as cflags will be used
448 # - targetdir: the directory to put the .o file and the .d file. By default
449 #   it is put in the same directory as the .m file
450 %define rule_compile_objc basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
452 ifneq (%(basename),)
453 BD_NIXFLAG ?= -nix
454 ifeq (%(targetdir),)
455   TMP_TARGETBASE := %(basename)
456 else
457   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
458 endif
460 # Adjust compiler flags to suit ObjC
461 TMP_OBJCFLAGS := %(cflags)
462 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
463 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
464 ifeq (%(dflags),)
465   TMP_OBJCDFLAGS := %(cflags)
466 else
467   TMP_OBJCDFLAGS := %(dflags)
468 endif
470 # Define the use of cross compiler
471 ifeq ($(TARGET_OBJC),)
472   TMP_CC := $(TARGET_CC)
473 else
474   TMP_CC := $(TARGET_OBJC)
475 endif
477 ifeq ($(findstring %(compiler),host kernel target),)
478   $(error unknown compiler %(compiler))
479 endif
480 ifeq (%(compiler),target)
481 BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
482 BD_STRIP ?= $(TARGET_STRIP)
483 $(TMP_TARGETBASE).o : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
484 $(TMP_TARGETBASE).d : TMP_CMD:=$(TMP_CC) $(TARGET_SYSROOT)
485 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
486 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
487 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
488 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
489 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
490 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
491 endif
492 ifeq (%(compiler),host)
493 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
494 BD_STRIP ?= $(HOST_STRIP)
495 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
496 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
497 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
498 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
499 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(HOST_IQUOTE)
500 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(HOST_IQUOTE)
501 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
502 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
503 endif
504 ifeq (%(compiler),kernel)
505 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
506 BD_STRIP ?= $(ECHO) >/dev/null
507 $(TMP_TARGETBASE).o : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
508 $(TMP_TARGETBASE).d : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
509 $(TMP_TARGETBASE).o : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
510 $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
511 $(TMP_TARGETBASE).o : TMP_IQUOTE:=$(KERNEL_IQUOTE)
512 $(TMP_TARGETBASE).d : TMP_IQUOTE:=$(KERNEL_IQUOTE)
513 $(TMP_TARGETBASE).o : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
514 $(TMP_TARGETBASE).d : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
515 endif
517 $(TMP_TARGETBASE).o : CFLAGS := $(TMP_OBJCFLAGS)
518 $(TMP_TARGETBASE).o : %(basename).m
519         %compile_q cmd=$(TMP_CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
521 ifeq (%(nix),yes)
522   $(TMP_TARGETBASE).d : TMP_OBJCDFLAGS:=$(BD_NIXFLAG) $(TMP_OBJCDFLAGS)
523 endif
524 $(TMP_TARGETBASE).d : %(basename).m
525         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_OBJCDFLAGS)
527 endif
529 %end
530 #------------------------------------------------------------------------------
533 #------------------------------------------------------------------------------
534 # Generate a rule to compile multiple C source files to an object file and
535 # generate the corresponding dependency files. The generated file will be put
536 # in the object directory without the directory part of the source file.
537 # options
538 # - basenames: the basenames of the files to compile. The names may include
539 #   relative or absolute path names. No wildcard is allowed
540 # - cflags (default $(CFLAGS)): the C flags to use for compilation
541 # - dflags: the flags used during creation of dependency file. If not specified
542 #   the same value as cflags will be used
543 # - targetdir: the directory to put the .o file and the .d file. By default
544 #   it is put in the same directory as the .c file. When targetdir is not
545 #   empty, path names will be stripped from the file names so that all files
546 #   are in that dir and not in subdirectories.
547 # - compiler (default target): compiler to use, target, kernel or host
548 %define rule_compile_multi basenames=/A cflags=$(CFLAGS) dflags= targetdir= \
549     compiler=target
551 ifeq (%(targetdir),)
552 TMP_TARGETS := $(addsuffix .o,%(basenames))
553 TMP_DTARGETS := $(addsuffix .d,%(basenames))
554 TMP_WILDCARD := %
555 else
556 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
557 TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,$(notdir %(basenames))))
558 TMP_WILDCARD := %(targetdir)/%
560 # Be sure that all .c files are generated
561 $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .c,%(basenames))
563 # Be sure that all .c files are found
564 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
565 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
566 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
567 ifneq ($(TMP_DIRS),)
568     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
569     vpath %.c $(TMP_DIRS)
570 endif
572 endif
574 TMP_CFLAGS := %(cflags)
575 ifeq (%(dflags),)
576   TMP_DFLAGS := %(cflags)
577 else
578   TMP_DFLAGS := %(dflags)
579 endif
581 ifeq ($(findstring %(compiler),host kernel target),)
582   $(error unknown compiler %(compiler))
583 endif
584 ifeq (%(compiler),target)
585 BD_LINK ?= $(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
586 BD_STRIP ?= $(TARGET_STRIP)
587 BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
588 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TARGET_CC) $(TARGET_SYSROOT)
589 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(TARGET_CFLAGS) $(TMP_CFLAGS)
590 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(TARGET_CFLAGS) $(TMP_DFLAGS)
591 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
592 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
593 endif
594 ifeq (%(compiler),host)
595 BD_LINK ?= $(HOST_CC) $(HOST_LDFLAGS)
596 BD_STRIP ?= $(HOST_STRIP)
597 BD_ASSEMBLER ?= $HOST_CC) $(HOST_SYSROOT)
598 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_CC)
599 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(HOST_CFLAGS) $(TMP_CFLAGS)
600 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(HOST_CFLAGS) $(TMP_DFLAGS)
601 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
602 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
603 endif
604 ifeq (%(compiler),kernel)
605 BD_LINK ?= $(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
606 BD_STRIP ?= $(ECHO) >/dev/null
607 BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
608 $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT)
609 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_CFLAGS:=$(KERNEL_CFLAGS) $(TMP_CFLAGS)
610 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_DFLAGS:=$(KERNEL_CFLAGS) $(TMP_DFLAGS)
611 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
612 $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
613 endif
615 $(TMP_TARGETS) : CFLAGS := %(TMP_CFLAGS)
616 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.c
617         %compile_q cmd=$(CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
619 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.c
620         %mkdepend_q cc=$(CMD) flags=$(TMP_DFLAGS)
621 %end
622 #------------------------------------------------------------------------------
625 #------------------------------------------------------------------------------
626 # Generate a rule to compile multiple C++ source files to an object file and
627 # generate the corresponding dependency files. The generated file will be put
628 # in the object directory without the directory part of the source file.
629 # options
630 # - basenames: the basenames of the files to compile. The names may include
631 #   relative or absolute path names. No wildcard is allowed. basenames will be 
632 #   matched to supported AROS_CXXEXTS.
633 # - cflags (default $(CFLAGS)): the C flags to use for compilation
634 # - dflags: the flags used during creation of dependency file. If not specified
635 #   the same value as cflags will be used
636 # - targetdir: the directory to put the .o file and the .d file. By default
637 #   it is put in the same directory as the .c file. When targetdir is not
638 #   empty, path names will be stripped from the file names so that all files
639 #   are in that dir and not in subdirectories.
640 # - compiler (default target): compiler to use, target, kernel or host
641 %define rule_compile_cxx_multi basenames=/A cxxflags=$(CXXFLAGS) dxxflags= \
642     targetdir= compiler=target
644 TMP_CXXABSBASENAMES := $(foreach TMP_CXXBASE,%(basenames),$(if $(filter /%,$(TMP_CXXBASE)),$(TMP_CXXBASE),$(abspath $(SRCDIR)/$(CURDIR)/$(TMP_CXXBASE))))
646 ifneq ($(TMP_CXXABSBASENAMES),)
648 TMP_CXXBASENAMES := $(basename $(TMP_CXXABSBASENAMES))
650 # Identify the "real" c++ files from the passed in basenames
651 TMP_CXXFILES  := $(strip $(foreach TMP_CXXBASE,$(TMP_CXXABSBASENAMES), $(firstword $(wildcard $(foreach TMP_EXT, $(AROS_CXXEXTS),$(addsuffix .$(TMP_EXT),$(TMP_CXXBASE)))))))
653 ifeq (%(targetdir),)
654   TMP_CXXTARGETS := $(notdir $(TMP_CXXBASENAMES:=.o))
655   TMP_CXXDTARGETS := $(notdir $(TMP_CXXBASENAMES:=.d))
656   TMP_WILDCARD := %
657 else
658   TMP_CXXTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.o)))
659   TMP_CXXDTARGETS := $(addprefix %(targetdir)/,$(notdir $(TMP_CXXBASENAMES:=.d)))
660   TMP_WILDCARD := %(targetdir)/%
662   # Be sure that all source files are generated
663   $(TMP_CXXTARGETS) $(TMP_CXXDTARGETS) : | $(TMP_CXXFILES)
664 endif
666 # Adjust compiler flags to suit C++
667 TMP_CXXFLAGS := %(cxxflags)
668 ifeq (%(dxxflags),)
669   TMP_DXXFLAGS := %(cxxflags)
670 else
671   TMP_DXXFLAGS := %(dxxflags)
672 endif
674 ifeq ($(findstring %(compiler),host kernel target),)
675   $(error unknown compiler %(compiler))
676 endif
677 ifeq (%(compiler),host)
678   BD_LINK ?= $(HOST_CXX) $(HOST_LDFLAGS)
679   BD_STRIP ?= $(HOST_STRIP)
680   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
681   TMP_CXXCMD:=$(HOST_CXX)
682   TMP_CXXFLAGS := $(HOST_CXXFLAGS) $(TMP_CXXFLAGS)
683   TMP_DXXFLAGS := $(HOST_CXXFLAGS) $(TMP_DXXFLAGS)
684   TMP_CXXIQUOTE:=$(HOST_IQUOTE)
685   TMP_CXXIQUOTE_END:=$(HOST_IQUOTE_END)
686 endif
687 ifeq (%(compiler),target)
688   BD_LINK ?= $(AROS_CXX) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
689   BD_STRIP ?= $(TARGET_STRIP)
690   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
691   TMP_CXXCMD:=$(AROS_CXX) $(TARGET_SYSROOT)
692   TMP_CXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_CXXFLAGS)
693   TMP_DXXFLAGS := $(TARGET_CXXFLAGS) $(TMP_DXXFLAGS)
694   TMP_CXXIQUOTE:=$(CFLAGS_IQUOTE)
695   TMP_CXXIQUOTE_END:=$(CFLAGS_IQUOTE_END)
696 endif
697 ifeq (%(compiler),kernel)
698   KERNEL_CXX ?= $(KERNEL_CC)
699   BD_LINK ?= $(KERNEL_CXX) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
700   BD_STRIP ?= $(ECHO) >/dev/null
701   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
702   TMP_CXXCMD:=$(KERNEL_CXX) $(KERNEL_SYSROOT)
703   TMP_CXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_CXXFLAGS)
704   TMP_DXXFLAGS := $(KERNEL_CXXFLAGS) $(TMP_DXXFLAGS)
705   TMP_CXXIQUOTE:=$(KERNEL_IQUOTE)
706   TMP_CXXIQUOTE_END:=$(KERNEL_IQUOTE_END)
707 endif
709 define cxx_multi_recipe_template
710  $(1).o : $(2)
711         %compile_q cmd=$(TMP_CXXCMD) opt=$(TMP_CXXFLAGS) iquote=$(TMP_CXXIQUOTE) iquote_end=$(TMP_CXXIQUOTE_END) from=$(2) to=$(1).o
713  $(1).d : $(2)
714         %mkdepend_q cc=$(TMP_CXXCMD) flags=$(TMP_DXXFLAGS) from=$(2) to=$(1).d
715 endef
716 ifeq (%(targetdir),)
717   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(notdir $(basename $(TMP_CXXFILE))),$(TMP_CXXFILE))))
718 else
719   $(foreach TMP_CXXFILE,$(TMP_CXXFILES),$(eval $(call cxx_multi_recipe_template,$(addprefix %(targetdir)/,$(notdir $(basename $(TMP_CXXFILE)))),$(TMP_CXXFILE))))
720 endif
722 endif
724 %end
725 #------------------------------------------------------------------------------
728 #------------------------------------------------------------------------------
729 # Generate a rule to compile multiple ObjC source files to an object file and
730 # generate the corresponding dependency files. The generated file will be put
731 # in the object directory without the directory part of the source file.
732 # options
733 # - basenames: the basenames of the files to compile. The names may include
734 #   relative or absolute path names. No wildcard is allowed
735 # - cflags (default $(CFLAGS)): the C flags to use for compilation
736 # - dflags: the flags used during creation of dependency file. If not specified
737 #   the same value as cflags will be used
738 # - targetdir: the directory to put the .o file and the .d file. By default
739 #   it is put in the same directory as the .m file. When targetdir is not
740 #   empty, path names will be stripped from the file names so that all files
741 #   are in that dir and not in subdirectories.
742 # - compiler (default target): compiler to use, target, kernel or host
743 %define rule_compile_objc_multi basenames=/A cflags=$(CFLAGS) dflags= \
744     targetdir= compiler=target
746 ifneq (%(basenames),)
748 ifeq (%(targetdir),)
749   TMP_TARGETS := $(addsuffix .o,%(basenames))
750   TMP_DTARGETS := $(addsuffix .d,%(basenames))
751   TMP_WILDCARD := %
752 else
753   TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,%(basenames)))
754   TMP_DTARGETS := $(addsuffix .d,$(addprefix %(targetdir)/,%(basenames)))
755   TMP_WILDCARD := %(targetdir)/%
757   # Be sure that all .m files are generated
758   $(TMP_TARGETS) $(TMP_DTARGETS) : | $(addsuffix .m,%(basenames))
760   # Be sure that all .m files are found
761   TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
762   TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
763   TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
764   ifneq ($(TMP_DIRS),)
765     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
766     vpath %.m $(TMP_DIRS)
767   endif
768 endif
770 # Define the use of cross compiler
771 ifeq ($(TARGET_OBJC),)
772   TMP_CC := $(TARGET_CC)
773 else
774   TMP_CC := $(TARGET_OBJC)
775 endif
777 # Adjust compiler flags to suit ObjC
778 TMP_OBJCFLAGS := %(cflags)
779 TMP_OBJCFLAGS := $(TMP_OBJCFLAGS) -isystem $(AROS_DEVELOPMENT)/include
780 TMP_OBJCFLAGS := $(subst -Wno-pointer-sign,, $(subst -Werror-implicit-function-declaration,, $(TMP_OBJCFLAGS)))
781 ifeq (%(dflags),)
782   TMP_OBJCDFLAGS := %(cflags)
783 else
784   TMP_OBJCDFLAGS := %(dflags)
785 endif
787 ifeq ($(findstring %(compiler),host kernel target),)
788   $(error unknown compiler %(compiler))
789 endif
790 ifeq (%(compiler),target)
791   BD_LINK ?= $(TMP_CC) $(TARGET_SYSROOT) $(TARGET_LDFLAGS)
792   BD_STRIP ?= $(TARGET_STRIP)
793   BD_ASSEMBLER ?= $(TARGET_CC) $(TARGET_SYSROOT)
794   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(TMP_CC) $(TARGET_SYSROOT)
795   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCFLAGS)
796   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(TARGET_CFLAGS) $(TMP_OBJCDFLAGS)
797   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
798   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
799 endif
800 ifeq (%(compiler),host)
801   BD_LINK ?= $(HOST_OBJC) $(HOST_LDFLAGS)
802   BD_STRIP ?= $(HOST_STRIP)
803   BD_ASSEMBLER ?= $(HOST_CC) $(HOST_SYSROOT)
804   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(HOST_OBJC)
805   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCFLAGS)
806   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(HOST_CFLAGS) $(TMP_OBJCDFLAGS)
807   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(HOST_IQUOTE)
808   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
809 endif
810 ifeq (%(compiler),kernel)
811   KERNEL_OBJC ?= $(KERNEL_CC)
812   BD_LINK ?= $(KERNEL_OBJC) $(KERNEL_SYSROOT) $(KERNEL_LDFLAGS)
813   BD_STRIP ?= $(ECHO) >/dev/null
814   BD_ASSEMBLER ?= $(KERNEL_CC) $(KERNEL_SYSROOT)
815   $(TMP_TARGETS) $(TMP_DTARGETS) : CMD:=$(KERNEL_OBJC) $(KERNEL_SYSROOT)
816   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCFLAGS)
817   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_OBJCDFLAGS:=$(KERNEL_CFLAGS) $(TMP_OBJCDFLAGS)
818   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
819   $(TMP_TARGETS) $(TMP_DTARGETS) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
820 endif
822 $(TMP_TARGETS) : CFLAGS := $(TMP_OBJCFLAGS)
823 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %.m
824         %compile_q cmd=$(CMD) opt=$(TMP_OBJCFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
826 $(TMP_DTARGETS) : $(TMP_WILDCARD).d : %.m
827         %mkdepend_q cc=$(CMD) flags=$(DFLAGS)
829 endif
831 %end
832 #------------------------------------------------------------------------------
835 #------------------------------------------------------------------------------
836 # Make an alias from one arch specific build to another arch.
837 # arguments:
838 # - mainmmake: the mmake of the module in the main tree
839 # - arch: the current arch
840 # - alias: the alias to which this should point
841 %define rule_archalias mainmmake=\A arch=\A alias=\A
843 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
844 %end
845 #------------------------------------------------------------------------------
848 #------------------------------------------------------------------------------
849 # Generate a rule to assemble a source file to an object file. Basename may
850 # contain a directory part, then the source file has to be in that directory.
851 # The generated file will be put in the object directory without the directory.
852 # options
853 # - basename: the basename of the file to compile. Use % for a wildcard rule
854 # - flags (default $(AFLAGS)): the asm flags to use for assembling
855 # - targetdir: the directory to put the .o file in. By default it is put in the
856 #   same directory as the .s file
857 %define rule_assemble basename=/A aflags=$(AFLAGS) targetdir=
859 ifeq (%(targetdir),)
860 %(basename).o : AFLAGS := %(aflags)
861 %(basename).o : %(basename).s
862         %assemble_q
863 %(basename).o : %(basename).S
864         %assemble_q
866 else
867 %(targetdir)/$(notdir %(basename)).o : AFLAGS := %(aflags)
868 %(targetdir)/$(notdir %(basename)).o : %(basename).s
869         %assemble_q
870 %(targetdir)/$(notdir %(basename)).o : %(basename).S
871         %assemble_q
873 endif
874 %end
875 #------------------------------------------------------------------------------
878 #------------------------------------------------------------------------------
879 # Generate a rule to assemble multiple source files to an object file. The
880 # generated file will be put in the object directory with the directory part
881 # of the source file stripped off.
882 # options
883 # - basenames: the basenames of the files to compile. The names may include
884 #   relative or absolute path names. No wildcard is allowed
885 # - aflags (default $(AFLAGS)): the flags to use for assembly
886 # - targetdir: the directory to put the .o file and the .d file. By default
887 #   it is put in the same directory as the .c file. When targetdir is not
888 #   empty, path names will be stripped from the file names so that all files
889 #   are in that dir and not in subdirectories.
890 %define rule_assemble_multi cmd="$(CC) $(TARGET_SYSROOT)"  basenames=/A aflags=$(AFLAGS) targetdir= suffix=.s
892 ifeq (%(targetdir),)
893 TMP_TARGETS := $(addsuffix .o,%(basenames))
894 TMP_WILDCARD := %
895 else
896 TMP_TARGETS := $(addsuffix .o,$(addprefix %(targetdir)/,$(notdir %(basenames))))
897 TMP_WILDCARD := %(targetdir)/%
899 # Be sure that all .s files are generated
900 $(TMP_TARGETS) : | $(addsuffix %(suffix),%(basenames))
902 # Be sure that all .c files are found
903 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
904 TMP_BASEDIRS := $(shell echo $(sort $(dir %(basenames))) | sed 's/\(.\):\//\/\1\//g')
905 TMP_DIRS := $(foreach dir, $(TMP_BASEDIRS), $(if $(filter /%,$(dir)),$(dir),$(TMP_SRCDIR)/$(CURDIR)/$(dir)))
906 ifneq ($(TMP_DIRS),)
907     TMP_DIRS := $(shell echo $(TMP_DIRS) | sed 's/\(.\):\//\/\1\//g')
908     vpath %%(suffix) $(TMP_DIRS)
909 endif
911 endif
913 BD_ASSEMBLER ?= %(cmd)
915 $(TMP_TARGETS) : TMP_CMD:= $(BD_ASSEMBLER)
917 $(TMP_TARGETS) : AFLAGS := %(aflags)
918 $(TMP_TARGETS) : $(TMP_WILDCARD).o : %%(suffix)
919         %assemble_q cmd=$(TMP_CMD) opt=$(AFLAGS)
920 %end
921 #------------------------------------------------------------------------------
924 #------------------------------------------------------------------------------
925 # Link %(objs) to %(prog) using the libraries in %(uselibs)
926 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
927     usehostlibs= usestartup=yes detach=no nix=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
929 TMP_EXTRA_LDFLAGS := 
930 TMP_EXTRA_LIBS :=
931 ifeq (%(nix),yes)
932     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
933 endif
934 ifeq (%(usestartup),no)
935     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
936 endif
937 ifeq (%(detach),yes)
938     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
939 endif
941 # Make a list of the lib files this program depends on.
942 # In LDFLAGS remove white space between -L and directory
943 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
944 # Filter out only the libdirs and remove -L
945 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
946 # Add trailing /
947 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
948 # Add normal linklib path
949 TMP_DIRS += $(AROS_LIB)/
950 # add lib and .a to static linklib names
951 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
952 ifeq (%(usestartup),yes)
953     TMP_LIBS += startup.o
954 endif
955 ifeq (%(detach),yes)
956     TMP_LIBS += detach.o
957 endif
958 # search for the linklibs in the given path, ignore ones not found
959 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
960     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
963 %(prog) : OBJS := %(objs)
964 %(prog) : LDFLAGS := %(ldflags) $(TMP_EXTRA_LDFLAGS)
965 %(prog) : LIBS := $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
966 %(prog) : %(objs) $(TMP_DEPLIBS)
967         %link_q cmd="%(cmd)" strip="%(strip)" from=$(OBJS) opt=$(LDFLAGS) libs=$(LIBS)
968 %end
969 #------------------------------------------------------------------------------
972 #------------------------------------------------------------------------------
973 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
974 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
975 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) nix=%(nix) \
976     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
977     usestartup=yes detach=no cmd="$(AROS_CC) $(TARGET_SYSROOT)" strip=$(TARGET_STRIP)
979 TMP_EXTRA_LDFLAGS := 
980 TMP_EXTRA_LIBS :=
981 ifeq (%(nix),yes)
982     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
983 endif
984 ifeq (%(usestartup),no)
985     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
986 endif
987 ifeq (%(detach),yes)
988     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
989 endif
991 # Make a list of the lib files the programs depend on.
992 # In LDFLAGS remove white space between -L and directory
993 TMP_DIRS := $(subst -L ,-L,$(strip %(ldflags)))
994 # Filter out only the libdirs and remove -L
995 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
996 # Add trailing /
997 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
998 # Add normal linklib path
999 TMP_DIRS += $(AROS_LIB)/
1000 # add lib and .a to static linklib names
1001 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs) $(TMP_EXTRA_LIBS)))
1002 # search for the linklibs in the given path, ignore ones not found
1003 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1004     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1006 TMP_PROGS := $(addprefix %(targetdir)/,%(progs))
1008 $(TMP_PROGS) : LDFLAGS:= %(ldflags) $(TMP_EXTRA_LDFLAGS)
1009 $(TMP_PROGS) : LIBS:= $(addprefix -l,%(uselibs) $(TMP_EXTRA_LIBS) %(usehostlibs))
1010 $(TMP_PROGS) : %(targetdir)/% : %(objdir)/%.o $(TMP_DEPLIBS)
1011         %link_q cmd="%(cmd)" strip="%(strip)" from=$< opt=$(LDFLAGS) libs=$(LIBS)
1012 %end
1013 #------------------------------------------------------------------------------
1016 #------------------------------------------------------------------------------
1017 # Link the %(objs) to the library %(libdir)/lib%(libname).a
1018 %define rule_link_linklib libname=/A objs=/A libdir=$(AROS_LIB) linker=target
1020 ifeq (%(linker),target)
1021 %(libdir)/lib%(libname).a : TMP_AR:=$(AR)
1022 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(RANLIB)
1023 endif
1024 ifeq (%(linker),host)
1025 %(libdir)/lib%(libname).a : TMP_AR:=$(HOST_AR)
1026 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(HOST_RANLIB)
1027 endif
1028 ifeq (%(linker),kernel)
1029 %(libdir)/lib%(libname).a : TMP_AR:=$(KERNEL_AR)
1030 %(libdir)/lib%(libname).a : TMP_RANLIB:=$(KERNEL_RANLIB)
1031 endif
1033 %(libdir)/lib%(libname).a : %(objs)
1034         %mklib_q from=$^ ar=$(TMP_AR) ranlib=$(TMP_RANLIB)
1035 %end
1036 #------------------------------------------------------------------------------
1038 #------------------------------------------------------------------------------
1039 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
1040 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
1041 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A objdir=$(OBJDIR) \
1042     cmd="$(AROS_CC) $(TARGET_SYSROOT)" ldflags=$(LDFLAGS) uselibs= usehostlibs=
1044 TMP_LDFLAGS  := %(ldflags)
1045 # Make a list of the lib files the programs depend on.
1046 # In LDFLAGS remove white space between -L and directory
1047 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
1048 # Filter out only the libdirs and remove -L
1049 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
1050 # Add trailing /
1051 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
1052 # Add normal linklib path
1053 TMP_DIRS += $(AROS_LIB)/
1054 # add lib and .a to static linklib names
1055 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
1056 # search for the linklibs in the given path, ignore ones not found
1057 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
1058     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
1061 %(module) : LIB_NAMES := %(uselibs)
1062 %(module) : OBJS := %(objs)
1063 %(module) : ENDTAG := %(endobj)
1064 %(module) : ERR := %(err)
1065 %(module) : OBJDIR := %(objdir)
1066 %(module) : LDFLAGS := $(TMP_LDFLAGS)
1067 ifeq (%(usehostlibs),)
1068 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES))
1069 else
1070 # Warning: the -L/usr/lib here can result in modules
1071 # linking against host libs instead of AROS libs (e.g stdc++) !!
1072 %(module) : LIBS := $(addprefix -l,$(LIB_NAMES)) \
1073                     -L/usr/lib $(addprefix -l,%(usehostlibs))
1074 endif 
1075 %(module) : %(objs) %(endobj) $(TMP_DEPLIBS) $(USER_DEPLIBS)
1076         %link_module_q cmd="%(cmd)" err=$(ERR) endtag=$(ENDTAG) objs=$(OBJS) libs=$(LIBS) objdir=$(OBJDIR) ldflags=$(LDFLAGS)
1078 %end
1079 #------------------------------------------------------------------------------
1082 #------------------------------------------------------------------------------
1083 # Generate the libdefs.h include file for a module.
1084 %define rule_genmodule_genlibdefs modname=/A modtype=/A modsuffix= conffile= targetdir= version=
1086 TMP_TARGET := %(modname)_libdefs.h
1087 TMP_DEPS := $(GENMODULE)
1088 TMP_OPTS := 
1089 ifneq (%(conffile),)
1090     ifeq ($(dir %(conffile)),./)
1091         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1092         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1093     else
1094         TMP_OPTS += -c %(conffile)
1095         TMP_DEPS += %(conffile)
1096     endif 
1097 else
1098     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1099     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1100 endif
1101 ifneq (%(modsuffix),)
1102     TMP_OPTS += -s %(modsuffix)
1103 endif
1104 ifneq (%(targetdir),)
1105     TMP_OPTS += -d %(targetdir)
1106     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1107 endif
1108 ifneq (%(version),)
1109     TMP_OPTS += -v %(version)
1110 endif
1112 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1113 $(TMP_TARGET) : MODNAME := %(modname)
1114 $(TMP_TARGET) : MODTYPE := %(modtype)
1115 $(TMP_TARGET) : $(TMP_DEPS)
1116         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1117         @$(GENMODULE) $(OPTS) writelibdefs $(MODNAME) $(MODTYPE)
1118 %end
1119 #------------------------------------------------------------------------------
1121 #------------------------------------------------------------------------------
1122 # Generate the _lib.fd file for a module.
1123 %define rule_genmodule_fd modname=/A modtype=/A modsuffix= conffile= targetdir=
1125 TMP_TARGET := %(modname)_lib.fd
1126 TMP_DEPS := $(GENMODULE)
1127 TMP_OPTS := 
1128 ifneq (%(conffile),)
1129     ifeq ($(dir %(conffile)),./)
1130         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1131         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1132     else
1133         TMP_OPTS += -c %(conffile)
1134         TMP_DEPS += %(conffile)
1135     endif 
1136 else
1137     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1138     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1139 endif
1140 ifneq (%(modsuffix),)
1141     TMP_OPTS += -s %(modsuffix)
1142 endif
1143 ifneq (%(targetdir),)
1144     TMP_OPTS += -d %(targetdir)
1145     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1146 endif
1148 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1149 $(TMP_TARGET) : MODNAME := %(modname)
1150 $(TMP_TARGET) : MODTYPE := %(modtype)
1151 $(TMP_TARGET) : $(TMP_DEPS)
1152         @$(ECHO) "Generating $(subst $(TARGETDIR)/,,$@)"
1153         @$(GENMODULE) $(OPTS) writefd $(MODNAME) $(MODTYPE)
1154 %end
1155 #------------------------------------------------------------------------------
1157 #------------------------------------------------------------------------------
1158 # Generate a Makefile.%(modname)%(modtype) with the genmodule program and include this
1159 # generated file in this Makefile
1160 %define rule_genmodule_makefile modname=/A modtype=/A modsuffix= conffile= \
1161     targetdir=
1163 TMP_TARGET := Makefile.%(modname)%(modtype)
1164 TMP_DEPS := $(GENMODULE)
1165 TMP_OPTS := 
1166 ifneq (%(conffile),)
1167     ifeq ($(dir %(conffile)),./)
1168         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1169         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1170     else
1171         TMP_OPTS += -c %(conffile)
1172         TMP_DEPS += %(conffile)
1173     endif 
1174 else
1175     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1176     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1177 endif
1178 ifneq (%(modsuffix),)
1179     TMP_OPTS += -s %(modsuffix)
1180 endif
1181 ifneq (%(targetdir),)
1182     TMP_OPTS += -d %(targetdir)
1183     TMP_TARGET := %(targetdir)/$(TMP_TARGET)
1184 endif
1186 $(TMP_TARGET) : OPTS := $(TMP_OPTS)
1187 $(TMP_TARGET) : MODNAME := %(modname)
1188 $(TMP_TARGET) : MODTYPE := %(modtype)
1189 $(TMP_TARGET) : $(TMP_DEPS)
1190         @$(GENMODULE) $(OPTS) writemakefile $(MODNAME) $(MODTYPE)
1191 %end
1192 #------------------------------------------------------------------------------
1195 #------------------------------------------------------------------------------
1196 # Generate the support files for compiling a module. This includes include
1197 # files and source files. This rule has to be preceeded by
1198 # %rule_genmodule_makefile
1199 %define rule_genmodule_files modname=/A modtype=/A modsuffix= targetdir= \
1200     conffile=
1202 TMP_TARGETS := $(%(modname)_STARTFILES) $(%(modname)_ENDFILES) \
1203                $(%(modname)_LINKLIBFILES) $(%(modname)_RELLINKLIBFILES)
1204 TMP_TARGETS := $(addsuffix .c,$(TMP_TARGETS)) \
1205                $(addsuffix .S, $(%(modname)_LINKLIBAFILES) $(%(modname)_RELLINKLIBAFILES))
1207 TMP_DEPS := $(GENMODULE)
1208 TMP_OPTS :=
1210 ifneq (%(conffile),)
1211     ifeq ($(dir %(conffile)),./)
1212         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1213         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1214     else
1215         TMP_OPTS += -c %(conffile)
1216         TMP_DEPS += %(conffile)
1217     endif 
1218 else
1219     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1220     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1221 endif
1222 ifneq (%(modsuffix),)
1223     TMP_OPTS += -s %(modsuffix)
1224 endif
1225 ifneq (%(targetdir),)
1226     TMP_OPTS += -d %(targetdir)
1227     TMP_TARGETDIR := $(shell echo %(targetdir) | sed 's/^\(.\):\//\/\1\//')
1228     TMP_TARGETS := $(addprefix $(TMP_TARGETDIR)/,$(TMP_TARGETS))
1229 endif
1231 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1232 $(TMP_TARGETS) : MODNAME := %(modname)
1233 $(TMP_TARGETS) : MODTYPE := %(modtype)
1234 $(TMP_TARGETS) : $(TMP_DEPS)
1235         @$(ECHO) "Generating support files for module $(MODNAME$(BDID))"
1236 ifneq (%(conffile),lib.conf)
1237         @$(IF) $(TEST) -f lib.conf; then \
1238           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
1239         fi
1240 endif
1241         @$(IF) $(TEST) -f libdefs.h; then \
1242           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
1243         fi
1244         @$(GENMODULE) $(OPTS) writefiles $(MODNAME) $(MODTYPE)
1245 %end
1246 #------------------------------------------------------------------------------
1249 #------------------------------------------------------------------------------
1250 # Generate the support files for compiling a module. This includes include
1251 # files and source files.
1252 %define rule_genmodule_includes modname=/A modtype=/A modsuffix= \
1253     targetdir= conffile=
1255 ifneq ($(%(modname)_INCLUDES),)
1256 TMP_TARGETS := $(%(modname)_INCLUDES)
1258 TMP_DEPS := $(GENMODULE)
1259 TMP_OPTS :=
1261 ifneq (%(conffile),)
1262     ifeq ($(dir %(conffile)),./)
1263         TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(conffile)
1264         TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(conffile)
1265     else
1266         TMP_OPTS += -c %(conffile)
1267         TMP_DEPS += %(conffile)
1268     endif 
1269 else
1270     TMP_OPTS += -c $(SRCDIR)/$(CURDIR)/%(modname).conf
1271     TMP_DEPS += $(SRCDIR)/$(CURDIR)/%(modname).conf
1272 endif
1273 ifneq (%(modsuffix),)
1274     TMP_OPTS += -s %(modsuffix)
1275 endif
1276 ifneq (%(targetdir),)
1277     TMP_OPTS += -d %(targetdir)
1278     TMP_TARGETS := $(addprefix %(targetdir)/,$(TMP_TARGETS))
1279 endif
1281 $(TMP_TARGETS) : OPTS := $(TMP_OPTS)
1282 $(TMP_TARGETS) : MODNAME := %(modname)
1283 $(TMP_TARGETS) : MODTYPE := %(modtype)
1284 $(TMP_TARGETS) : $(TMP_DEPS)
1285         @$(ECHO) "Generating $(MODNAME).$(MODTYPE) includes"
1286         @$(GENMODULE) $(OPTS) writeincludes $(MODNAME) $(MODTYPE)
1287 endif
1288 %end
1289 #------------------------------------------------------------------------------
1291 #------------------------------------------------------------------------------
1292 # Link %(objs) to binary blob in %(file) using %(name) as name of embedded binary object
1293 # 'start' is an optional starting address
1294 # 'ldflags' is optional additional flags for the linker
1295 %define rule_link_binary file=/A name=/A objs= files= start=0 ldflags=
1297 BD_OUTDIR := $(dir %(file))
1298 # This trick removes the trailing '/', otherwise findstring below fails, causing a warning
1299 BD_OUTDIR := $(subst /*,,$(addsuffix *,$(BD_OUTDIR)))
1300 BD_TMPDIR := $(GENDIR)/$(CURDIR)
1301 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1302 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir %(files))))
1303 BD_OBJS += %(objs)
1305 %rule_compile_multi basenames="%(files)" targetdir=$(BD_OBJDIR)
1307 %(file) : $(BD_OBJS) $(BD_DEPS) $(BD_OUTDIR)
1308         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)..."
1309         @$(KERNEL_LD) %(ldflags) --entry=%(start) --oformat=binary -Ttext=%(start) -o $(BD_TMPDIR)/%(name) $(BD_OBJS)
1310         @cd $(BD_TMPDIR) && $(AROS_LD) %(ldflags) -r --format binary %(name) -o $@
1312 ifeq ($(findstring $(BD_OUTDIR),$(GLOB_MKDIRS)),)
1313     GLOB_MKDIRS += $(BD_OUTDIR)
1314 endif
1316 %end
1318 #------------------------------------------------------------------------------
1319 # Common rules for all makefiles
1320 %define common
1321 # Delete generated makefiles
1323 clean ::
1324         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
1326 include $(SRCDIR)/config/make.tail
1328 BDID := $(BDTARGETID)
1329 %end
1330 #------------------------------------------------------------------------------
1331       
1333 #############################################################################
1334 #############################################################################
1335 ##                                                                         ##
1336 ## Here are the mmakefile build macros. These are macros that takes care   ##
1337 ## of everything to go from the sources to the generated target. Also all  ##
1338 ## intermediate files and directories that are needed are created by these ##
1339 ## rules.                                                                  ##
1340 ##                                                                         ##
1341 #############################################################################
1342 #############################################################################
1344 #------------------------------------------------------------------------------
1345 # Build a program
1346 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME) cxxfiles= \
1347     objcfiles= \
1348     asmfiles= objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1349     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) ldflags=$(LDFLAGS) \
1350     aflags=$(AFLAGS) uselibs= usehostlibs= usestartup=yes detach=no nix=no \
1351     includedir= libdir= \
1352     compiler=target linker=
1354 .PHONY : %(mmake)
1356 BD_PROGNAME  := %(progname)
1357 BD_OBJDIR    := %(objdir)
1358 BD_TARGETDIR := %(targetdir)
1359 BD_LINKER    := %(linker)
1361 # If not supplied, linker is equal to compiler
1362 ifeq ($(BD_LINKER),)
1363     BD_LINKER := %(compiler)
1364 endif
1366 BD_FILES     := %(files)
1367 BD_OBJCFILES := %(objcfiles)
1368 BD_ASMFILES  := %(asmfiles)
1369 BD_CXXFILES := %(cxxfiles)
1371 BD_ARCHOBJS   := $(wildcard $(BD_OBJDIR)/arch/*.o)
1372 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1373 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1375 TMP_FILES := $(BD_NARCHFILES) $(BD_CXXFILES) $(BD_ASMFILES) $(BD_OBJCFILES)
1376 BD_OBJS := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1377 BD_DEPS := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(notdir $(TMP_FILES))))
1379 BD_CFLAGS    := %(cflags)
1380 BD_CXXFLAGS := %(cxxflags)
1381 ifneq (%(includedir),)
1382 BD_CFLAGS    += -I%(includedir)
1383 BD_CXXFLAGS += -I%(includedir)
1384 endif
1385 BD_AFLAGS    := %(aflags)
1386 ifneq (%(includedir),)
1387 BD_AFLAGS    += -I%(includedir)
1388 endif
1389 BD_DFLAGS    := %(dflags)
1390 BD_DXXFLAGS := %(dxxflags)
1391 BD_LDFLAGS   := %(ldflags)
1392 ifneq (%(libdir),)
1393 BD_LDFLAGS   += -L%(libdir)
1394 endif
1397 %(mmake)-quick : %(mmake)
1399 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1400 %(mmake) : $(BD_TARGETDIR)/$(BD_PROGNAME)
1402 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-gz-quick),)
1403 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir=$(BD_OBJDIR) \
1404     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) compiler="%(compiler)"
1405 %rule_compile_objc_multi basenames=$(BD_OBJCFILES) targetdir=$(BD_OBJDIR) \
1406     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1407 %rule_compile_multi basenames=$(BD_NARCHFILES) targetdir=$(BD_OBJDIR) \
1408     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) compiler="%(compiler)"
1409 %rule_assemble_multi cmd=$(BD_ASSEMBLER) basenames=$(BD_ASMFILES) targetdir=$(BD_OBJDIR) \
1410     aflags=$(BD_AFLAGS)
1412 %rule_link_prog prog=$(BD_TARGETDIR)/$(BD_PROGNAME) \
1413     objs="$(BD_OBJS) $(BD_ARCHOBJS) $(USER_OBJS)" ldflags=$(BD_LDFLAGS) \
1414     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1415     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)" \
1416     cmd=$(BD_LINK) strip=$(BD_STRIP)
1418 endif
1420 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1422 $(BD_OBJS) $(BD_DEPS) : | $(BD_OBJDIR)
1423 $(BD_TARGETDIR)/$(BD_PROGNAME) : | $(BD_TARGETDIR)
1424 GLOB_MKDIRS += $(BD_OBJDIR) $(BD_TARGETDIR)
1426 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_TARGETDIR)/$(BD_PROGNAME) $(BD_DEPS)
1428 %(mmake)-clean ::
1429         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1430         @$(RM) $(FILES)
1432 %end
1433 #------------------------------------------------------------------------------
1436 #------------------------------------------------------------------------------
1437 # Build programs, for every C file an executable will be built with the same
1438 # name as the C file
1439 %define build_progs mmake=/A files=/A nix=no \
1440     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
1441     cflags=$(CFLAGS) dflags=$(BD_CFLAGS) ldflags=$(LDFLAGS) \
1442     includedir= libdir= \
1443     uselibs= usehostlibs= usestartup=yes detach=no
1445 .PHONY : %(mmake)
1447 BD_OBJDIR    := %(objdir)
1448 BD_TARGETDIR := %(targetdir)
1450 BD_FILES     := %(files)
1451 BD_OBJS      := $(addsuffix .o,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1452 BD_DEPS      := $(addsuffix .d,$(addprefix $(BD_OBJDIR)/,$(BD_FILES)))
1453 BD_EXES      := $(addprefix $(BD_TARGETDIR)/,$(BD_FILES))
1455 BD_CFLAGS    := %(cflags)
1456 ifneq (%(includedir),)
1457     BD_CFLAGS += -I%(includedir)
1458 endif
1459 BD_DFLAGS    := %(dflags)
1460 BD_LDFLAGS   := %(ldflags)
1461 ifneq (%(libdir),)
1462     BD_LDFLAGS += -L%(libdir)
1463 endif
1466 %(mmake)-quick : %(mmake)
1468 #MM %(mmake) : includes-generate-deps core-linklibs linklibs-%(uselibs)
1469 %(mmake) : $(BD_EXES)
1471 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
1472 %rule_compile_multi basenames=$(BD_FILES) targetdir=$(BD_OBJDIR) \
1473     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
1475 %rule_link_progs progs=$(BD_FILES) nix="%(nix)" \
1476     targetdir=$(BD_TARGETDIR) objdir=$(BD_OBJDIR) \
1477     ldflags=$(BD_LDFLAGS) \
1478     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
1479     usestartup="%(usestartup)" detach="%(detach)" \
1480      cmd=$(BD_LINK) strip=$(BD_STRIP)
1482 endif
1484 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
1486 $(addprefix $(BD_TARGETDIR)/,$(BD_FILES)) : | $(BD_TARGETDIR)
1487 $(BD_DEPS) $(BD_OBJS) : | $(BD_OBJDIR)
1488 GLOB_MKDIRS += $(BD_TARGETDIR) $(BD_OBJDIR)
1490 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_EXES) $(BD_DEPS)
1492 %(mmake)-clean ::
1493         @$(ECHO) "Cleaning up for metatarget %(mmake)"
1494         @$(RM) $(FILES)
1496 %end
1497 #------------------------------------------------------------------------------
1500 #------------------------------------------------------------------------------
1501 # Build a module.
1502 # This is a bare version: It just compiles and links the given files. It is
1503 # assumed that all needed boiler plate code is in the files. This should only
1504 # be used for compiling external code. For AROS code use %build_module
1505 %define build_module_simple mmake=/A modname=/A modtype=/A \
1506     files="$(basename $(call WILDCARD, *.c))" \
1507     cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) \
1508     objdir=$(OBJDIR) moduledir= \
1509     uselibs= usehostlibs= compiler=target
1511 # Define metamake targets and their dependencies
1512 #MM %(mmake) : core-linklibs includes-generate-deps
1513 #MM %(mmake)-kobj : core-linklibs includes-generate-deps
1514 #MM %(mmake)-kobj-quick
1515 #MM %(mmake)-quick
1516 #MM %(mmake)-clean
1518 BD_ALLTARGETS := %(mmake) %(mmake)-clean %(mmake)-quick %(mmake)-kobj
1520 .PHONY : $(BD_ALLTARGETS)
1522 ifeq (%(modname),)
1523 $(error using %build_module_simple: modname may not be empty)
1524 endif
1525 ifeq (%(modtype),)
1526 $(error using %build_module_simple: $(MODTYPE) has to be defined with the type of the module)
1527 endif
1529 # Default values for variables and arguments
1530 BD_DEFLINKLIBNAME := %(modname)
1531 BD_DEFDFLAGS := %(cflags)
1532 BD_DEFDXXFLAGS := %(dxxflags)
1533 OBJDIR ?= $(GENDIR)/$(CURDIR)
1534 BD_MODDIR := %(moduledir)
1535 ifeq ($(BD_MODDIR),)
1536   ifeq (%(modtype),library)
1537     BD_MODDIR  := $(AROS_LIBRARIES)
1538   endif
1539   ifeq (%(modtype),gadget)
1540     BD_MODDIR  := $(AROS_GADGETS)
1541   endif
1542   ifeq (%(modtype),datatype)
1543     BD_MODDIR  := $(AROS_DATATYPES)
1544   endif
1545   ifeq (%(modtype),handler)
1546     BD_MODDIR  := $(AROS_FS)
1547   endif
1548   ifeq (%(modtype),device)
1549     BD_MODDIR  := $(AROS_DEVS)
1550   endif
1551   ifeq (%(modtype),resource)
1552     BD_MODDIR  := $(AROS_RESOURCES)
1553   endif
1554   ifeq (%(modtype),hook)
1555     BD_MODDIR  := $(AROS_RESOURCES)
1556   endif
1557   ifeq (%(modtype),mui)
1558     BD_MODDIR  := $(AROS_CLASSES)/Zune
1559   endif
1560   ifeq (%(modtype),mcc)
1561     BD_MODDIR  := $(AROS_CLASSES)/Zune
1562   endif
1563   ifeq (%(modtype),mcp)
1564     BD_MODDIR  := $(AROS_CLASSES)/Zune
1565   endif
1566   ifeq (%(modtype),usbclass)
1567     BD_MODDIR  := $(AROS_CLASSES)/USB
1568   endif
1569   ifeq (%(modtype),hidd)
1570     BD_MODDIR  := $(AROS_DRIVERS)
1571   endif
1572   ifeq (%(modtype),printer)
1573     BD_MODDIR  := $(AROS_PRINTERS)
1574   endif
1575 endif
1576 ifeq ($(BD_MODDIR),)
1577   $(error Don't know where to put the file for modtype %(modtype). Specify moduledir=)
1578 endif
1580 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1581 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1582 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),%(files))
1584 %rule_compile_multi \
1585     basenames=$(BD_NARCHFILES) targetdir="%(objdir)" \
1586     cflags="%(cflags)" dflags="%(dflags)" \
1587     compiler="%(compiler)"
1589 # Handlers use dash instead of dot in their names
1590 ifeq (%(modtype),handler)
1591 BD_MODULE := $(BD_MODDIR)/%(modname)-%(modtype)
1592 else
1593 ifeq (%(modtype),printer)
1594 BD_MODULE := $(BD_MODDIR)/%(modname)
1595 else
1596 BD_MODULE := $(BD_MODDIR)/%(modname).%(modtype)
1597 endif
1598 endif
1599 BD_KOBJ   := $(KOBJSDIR)/%(modname)_%(modtype).o
1601 %(mmake)-quick : %(mmake)
1602 %(mmake)-kobj-quick : $(BD_KOBJ)
1603 %(mmake)       : $(BD_MODULE)
1604 %(mmake)-kobj  : $(BD_KOBJ)
1606 # The module is linked from all the compiled .o files
1607 BD_OBJS       := $(BD_ARCHOBJS) $(addprefix %(objdir)/, $(addsuffix .o,$(notdir $(BD_NARCHFILES))))
1609 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1610 # This breaks con-handler build. Here we work around this
1611 ifeq (%(modname),con)
1612     BD_ERR := $(notdir $(BD_MODULE)).err
1613 else
1614     BD_ERR := %(modname).err
1615 endif
1617 %rule_linkmodule module=$(BD_MODULE) objs=$(BD_OBJS) \
1618                  endobj= err=$(BD_ERR) objdir="%(objdir)" \
1619                  ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1620                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1622 # Link kernel object file
1623 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
1625 # Make these symbols local
1626 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
1627             UtilityBase ExpansionBase KeymapBase KernelBase
1629 BD_SYMBOLS := $(BD_KBASE)
1631 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
1632 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
1633 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS)
1634 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
1635 $(BD_KOBJ) : USER_LDFLAGS := $(USER_LDFLAGS)
1636 $(BD_KOBJ) : $(BD_OBJS) $(BD_ENDOBJS)
1637         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
1638         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
1639         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
1642 ## Dependency fine-tuning
1644 BD_DEPS       := $(addprefix %(objdir)/, $(addsuffix .d,%(files)))
1645 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS)
1647 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
1648 $(BD_MODULE) : | $(BD_MODDIR)
1649 $(BD_KOBJ) : | $(KOBJSDIR)
1650 GLOB_MKDIRS += %(objdir) $(BD_MODDIR) $(KOBJSDIR)
1652 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_MODULE) $(BD_KOBJ) $(BD_DEPS)
1653 %(mmake)-clean ::
1654         @$(ECHO) "Cleaning up for module %(modname)"
1655         @$(RM) $(FILES)
1656 %end
1657 #------------------------------------------------------------------------------
1660 #------------------------------------------------------------------------------
1661 # Build a module - core routine
1662 # Explanation of this macro is done in the developer's manual
1663 %define build_module_core mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
1664   files="$(basename $(call WILDCARD, *.c))" \
1665   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
1666   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
1667   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
1668   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
1669   compiler=target nostartup=yes archspecific=no \
1670   includedir= libdir= \
1671   build_abi= build_library=
1673 # We will employ a terrifying, but unavoidable, hack here.
1674 # genmf has no concept of conditionals (ie %ifeq), and MetaMake
1675 # ignores GNU Make ifeq() statements, but will process any #MM
1676 # headed lines in the file.
1678 # So, to make the following #MM lines conditional on whether we want
1679 # to build the ABI, Library, or both, we define build_abi= and 
1680 # build_library as 'M' to enable, or '' to disable, which allows genmf
1681 # to do the following conversions:
1683 #  #%(build_abi)M includes-foo: foo-include
1684 #    becomes, when build_abi=M
1685 #  #MM includes-foo: foo-include   <= Processed by MetaMake
1686 #    but, when build_abi= ...
1687 #  #M includes-foo: foo-includes   <= ignored by MetaMake! Yes!
1689 # Taking full blame for this: Jason S. McMullan <jason.mcmullan@gmail.com>
1691 # Define metamake targets and their dependencies
1692 #MM %(mmake)
1693 #MM %(mmake)-quick
1694 #MM %(mmake)-makefile
1695 #MM %(mmake)-clean
1697 # ABI targets:
1698 #M%(build_abi)- includes-all : %(mmake)-includes
1699 #M%(build_abi)- linklibs-%(modname): %(mmake)-linklib
1700 #M%(build_abi)- linklibs-%(modname)_rel : %(mmake)-linklib
1701 #M%(build_abi)- includes-%(modname): %(mmake)-includes
1702 #M%(build_abi)- includes-%(modname)_rel : %(mmake)-includes
1703 #M%(build_abi)- %(mmake) : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1704 #M%(build_abi) %(mmake)-linklib : %(mmake)-includes includes-%(uselibs)
1705 #M%(build_abi)- %(mmake)-quick : %(mmake)-includes-quick
1706 #M%(build_abi) %(mmake)-includes : %(mmake)-makefile %(mmake)-includes-dirs \
1707 #M%(build_abi)     includes-generate-deps %(mmake)-fd
1708 #M%(build_abi) %(mmake)-includes-quick
1709 #M%(build_abi) %(mmake)-includes-dirs
1710 #M%(build_abi) %(mmake)-fd
1712 # Library targets
1713 #%(build_library)M %(mmake)-kobj : core-linklibs linklibs-%(uselibs)
1714 #%(build_library)M %(mmake)-kobj-quick : 
1716 # Library with ABI targets:
1717 #%(build_library)%(build_abi) %(mmake)-kobj : %(mmake)-includes core-linklibs linklibs-%(uselibs)
1718 #%(build_library)%(build_abi) %(mmake)-kobj-quick : %(mmake)-includes-quick
1720 # All MetaMake targets defined by this macro
1721 BD_ALLTARGETS := %(mmake) %(mmake)-quick %(mmake)-clean
1723 ifeq (%(build_library),M)
1724 BD_ALLTARGETS += %(mmake)-kobj %(mmake)-kobj-quick
1725 endif
1727 ifeq (%(build_abi),M)
1728 BD_ALLTARGETS += %(mmake)-includes \
1729                  %(mmake)-includes-quick %(mmake)-includes-dirs  \
1730                  %(mmake)-linklib %(mmake)-fd
1731 endif
1733 .PHONY : $(BD_ALLTARGETS) %(mmake)-makefile
1735 ifeq (%(modname),)
1736 $(error using %build_module: modname may not be empty)
1737 endif
1738 ifeq (%(modtype),)
1739 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
1740 endif
1742 # Default values for variables and arguments
1743 BD_DEFLINKLIBNAME := %(modname)
1744 BD_DEFDFLAGS := %(cflags)
1745 BD_DEFDXXFLAGS := %(cxxflags)
1746 ifneq (%(includedir),)
1747     BD_DEFDFLAGS += -I%(includedir)
1748     BD_DEFDXXFLAGS += -I%(includedir)
1749 endif
1750 OBJDIR ?= $(GENDIR)/$(CURDIR)
1752 ## Create genmodule include Makefile for the module
1754 %(mmake)-makefile : %(objdir)/Makefile.%(modname)%(modtype)
1756 %rule_genmodule_makefile \
1757     modname="%(modname)" modtype="%(modtype)" \
1758     modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1759     conffile="%(conffile)"
1761 %(objdir)/Makefile.%(modname)%(modtype) : | %(objdir)
1763 GLOB_MKDIRS += %(objdir)
1765 # Do not parse these statements if metatarget is not appropriate
1766 ifneq ($(filter $(TARGET),$(BD_ALLTARGETS)),)
1768 include %(objdir)/Makefile.%(modname)%(modtype)
1770 BD_DEFMODDIR := $(%(modname)_MODDIR)
1771 ifeq (%(archspecific),yes)
1772 BD_DEFMODDIR := $(AROS_DIR_ARCH)/$(BD_DEFMODDIR)
1773 endif
1776 ## include files generation
1778 ifneq (%(includedir),)
1779 BD_INCDIR    := %(includedir)
1780 else
1781 BD_INCDIR    := %(prefix)/$(AROS_DIR_INCLUDE)
1782 endif
1783 BD_LIBDEFSINC := %(objdir)/include/%(modname)_libdefs.h
1784 BD_DEFLIBDEFSINC := %(objdir)/include/%(modname)_deflibdefs.h
1786 ifeq (%(build_abi),M)
1787 %(mmake)-includes-quick : %(mmake)-includes
1788 %(mmake)-includes : $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
1789     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
1790     $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC)
1792 ifneq ($(%(modname)_INCLUDES),)
1793 %rule_genmodule_includes modname="%(modname)" modtype="%(modtype)" \
1794                          modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1795                          conffile="%(conffile)"
1797 %rule_copy_diff_multi \
1798     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(GENINCDIR) \
1799     stampfile="%(objdir)/%(modname)_geninc"
1801 %rule_copy_diff_multi \
1802     files=$(%(modname)_INCLUDES) srcdir="%(objdir)/include" targetdir=$(BD_INCDIR) \
1803     stampfile="%(objdir)/%(modname)_incs"
1805 BD_INCDIRS := $(filter-out ./,$(sort $(dir $(%(modname)_INCLUDES))))
1807 TMP%(modname)_INCDIRS := \
1808     %(objdir)/include $(addprefix %(objdir)/include/,$(BD_INCDIRS)) \
1809     $(GENINCDIR) $(addprefix $(GENINCDIR)/,$(BD_INCDIRS)) \
1810     $(BD_INCDIR) $(addprefix $(BD_INCDIR)/,$(BD_INCDIRS))
1811 %rule_makedirs dirs=$(TMP%(modname)_INCDIRS) setuptarget="%(mmake)-includes-dirs"
1813 endif
1815 endif
1817 %rule_genmodule_genlibdefs modname="%(modname)" modtype="%(modtype)" \
1818                            modsuffix="%(modsuffix)" targetdir="%(objdir)/include" \
1819                            conffile="%(conffile)" version="%(version)"
1821 $(BD_DEFLIBDEFSINC) : FILENAME := $(BD_LIBDEFSINC)
1822 $(BD_DEFLIBDEFSINC) :
1823         @$(ECHO) "Generating $@"
1824         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(FILENAME)\"" >$@
1826 $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) : | %(objdir)/include
1827 GLOB_MKDIRS += %(objdir)/include
1829 ## Extra genmodule src files generation
1830 ## 
1831 %rule_genmodule_files modname="%(modname)" modtype="%(modtype)" \
1832                       modsuffix="%(modsuffix)" targetdir="%(objdir)" \
1833                       conffile="%(conffile)"
1836 ifeq (%(build_abi),M)
1837 ## Create FD file
1838 ifeq (%(includedir),)
1839 BD_FDDIR := %(prefix)/$(AROS_DIR_DEVELOPMENT)/fd
1840 else
1841 BD_FDDIR := %(includedir)/../fd
1842 endif
1843 %(mmake)-fd : $(BD_FDDIR)/%(modname)_lib.fd
1845 %rule_genmodule_fd modname="%(modname)" modtype="%(modtype)" \
1846                    modsuffix="%(modsuffix)" targetdir=$(BD_FDDIR) conffile="%(conffile)"
1848 $(BD_FDDIR)/%(modname)_lib.fd : | $(BD_FDDIR)
1850 GLOB_MKDIRS += $(BD_FDDIR)
1851 endif
1853 ## Compilation
1855 BD_FILES      := %(files)
1856 BD_CXXFILES := %(cxxfiles)
1858 BD_FDIRS      := $(sort $(dir $(BD_FILES)))
1860 BD_STARTFILES := $(addprefix %(objdir)/,$(%(modname)_STARTFILES))
1861 BD_ENDFILES   := $(addprefix %(objdir)/,$(%(modname)_ENDFILES))
1863 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
1864 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
1865 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
1867 BD_CFLAGS     := %(cflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CFLAGS)
1868 BD_CXXFLAGS := %(cxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_CXXFLAGS)
1869 ifneq (%(includedir),)
1870 BD_CFLAGS     += -I%(includedir)
1871 BD_CXXFLAGS += -I%(includedir)
1872 endif
1873 BD_DFLAGS     := %(dflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DFLAGS)
1874 BD_DXXFLAGS := %(dxxflags) -I%(objdir)/include -include $(BD_DEFLIBDEFSINC) $(%(modname)_DXXFLAGS)
1876 ifeq (%(modtype),library)
1877     BD_LIBSUFFIX := 
1878 else
1879     BD_LIBSUFFIX := .%(modtype)
1880 endif
1882 ifeq (%(libdir),)
1883 BD_LIBDIR := %(prefix)/$(AROS_DIR_LIB)
1884 else
1885 BD_LIBDIR := %(libdir)
1886 endif
1888 ifeq (%(build_abi),M)
1889 BD_LINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBFILES))
1890 BD_LINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_LINKLIBAFILES))
1891 ifeq ($(strip $(%(modname)_LINKLIBFILES) $(%(modname)_LINKLIBAFILES) %(linklibfiles)),)
1892     BD_LINKLIB :=
1893 else
1894     BD_LINKLIB := $(BD_LIBDIR)/lib%(modname)$(BD_LIBSUFFIX).a
1895     ifneq (%(modname),%(linklibname))
1896         BD_LINKLIB += $(BD_LIBDIR)/lib%(linklibname)$(BD_LIBSUFFIX).a
1897     endif
1898 endif
1899 BD_LINKLIBFILES := $(BD_LINKLIBCFILES) $(BD_LINKLIBAFILES)
1901 BD_RELLINKLIBCFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBFILES))
1902 BD_RELLINKLIBAFILES := $(addprefix %(objdir)/,$(%(modname)_RELLINKLIBAFILES))
1903 ifeq ($(strip $(%(modname)_RELLINKLIBFILES) $(%(modname)_RELLINKLIBAFILES) %(linklibfiles)),)
1904     BD_RELLINKLIB :=
1905 else
1906     BD_RELLINKLIB := $(BD_LIBDIR)/lib%(modname)_rel$(BD_LIBSUFFIX).a
1907     ifneq (%(modname),%(linklibname))
1908         BD_RELLINKLIB += $(BD_LIBDIR)/lib%(linklibname)_rel$(BD_LIBSUFFIX).a
1909     endif
1910 endif
1911 BD_RELLINKLIBFILES := $(BD_RELLINKLIBCFILES) $(BD_RELLINKLIBAFILES)
1912 endif
1914 BD_CCFILES := $(BD_NARCHFILES) %(linklibfiles)
1915 BD_TARGETCCFILES := $(BD_STARTFILES) $(BD_ENDFILES) $(BD_LINKLIBCFILES) \
1916     $(BD_RELLINKLIBCFILES)
1918 %rule_compile_cxx_multi \
1919     basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
1920     cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS) \
1921     compiler="%(compiler)"
1922 %rule_compile_multi \
1923     basenames=$(BD_CCFILES) targetdir="%(objdir)" \
1924     cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS) \
1925     compiler="%(compiler)"
1926 %rule_compile_multi \
1927     basenames=$(BD_TARGETCCFILES) targetdir="%(objdir)" \
1928     cflags="$(BD_CFLAGS) -D__AROS__" dflags=$(BD_DFLAGS) \
1929     compiler="%(compiler)"
1931 ifneq ($(BD_LINKLIBAFILES),)
1932 %rule_assemble_multi \
1933     cmd=$(BD_ASSEMBLER) basenames="$(BD_LINKLIBAFILES) $(BD_RELLINKLIBAFILES)" targetdir="%(objdir)" suffix=.S
1934 endif
1936 ## Linking
1938 ifeq (%(modsuffix),)
1939 BD_SUFFIX := %(modtype)
1940 else
1941 BD_SUFFIX := %(modsuffix)
1942 endif
1944 ifeq (%(build_library),M)
1945 # Handlers use dash instead of dot in their names
1946 ifeq ($(BD_SUFFIX),handler)
1947 BD_MODULE := %(prefix)/%(moduledir)/%(modname)-$(BD_SUFFIX)
1948 else
1949 BD_MODULE := %(prefix)/%(moduledir)/%(modname).$(BD_SUFFIX)
1950 endif
1951 BD_KOBJ   := $(KOBJSDIR)/%(modname)_$(BD_SUFFIX).o
1952 else
1953 BD_MODULE :=
1954 BD_KOBJ   :=
1955 endif
1957 %(mmake)-quick      : %(mmake)
1958 %(mmake)            : $(BD_MODULE) $(BD_LINKLIB) $(BD_RELLINKLIB)
1959 ifeq (%(build_library),M)
1960 %(mmake)-kobj       : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1961 %(mmake)-kobj-quick : $(BD_KOBJ) $(BD_LINKLIB) $(BD_RELLINKLIB)
1962 endif
1963 ifeq (%(build_abi),M)
1964 %(mmake)-linklib    : $(BD_LINKLIB) $(BD_RELLINKLIB)
1965 endif
1967 BD_OBJS := $(addsuffix .o,$(BD_STARTFILES)) $(BD_ARCHOBJS) \
1968            $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o)))
1970 ifeq (%(nostartup),yes)
1971 # Handlers always have entry point
1972 ifneq (%(modtype),handler)
1973 BD_STARTOBJS  := $(addsuffix .o,$(addprefix $(GENDIR)/,$(RESIDENT_BEGIN)))
1974 endif
1975 endif
1977 BD_ENDOBJS    := $(addsuffix .o,$(BD_ENDFILES))
1978 BD_LINKLIBOBJS:= $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_LINKLIBFILES)) \
1979                  %(linklibobjs)
1980 BD_RELLINKLIBOBJS \
1981               := $(addsuffix .o,$(addprefix %(objdir)/,$(notdir %(linklibfiles))) $(BD_RELLINKLIBFILES)) \
1982                  %(linklibobjs)
1984 # Under Windows con* is a reserved name, it refers to console. Files with such names can't be created.
1985 # This breaks con-handler build. Here we work around this
1986 ifeq (%(modname),con)
1987     BD_ERR := $(notdir $(BD_MODULE)).err
1988 else
1989     BD_ERR := %(modname).err
1990 endif
1992 ifeq (%(build_library),M)
1993 # The module is linked from all the compiled .o files
1994 %rule_linkmodule module=$(BD_MODULE) objs="$(BD_STARTOBJS) $(BD_OBJS) $(USER_OBJS)" \
1995                  endobj=$(BD_ENDOBJS) err=$(BD_ERR) objdir="%(objdir)" \
1996                  cmd=$(BD_LINK) ldflags="$(LDFLAGS) $(%(modname)_LDFLAGS)" \
1997                  uselibs="%(uselibs) $(%(modname)_LIBS)" usehostlibs="%(usehostlibs)"
1998 endif
2000 ifeq (%(build_abi),M)
2001 # Link static lib
2002 BD_LINKLIBNAME := $(shell echo %(linklibname) | tr A-Z a-z)
2003 BD_MODNAME     := $(shell echo %(modname) | tr A-Z a-z)
2004 ifneq ($(BD_LINKLIB),)
2005 %rule_link_linklib libname="%(linklibname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2006 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2007 %rule_link_linklib libname="%(modname)$(BD_LIBSUFFIX)" objs=$(BD_LINKLIBOBJS) libdir="$(BD_LIBDIR)"
2008 endif
2010 $(BD_LINKLIB) : | $(BD_LIBDIR)
2011 GLOB_MKDIRS += $(BD_LIBDIR)
2012 endif
2014 ifneq ($(BD_RELLINKLIB),)
2015 %rule_link_linklib libname="%(linklibname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2016 ifneq ($(BD_MODNAME),$(BD_LINKLIBNAME))
2017 %rule_link_linklib libname="%(modname)_rel$(BD_LIBSUFFIX)" objs=$(BD_RELLINKLIBOBJS) libdir="$(BD_LIBDIR)"
2018 endif
2020 $(BD_RELLINKLIB) : | $(BD_LIBDIR)
2021 GLOB_MKDIRS += $(BD_LIBDIR)
2022 endif
2023 endif
2025 ifeq (%(build_library),M)
2026 # Link kernel object file
2027 BD_KAUTOLIB := dos intuition layers graphics oop utility expansion keymap
2029 # Make these symbols local
2030 BD_KBASE := DOSBase IntuitionBase LayersBase GfxBase OOPBase \
2031             UtilityBase ExpansionBase KeymapBase KernelBase
2033 BD_SYMBOLS := $(BD_KBASE)
2035 BD_KLIB := hiddstubs amiga arossupport autoinit libinit
2036 BD_KOBJ_LIBS := $(filter-out $(BD_KLIB),%(uselibs)) $(BD_KAUTOLIB)
2037 $(BD_KOBJ) : LINKLIBS:=$(BD_KOBJ_LIBS) $(%(modname)_LIBS)
2038 $(BD_KOBJ) : FILTBASES:=$(addprefix -L ,$(BD_SYMBOLS))
2039 $(BD_KOBJ) : USER_LDFLAGS:=$(USER_LDFLAGS)
2040 $(BD_KOBJ) : $(BD_OBJS) $(USER_OBJS) $(BD_ENDOBJS)
2041         @$(ECHO) "Linking    $(subst $(TARGETDIR)/,,$@)"
2042         @$(AROS_LD) -Ur -o $@ $^ $(USER_LDFLAGS) -L$(AROS_LIB) $(addprefix -l,$(LINKLIBS))
2043         @$(OBJCOPY) $@ $(FILTBASES) `$(NM_PLAIN) $@ | $(AWK) '($$3 ~ /^__.*_(LIST|END)__\r?$$/) || ($$3 ~ /^__aros_lib.*\r?$$/) {print "-L " $$3;}'`
2044 endif
2046 ## Dependency fine-tuning
2048 BD_DEPS := $(addprefix %(objdir)/,$(notdir $(BD_CCFILES:=.d) $(BD_TARGETCCFILES:=.d) $(BD_CXXFILES:=.d)))
2050 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick" deps=$(BD_DEPS)
2052 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2053 $(BD_MODULE) : | %(prefix)/%(moduledir)
2054 $(BD_KOBJ)   : | $(KOBJSDIR)
2055 GLOB_MKDIRS += %(objdir) %(prefix)/%(moduledir) $(KOBJSDIR)
2057 # Some include files need to be generated before the .c can be parsed.
2058 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj %(mmake)-kobj-quick),) # Only for this target these deps are wanted
2060 BD_DFILE_DEPS := $(BD_LIBDEFSINC) $(BD_DEFLIBDEFSINC) \
2061     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES))
2062 $(BD_DEPS) : $(BD_DFILE_DEPS)
2063 endif
2065 BD_TOCLEAN := $(BD_OBJS) $(BD_DEPS) \
2066     $(BD_MODULE) $(BD_LINKLIB) $(BD_KOBJ) \
2067     %(objdir)/Makefile.%(modname)%(modtype) \
2068     $(addprefix %(objdir)/include/,$(%(modname)_INCLUDES)) \
2069     $(addprefix $(GENINCDIR)/,$(%(modname)_INCLUDES)) \
2070     $(addprefix $(BD_INCDIR)/,$(%(modname)_INCLUDES)) \
2071     %(objdir)/%(modname)_geninc %(objdir)/%(modname)_incs \
2072     $(addsuffix .c,$(BD_LINKLIBFILES)) $(BD_LINKLIBOBJS) $(BD_LIBDEFSINC) \
2073     $(BD_DEFLIBDEFSINC) $(addsuffix .c,$(BD_STARTFILES) $(BD_ENDFILES)) \
2074     $(BD_ENDOBJS)
2075 %(mmake)-clean : FILES := $(BD_TOCLEAN)
2076 %(mmake)-clean ::
2077         @$(ECHO) "Cleaning up for module %(modname)"
2078         @$(RM) $(FILES)
2080 endif # $(TARGET) in $(BD_ALLTARGETS)
2081 %end
2082 #------------------------------------------------------------------------------
2084 #------------------------------------------------------------------------------
2085 # Build a module - ABI and library
2086 # Explanation of this macro is done in the developer's manual
2087 %define build_module mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2088   files="$(basename $(call WILDCARD, *.c))" \
2089   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2090   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2091   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2092   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2093   compiler=target nostartup=yes archspecific=no \
2094   includedir= libdir=
2096 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2097    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2098    files="%(files)" cxxfiles="%(cxxfiles)" \
2099    linklibname="%(linklibname)" \
2100    linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2101    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2102    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2103    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2104    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2105    includedir="%(includedir)" libdir="%(libdir)" \
2106    build_abi=M build_library=M
2108 %end
2109 #------------------------------------------------------------------------------
2112 #------------------------------------------------------------------------------
2113 # Build a module skeleton ABI
2114 # This is a stripped-down version of build_module, it only creates include
2115 # files and the linklibs.
2116 # This is used when for plugins or classes with the same API, but no actual
2117 # implementation here.
2118 %define build_module_abi mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2119   linklibfiles= linklibobjs= cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_DEFDXXFLAGS) \
2120   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2121   linklibname=$(BD_DEFLINKLIBNAME) uselibs= usehostlibs= \
2122   compiler=target nostartup=yes archspecific=no \
2123   includedir= libdir=
2125 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2126   modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2127   linklibname="%(linklibname)" \
2128   linklibfiles="%(linklibfiles)" linklibobjs="%(linklibobjs)" \
2129   cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2130   objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2131   uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2132   nostartup="%(nostartup)" archspecific="%(archspecific)" \
2133   includedir="%(includedir)" libdir="%(libdir)" \
2134   build_abi=M build_library=
2136 %end
2137 #------------------------------------------------------------------------------
2139 #------------------------------------------------------------------------------
2140 # Build a module library - no includes nor linklibs
2141 # Explanation of this macro is done in the developer's manual
2142 %define build_module_library mmake=/A modname=/A modtype=/A modsuffix= version= conffile= \
2143   files="$(basename $(call WILDCARD, *.c))" \
2144   cxxfiles="$(basename $(call WILDCARD $(foreach CXX_EXT, $(AROS_CXXEXTS), *.$(CXX_EXT))))" \
2145   cflags=$(CFLAGS) dflags=$(BD_DEFDFLAGS) cxxflags="$(CXXFLAGS)" dxxflags="$(BD_DEFDXXFLAGS)" \
2146   objdir=$(OBJDIR) moduledir=$(BD_DEFMODDIR) prefix=$(AROSDIR) \
2147   uselibs= usehostlibs= \
2148   compiler=target nostartup=yes archspecific=no \
2149   includedir= libdir=
2151 %build_module_core mmake="%(mmake)" modname="%(modname)" modtype="%(modtype)" \
2152    modsuffix="%(modsuffix)" version="%(version)" conffile="%(conffile)" \
2153    files="%(files)" cxxfiles="%(cxxfiles)" \
2154    cflags="%(cflags)" dflags="%(dflags)" cxxflags="%(cxxflags)" dxxflags="%(dxxflags)" \
2155    objdir="%(objdir)" moduledir="%(moduledir)" prefix="%(prefix)" \
2156    uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" compiler="%(compiler)" \
2157    nostartup="%(nostartup)" archspecific="%(archspecific)" \
2158   includedir="%(includedir)" libdir="%(libdir)" \
2159    build_abi= build_library=M
2161 %end
2162 #------------------------------------------------------------------------------
2166 #------------------------------------------------------------------------------
2167 # Build a linklib.
2168 # - mmake is the mmaketarget
2169 # - libname is the baselibname e.g. lib%(libname).a will be created
2170 # - files are the C source files to include in the lib. The list of files
2171 #   has to be given without the .c suffix
2172 # - cxxfiles are C++ source files without suffix.
2173 #   NB: files will be matched in the order .cpp > .cxx > .cc
2174 # - asmfiles are the asm files to include in the lib. The list of files has to
2175 #   be given without the .s suffix
2176 # - objs additional object to link into the linklib. The objects have to be
2177 #   given with full absolute path and the .o suffix.
2178 # - objdir is where the .o are generated. Defaults to $(GENDIR)/$(CURDIR)
2179 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2180 # - cflags are the flags to compile the source (default $(CFLAGS))
2181 # - dflags are the flags use during makedepend (default equal to cflags)
2182 # - aflags are the flags use during assembling (default $(AFLAGS))
2183 # - libdir is the directory where the linklib will be placed (default $(AROS_LIB))
2184 %define build_linklib mmake=/A libname=/A files= cxxfiles= \
2185   asmfiles= objs= objdir=$(GENDIR)/$(CURDIR) libdir=$(AROS_LIB) \
2186   includedir= \
2187   cflags=$(CFLAGS) dflags=$(BD_CFLAGS) cxxflags=$(CXXFLAGS) dxxflags=$(BD_CXXFLAGS) \
2188   aflags=$(AFLAGS) compiler=target
2190 # assign and generate the local variables used in this macro
2191 BD_LIBNAME    := %(libname)
2192 BD_LINKLIB    := %(libdir)/lib%(libname).a
2194 BD_FILES      := %(files)
2195 BD_ASMFILES   := %(asmfiles)
2196 BD_CXXFILES := %(cxxfiles)
2198 BD_ARCHOBJS   := $(wildcard %(objdir)/arch/*.o)
2199 BD_ARCHFILES  := $(basename $(notdir $(BD_ARCHOBJS)))
2200 BD_NARCHFILES := $(filter-out $(BD_ARCHFILES),$(BD_FILES))
2202 BD_OBJS       := $(BD_ARCHOBJS) \
2203                  $(addprefix %(objdir)/,$(notdir $(BD_NARCHFILES:=.o) $(BD_CXXFILES:=.o) $(BD_ASMFILES:=.o))) \
2204                  %(objs)
2205 BD_DEPS       := $(patsubst %.o,%.d,$(BD_OBJS))
2207 BD_CFLAGS    := %(cflags)
2208 BD_CXXFLAGS := %(cxxflags)
2209 ifneq (%(includedir),)
2210 BD_CFLAGS    += -I%(includedir)
2211 BD_CXXFLAGS += -I%(includedir)
2212 endif
2213 BD_AFLAGS    := %(aflags)
2214 BD_DFLAGS    := %(dflags)
2215 BD_DXXFLAGS := %(dxxflags)
2217 .PHONY : %(mmake) %(mmake)-clean %(mmake)-quick
2220 %(mmake)-quick : %(mmake)
2222 #MM %(mmake) : includes-generate-deps
2223 %(mmake) : $(BD_LINKLIB)
2225 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
2227 %rule_compile_cxx_multi basenames=$(BD_CXXFILES) targetdir="%(objdir)" \
2228     compiler="%(compiler)" cxxflags=$(BD_CXXFLAGS) dxxflags=$(BD_DXXFLAGS)
2229 %rule_compile_multi basenames=$(BD_FILES) targetdir="%(objdir)" \
2230     compiler="%(compiler)" cflags=$(BD_CFLAGS) dflags=$(BD_DFLAGS)
2231 %rule_assemble basename=% targetdir="%(objdir)" \
2232     aflags=$(BD_AFLAGS)
2234 %rule_link_linklib libname="%(libname)" objs=$(BD_OBJS) libdir="%(libdir)" linker="%(compiler)"
2235 endif
2237 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS)
2239 $(BD_OBJS) $(BD_DEPS) : | %(objdir)
2240 $(BD_LINKLIB) : | %(libdir)
2241 GLOB_MKDIRS += %(objdir) %(libdir)
2243 %(mmake)-clean : FILES := $(BD_OBJS) $(BD_LINKLIB) $(BD_DEPS)
2245 %(mmake)-clean ::
2246         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2247         @$(RM) $(FILES)
2249 %end
2250 #------------------------------------------------------------------------------
2253 #------------------------------------------------------------------------------
2254 # Build catalogs.
2255 # - mmake is the mmaketarget
2256 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
2257 # - description is the catalog description file (.cd), without the .cd suffix (default *.cd)
2258 # - subdir is the destination subdirectory of the catalogs
2259 # - name is the name of the destination catalog, without the .catalog suffix
2260 # - source is the path to the generated source code file
2261 # - dir is the base destination directory (default $(AROS_CATALOGS))
2262 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
2263 # - srcdir is the directory in which the *.cd and *.ct files are searched
2265 %define build_catalogs mmake=/A name=/A subdir=/A \
2266  catalogs= source="../strings.h" description= dir=$(AROS_CATALOGS) \
2267  sourcedescription=$(TOOLDIR)/C_h_aros srcdir=$(SRCDIR)/$(CURDIR)
2269 ifeq (%(description),)
2270 BD_DESC := $(basename $(wildcard %(srcdir)/*.cd))
2271 else
2272 BD_DESC := %(description)
2273 endif
2275 BD_SRC := $(shell echo %(sourcedescription) | sed 's/^\(.\):\//\/\1\//')
2277 ifeq (%(catalogs),)
2278 BD_LNGS := $(basename $(notdir $(call WILDCARD, %(srcdir)/*.ct)))
2279 else
2280 BD_LNGS := %(catalogs)
2281 endif
2283 BD_OBJS := $(addsuffix /%(subdir)/%(name).catalog, $(addprefix %(dir)/, $(BD_LNGS)))
2284 BD_DIRS := $(addsuffix /%(subdir), $(addprefix %(dir)/, $(BD_LNGS))) $(dir %(source))
2287 %(mmake) : $(BD_OBJS) %(source)
2289 $(BD_OBJS) : | $(BD_DIRS)
2290 GLOB_MKDIRS += $(BD_DIRS)
2292 %(dir)/%/%(subdir)/%(name).catalog : %(srcdir)/%.ct $(BD_DESC).cd
2293         @$(ECHO) "Creating   %(name) catalog for language $*."
2294         @$(FLEXCAT) $(BD_DESC).cd $< CATALOG="%(dir)/$*/%(subdir)/%(name).catalog" || [ $$? -lt 10 ]
2296 ifneq (%(source),)
2297 %(source) : BD_DESC := $(BD_DESC)
2298 %(source) : BD_SRC := $(BD_SRC)
2299 %(source) : $(BD_DESC).cd $(BD_SRC).sd | $(dir %(source))
2300         @$(ECHO) "Creating   %(name) catalog source file $@"
2301         @$(FLEXCAT) $(BD_DESC).cd $@=$(BD_SRC).sd
2302 endif
2304 %(mmake)-clean : FILES := $(BD_OBJS) %(source)
2306 %(mmake)-clean ::
2307         @$(ECHO) "Cleaning up for metatarget %(mmake)"
2308         @$(RM) $(FILES)
2310 .PHONY: %(mmake) %(mmake)-clean
2312 %end
2313 #-----------------------------------------------------------------------------
2316 #-----------------------------------------------------------------------------
2317 # Build icons.
2318 # - mmake is the mmaketarget
2319 # - icons is a list of icon base names (ie. without the .info suffix)
2320 # - dir is the destination directory
2321 # - srcdir is where *.png and *.info.src are searched
2322 #-----------------------------------------------------------------------------
2324 %define build_icons mmake=/A icons=/A dir=/A srcdir=$(SRCDIR)/$(CURDIR) image=
2326 BD_OBJS := $(addprefix  %(dir)/, $(addsuffix .info,%(icons)))
2329 %(mmake) : $(BD_OBJS)
2331 ifeq (%(image),)
2333 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%.png
2334         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2335         @$(ILBMTOICON) $+ $@
2337 else
2339 %(dir)/%.info : %(srcdir)/%.info.src %(srcdir)/%(image)
2340         @$(ECHO) "Creating   $(subst $(TARGETDIR)/,,$@)..."
2341         @$(ILBMTOICON) $+ $@
2343 endif
2345 $(BD_OBJS) : | %(dir)
2346 GLOB_MKDIRS += %(dir)
2348 %(mmake)-clean : FILES := $(BD_OBJS)
2350 %(mmake)-clean ::
2351         @$(RM) $(FILES)
2353 .PHONY: %(mmake) %(mmake)-clean
2355 %end
2356 #-----------------------------------------------------------------------------
2359 #------------------------------------------------------------------------------
2360 # Compile files for an arch-specific replacement of code for a module
2361 # - files: the basenames of the C files to compile.
2362 # - asmfiles: the basenames of the asm files to assemble.
2363 # - mainmmake: the mmake of the module in the main directory to compile these
2364 #   arch specific files for.
2365 # - maindir: the object directory for the main module
2366 # - arch: the arch for which to compile these files. It can have the form
2367 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
2368 # - cflags (default $(CFLAGS)): the C flags to use for compilation
2369 # - dflags: the flags used during creation of dependency file. If not specified
2370 #   the same value as cflags will be used
2371 # - aflags: the flags used during assembling
2372 # - compiler: (host, kernel or target) specifies which compiler to use. By default
2373 #   the target compiler is used
2374 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
2375 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
2377 ifeq (%(files) %(asmfiles),)
2378   $(error no files or asmfiles given)
2379 endif
2381 %buildid targets="%(mainmmake)-%(arch)"
2383 #MM- %(mainmmake) :         %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2384 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2385 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2386 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2387 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2388 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2389 #MM- %(mainmmake)-kobj :    %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH)-$(CPU) \
2390 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT) %(mainmmake)-$(ARCH) \
2391 #MM                         %(mainmmake)-$(FAMILY) %(mainmmake)-$(CPU)
2392 #MM- %(mainmmake)-kobj-quick : %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2393 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2394 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2395 #MM- %(mainmmake)-quick :   %(mainmmake)-$(ARCH)-$(CPU)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-$(CPU)-quick \
2396 #MM                         %(mainmmake)-$(ARCH)-$(AROS_TARGET_VARIANT)-quick %(mainmmake)-$(ARCH)-quick \
2397 #MM                         %(mainmmake)-$(FAMILY)-quick %(mainmmake)-$(CPU)-quick
2399 #MM %(mainmmake)-%(arch) : %(mainmmake)-includes
2401 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
2402 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2403 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
2404 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
2405 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
2407 ifneq (%(modulename),)
2408 BD_DEFLIBDEFSINC$(BDID) := -include $(GENDIR)/%(maindir)/include/%(modulename)_deflibdefs.h
2409 endif
2411 ifeq ($(TARGET),%(mainmmake)-%(arch)-quick)
2412     BD_TARGET := %(mainmmake)-%(arch)-quick
2413 else
2414     BD_TARGET := %(mainmmake)-%(arch)
2415 endif
2418 ifeq ($(TARGET),$(BD_TARGET))
2419 TMP_SRCDIR := $(shell echo $(SRCDIR) | sed 's/^\(.\):\//\/\1\//')
2420 vpath %.c $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(files)))
2421 vpath %.s $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2422 vpath %.S $(addprefix $(TMP_SRCDIR)/$(CURDIR)/,$(dir %(asmfiles)))
2423 endif
2425 $(BD_OBJS$(BDID)) : | $(BD_OBJDIR$(BDID))
2426 GLOB_MKDIRS += $(BD_OBJDIR$(BDID))
2429 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
2432 %(mainmmake)-%(arch)-quick :: $(BD_OBJS$(BDID))
2434 ifeq ($(findstring %(compiler),host kernel target),)
2435   $(error unknown compiler %(compiler))
2436 endif
2437 ifeq (%(compiler),target)
2438 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)
2439 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(CFLAGS_IQUOTE)
2440 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(CFLAGS_IQUOTE_END)
2441 endif
2442 ifeq (%(compiler),host)
2443 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(HOST_CC)
2444 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(HOST_IQUOTE)
2445 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(HOST_IQUOTE_END)
2446 endif
2447 ifeq (%(compiler),kernel)
2448 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_CMD:=$(KERNEL_CC) $(KERNEL_SYSROOT) $(KERNEL_CFLAGS)
2449 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE:=$(KERNEL_IQUOTE)
2450 $(BD_COBJS$(BDID)) $(BD_DEPS$(BDID)) : TMP_IQUOTE_END:=$(KERNEL_IQUOTE_END)
2451 endif
2452 ifneq (%(modulename),)
2453 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) $(BD_DEFLIBDEFSINC$(BDID))
2454 else
2455 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
2456 endif
2457 ifeq ($(TARGET),$(BD_TARGET))
2458 $(BD_OBJDIR$(BDID))/%.o : $(SRCDIR)/$(CURDIR)/%.c
2459         %compile_q cmd=$(TMP_CMD) opt=$(TMP_CFLAGS) iquote=$(TMP_IQUOTE) iquote_end=$(TMP_IQUOTE_END)
2460 endif
2462 ifeq (%(dflags),)
2463 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags) $(BD_DEFLIBDEFSINC$(BDID))
2464 else
2465 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
2466 endif
2467 ifeq ($(TARGET),$(BD_TARGET))
2468 $(BD_OBJDIR$(BDID))/%.d : $(SRCDIR)/$(CURDIR)/%.c
2469         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
2470 endif
2472 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
2474 ifeq ($(TARGET),$(BD_TARGET))
2475 $(BD_OBJDIR$(BDID))/%.o : %.s
2476         %assemble_q opt=$(AFLAGS)
2477 $(BD_OBJDIR$(BDID))/%.o : %.S
2478         %assemble_q opt=$(AFLAGS)
2479 endif
2481 %include_deps depstargets=$(BD_TARGET) deps=$(BD_DEPS$(BDID))
2482 %end
2483 #------------------------------------------------------------------------------
2486 #------------------------------------------------------------------------------
2487 # generate asm files from c files (for debugging purposes)
2488 %define ctoasm_q
2489 %.s : %.c
2490         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
2491         @$(TARGET_CC) $(TARGET_SYSROOT) -S $(CFLAGS) $(TARGET_CFLAGS) $< -c -o $@
2492 %end
2493 #------------------------------------------------------------------------------
2496 #------------------------------------------------------------------------------
2497 # Copy files from one directory to another.
2499 %define copy_files_q mmake=/A files=$(FILES) src=. dst=/A
2501 %(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//')
2503 GLOB_MKDIRS += %(dst)
2505 .PHONY : %(mmake)
2508 %(mmake) : | %(dst) 
2509         $(foreach file, %(files), $(shell $(CP) $(addprefix $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC))/, $(file)) $(addprefix %(dst)/, $(file))))
2511 %end
2512 #------------------------------------------------------------------------------
2515 #------------------------------------------------------------------------------
2516 # Copy a directory recursively to another place, preserving the original 
2517 # hierarchical structure
2519 # src: the source directory whose content will be copied.
2520 # dst: the directories where to copy src's content. If not existing, they will be made.
2521 # excludefiles: files which must not be copied. Path must be relative to src.
2523 %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles=
2525 .PHONY : %(mmake)
2528 %(mmake) :
2529         @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e %(excludefiles)
2531 %end
2532 #------------------------------------------------------------------------------
2535 #------------------------------------------------------------------------------
2536 #   Copy include files into the includes directories. There are currently
2537 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
2538 #   for building tools that need to run on the host system $(GENINCDIR). The
2539 #   $(GENINCDIR) path must not contain any references to the C runtime
2540 #   library header files.
2542 %define copy_includes mmake=includes-copy includes=$(INCLUDE_FILES) path=. \
2543     dir= compiler=target includedir=$(AROS_INCLUDES)
2545 ifeq ($(findstring %(compiler),host kernel target),)
2546 $(error %copy_includes: compiler argument (%(compiler)) has to be host, kernel or target)
2547 endif
2549 ifneq (%(dir),)
2550 TMP_DIR := %(dir)
2551 $(eval TMP_DIRREMAIN := $$$(TMP_DIR))
2552 TMP_DIRFIRST := $(subst $(TMP_DIRREMAIN),,$(TMP_DIR))
2553 BD_INCL_FILES := $(subst %(dir),$(GENINCDIR)/%(path),$(dir %(includes)))
2554 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,$(notdir %(includes)))
2555 ifeq ($(TMP_DIRFIRST),/)
2556 BD_INC_PATH := %(dir)/
2557 else
2558 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/%(dir)/
2559 endif
2560 else
2561 BD_INCL_FILES := $(addprefix $(GENINCDIR)/%(path)/,%(includes))
2562 BD_INC_PATH := $(SRCDIR)/$(CURDIR)/
2563 endif
2565 $(BD_INCL_FILES) : $(GENINCDIR)/%(path)/% : $(BD_INC_PATH)%
2566         @$(CP) $< $@
2569 ifeq (%(compiler),target)
2571 ifneq (%(dir),)
2572 BD_INCL_FILES2 := $(subst %(dir),%(includedir)/%(path),$(dir %(includes)))
2573 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,$(notdir %(includes)))
2574 else
2575 BD_INCL_FILES2 := $(addprefix %(includedir)/%(path)/,%(includes))
2576 endif
2578 BD_INCL_FILES += $(BD_INCL_FILES2)
2580 $(BD_INCL_FILES2) : %(includedir)/%(path)/% : $(BD_INC_PATH)%
2581         @$(CP) $< $@
2582 endif
2585 %(mmake) : $(BD_INCL_FILES)
2587 .PHONY: %(mmake)
2589 $(BD_INCL_FILES) : | $(dir $(BD_INCL_FILES))
2590 GLOB_MKDIRS += $(dir $(BD_INCL_FILES))
2591 %end
2592 #------------------------------------------------------------------------------
2595 #------------------------------------------------------------------------------
2596 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
2597 STUBS_SRC := $(addprefix $(SRCDIR)/$(CURDIR)/,$(addsuffix .c,$(STUBS)))
2598 STUBS_MEM := $(addsuffix .o,$(STUBS))
2599 STUBS_OBJ := $(addprefix $(OBJDIR)/,$(STUBS_MEM))
2600 STUBS_DEP := $(addprefix $(OBJDIR)/,$(addsuffix .d,$(STUBS)))
2601 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
2603 #MM- linklibs : hidd-%(hidd)-stubs
2604 #MM- %(parenttarget): hidd-%(hidd)-stubs
2605 #MM hidd-%(hidd)-stubs : includes includes-copy
2606 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
2608 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
2609         %mklib_q from=$^
2611 $(STUBS_OBJ) : $(STUBS_SRC) 
2612         %compile_q cmd="$(TARGET_CC) $(TARGET_SYSROOT) $(TARGET_CFLAGS)" opt="%(cflags)" iquote=$(CFLAGS_IQUOTE) iquote_end=$(CFLAGS_IQUOTE_END)
2614 $(STUBS_DEP) : $(STUBS_SRC)
2615         %mkdepend_q flags="%(dflags)"
2617 setup ::
2618         %mkdirs_q $(OBJDIR) $(AROS_LIB)
2621 clean ::
2622         -@$(RM) $(HIDD_LIB) $(OBJDIR)
2624 DEPS := $(DEPS) $(STUBS_DEP)
2626 %end
2627 #------------------------------------------------------------------------------
2630 #------------------------------------------------------------------------------
2631 # Build an imported source tree which uses the configure script from the
2632 # autoconf package.  This rule will try to "integrate" the produced files as
2633 # much as possible in the AROS build, for example by putting libraries in the
2634 # standard library directory, includes in the standard include directory, and
2635 # so on. You can however override this behaviour.
2637 # As a special "bonus" for you, the PROGDIR environment variable is defined to
2638 # be %(bindir) (or its deduced value) when running "make install", and
2639 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
2640 # configure script some more parameters whose value depends upon the PROGDIR
2641 # env var, so that the program gets all its stuff installed in the proper place
2642 # when building it, but when running it from inside AROS it can also find that
2643 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
2644 # the configuration parameters set when running ./configure
2646 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
2647 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
2648 # to the name which has to follow it.
2650 # Arguments:
2652 #     - mmake           = the meta make target.
2653 #     - package         = name of the package to be built.
2654 #     - srcdir          = the location of the unpacked source code. Defaults
2655 #                         to $(SRCDIR)/$(CURDIR).
2656 #     - prefix          = the target directory. Must be an absolute path of the
2657 #                         host system. Defaults to $(AROS_CONTRIB).
2658 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2659 #                         Defaults to the value of the prefix option.
2660 #     - extraoptions    = additional options for the configure script.
2661 #     - extracflags     = additional flags to use with the C compiler.
2662 #     - extracxxflags   = additional flags to use with the C++ compiler.
2663 #     - nix_dir_layout  = if yes the binary will be stored in a bin subdirectory.
2664 #                         Defaults to the value of the nix argument.
2665 #     - nix             = enable u*nix path handling, i.e. a path like
2666 #                         /progdir//./file will be translated to
2667 #                         progdir:file during run-time. Defaults to no.
2668 #     - compiler        = target, host or kernel. Defaults to target.
2669 #     - install_target  = the command used for installing. Defaults to install. Leave
2670 #                         it empty if you want to suppress installing.
2671 #     - preconfigure    = a metatarget which is executed before configure is called.
2672 #     - postconfigure   = a metatarget which is executed after configure is called.
2673 #     - postinstall     = a metatarget which is executed after installing.
2674 #     - install_env     = set additional options for installing.
2675 #     - use_build_env   = if yes the configuration environment is used for
2676 #                         installing, too. Defaults to no.
2678 # The arguments aros_prefix, nix and nix_dir_layout are related. The logic is
2679 # like this:
2681 # if nix_dir_layout
2682 #    --prefix = $(aros_prefix)
2683 #    progdir = $(aros_prefix)/bin
2684 # else
2685 #    if nix
2686 #        --prefix = /PROGDIR
2687 #        --bindir = /PROGDIR
2688 #        --sbindir = /PROGDIR
2689 #        --libdir = /LIB
2690 #        --includedir = /INCLUDE
2691 #        --oldincludedir = /INCLUDE   
2692 #    else
2693 #        --prefix = $(aros_prefix)
2694 #    endif
2696 #    progdir = $(aros_prefix)
2698 #    # Install options
2699 #    bindir = $(prefix)
2700 #    sbindir = $(prefix)
2701 #    libdir = $(AROS_LIB)
2702 #    includedir = $(AROS_INCLUDES)
2703 #    oldincludedir = $(AROS_INCLUDES)
2704 # endif
2707 %define build_with_configure mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2708     aros_prefix= extraoptions= extracflags= extracxxflags= nix_dir_layout= nix=no compiler=target \
2709     install_target=install preconfigure= postconfigure= postinstall= \
2710     config_env_extra= install_env= use_build_env=no
2712 ifneq (%(prefix),)
2713     %(mmake)-prefix := %(prefix)
2714 else
2715     %(mmake)-prefix := $(AROS_CONTRIB)
2716 endif
2718 ifneq (%(aros_prefix),)
2719     %(mmake)-aros_prefix := %(aros_prefix)
2720 else
2721     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2722 endif
2724 BD_NIXFLAG ?= -nix
2726 ifeq (%(nix),yes)
2727     %(mmake)-nix    := $(BD_NIXFLAG)
2728     %(mmake)-volpfx := /
2729     %(mmake)-volsfx := /
2730     
2731     ifeq (%(nix_dir_layout),)
2732         %(mmake)-nix_dir_layout := yes
2733     endif
2734 else
2735     %(mmake)-volsfx := :
2736     
2737     ifeq (%(nix_dir_layout),)
2738         %(mmake)-nix_dir_layout := no
2739     endif
2740 endif
2742 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
2744 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) \
2745         exec_prefix=$(%(mmake)-prefix) %(install_env)
2747 # Check if chosen compiler is valid
2748 ifeq ($(findstring %(compiler),host target kernel),)
2749   $(error unknown compiler %(compiler))
2750 endif
2752 # Set legacy 'host' variable based on chosen compiler
2753 ifeq (%(compiler),host)
2754     host := yes
2755     ifeq (%(package),)
2756         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
2757     else
2758         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
2759     endif
2760 else
2761     host := no
2762     ifeq (%(package),)
2763         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
2764     else
2765         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
2766     endif
2767 endif
2768 ifneq (%(gendir),)
2769     ifeq (%(package),)
2770         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
2771     else
2772         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
2773     endif
2774 endif
2776 %(mmake)-configflag := $(%(mmake)-pkgdir)/.configured
2777 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
2779 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) $(host)),yes)
2780     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
2781     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2782 else
2783     ifeq (%(nix),yes)
2784         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
2785         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
2786     else
2787         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
2788     endif
2790     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
2791     
2792     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) \
2793         sbindir=$(%(mmake)-prefix) \
2794         libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) \
2795         oldincludedir=$(AROS_INCLUDES) %(install_env)
2796 endif
2798 ifneq ($(DEBUG),yes)
2799     %(mmake)-s_flag = -s
2800 endif
2802 # Set up build environment, and options for configure script
2803 ifeq (%(compiler),host)
2804     # NB: We need to pass in our crosstoolsdir, but cannot set CLFAGS since it
2805     # confused configure scripts. We also cannot pass it via _FOR_BUILD
2806     # since that wont get picked up during configure.
2807     # We also cannot pass in the compiler including std flags so we need to use
2808     # the "plain" host compiler.
2809     CONFIG_ENV := %(config_env_extra) \
2810         CPP="$(HOST_CPP)" \
2811         CXXCPP="$(HOST_CPP)" \
2812         CC="$(HOST_DEF_CC) $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include" \
2813         CXX="$(HOST_CXX) $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include" \
2814         LDFLAGS="-L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)" \
2815         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2816         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2817         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2818         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2819         TARGET_AS="$(TARGET_AS)" \
2820         OBJCOPY="$(OBJCOPY)" \
2821         TARGET_RANLIB="$(RANLIB)" \
2822         TARGET_STRIP="$(STRIP_PLAIN)" \
2823         TARGET_NM="$(NM_PLAIN)" \
2824         TARGET_OBJCOPY="$(TARGET_OBJCOPY)"
2825 endif
2826 ifeq (%(compiler),target)
2827     CONFIG_ENV := %(config_env_extra) \
2828         PKG_CONFIG_LIBDIR="$(AROS_DEVELOPMENT)/lib/pkgconfig" \
2829         PKG_CONFIG_SYSROOT_DIR="$(AROSDIR)" \
2830         CPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2831         CXXCPP="$(TARGET_CPP) $(TARGET_SYSROOT)" \
2832         CC="$(TARGET_CC) $(TARGET_SYSROOT)" \
2833         CFLAGS=" $(TARGET_CFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2834         CXX="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2835         CXXFLAGS=" $(TARGET_CXXFLAGS) $(DEBUG_CFLAGS) $(OPTIMIZATION_CFLAGS) %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2836         LDFLAGS="-L$(AROS_DEVELOPMENT)/lib $(USER_LDFLAGS)" \
2837         AS="$(TARGET_AS)" \
2838         CC_FOR_BUILD="$(HOST_DEF_CC)" \
2839         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2840         CXX_FOR_BUILD="$(HOST_CXX)" \
2841         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2842         RANLIB="$(RANLIB)" \
2843         AR="$(AR_PLAIN)" \
2844         STRIP="$(STRIP_PLAIN)" \
2845         TARGET_CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2846         TARGET_CFLAGS="$(KERNEL_CFLAGS) $(%(mmake)-s_flag)" \
2847         TARGET_CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2848         TARGET_CXXFLAGS="$(KERNEL_CXXFLAGS) $(%(mmake)-s_flag)" \
2849         TARGET_AS="$(TARGET_AS)" \
2850         OBJCOPY="$(OBJCOPY)" \
2851         TARGET_RANLIB="$(RANLIB)" \
2852         TARGET_STRIP="$(STRIP_PLAIN)" \
2853         TARGET_NM="$(NM_PLAIN)" \
2854         CC_FOR_TARGET="$(TARGET_CC) $(TARGET_SYSROOT)" \
2855         CFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)" \
2856         CXX_FOR_TARGET="$(TARGET_CXX) $(TARGET_SYSROOT)" \
2857         CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS) -L$(AROS_DEVELOPMENT)/lib %(extracxxflags) $(ISA_FLAGS) $(%(mmake)-nix) $(%(mmake)-s_flag)"
2858     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2859         --host=$(AROS_TARGET_CPU)-aros\
2860         --target=$(AROS_TARGET_CPU)-aros\
2861         --disable-nls\
2862         --without-x --without-pic --disable-shared
2863 endif
2864 ifeq (%(compiler),kernel)
2865     CONFIG_ENV := %(config_env_extra) \
2866         CPP="$(KERNEL_CPP)" \
2867         CXXCPP="$(KERNEL_CPP)" \
2868         CC="$(KERNEL_CC) $(KERNEL_SYSROOT)" \
2869         CFLAGS="$(KERNEL_CFLAGS) %(extracflags) $(%(mmake)-s_flag)" \
2870         CXX="$(KERNEL_CXX) $(KERNEL_SYSROOT)" \
2871         CXXFLAGS="$(KERNEL_CXXFLAGS) %(extracxxflags) $(%(mmake)-s_flag)" \
2872         AS="$(KERNEL_AS)" \
2873         CC_FOR_BUILD="$(HOST_DEF_CC)" \
2874         CFLAGS_FOR_BUILD="$(HOST_CFLAGS)" \
2875         CXX_FOR_BUILD="$(HOST_CXX)" \
2876         CXXFLAGS_FOR_BUILD="$(HOST_CXXFLAGS)" \
2877         RANLIB="$(RANLIB)" \
2878         TARGET_RANLIB="$(RANLIB)" \
2879         TARGET_STRIP="$(STRIP_PLAIN)" \
2880         TARGET_NM="$(NM_PLAIN)"
2881     %(mmake)-config_opts += --build=$(AROS_HOST_CPU)-$(AROS_HOST_ARCH)\
2882         --host=$(AROS_TARGET_CPU)-aros\
2883         --target=$(AROS_TARGET_CPU)-aros --disable-nls\
2884         --without-x --without-pic --disable-shared
2885 endif
2887 ifeq (%(use_build_env),yes)
2888     BUILD_ENV := $(CONFIG_ENV)
2889 endif
2891 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
2893 # When building for the host, we don't need to build the
2894 # linklibs - this is especially true when building the
2895 # crosstool toolchain on 'foreign' architectures (such as
2896 # building PPC on x86)
2898 #MM- %(mmake)-host : setup includes %(mmake)-quick
2899 #MM- %(mmake)-target : setup includes core-linklibs %(mmake)-quick
2900 #MM- %(mmake): %(mmake)-%(compiler)
2902 # Using -j1 in install_command may result in a warning but finally
2903 # it does its job. make install for gcc does not work reliably for -jN
2904 # where N > 1.
2905 ifneq (%(install_target),)
2906     %(mmake)-install_command = \
2907         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
2908         -C $(%(mmake)-pkgdir) %(install_target) -j1
2910     %(mmake)-uninstall_command = \
2911     $(RM) $(%(mmake)-installflag) && \
2912     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" \
2913     $(%(mmake)-install_opts) -C $(%(mmake)-pkgdir) uninstall
2914 else
2915     %(mmake)-install_command   := true
2916     %(mmake)-uninstall_command := true
2917 endif
2919 #MM- %(mmake)-quick : %(preconfigure) %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
2922 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
2924 $(%(mmake)-installflag) : $(%(mmake)-configflag)
2925         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(%(mmake)-pkgdir); then \
2926             $(RM)  $(%(mmake)-installflag) && \
2927             $(BUILD_ENV) $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)"\
2928              -C $(%(mmake)-pkgdir) && \
2929             $(%(mmake)-install_command) && \
2930             $(TOUCH) $@ -r $^; \
2931         fi
2933 $(%(mmake)-pkgdir)/.files-touched:
2934         %mkdirs_q $(%(mmake)-pkgdir)
2935         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/configure '{}' \; && \
2936         $(TOUCH) $@
2939 %(mmake)-uninstall :
2940         $(%(mmake)-uninstall_command)
2943 %(mmake)-configure : $(%(mmake)-configflag)
2945 $(%(mmake)-configflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
2946 $(%(mmake)-configflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
2947         $(RM) $@
2948         %mkdirs_q $(%(mmake)-pkgdir)
2949         cd $(%(mmake)-pkgdir) && \
2950         find . -name config.cache -exec $(RM) '{}' \; && \
2951         $(CONFIG_ENV) $(TMP_SRCDIR)/configure $(%(mmake)-config_opts) \
2952             %(extraoptions) && \
2953         $(TOUCH) $@
2956 %(mmake)-clean : %(mmake)-uninstall
2957         @$(RM) $(%(mmake)-pkgdir)
2958 %end
2959 #------------------------------------------------------------------------------
2962 #------------------------------------------------------------------------------
2963 # Build an imported source tree which uses cmake 
2965 # Arguments:
2967 #     - mmake           = the meta make target.
2968 #     - package         = name of the package to be built.
2969 #     - srcdir          = the location of the unpacked source code. Defaults
2970 #                         to $(SRCDIR)/$(CURDIR).
2971 #     - prefix          = the target directory. Must be an absolute path of the
2972 #                         host system. Defaults to $(AROS_CONTRIB).
2973 #     - aros_prefix     = set a path which is valid within the AROS filesystem.
2974 #                         Defaults to the value of the prefix option.
2975 #     - extraoptions    = additional options for the cmake script.
2976 #     - installoptions    = additional options for the install step.
2979 %define build_with_cmake mmake=/A package= srcdir=$(SRCDIR)/$(CURDIR) gendir= prefix= \
2980     aros_prefix= extraoptions= installoptions= maketarget= compiler=target \
2981     cflags=$(CFLAGS) cxxflags=$(CXXFLAGS) ldflags=$(LDFLAGS)
2983 ifneq (%(prefix),)
2984     %(mmake)-prefix := %(prefix)
2985 else
2986     %(mmake)-prefix := $(AROS_CONTRIB)
2987 endif
2989 ifneq (%(aros_prefix),)
2990     %(mmake)-aros_prefix := %(aros_prefix)
2991 else
2992     %(mmake)-aros_prefix := $(%(mmake)-prefix)
2993 endif
2995 ifeq (%(compiler),host)
2996     BD_LDFLAGS   := -L$(CROSSTOOLSDIR)/lib $(USER_LDFLAGS)
2997     BD_CFLAGS := $(HOST_CFLAGS) -I$(CROSSTOOLSDIR)/include
2998     BD_CXXFLAGS := $(HOST_CXXFLAGS) -I$(CROSSTOOLSDIR)/include
2999     %(mmake)-cmake_opts  := -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$(HOST_DEF_CC)" -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_COMPILER="$(HOST_CXX)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)"
3000     ifeq (%(package),)
3001         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)
3002     else
3003         %(mmake)-pkgdir := $(HOSTGENDIR)/$(CURDIR)/%(package)
3004     endif
3005 else
3006     BD_LDFLAGS   := %(ldflags)
3007     BD_CFLAGS := %(cflags)
3008     BD_CXXFLAGS := %(cxxflags)
3009     %(mmake)-cmake_opts  := -DCMAKE_TOOLCHAIN_FILE=$(GENDIR)/config/conf.cmake -DCMAKE_INSTALL_PREFIX=$(%(mmake)-prefix) -DCMAKE_C_FLAGS="$(BD_CFLAGS)" -DCMAKE_CXX_FLAGS="$(BD_CXXFLAGS)" -DCMAKE_EXE_LINKER_FLAGS="$(BD_LDFLAGS)"
3010     ifeq (%(package),)
3011         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)
3012     else
3013         %(mmake)-pkgdir := $(GENDIR)/$(CURDIR)/%(package)
3014     endif
3015 endif
3016 ifneq (%(gendir),)
3017     ifeq (%(package),)
3018         %(mmake)-pkgdir := %(gendir)/$(CURDIR)
3019     else
3020         %(mmake)-pkgdir := %(gendir)/$(CURDIR)/%(package)
3021     endif
3022 endif
3024 %(mmake)-cmakeflag := $(%(mmake)-pkgdir)/.cmake
3025 %(mmake)-installflag := $(%(mmake)-pkgdir)/.installed
3027 .PHONY : %(mmake) %(mmake)-clean %(mmake)-build_and_install-quick
3029 #MM- %(mmake): setup includes core-linklibs %(mmake)-quick
3031 #MM- %(mmake)-quick : %(mmake)-cmake %(mmake)-build_and_install-quick
3034 %(mmake)-build_and_install-quick :  $(%(mmake)-installflag)
3036 $(%(mmake)-installflag) : $(%(mmake)-cmakeflag)
3037         if ! $(MAKE) -q -C $(%(mmake)-pkgdir); then \
3038             $(RM)  $(%(mmake)-installflag) && \
3039             $(MAKE) -C $(%(mmake)-pkgdir) %(maketarget) && \
3040             cd $(%(mmake)-pkgdir) && \
3041             cmake %(installoptions) -P cmake_install.cmake && \
3042             $(TOUCH) $@ -r $^; \
3043         fi
3045 $(%(mmake)-pkgdir)/.files-touched:
3046         %mkdirs_q $(%(mmake)-pkgdir)
3047         find %(srcdir) -exec $(TOUCH) -c -r %(srcdir)/CMakeLists.txt '{}' \; && \
3048         $(TOUCH) $@
3051 %(mmake)-cmake : $(%(mmake)-cmakeflag)
3053 $(%(mmake)-cmakeflag) : TMP_SRCDIR := $(shell echo %(srcdir) | sed 's/^\(.\):\//\/\1\//')
3054 $(%(mmake)-cmakeflag) : $(%(mmake)-pkgdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
3055         $(RM) $@
3056         %mkdirs_q $(%(mmake)-pkgdir)
3057         cd $(%(mmake)-pkgdir) && \
3058         $(RM) -Rf CMakeCache.txt CMakeFiles \; && \
3059         cmake $(%(mmake)-cmake_opts) %(extraoptions) $(TMP_SRCDIR) && \
3060         $(TOUCH) $@
3063 %(mmake)-clean : %(mmake)-uninstall
3064         @$(RM) $(%(mmake)-pkgdir)
3065 %end
3066 #------------------------------------------------------------------------------
3069 #------------------------------------------------------------------------------
3070 # Given an archive name, patches names and locations where to find them, fetch
3071 # the archive and the patches from any of those locations, unpack the archive
3072 # and then apply the patches.
3074 # Locations currently supported are http and ftp sites, plus local filesystem
3075 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
3076 # the fetch.sh script needs to be modified, since this macro relies on that script.
3078 # Arguments:
3080 #     - mmake           = mmaketarget
3081 #     - archive_origins = list of locations where to find the archive. They are tried
3082 #                         in sequence, until the archive is found and fetching it 
3083 #                         succeeded. If not specified, the current directory is assumed.
3084 #     - archive         = the archive name. Mandatory.
3085 #     - suffixes        = a list of suffixes to append to the the package name plus the
3086 #                         version. Each one of them is tried until a matching archive is
3087 #                         found. They are appended to patches and these are tried the
3088 #                         same way as packages are.
3089 #     - location        = the local directory where to put the fetched archive and patches.
3090 #                         If not specified, the directory specified by destination is used.
3091 #     - destination     = the directory to unpack the archive to.
3092 #                         If not specified, the current directory is assumed.
3093 #     - patches_origins = list of locations where to find the patches. They are tried
3094 #                         in sequence, until a patch is found and fetching it 
3095 #                         succeeded. If not specified, the current directory is assumed.
3096 #     - patches_specs   = list of "patch specs". A patch spec is of the form
3097 #                         patch_name[:[patch_subdir][:patch_opt]].
3099 #                             - patch_name   = the name of the patch file
3100 #                             - patch_subdir = the directory within \destination\ where to
3101 #                                              apply the patch.
3102 #                             - patch_opt    = any options to pass to the `patch' command
3103 #                                              when applying the patch.
3104 #                         
3105 #                         The patch_subdir and patch_opt fields are optional.
3107 %define fetch mmake=/A archive_origins=. archive=/A suffixes= location= destination=. \
3108     patches_origins=$(SRCDIR)/$(CURDIR) patches_specs=::
3110 .PHONY: %(mmake)
3112 ifneq (%(location),)
3113     %(mmake)-location := %(location)
3114 else
3115     %(mmake)-location := %(destination)
3116 endif
3119 %(mmake) :
3120         $(FETCH) -ao "%(archive_origins)" -a %(archive) -s "%(suffixes)" -l $(%(mmake)-location) \
3121         -d %(destination) -po "%(patches_origins)" -p "%(patches_specs)"
3122 %end
3123 #------------------------------------------------------------------------------
3126 #------------------------------------------------------------------------------
3127 # This macro can aid in patch creation for fetched ports. It temporarily creates another
3128 # unpatched source tree and runs diff against this and a previously fetched and possibly
3129 # patched tree. Depending on what happens after patching during a normal build it might
3130 # give best results if the new patch is created directly after fetch.
3132 # Arguments:
3134 #     - mmake       = mmaketarget
3135 #     - archive     = archive base name
3136 #     - srcdir      = the top level directory the package is unpacked to, useful if
3137 #                     an archive unpacks to a directory other than its name suggests.
3138 #                     this should not be deeper than a single path element.
3139 #     - suffixes    = a list of suffixes to append to the the package name plus the
3140 #                     version. Each one of them is tried until a matching archive is
3141 #                     found.
3142 #     - destination = the directory to unpack the archive to.
3143 #     - excludes    = diff patterns to exclude files or directories from the patch
3145 %define create_patch mmake=/A archive=/A srcdir= suffixes="tar.bz2 tar.gz" destination=/A excludes=
3147 .PHONY: %(mmake)
3149 ifneq (%(excludes),)
3150     %(mmake)-exclude := -X ./exclude.patterns
3151 endif
3153 ifneq (%(srcdir),)
3154     %(mmake)-srcdir := %(srcdir)
3155 else
3156     %(mmake)-srcdir := %(archive)
3157 endif
3159 #MM- %(mmake) : %(mmake)-diff
3160 #MM- %(mmake)-quick : %(mmake)-diff
3163 %(mmake)-diff:
3164         @$(FETCH) -a %(archive) -s "%(suffixes)" -l $(PORTSSOURCEDIR) -d %(destination)/tmp ; \
3165         $(MV) %(destination)/$(%(mmake)-srcdir) %(destination)/tmp/$(%(mmake)-srcdir).aros ; \
3166         cd %(destination)/tmp ; \
3167         $(FOR) f in %(excludes) ; do \
3168             $(ECHO) $$f >> ./exclude.patterns ; \
3169         done ; \
3170         diff -ruN $(%(mmake)-exclude) \
3171             $(%(mmake)-srcdir) \
3172             $(%(mmake)-srcdir).aros \
3173             >$(SRCDIR)/$(CURDIR)/%(archive)-aros-new.diff ; \
3174         $(MV) %(destination)/tmp/$(%(mmake)-srcdir).aros %(destination)/$(%(mmake)-srcdir) ; \
3175         $(RM) %(destination)/tmp
3176 %end
3177 #------------------------------------------------------------------------------
3180 #------------------------------------------------------------------------------
3181 # Joins the features of %fetch and %build_with_configure.
3183 # If a patch is provided, it *must* be named the following way:
3185 #    <package name>-<version number>-aros.diff
3187 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3188 # CD'ing into the archive's extracted directory.
3190 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3191 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3192 # to make that patch fully comprehensive.
3194 # Arguments:
3196 #    - mmake            = the meta make target.
3197 #    - package          = the GNU package name, sans version and archive format suffixes.
3198 #    - subpackage       = ???
3199 #    - compiler         = same meaning as the one for the %build_with_configure macro.
3200 #    - install_target   = same meaning as the one for the %build_with_configure macro.
3201 #    - version          = the package's version number, or otherwise any other version string.
3202 #                         It gets appended to the package name to form the basename of the archive.
3203 #    - suffixes         = a list of suffixes to apped to the the package name plus the
3204 #                         version. Each one of them is tried until a matching archive is found.
3205 #                         Defaults to "tar.bz2 tar.gz".
3206 #    - srcdir           = the top level directory the package is unpacked to (see create_patch).
3207 #    - builddir         = override the location we expect to run configure/make in.
3208 #    - package_repo     = same meaning as the one of the %fetch macro's %(archive_origins) argument
3209 #    - patch            = "yes" or "no", depending on whether a patch for this package needs to be
3210 #                         fetched or not. Default to no.
3211 #    - patch_repo       = same meaning as the one of the %fetch macro's %(patches_origins) argument
3212 #    - prefix           = same meaning as the one for the %build_with_configure macro.
3213 #    - aros_prefix      = same meaning as the one for the %build_with_configure macro.
3214 #    - extraoptions     = same meaning as the one for the %build_with_configure macro.
3215 #    - extracflags      = same meaning as the one for the %build_with_configure macro.
3216 #    - extracxxflags    = same meaning as the one for the %build_with_configure macro.
3217 #    - preconfigure     = same meaning as the one for the %build_with_configure macro.
3218 #    - postconfigure    = same meaning as the one for the %build_with_configure macro.
3219 #    - postinstall      = same meaning as the one for the %build_with_configure macro.
3220 #    - install_env      = same meaning as the one for the %build_with_configure macro.
3221 #    - use_build_env    = same meaning as the one for the %build_with_configure macro.
3222 #    - nix              = same meaning as the one for the %build_with_configure macro.
3223 #    - nix_dir_layout   = same meaning as the one for the %build_with_configure macro.
3224 #    - create_pkg       = create a distributable package of the compiled sources, defaults to no
3226 %define fetch_and_build mmake=/A package=/A subpackage= compiler=target install_target=install \
3227     version=/A suffixes="tar.bz2 tar.gz" srcdir= builddir= gendir= package_repo= patch=no patch_repo= \
3228     prefix= aros_prefix= extraoptions= extracflags= extracxxflags= preconfigure= postconfigure= postinstall= \
3229     config_env_extra= install_env= use_build_env=no nix=no nix_dir_layout= create_pkg=no
3231 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
3232 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
3233 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
3234 #MM- %(mmake)-create-patch : %(mmake)-%(subpackage)-create-patch
3236 %(mmake)-archbase  := %(package)-%(version)
3238 ifeq (%(compiler),host)
3239     %(mmake)-portdir  := $(HOSTDIR)/Ports/host/%(package)
3240 else
3241     %(mmake)-portdir  := $(PORTSDIR)/%(package)
3242 endif
3244 ifeq (%(prefix),)
3245     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
3246 else
3247     %(mmake)-prefix := %(prefix)
3248 endif
3250 ifneq (%(subpackage),)
3251     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
3252 else
3253     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
3254 endif
3256 ifneq (%(srcdir),)
3257     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
3258 else
3259     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
3260 endif
3262 ifneq (%(builddir),)
3263     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)/%(builddir)
3264 else
3265     %(mmake)-%(subpackage)-builddir  := $(%(mmake)-%(subpackage)-srcdir)
3266 endif
3268 ifeq (%(patch),yes)
3269     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-f,-p1
3270 else
3271     %(mmake)-%(subpackage)-patches_specs := ::
3272 endif
3274 %fetch mmake="%(mmake)-%(subpackage)-fetch" archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
3275     location=$(PORTSSOURCEDIR) destination=$(%(mmake)-portdir) \
3276     archive_origins=". %(package_repo)" \
3277     patches_specs=$(%(mmake)-%(subpackage)-patches_specs) patches_origins="$(SRCDIR)/$(CURDIR) %(patch_repo)"
3279 %create_patch mmake="%(mmake)-%(subpackage)-create-patch" \
3280     archive=$(%(mmake)-%(subpackage)-archbase) \
3281     srcdir=$(%(mmake)-%(subpackage)-srcdir) \
3282     suffixes="%(suffixes)" \
3283     destination=$(%(mmake)-portdir)
3285 #MM- %(mmake) : %(mmake)-%(subpackage)
3287 %(mmake)-%(subpackage)-package-dir := $(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-archbase)
3289 %(mmake)-%(subpackage)-package-basename := \
3290     $(DISTDIR)/Packages/$(%(mmake)-%(subpackage)-archbase)-aros.$(AROS_TARGET_CPU)
3292 ifneq (%(create_pkg),no)
3293     %(mmake)-%(subpackage)-package := $(%(mmake)-%(subpackage)-package-basename).tar.bz2
3294 endif
3296 %build_with_configure mmake="%(mmake)-%(subpackage)" package="%(package)" compiler="%(compiler)" install_target="%(install_target)" \
3297      srcdir=$(%(mmake)-portdir)/$(%(mmake)-%(subpackage)-builddir) gendir="%(gendir)" \
3298      config_env_extra="%(config_env_extra)" install_env="%(install_env)" use_build_env="%(use_build_env)" \
3299      nix="%(nix)" nix_dir_layout="%(nix_dir_layout)" prefix=$(%(mmake)-prefix) \
3300      aros_prefix="%(aros_prefix)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
3301      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3303 .PHONY : %(mmake)-%(subpackage)-make-package %(mmake)-%(subpackage)-create-patch
3304 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
3307 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package)
3309 #There seems to be a bug, either with my clock or with make, 'cause it may happen
3310 #that $^ and $@ have exactly the same mtime, and in that case make tries
3311 #to rebuild $@ again, which would fail because the directory where
3312 #the package got installed would not exist anymore. 
3313 #We work this around by using an if statement to manually check the mtimes.
3314 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
3315         @$(IF) test $(%(mmake)-installflag) -nt $@ || ! test -f $@; then \
3316         $(RM) $@ ; \
3317         $(ECHO) "Building   \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" ; \
3318         mkdir -p "$(DISTDIR)/Packages" ; \
3319         mkdir -p "$(%(mmake)-prefix)" ; \
3320         cd $(%(mmake)-%(subpackage)-package-dir) ; \
3321         tar -cvf $(%(mmake)-%(subpackage)-package-basename).tar * ; \
3322         bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar ; \
3323     fi
3324 %end
3325 #------------------------------------------------------------------------------
3328 #------------------------------------------------------------------------------
3329 # Joins the features of %fetch and %build_with_configure, taking advantage of
3330 # the naming scheme of GNU packages. GNU packages names are in the form
3332 #     <package name>-<version number>.<archive format suffix>
3334 # If a patch is provided, it *must* be named the following way:
3336 #    <package name>-<version number>-aros.diff
3338 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
3339 # CD'ing into the archive's extracted directory.
3341 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
3342 # the %fetch_and_build macro only accepts *one* patch for each package. It's up to you
3343 # to make that patch fully comprehensive.
3345 # NOTE: GNU packages are always compiled with *nix semantics turned on.
3347 # Arguments:
3349 #    Arguments have the same meaning as the one for the %fetch_and_build macro, except:
3351 #    - prefix           = defaults to $(GNUDIR).
3352 #    - aros_prefix      = defaults to /GNU.
3354 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3355     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
3356     aros_prefix=/GNU extraoptions= extracflags= extracxxflags= config_env_extra= preconfigure= postconfigure= postinstall= 
3358 GNU_REPOSITORY := gnu://
3360 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
3361     suffixes="%(suffixes)" srcdir="%(srcdir)" \
3362     package_repo="%(package_repo) $(GNU_REPOSITORY)%(package)" \
3363     patch="%(patch)" patch_repo="%(patch_repo)" \
3364     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)" \
3365     config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
3367 %end
3368 #------------------------------------------------------------------------------
3371 #------------------------------------------------------------------------------
3372 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
3373 # that the package is a "Development" package, and as such it needs to be placed
3374 # under the $(AROS_DEVELOPMENT) directory, as a default. 
3376 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
3377 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
3378 # "mmake" argument, because the metatarget is implicitely defined as
3380 #     #MM- development-%(package)
3382 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
3383     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
3384     aros_prefix=/Development config_env_extra= preconfigure= postconfigure= postinstall=  extraoptions= extracflags= extracxxflags=
3386 #MM- development : development-%(package)
3389 %fetch_and_build_gnu mmake="development-%(package)" package="%(package)" subpackage="%(subpackage)" \
3390    version="%(version)" suffixes="%(suffixes)" srcdir="%(srcdir)"  \
3391    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix="%(prefix)" \
3392    aros_prefix="%(aros_prefix)" config_env_extra="%(config_env_extra)" preconfigure="%(preconfigure)" postconfigure="%(postconfigure)" postinstall="postinstall-%(package)-delete-la-files %(postinstall)" \
3393    extraoptions="%(extraoptions)" extracflags="%(extracflags)" extracxxflags="%(extracxxflags)"
3396 postinstall-%(package)-delete-la-files:
3397         $(RM) $(AROS_DEVELOPMENT)/lib/*.la
3399 %end
3400 #------------------------------------------------------------------------------
3402 # Builds a kickstart package in PKG format
3404 # Arguments:
3406 #    - mmake   = target name
3407 #    - file    = destination file name with path
3409 # Other arguments are self-explanatory
3411 %define make_package mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3412     arch_classes= arch_devs= arch_handlers= arch_hidds= arch_libs= arch_res=
3414 PKG_CLASSES   := $(addprefix $(AROS_CLASSES)/,$(addsuffix .class, %(classes)))
3415 PKG_DEVICES   := $(addprefix $(AROS_DEVS)/,$(addsuffix .device, %(devs)))
3416 PKG_HANDLERS  := $(addprefix $(AROS_FS)/,$(addsuffix -handler, %(handlers)))
3417 PKG_HIDD      := $(addprefix $(AROS_DEVS)/Drivers/,$(addsuffix .hidd, %(hidds)))
3418 PKG_LIBS      := $(addprefix $(AROS_LIBRARIES)/,$(addsuffix .library, %(libs)))
3419 PKG_RESOURCES := $(addprefix $(AROS_DEVS)/,$(addsuffix .resource, %(res)))
3421 PKG_CLASSES_ARCH   := $(addprefix $(AROS_CLASSES_ARCH)/,$(addsuffix .class, %(arch_classes)))
3422 PKG_DEVICES_ARCH   := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .device, %(arch_devs)))
3423 PKG_HANDLERS_ARCH  := $(addprefix $(AROS_FS_ARCH)/,$(addsuffix -handler, %(arch_handlers)))
3424 PKG_HIDD_ARCH      := $(addprefix $(AROS_DEVS_ARCH)/Drivers/,$(addsuffix .hidd, %(arch_hidds)))
3425 PKG_LIBRARIES_ARCH := $(addprefix $(AROS_LIBRARIES_ARCH)/,$(addsuffix .library, %(arch_libs)))
3426 PKG_RESOURCES_ARCH := $(addprefix $(AROS_DEVS_ARCH)/,$(addsuffix .resource, %(arch_res)))
3428 PKG_FILES := $(PKG_CLASSES) $(PKG_DEVICES) $(PKG_HANDLERS) $(PKG_HIDD) $(PKG_LIBS) $(PKG_RESOURCES) \
3429     $(PKG_CLASSES_ARCH) $(PKG_DEVICES_ARCH) $(PKG_HANDLERS_ARCH) $(PKG_HIDD_ARCH) $(PKG_LIBRARIES_ARCH) $(PKG_RESOURCES_ARCH)
3430 PKG_DIR   := $(dir %(file))
3433 %(mmake) : %(file)
3436 %(mmake)-quick : %(file)
3438 %(file): $(PKG_FILES) | $(PKG_DIR)
3439         @$(ECHO) Packaging $@...
3440         @$(SRCDIR)/tools/package/pkg c $@ $^
3442 %compress_file mmake="%(mmake)" file="%(file)"
3444 GLOB_MKDIRS += $(PKG_DIR)
3446 %end
3448 #------------------------------------------------------------------------------
3449 # Compresses %(file) with a gzip.
3450 # Good in conjunction with for example %build_prog
3452 %define compress_file mmake=/A file=/A
3454 #MM- %(mmake)-gz : %(mmake) %(mmake)-gz-quick
3457 %(mmake)-gz-quick : %(file).gz
3459 %(file).gz: %(file)
3460         @$(ECHO) Compressing $(subst $(TARGETDIR)/,,$^)...
3461         @gzip -9 -f $^
3463 %end
3465 #------------------------------------------------------------------------------
3466 # Links a kickstart module in ELF format
3467 # Arguments are similar to make_package
3469 %define link_kickstart mmake=/A file=/A classes= devs= handlers= hidds= libs= res= \
3470     startup= uselibs= ldflags=$(LDFLAGS) map= deps=
3472 KOBJ_CLASSES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _class.o, %(classes)))
3473 KOBJ_DEVICES  := $(addprefix $(KOBJSDIR)/, $(addsuffix _device.o, %(devs)))
3474 KOBJ_HANDLERS := $(addprefix $(KOBJSDIR)/, $(addsuffix _handler.o, %(handlers)))
3475 KOBJ_HIDD     := $(addprefix $(KOBJSDIR)/, $(addsuffix _hidd.o, %(hidds)))
3476 KOBJ_LIBS     := $(addprefix $(KOBJSDIR)/, $(addsuffix _library.o, %(libs)))
3477 KOBJ_RES      := $(addprefix $(KOBJSDIR)/, $(addsuffix _resource.o, %(res)))
3479 ifeq (%(startup),)
3480     KOBJ_STARTUP := $(GENDIR)/$(RESIDENT_BEGIN).o
3481 else
3482     KOBJ_STARTUP := %(startup)
3483 endif
3485 KOBJS        := $(KOBJ_STARTUP) $(KOBJ_CLASSES) $(KOBJ_HANDLERS) $(KOBJ_LIBS) $(KOBJ_DEVICES) $(KOBJ_HIDD) $(KOBJ_RES)
3487 TMP_LDFLAGS := %(ldflags)
3489 # Make a list of the lib files this program depends on.
3490 # In LDFLAGS remove white space between -L and directory
3491 TMP_DIRS := $(subst -L ,-L,$(strip $(TMP_LDFLAGS)))
3492 # Filter out only the libdirs and remove -L
3493 TMP_DIRS := $(patsubst -L%,%,$(filter -L%,$(TMP_DIRS)))
3494 # Add trailing /
3495 TMP_DIRS := $(subst //,/,$(addsuffix /,$(TMP_DIRS)))
3496 # Add normal linklib path
3497 TMP_DIRS += $(AROS_LIB)/
3498 # add lib and .a to static linklib names
3499 TMP_LIBS := $(addprefix lib,$(addsuffix .a,%(uselibs)))
3500 # search for the linklibs in the given path, ignore ones not found
3501 TMP_DEPLIBS := $(foreach lib,$(TMP_LIBS), \
3502     $(firstword $(wildcard $(addsuffix $(lib),$(TMP_DIRS)))) \
3505 TMP_DIRS += $(dir %(file))
3506 ifneq (%(map),)
3507     TMP_LDFLAGS += $(GENMAP) %(map)
3508     TMP_DIRS    += $(dir %(map))
3509 endif
3511 #MM %(mmake) : %(deps)
3514 %(mmake) : %(file)
3517 %(mmake)-quick : %(file)
3519 %(file): KOBJS := $(KOBJS)
3520 %(file): LDFLAGS := $(TMP_LDFLAGS) $(NOSTARTUP_LDFLAGS) \
3521                     -static -nosysbase -Wl,-Ur
3522 %(file): LDLIBS := $(addprefix -l, %(uselibs))
3523 %(file): $(KOBJS) $(DEPLIBS) | $(TMP_DIRS)
3524         @$(ECHO) "Kickstart  $(subst $(TARGETDIR)/,,$@)..."
3525         @$(TARGET_CC) $(TARGET_SYSROOT) -o $@ $(KOBJS) $(LDFLAGS) $(LDLIBS)
3526         @$(STRIP) $@
3528 %compress_file mmake="%(mmake)" file="%(file)"
3530 GLOB_MKDIRS += $(TMP_DIRS)
3532 %end