Do not generate include files for gadgets and datatypes. This is to avoid
[AROS.git] / config / make.tmpl
blob02380c12a57ecc4f0b2fbb6f8ad90efbb638916a
1 #############################################################################
2 #############################################################################
3 ##                                                                         ##
4 ## Here are the mmakefile macro's that are used as commands in the body    ##
5 ## of a make rule.                                                         ##
6 ## They are used to help the portability of mmakefile to different         ##
7 ## platforms and also will handle the error handling in a standard way.    ##
8 ##                                                                         ##
9 #############################################################################
10 #############################################################################
12 #------------------------------------------------------------------------------
13 # Compile the file %(from) to %(to) with %(cmd). Write any errors to %(err)
14 # and use the options in %(opt).
15 %define compile_q cmd=$(TARGET_CC) opt=$(CFLAGS) from=$< to=$@
16         @$(ECHO) "Compiling $(notdir %(from))"
17         @$(IF) %(cmd) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
18             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
19                 $(ECHO) "%(from): %(cmd) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
20                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
21             else \
22                 $(NOP) ; \
23             fi ; \
24         else \
25             $(ECHO) "Compile failed: %(cmd) %(opt) -c %(from) -o %(to)" 1>&2 ; \
26             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
27             exit 1 ; \
28         fi
29 %end
30 #------------------------------------------------------------------------------
33 #------------------------------------------------------------------------------
34 # Assemble the file %(from) to %(to) with %(cmd) with the options in %(opt).
35 %define assemble_q cmd=$(AS) opt=$(AFLAGS) from=$< to=$@
36         @$(ECHO) "Assembling $(notdir %(from))..."
37         @$(IF) %(cmd) %(opt) -c %(from) -o %(to) > $(GENDIR)/cerrors 2>&1 ; then \
38             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
39                 $(ECHO) "$(notdir %(from)): %(cmd) %(opt) -c %(from) -o %(to)" >> $(GENDIR)/errors ; \
40                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
41             else \
42                 $(NOP) ; \
43             fi ; \
44         else \
45             $(ECHO) "Assemble failed: %(cmd) %(opt) -c %(from) -o %(to)" 1>&2 ; \
46             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
47             exit 1 ; \
48         fi
49 %end
50 #-------------------------------------------------------------------------
53 #------------------------------------------------------------------------------
54 # Link a specified number of objects to an executable
55 %define link_q cmd=$(AROS_CC) opt=$(LDFLAGS) from=$< to=$@ libs=$(LIBS)
56         @$(ECHO) "Linking %(to)..."
57         @$(IF) %(cmd) %(opt) %(from) -o %(to) %(libs) 2>&1 > $(GENDIR)/cerrors 2>&1 ; then \
58                 $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
59                                 $(ECHO) "%(to): %(cmd) %(opt) %(from) -o %(to) %(libs)" >> $(GENDIR)/errors ; \
60                                 $(CAT) $(GENDIR)/cerrors >> $(GENDIR)/errors ; \
61                 else \
62                         $(NOP) ; \
63                 fi ; \
64         else \
65             $(ECHO) "Link failed: %(cmd) %(opt) %(from) -o %(to) %(libs)" 1>&2 ; \
66             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
67             exit 1 ; \
68         fi; \
69         $(STRIP) %(to)
70 %end
72 #-------------------------------------------------------------------------
73 # Link a module based upon a number of arguments and the standard $(LIBS)
74 # and $(DEPLIBS) make variables.
76 %define link_module_q err="$(notdir $@).err" objs=/A endtag= module=$(MODULE) ldflags=$(LDFLAGS) libs=$(LIBS) objdir=$(OBJDIR)
77         @$(ECHO) "Building $(notdir $@) ..."
78         @if $(AROS_CC) $(NOSTARTUP_LDFLAGS) %(ldflags) \
79             $(GENMAP) %(objdir)/%(module).map \
80             %(objs) %(libs) %(endtag) \
81             -o $@ 2>&1 > %(objdir)/%(err); \
82         then \
83             cat %(objdir)/%(err); \
84         else \
85             cat %(objdir)/%(err); \
86             exit 1; \
87         fi
89         @if $(TEST) ! -s %(objdir)/%(err) ; then $(RM) %(objdir)/%(err) ; fi
90         @$(STRIP) $@
91 %end
92 #------------------------------------------------------------------------------
94 #------------------------------------------------------------------------------
95 # Create the library
96 %define mklib_q ar=$(AR) ranlib=$(RANLIB) to=$@ from=$(OBJS)
97         @$(ECHO) "Creating library %(to)..."
98         @%(ar) %(to) %(from)
99         @%(ranlib) %(to)
100 %end
102 #------------------------------------------------------------------------------
103 # Create the dependency file %(to) for %(from)
104 %define mkdepend_q flags=$(CFLAGS) from=$< to=$@ cc=$(AROS_CC)
105         %mkdir_q dir="$(dir %(to))"
106         @$(ECHO) "Makedepend $(CURDIR)/$(notdir %(from))..."
107         @AROS_CC="%(cc)" $(MKDEPEND) %(flags) %(from) -o %(to)
108 %end
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 # Create the function reference file %(to) to %(from)
113 %define mkref_q cc=$(AROS_CC) cppflags="-E -C -dD -D__CXREF__" cflags=$(CFLAGS) from=$< to=$@
114         @$(ECHO) "Generating ref for $(notdir %(from))..."
115         @$(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to) 2>$(GENDIR)/cerrors
116         @$(IF) $(TEST) -s %(to) ; \
117         then \
118             $(IF) $(TEST) -s $(GENDIR)/cerrors ; then \
119                 $(ECHO) "%(from): $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" >> $(GENDIR)/errors ; \
120                 tee < $(GENDIR)/cerrors -a $(GENDIR)/errors ; \
121             fi ; \
122         else \
123             $(ECHO) "Reference generation failed: $(CXREF) -raw -CPP '%(cc) %(cppflags) %(cflags)' %(from) >%(to)" 1>&2 ; \
124             tee < $(GENDIR)/cerrors -a $(GENDIR)/errors 1>&2 ; \
125             $(RM) %(to) ; \
126             exit 1 ; \
127         fi
128 %end
130 #------------------------------------------------------------------------------
131 # Create one directory without any output
132 %define mkdir_q dir=.
133         @$(IF) $(TEST) ! -d %(dir) ; then $(MKDIR) %(dir) ; else $(NOP) ; fi
134 %end
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
144 #############################################################################
145 #############################################################################
146 ##                                                                         ##
147 ## Here are the mmakefile macro's that are used to do certain tasks in a   ##
148 ## mmakefile. They consist of one or more full makefile rules.             ##
149 ## In general the files generated in these macro's are also defined as     ##
150 ## make targets so that they can be used as a dependency in other rules    ##
151 ##                                                                         ##
152 #############################################################################
153 #############################################################################
155 #------------------------------------------------------------------------------
156 # Generate a unique id for each of the %build... rules
157 %define buildid targets=/A
158 BDID := $(BDID)_
159 ifneq ($(filter $(TARGET),%(targets)),)
160 BDTARGETID := $(BDID)
161 endif
162 %end
163 #------------------------------------------------------------------------------
166 #------------------------------------------------------------------------------
167 # Copy file %(from) to %(to) in a makefile rule
168 %define rule_copy from=/A to=/A
169 %(to) : %(from)
170         @$(CP) $< $@
171 %end
172 #------------------------------------------------------------------------------
175 #------------------------------------------------------------------------------
176 # Will join all the files in %(from) to %(to). When text is specified it will
177 # be displayed.
178 # Restriction: at the moment when using a non-empty target dir %(from) may
179 # not have 
180 %define rule_join to=/A from=/A text=
182 %(to) : %(from)
183 ifneq (%(text),)
184         @$(ECHO) %(text)
185 endif
186         @$(CAT) $(BD_REFFILES$(BDID)) >$@
187 %end
188 #------------------------------------------------------------------------------
191 #------------------------------------------------------------------------------
192 # Include the dependency files and add some internal rules
193 # When depstargets is provided the depencies will only be included when one of
194 # these targets is the $(TARGET). Otherwise the dependencies will only be
195 # include when the $(TARGET) is not for setup or clean 
196 %define include_deps deps=$(DEPS)/M  depstargets=
197 ifneq (%(deps),)
198   ifneq (%(depstargets),)
199     ifneq ($(findstring $(TARGET),%(depstargets)),)
200       -include %(deps)
201     endif
202   else
203     ifeq (,$(filter clean% %clean %clean% setup% includes% %setup,$(TARGET)))
204       -include %(deps)
205     endif
206   endif
207 endif
208 %end
209 #------------------------------------------------------------------------------
212 #------------------------------------------------------------------------------
213 # Create the directories %(dirs). The creation will be done by adding rules to
214 # the %(setuptarget) make target with setup as the default. 
215 %define rule_makedirs dirs=/A setuptarget=setup
217 %(setuptarget) :: %(dirs)
219 # Only add a rule for a directory for which there is no rule yet.
221 TOCREATE_TMP := $(filter-out $(CREATED_DIRS_GLOB),%(dirs))
223 ifdef TOCREATE_TMP
224 $(TOCREATE_TMP) :
225         @$(ECHO) "Creating directory $@"
226         %mkdir_q dir=$@
228   ifdef CREATED_DIRS_GLOB
229     CREATED_DIRS_GLOB += $(TOCREATE_TMP)
230   else
231     CREATED_DIRS_GLOB := $(TOCREATE_TMP)
232   endif
233 endif
234 %end
235 #------------------------------------------------------------------------------
238 #------------------------------------------------------------------------------
239 # Rule to generate a functable
241 %define rule_genfunctable name=functable files=/A dir=. libdefs=libdefs.h
243 %(dir)/%(name).c : $(addsuffix .c,%(files)) $(SCRIPTDIR)/genfunctable.awk %(libdefs)
244         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
245 ifneq (%(files),)
246         $(AWK) -v file=%(libdefs) -f $(SCRIPTDIR)/genfunctable.awk $(addsuffix .c,%(files)) > $@
247 else
248         $(ARCHTOOL) -t
249         $(MV) functable.c $@
250 endif
251 %end
252 #------------------------------------------------------------------------------
255 #------------------------------------------------------------------------------
256 # Generate a rule to compile a C source file to an object file and generate
257 # the dependency file. Basename may contain a directory part, then the source
258 # file has to be in that directory. The generated file will be put in the
259 # object directory without the directory.
260 # options
261 # - basename: the basename of the file to compile. Use % for a wildcard rule
262 # - cflags (default $(CFLAGS)): the C flags to use for compilation
263 # - dflags: the flags used during creation of dependency file. If not specified
264 #   the same value as cflags will be used
265 # - targetdir: the directory to put the .o file and the .d file. By default
266 #   it is put in the same directory as the .c file
267 %define rule_compile basename=/A cflags=$(CFLAGS) dflags= targetdir= compiler=target
269 ifeq (%(targetdir),)
270   TMP_TARGETBASE := %(basename)
271 else
272   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
273 endif
275 ifeq ($(findstring %(compiler),host target),)
276   $(error unknown compiler %(compiler))
277 endif
278 ifeq (%(compiler),target)
279 $(TMP_TARGETBASE).o : TMP_CMD:=$(TARGET_CC)
280 $(TMP_TARGETBASE).d : TMP_CMD:=$(TARGET_CC)
281 endif
282 ifeq (%(compiler),host)
283 $(TMP_TARGETBASE).o : TMP_CMD:=$(HOST_CC)
284 $(TMP_TARGETBASE).d : TMP_CMD:=$(HOST_CC)
285 endif
287 $(TMP_TARGETBASE).o : %(basename).c
288         %compile_q opt="%(cflags)" cmd=$(TMP_CMD)
290 ifeq (%(dflags),)
291 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(cflags)
292 else
293 $(TMP_TARGETBASE).d : TMP_DFLAGS:=%(dflags)
294 endif
295 $(TMP_TARGETBASE).d : %(basename).c
296         %mkdepend_q cc=$(TMP_CMD) flags=$(TMP_DFLAGS)
297 %end
298 #------------------------------------------------------------------------------
301 #------------------------------------------------------------------------------
302 # Make an alias from one arch specific build to another arch.
303 # arguments:
304 # - mainmmake: the mmake of the module in the main tree
305 # - arch: the current arch
306 # - alias: the alias to which this should point
307 %define rule_archalias mainmmake=\A arch=\A alias=\A
309 #MM- %(mainmmake)-%(arch) : %(mainmmake)-%(alias)
310 %end
311 #------------------------------------------------------------------------------
314 #------------------------------------------------------------------------------
315 # Generate a rule to compile a C source file to an shared object file with a
316 # .so suffix. Basename may contain a directory part, then the source
317 # file has to be in that directory. The generated file will be put in the
318 # object directory without the directory.
319 # options
320 # - basename: the basename of the file to compile. Use % for a wildcard rule
321 # - cflags (default $(CFLAGS)): the C flags to use for compilation
322 # - targetdir: the directory to put the .o file and the .d file. By default
323 #   it is put in the same directory as the .c file
324 %define rule_compile_shared basename=/A cflags=$(CFLAGS) targetdir= compiler=target
326 ifeq (%(targetdir),)
327   TMP_TARGETBASE := %(basename)
328 else
329   TMP_TARGETBASE := %(targetdir)/$(notdir %(basename))
330 endif
332 ifeq ($(findstring %(compiler),host target),)
333   $(error unknown compiler %(compiler))
334 endif
335 ifeq (%(compiler),target)
336 $(TMP_TARGETBASE).so : TMP_CMD:=$(TARGET_CC)
337 endif
338 ifeq (%(compiler),host)
339 $(TMP_TARGETBASE).so : TMP_CMD:=$(HOST_CC)
340 endif
342 $(TMP_TARGETBASE).so : %(basename).c
343         %compile_q opt="$(SHARED_CFLAGS) %(cflags)" cmd=$(TMP_CMD)
344 %end
345 #------------------------------------------------------------------------------
348 #------------------------------------------------------------------------------
349 # Generate a rule to assemble a source file to an object file. Basename may
350 # contain a directory part, then the source file has to be in that directory.
351 # The generated file will be put in the object directory without the directory.
352 # options
353 # - basename: the basename of the file to compile. Use % for a wildcard rule
354 # - flags (default $(AFLAGS)): the asm flags to use for assembling
355 # - targetdir: the directory to put the .o file. By default it is put in the
356 #   same directory as the .s file
357 %define rule_assemble basename=/A flags=$(AFLAGS) targetdir=
359 ifeq (%(targetdir),)
360 %(basename).o : %(basename).s
361         %assemble_q opt=%(flags)
363 else
364 %(targetdir)/$(notdir %(basename)).o : %(basename).s
365         %assemble_q opt=%(flags)
367 endif
368 %end
369 #------------------------------------------------------------------------------
372 #------------------------------------------------------------------------------
373 # Link %(objs) to %(prog) using the libraries in %(uselibs)
374 %define rule_link_prog prog=/A objs=/A ldflags=$(LDFLAGS) uselibs= \
375     usehostlibs= usestartup=yes detach=no nix=no
377 TMP_EXTRA_LDFLAGS := 
378 ifeq (%(nix),yes)
379     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
380 endif
381 ifeq (%(usestartup),no)
382     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
383 endif
384 ifeq (%(detach),yes)
385     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
386 endif
387 %(prog) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
389 %(prog) : %(objs) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
390         %link_q from="%(objs)" opt="%(ldflags) $(EXTRA_LDFLAGS)" \
391             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
392 %end
393 #------------------------------------------------------------------------------
396 #------------------------------------------------------------------------------
397 # Link %(progs) from object in %(objdir) to executables in %(targetdir) using
398 # the AROS libraries in %(uselibs) and the host libraries in %(usehostlibs)
399 %define rule_link_progs progs=/A targetdir=$(AROSDIR)/$(CURDIR) \
400     objdir=$(GENDIR)/$(CURDIR) ldflags=$(LDFLAGS) uselibs= usehostlibs= \
401     usestartup=yes detach=no
403 TMP_EXTRA_LDFLAGS := 
404 ifeq (%(nix),yes)
405     TMP_EXTRA_LDFLAGS += $(NIX_LDFLAGS)
406 endif
407 ifeq (%(usestartup),no)
408     TMP_EXTRA_LDFLAGS += $(NOSTARTUP_LDFLAGS)
409 endif
410 ifeq (%(detach),yes)
411     TMP_EXTRA_LDFLAGS += $(DETACH_LDFLAGS)
412 endif
413 $(addprefix %(targetdir)/,%(progs)) : EXTRA_LDFLAGS:=$(TMP_EXTRA_LDFLAGS)
415 $(addprefix %(targetdir)/,%(progs)) : %(targetdir)/% : %(objdir)/%.o \
416     $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
417         %link_q from=$< opt="%(ldflags) $(EXTRA_LDFLAGS)" \
418             libs="$(addprefix -l,%(uselibs)) $(addprefix -l,%(usehostlibs))"
419 %end
420 #------------------------------------------------------------------------------
423 #------------------------------------------------------------------------------
424 # Link the %(objs) to the library %(libdir)/lib%(libname).a in
425 %define rule_link_linklib libname=/A objs=/A libdir=$(LIBDIR)
427 %(libdir)/lib%(libname).a : %(objs)
428         %mklib_q from=$^
429 %end
430 #------------------------------------------------------------------------------
433 #------------------------------------------------------------------------------
434 # Link the %(objs) to the library %(libdir)/lib%(libname).so in
435 %define rule_link_shlib libname=/A objs=/A libdir=$(LIBDIR)
437 %(libdir)/lib%(libname).so : %(objs)
438         @$(SHARED_LD) $(SHARED_LDFLAGS) -o $@ $^
439 %end
440 #------------------------------------------------------------------------------
443 #------------------------------------------------------------------------------
444 # Link the %(objs) and %(endobj) to %(module) with errors in %(err) and using
445 # the libraries in %(uselibs) and the host libraries in %(usehostlibs)
446 %define rule_linkmodule module=/A objs=/A endobj=/A err=/A uselibs= usehostlibs=
448 %(module) : %(objs) %(endobj) $(addprefix $(LIBDIR)/lib,$(addsuffix .a,%(uselibs) libinit autoinit))
449         %link_module_q err="%(err)" endtag="%(endobj)" objs="%(objs)" \
450                        libs="$(addprefix -l,%(uselibs)) -lautoinit -llibinit -L/usr/lib $(addprefix -l,%(usehostlibs))"
452 %end
453 #------------------------------------------------------------------------------
456 #------------------------------------------------------------------------------
457 # Generate a rule to generate a function reference file from a C source file.
458 # Basename may contain a directory part, then the source file has to be in that
459 # directory. The generated file will be put in the object directory without the
460 # directory.
461 # options
462 # - basename: the basename of the file to compile. Use % for a wildcard rule
463 # - cflags (default $(CFLAGS)): the C flags to use for compilation
464 # - targetdir: the directory to put the generated .ref file. By default the
465 #   .ref file will be put in the same directory as the .c file.
466 # - includefile: This file will be included at the head of the source file
467 %define rule_ref basename=/A cflags=$(CFLAGS) targetdir= includefile= compiler=target
469 ifeq (%(targetdir),)
470 GENFILE_TMP := %(basename).ref
471 else
472 GENFILE_TMP := %(targetdir)/$(notdir %(basename)).ref
473 endif
475 ifeq ($(filter %(compiler),target host),)
476 $(error use of %rule_ref: compiler has to be 'host' or 'target')
477 endif
479 ifeq (%(compiler),target)
480 $(GENFILE_TMP) : CC:=$(TARGET_CC)
481 else
482 $(GENFILE_TMP) : CC:=$(HOST_CC)
483 endif
485 $(GENFILE_TMP) : %(basename).c $(CXREF) %(includefile)
486 ifeq (%(includefile),)
487         %mkref_q cc=$(CC) cflags="%(cflags)"
488 else
489         %mkref_q cc=$(CC) cflags="%(cflags) -include %(includefile)"
490 endif
492 %end
493 #------------------------------------------------------------------------------
496 #------------------------------------------------------------------------------
497 # Generate the libdefs.h include file for a module.
498 %define rule_genlibdefs modname=/A modtype=/A modsuffix= conffile=/A targetdir=/A
500 %(targetdir)/%(modname)_libdefs.h : %(conffile) $(GENLIBDEFS)
501         @$(ECHO) "Generating $(notdir $@)"
502         @$(GENLIBDEFS) %(modname) %(modtype) %(modsuffix) %(conffile) %(targetdir)
503 %end
504 #------------------------------------------------------------------------------
507 #------------------------------------------------------------------------------
508 # Generate dummy support files so cxref when used on the a module source file
509 # will find something to include.
510 %define rule_genmodule_dummy modname=/A modtype=/A modsuffix= conffile=/A targetdir=/A
512 %(targetdir)/clib/%(modname)_protos.h %(targetdir)/defines/%(modname).h \
513 %(targetdir)/proto/%(modname).h : %(conffile) $(GENMODULEDUMMY)
514         @$(ECHO) "Generating $(notdir $@)"
515         %mkdirs_q dirs="%(targetdir) %(targetdir)/clib %(targetdir)/defines %(targetdir)/proto"
516         $(GENMODULEDUMMY) %(modname) %(modtype) %(modsuffix) %(conffile) %(targetdir)
517 %end
518 #------------------------------------------------------------------------------
521 #------------------------------------------------------------------------------
522 # Generate the support files for compiling a module. This includes include
523 # files and source files.
524 %define rule_genmodule modname=/A modtype=/A modsuffix= objdir=/A conffile=/A reffile=/A
526 GENFILES_TMP := %(objdir)/%(modname)_start.c %(objdir)/%(modname)_end.c
528 # Some of the generated files are dependent on the module type.
529 ifneq ($(findstring %(modtype),library device resource gadget datatype),)
530 GENFILES_TMP += %(objdir)/%(modname)_autoinit.c %(objdir)/%(modname)_stubs.c \
531                 $(GENINCDIR)/clib/%(modname)_protos.h \
532                 $(GENINCDIR)/defines/%(modname).h \
533                 $(GENINCDIR)/proto/%(modname).h
534 endif
536 ifneq ($(findstring %(modtype),mcc mui mcp),)
537 GENFILES_TMP += %(objdir)/%(modname)_stubs.c
538 endif
540 $(GENFILES_TMP) : %(conffile) $(GENMODULE) %(reffile)
541         @$(ECHO) "Generating functable and includes for module $(BD_MODNAME$(BDID))"
542 ifneq (%(conffile),lib.conf)
543         @$(IF) $(TEST) -f lib.conf; then \
544           $(ECHO) "WARNING !!! $(CURDIR)/lib.conf may probably be removed"; \
545         fi
546 endif
547         @$(IF) $(TEST) -f libdefs.h; then \
548           $(ECHO) "WARNING !!! $(CURDIR)/libdefs.h may probably be removed"; \
549         fi
550         @$(GENMODULE) %(modname) %(modtype) %(modsuffix) %(conffile) %(objdir) $(GENINCDIR) %(reffile)
551 %end
552 #------------------------------------------------------------------------------
554 #------------------------------------------------------------------------------
555 # Common rules for all makefiles
556 %define common
557 # Delete generated makefiles
559 clean ::
560         @$(RM) $(TOP)/$(CURDIR)/mmakefile $(TOP)/$(CURDIR)/mmakefile.bak
562 include $(TOP)/config/make.tail
564 BDID := $(BDTARGETID)
565 %end
566 #------------------------------------------------------------------------------
567       
569 #############################################################################
570 #############################################################################
571 ##                                                                         ##
572 ## Here are the mmakefile build macro's. These are macro's that takes care ##
573 ## of everything to go from the sources to the generated target. Also all  ##
574 ## intermediate files and directories that are needed are created by these ##
575 ## rules.                                                                  ##
576 ##                                                                         ##
577 #############################################################################
578 #############################################################################
580 #------------------------------------------------------------------------------
581 # Build a program
582 %define build_prog mmake=/A progname=/A files=$(BD_PROGNAME$(BDID)) asmfiles= \
583     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
584     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
585     aflags=$(AFLAFS) uselibs= usehostlibs= usestartup=yes detach=no nix=no
587 .PHONY : %(mmake) %(mmake)-setup
589 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean %(mmake)-quick"
591 BD_PROGNAME$(BDID)  := %(progname)
592 BD_OBJDIR$(BDID)    := %(objdir)
593 BD_TARGETDIR$(BDID) := %(targetdir)
595 BD_FILES$(BDID)     := %(files)
596 BD_ASMFILES$(BDID)  := %(asmfiles)
597 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID))))
598 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
600 BD_CFLAGS$(BDID)    := %(cflags)
601 BD_AFLAGS$(BDID)    := %(aflags)
602 BD_DFLAGS$(BDID)    := %(dflags)
603 BD_LDFLAGS$(BDID)   := %(ldflags)
605 #MM %(mmake) : %(mmake)-setup
608 %(mmake)-quick : %(mmake)
610 %(mmake) : $(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID))
612 #MM %(mmake)-setup
613 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_TARGETDIR$(BDID))" \
614     setuptarget=%(mmake)-setup
616 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
617 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
618     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
619 %rule_assemble basename=% targetdir=$(BD_OBJDIR$(BDID)) \
620                flags=$(BD_AFLAGS$(BDID))
622 %rule_link_prog prog=$(BD_TARGETDIR$(BDID))/$(BD_PROGNAME$(BDID)) \
623     objs=$(BD_OBJS$(BDID)) ldflags=$(BD_LDFLAGS$(BDID)) \
624     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
625     usestartup="%(usestartup)" detach="%(detach)" nix="%(nix)"
627 endif
629 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
630 %end
631 #------------------------------------------------------------------------------
634 #------------------------------------------------------------------------------
635 # Build programs, for every C file an executable will be built with the same
637 %define build_progs mmake=/A files=/A \
638     objdir=$(GENDIR)/$(CURDIR) targetdir=$(AROSDIR)/$(CURDIR) \
639     cflags=$(CFLAGS) dflags=$(BD_CFLAGS$(BDID)) ldflags=$(LDFLAGS) \
640     uselibs= usehostlibs= usestartup=yes detach=no
642 .PHONY : %(mmake) %(mmake)-setup
644 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean %(mmake)-quick"
646 BD_OBJDIR$(BDID)    := %(objdir)
647 BD_TARGETDIR$(BDID) := %(targetdir)
649 BD_FILES$(BDID)     := %(files)
650 BD_OBJS$(BDID)      := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
651 BD_DEPS$(BDID)      := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_FILES$(BDID))))
652 BD_EXES$(BDID)      := $(addprefix $(BD_TARGETDIR$(BDID))/,$(BD_FILES$(BDID)))
654 BD_CFLAGS$(BDID)    := %(cflags)
655 ifneq ($(strip $(filter arosc_shared,%(uselibs))),)
656 BD_CFLAGS$(BDID)    += -D_CLIB_LIBRARY_ -I$(TOP)/rom/exec
657 endif
658 BD_DFLAGS$(BDID)    := %(dflags)
659 BD_LDFLAGS$(BDID)   := %(ldflags)
661 #MM %(mmake) : %(mmake)-setup
664 %(mmake)-quick : %(mmake)
666 %(mmake) : $(BD_EXES$(BDID))
668 #MM %(mmake)-setup
669 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_TARGETDIR$(BDID))" \
670     setuptarget=%(mmake)-setup
672 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick),)
673 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
674     cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
676 %rule_link_progs progs=$(BD_FILES$(BDID)) \
677     targetdir=$(BD_TARGETDIR$(BDID)) objdir=$(BD_OBJDIR$(BDID)) \
678     ldflags=$(BD_LDFLAGS$(BDID)) \
679     uselibs="%(uselibs)" usehostlibs="%(usehostlibs)" \
680     usestartup="%(usestartup)" detach="%(detach)"
682 endif
684 %include_deps depstargets="%(mmake) %(mmake)-quick" deps=$(BD_DEPS$(BDID))
685 %end
686 #------------------------------------------------------------------------------
689 #------------------------------------------------------------------------------
690 # Build a module
691 # Explanation of this macro is done in the developer's manual
692 %define build_module mmake=/A modname=/A modtype=/A modsuffix= \
693   conffile=$(BD_MODNAME$(BDID)).conf files="$(basename $(wildcard *.c))" \
694   linklibfiles= cflags=$(CFLAGS) dflags= \
695   objdir=$(OBJDIR) moduledir= prefix=$(AROSDIR)\
696   reffile=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_ALL.ref noref= \
697   linklibname=$(BD_MODNAME$(BDID)) uselibs= \
698   compiler=target
700 %buildid targets="%(mmake) %(mmake)-includes %(mmake)-setup %(mmake)-clean %(mmake)-quick %(mmake)-kobj"
702 .PHONY : setup-module$(BDID) %(mmake) %(mmake)-includes %(mmake)-setup %(mmake)-clean %(mmake)-quick %(mmake)-kobj
704 ifeq (%(modname),)
705 $(error using %build_module: modname may not be empty)
706 endif
707 ifeq (%(modtype),)
708 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
709 endif
711 # assign and generate the local variables used in this macro
712 BD_MODNAME$(BDID)    := %(modname)
713 BD_MODTYPE$(BDID)    := %(modtype)
714 ifeq (%(modsuffix),)
715 BD_MODSUFFIX$(BDID)  := %(modtype)
716 else
717 BD_MODSUFFIX$(BDID)  := %(modsuffix)
718 endif
719 BD_CONFFILE$(BDID)   := %(conffile)
720 OBJDIR               ?= $(GENDIR)/$(CURDIR)
721 BD_OBJDIR$(BDID)     := %(objdir)
722 BD_PREFIX$(BDID)     := %(prefix)
723 BD_INCLUDE$(BDID)    := $(BD_PREFIX$(BDID))/$(AROS_DIR_INCLUDE)
725 BD_FILES$(BDID)      := %(files)
726 BD_LIBFILES$(BDID)   := %(linklibfiles)
727 BD_STARTFILE$(BDID)  := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_start
728 BD_ENDFILE$(BDID)    := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_end
730 BD_ARCHOBJS$(BDID)   := $(wildcard $(BD_OBJDIR$(BDID))/arch/*.o)
731 BD_ARCHFILES$(BDID)  := $(basename $(notdir $(BD_ARCHOBJS$(BDID))))
732 BD_NARCHFILES$(BDID) := $(filter-out $(BD_ARCHFILES$(BDID)),$(BD_FILES$(BDID)))
733 BD_NEWARCHFILES$(BDID):= $(filter-out $(BD_FILES$(BDID)),$(BD_ARCHFILES$(BDID)))
734 BD_ARCHOBJS$(BDID)   := $(addsuffix .o, $(addprefix $(BD_OBJDIR$(BDID))/arch/,$(BD_ARCHFILES$(BDID))))
735 BD_NARCHOBJS$(BDID)  := $(addsuffix .o, $(addprefix $(BD_OBJDIR$(BDID))/,$(BD_NARCHFILES$(BDID))))
736 BD_OBJS$(BDID)       := $(BD_ARCHOBJS$(BDID)) $(BD_NARCHOBJS$(BDID))
737 BD_STARTOBJ$(BDID)   := $(addsuffix .o,$(BD_STARTFILE$(BDID)))
738 BD_ENDOBJ$(BDID)     := $(addsuffix .o,$(BD_ENDFILE$(BDID)))
740 BD_DEPS$(BDID)       := $(patsubst %.o,%.d,$(BD_NARCHOBJS$(BDID)))
742 ifeq (%(noref),)
743 BD_REFFILES$(BDID)   := $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .ref, $(notdir $(BD_FILES$(BDID)))))
744 else
745 BD_REFFILES$(BDID)   := $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .ref, $(notdir $(filter-out %(noref),$(BD_FILES$(BDID))))))
746 endif
747 BD_REFFILE$(BDID)    := %(reffile)
749 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource),)
750 BD_GENINCS$(BDID)    := clib/$(BD_MODNAME$(BDID))_protos.h defines/$(BD_MODNAME$(BDID)).h proto/$(BD_MODNAME$(BDID)).h
751 endif
752 BD_LIBDEFSINC$(BDID) := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_libdefs.h
754 BD_CFLAGS$(BDID)     := %(cflags) -I$(BD_INCLUDE$(BDID)) -I$(BD_OBJDIR$(BDID)) -idirafter $(TOP)/$(CURDIR) -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
755 ifeq (%(dflags),)
756 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
757 else
758 BD_DFLAGS$(BDID)     := %(dflags) -I$(BD_INCLUDE$(BDID)) -I$(BD_OBJDIR$(BDID)) -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
759 endif
761 # Add additional files depending the module type
762 ifeq ($(findstring $(BD_MODTYPE$(BDID)),library device mcc mui mcp resource gadget datatype),)
763     $(error unhandled MODTYPE %(modtype))
764 endif
765 ifeq ($(BD_MODTYPE$(BDID)),library)
766   BD_MODDIR$(BDID)         := $(BD_PREFIX$(BDID))/$(AROS_DIR_LIBS)
767   BD_LINKLIBFILES$(BDID)   := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_autoinit.c 
768   BD_LINKLIBOBJS$(BDID)    := $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .o,$(BD_LIBFILES$(BDID)))) \
769                               $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_autoinit.o 
770   BD_LINKLIBGENFILES$(BDID):= $(BD_PREFIX$(BDID))/$(AROS_DIR_LIB)/lib%(linklibname).a
771   %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_autoinit \
772                 targetdir=$(BD_OBJDIR$(BDID)) \
773                 cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
774                 compiler=%(compiler)
775 endif
777 ifeq ($(BD_MODTYPE$(BDID)),device)
778   BD_MODDIR$(BDID)         := $(BD_PREFIX$(BDID))/$(AROS_DIR_DEVS)
779   BD_LINKLIBFILES$(BDID)   := 
780   BD_LINKLIBOBJS$(BDID)    := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(addsuffix .o,$(BD_LIBFILES$(BDID)))) \
781                               $(BD_LIBARCHOBJS$(BDID))
782   BD_LINKLIBGENFILES$(BDID):= $(BD_PREFIX$(BDID))/$(AROS_DIR_LIB)/lib%(linklibname).a
783 endif
785 ifeq ($(BD_MODTYPE$(BDID)),resource)
786   BD_MODDIR$(BDID)         := $(BD_PREFIX$(BDID))/$(AROS_DIR_DEVS)
787   BD_LINKLIBFILES$(BDID)   := 
788   BD_LINKLIBOBJS$(BDID)    := $(addprefix $(BD_LIBOBJDIR$(BDID))/,$(addsuffix .o,$(BD_LIBFILES$(BDID)))) \
789                               $(BD_LIBARCHOBJS$(BDID))
790   BD_LINKLIBGENFILES$(BDID):= $(BD_PREFIX$(BDID))/$(AROS_DIR_LIB)/lib%(linklibname).a
791 endif
793 ifneq ($(findstring $(BD_MODTYPE$(BDID)),mcc mui mcp),)
794   BD_MODDIR$(BDID)       := $(BD_PREFIX$(BDID))/$(AROS_DIR_CLASSES)/Zune
795   BD_LINKLIBGENFILES$(BDID):= 
796 endif
798 ifeq ($(BD_MODTYPE$(BDID)),gadget)
799   BD_MODDIR$(BDID)       := $(BD_PREFIX$(BDID))/$(AROS_DIR_CLASSES)/Gadgets
800   BD_LINKLIBGENFILES$(BDID):= 
801 endif
803 ifeq ($(BD_MODTYPE$(BDID)),datatype)
804   BD_MODDIR$(BDID)       := $(BD_PREFIX$(BDID))/$(AROS_DIR_CLASSES)/DataTypes
805   BD_LINKLIBGENFILES$(BDID):= 
806 endif
808 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource mcc mcp),)
809   BD_LINKLIBFILES$(BDID)   += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_stubs.c
810   BD_LINKLIBOBJS$(BDID)    += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_stubs.o
811   BD_LINKLIBDEPS$(BDID)    := $(patsubst %.o,%.d,$(BD_LINKLIBOBJS$(BDID))) 
812   %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_stubs \
813                 targetdir=$(BD_OBJDIR$(BDID)) \
814                 cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
815                 compiler=%(compiler)
816 endif
818 ifneq (%(moduledir),)
819   BD_MODDIR$(BDID)    := $(BD_PREFIX$(BDID))/%(moduledir)
820 endif
822 BD_MODULE$(BDID)    := $(BD_MODDIR$(BDID))/$(BD_MODNAME$(BDID)).$(BD_MODSUFFIX$(BDID))
823 BD_GENFILES$(BDID)  := $(BD_MODULE$(BDID)) $(BD_LINKLIBGENFILES$(BDID))
824 BD_DEPS$(BDID)      += $(BD_LINKLIBDEPS$(BDID))
826 # What are the files that need to be generated before the .d and .ref files
827 # can be generated ?
828 BD_REFFILE_DEPS$(BDID) := $(BD_LIBDEFSINC$(BDID)) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
829 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource gadget datatype),)
830   BD_REFFILE_DEPS$(BDID) += $(addprefix $(BD_OBJDIR$(BDID))/dummyinc/,$(BD_GENINCS$(BDID)))
831 endif
832 BD_DFILE_DEPS$(BDID) := $(BD_LIBDEFSINC$(BDID)) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
833 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource gadget datatype),)
834   BD_DFILE_DEPS$(BDID) += $(addprefix $(BD_INCLUDE$(BDID))/,$(BD_GENINCS$(BDID)))
835 endif
837 #MM- includes-all : %(mmake)-includes
838 #MM %(mmake) : %(mmake)-includes
839 #MM %(mmake)-kobj : %(mmake)-includes
840 #MM %(mmake)-includes : %(mmake)-setup includes-generate-deps
843 %(mmake)-quick : %(mmake)
846 %(mmake) : $(BD_GENFILES$(BDID))
849 %(mmake)-includes : $(addprefix $(BD_INCLUDE$(BDID))/,$(BD_GENINCS$(BDID)))
852 %(mmake)-clean ::
853         @$(ECHO) "Cleaning up for module $(BD_MODNAME$(BDID))"
854         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_REFFILE$(BDID)) \
855             $(BD_REFFILES$(BDID))\
856             $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .c,$(BD_GENFILES$(BDID)))) \
857             $(addprefix $(GENINCDIR)/,$(BD_GENINCS$(BDID))) \
858             $(addprefix $(BD_INCLUDE$(BDID))/,$(BD_GENINCS$(BDID))) \
859             $(BD_LINKLIBFILES$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_LIBDEFSINC$(BDID)) \
860             $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h \
861             $(addsuffix .c,$(BD_STARTFILE$(BDID)) $(BD_ENDFILE$(BDID))) \
862             $(BD_STARTOBJ$(BDID)) $(BD_ENDOBJ$(BDID))
865 %(mmake)-setup : setup-module$(BDID)
867 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Avoid conflicts
868 TMP_SRCDIR := $(filter-out ./,$(sort $(dir $(BD_FILES$(BDID)))))
869 ifneq ($(TMP_SRCDIR),)
870 vpath %.c $(TMP_SRCDIR)
871 %rule_makedirs dirs="$(addprefix $(BD_OBJDIR$(BDID))/,$(TMP_SRCDIR))" setuptarget=setup-module$(BDID)
872 endif
874 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
875               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
876               compiler=%(compiler)
877 %rule_ref     basename=% targetdir=$(BD_OBJDIR$(BDID)) \
878               cflags="-I$(dir $(GENMODULE))/genmod_inc -I$(BD_OBJDIR$(BDID))/dummyinc $(strip $(BD_CFLAGS$(BDID)))" \
879               compiler=%(compiler)
880 %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_start targetdir=$(BD_OBJDIR$(BDID)) \
881               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
882               compiler=%(compiler)
883 %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_end targetdir=$(BD_OBJDIR$(BDID)) \
884               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
885               compiler=%(compiler)
886 endif
888 # Some include files need to be generated before the .c can be parsed.
889 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-includes %(mmake)-quick %(mmake)-kobj),) # Only for this target these deps are wanted
890 $(BD_REFFILES$(BDID)) : $(BD_REFFILE_DEPS$(BDID)) $(dir $(GENMODULE))/genmod_inc/aros/libcall.h
891 $(BD_DEPS$(BDID)) : $(BD_DFILE_DEPS$(BDID))
892 endif
894 # Generation of the autogenerated .c and .h files.
895 %rule_genmodule modname=$(BD_MODNAME$(BDID)) modtype=$(BD_MODTYPE$(BDID)) \
896                 modsuffix=$(BD_MODSUFFIX$(BDID)) objdir=$(BD_OBJDIR$(BDID)) \
897                 conffile=$(BD_CONFFILE$(BDID)) reffile=$(BD_REFFILE$(BDID))
899 %rule_genmodule_dummy modname=$(BD_MODNAME$(BDID)) modtype=$(BD_MODTYPE$(BDID)) \
900                       modsuffix=$(BD_MODSUFFIX$(BDID)) \
901                       targetdir=$(BD_OBJDIR$(BDID))/dummyinc conffile=$(BD_CONFFILE$(BDID))
903 %rule_genlibdefs modname=$(BD_MODNAME$(BDID)) modtype=$(BD_MODTYPE$(BDID)) \
904                  modsuffix=$(BD_MODSUFFIX$(BDID)) targetdir=$(BD_OBJDIR$(BDID)) \
905                  conffile=$(BD_CONFFILE$(BDID))
907 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h : $(BD_CONFFILE$(BDID))
908         @$(ECHO) "generating $@"
909         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(BD_LIBDEFSINC$(BDID))\"" >$@
911 # The module ref file is the joint of all individual .ref files
912 %rule_join from=$(BD_REFFILES$(BDID)) to=$(BD_REFFILE$(BDID)) \
913            text="Collecting function references for module $(BD_MODNAME$(BDID))"
915 # The module is linked from all the compiled .o files
916 %rule_linkmodule module=$(BD_MODULE$(BDID)) objs="$(BD_STARTOBJ$(BDID)) $(BD_OBJS$(BDID))" \
917                  endobj=$(BD_ENDOBJ$(BDID)) err=$(BD_MODNAME).err uselibs="%(uselibs)"
919 # The include files generated in $(GENINCDIR) have to be mirrored in the AROS include directory
920 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource gadget datatype),)
921 %rule_makedirs dirs="$(addprefix $(BD_INCLUDE$(BDID))/, clib defines pragmas proto)" setuptarget=setup-module$(BDID)
922 %rule_copy from=$(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_protos.h to=$(BD_INCLUDE$(BDID))/clib/$(BD_MODNAME$(BDID))_protos.h
923 %rule_copy from=$(GENINCDIR)/defines/$(BD_MODNAME$(BDID)).h to=$(BD_INCLUDE$(BDID))/defines/$(BD_MODNAME$(BDID)).h
924 %rule_copy from=$(GENINCDIR)/pragmas/$(BD_MODNAME$(BDID)).h to=$(BD_INCLUDE$(BDID))/pragmas/$(BD_MODNAME$(BDID)).h
925 %rule_copy from=$(GENINCDIR)/proto/$(BD_MODNAME$(BDID)).h to=$(BD_INCLUDE$(BDID))/proto/$(BD_MODNAME$(BDID)).h
926 endif
928 # For a shared library and device also build a static link lib
929 ifneq ($(findstring $(BD_MODTYPE$(BDID)),library device resource),)
930 %rule_makedirs dirs=$(BD_PREFIX$(BDID))/$(AROS_DIR_LIB) setuptarget=setup-module$(BDID)
931 %rule_link_linklib libname=%(linklibname) objs=$(BD_LINKLIBOBJS$(BDID)) libdir=$(BD_PREFIX$(BDID))/$(AROS_DIR_LIB)
932 endif
934 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_OBJDIR$(BDID))/dummyinc/defines $(BD_OBJDIR$(BDID))/dummyinc/proto $(BD_OBJDIR$(BDID))/dummyinc/clib $(BD_MODDIR$(BDID)) $(KOBJSDIR)" \
935                setuptarget=setup-module$(BDID)
937 %(mmake)-kobj : $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODSUFFIX$(BDID)).o
939 $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODSUFFIX$(BDID)).o : \
940 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_start.o \
941 $(BD_OBJS$(BDID)) \
942 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_end.o
943         @$(ECHO) "Linking $@"
944         @$(AROS_LD) -Ur -o $@ $^
945         @$(OBJCOPY) $@ `$(NM_PLAIN) $@ | $(AWK) '$$3 ~ /^__.*_(LIST|END)__$$/ {print "-L " $$3;}'`
947 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-kobj" deps=$(BD_DEPS$(BDID))
948 %end
949 #------------------------------------------------------------------------------
952 #------------------------------------------------------------------------------
953 # Build a module using the deprecated macro's to define the functions in the
954 # library. Explanation of this macro is done in the developer's manual
955 %define build_module_macro mmake=/A modname=/A modtype=/A dir= \
956   conffile=$(BD_MODNAME$(BDID)).conf initfile=$(BD_MODNAME$(BDID))_init \
957   funcs= files= linklibfiles= cflags=$(CFLAGS) dflags= \
958   objdir=$(OBJDIR) uselibs= usehostlibs= \
959   genfunctable= genincludes= compiler=target
961 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean %(mmake)-includes %(mmake)-linklib %(mmake)-quick %(mmake)-kobj"
963 .PHONY : setup-module$(BDID)
965 ifeq (%(modname),)
966 $(error using %build_module: modname may not be empty)
967 endif
968 ifeq (%(modtype),)
969 $(error using %build_module: $(MODTYPE) has to be defined with the type of the module)
970 endif
972 # assign and generate the local variables used in this macro
973 BD_MODNAME$(BDID)    := %(modname)
974 BD_MODTYPE$(BDID)    := %(modtype)
975 BD_MODDIR$(BDID)     := %(dir)
976 BD_CONFFILE$(BDID)   := %(conffile)
977 OBJDIR               ?= $(GENDIR)/$(CURDIR)
978 BD_OBJDIR$(BDID)     := %(objdir)
980 BD_ARCHOBJS$(BDID)   := $(wildcard $(BD_OBJDIR$(BDID))/arch/*.o)
981 BD_ARCHFILES$(BDID)  := $(basename $(notdir $(BD_ARCHOBJS$(BDID))))
983 BD_INITFILE$(BDID)   := %(initfile)
984 BD_FUNCS$(BDID)      := $(filter-out $(BD_ARCHFILES$(BDID)),%(funcs))
985 BD_FILES$(BDID)      := $(filter-out $(BD_ARCHFILES$(BDID)),%(files))
986 BD_LIBFILES$(BDID)   := %(linklibfiles)
987 ifneq ($(wildcard $(BD_CONFFILE$(BDID))),)
988 BD_ENDFILE$(BDID)    := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_end
989 else
990 BD_ENDFILE$(BDID)    := 
991 endif
993 BD_FUNCSRCS$(BDID)   := $(addsuffix .c,%(funcs))
994 BD_SRCS$(BDID)       := $(addsuffix .c,$(BD_FILES$(BDID)))
995 ifeq ($(filter $(BD_INITFILE$(BDID)), $(BD_ARCHFILES$(BDID))),)
996   BD_INITOBJ$(BDID)  := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir $(BD_INITFILE$(BDID)))))
997 else
998   TMP_INITREPLACE    := $(filter $(notdir $(BD_INITFILE$(BDID))), $(BD_ARCHFILES$(BDID)))
999   TMP_INITKEEP       := $(filter-out $(TMP_INITREPLACE),$(notdir $(BD_INITFILE$(BDID))))
1000   BD_INITOBJ$(BDID)  := $(addsuffix .o, \
1001                             $(addprefix $(BD_OBJDIR$(BDID))/arch/,$(TMP_INITREPLACE)) \
1002                             $(addprefix $(BD_OBJDIR$(BDID))/,$(TMP_INITKEEP)) \
1003                          )
1004   BD_ARCHOBJS$(BDID) := $(filter-out $(BD_INITOBJ$(BDID)),$(BD_ARCHOBJS$(BDID)))
1005 endif
1007 TMP_FILES            := $(notdir $(BD_FILES$(BDID)))
1008 ifeq (%(genfunctable),yes)
1009   TMP_FILES          := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1010 else
1011   ifneq ($(BD_FUNCS$(BDID)),)
1012     ifeq (%(genfunctable),)
1013       ifneq ($(BD_MODTYPE$(BDID)),resource)
1014         TMP_FILES    := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1015       endif
1016     else
1017       ifneq (%(genfunctable),no)
1018         TMP_FILES    := $(BD_MODNAME$(BDID))_functable $(TMP_FILES)
1019       endif
1020     endif
1021     TMP_FILES        += $(BD_FUNCS$(BDID))
1022   endif
1023 endif
1024 BD_OBJS$(BDID)       := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(TMP_FILES))) $(BD_ARCHOBJS$(BDID))
1025 BD_ENDOBJ$(BDID)     := $(addsuffix .o,$(BD_ENDFILE$(BDID)))
1027 BD_DEPS$(BDID)       := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(BD_INITFILE$(BDID)) $(TMP_FILES)))
1029 BD_GENINCS$(BDID)    :=
1030 ifneq (%(genincludes),)
1031   ifeq (%(genincludes),yes)
1032     BD_GENINCS$(BDID):= clib/$(BD_MODNAME$(BDID))_protos.h defines/$(BD_MODNAME$(BDID)).h proto/$(BD_MODNAME$(BDID)).h
1033   endif
1034 else
1035   ifneq ($(BD_FUNCS$(BDID)),)
1036     ifneq ($(findstring $(BD_MODTYPE$(BDID)),library gadget device),)
1037       BD_GENINCS$(BDID):= clib/$(BD_MODNAME$(BDID))_protos.h defines/$(BD_MODNAME$(BDID)).h proto/$(BD_MODNAME$(BDID)).h
1038     endif
1039   endif
1040 endif
1041 # Only generate libdefs.h if the config file exists
1042 ifneq ($(wildcard $(BD_CONFFILE$(BDID))),)
1043   BD_LIBDEFSINC$(BDID):= $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_libdefs.h
1044 else
1045   BD_LIBDEFSINC$(BDID):=
1046 endif
1048 BD_CFLAGS$(BDID)     := %(cflags) -I$(BD_OBJDIR$(BDID)) -I. -I$(TOP)/workbench/libs -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1049 ifeq (%(dflags),)
1050 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
1051 else
1052 BD_DFLAGS$(BDID)     := %(dflags) -I$(BD_OBJDIR$(BDID)) -I. -I$(TOP)/workbench/libs -include $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1053 endif
1055 # Add additional files depending the module type
1056 ifeq ($(findstring $(BD_MODTYPE$(BDID)),library gadget datatype handler device resource mui mcc mcp hidd),)
1057     $(error unhandled MODTYPE %(modtype))
1058 endif
1059 ifeq ($(BD_MODDIR$(BDID)),)
1060   ifeq ($(BD_MODTYPE$(BDID)),library)
1061     BD_MODDIR$(BDID)  := $(AROS_LIBS)
1062   endif
1063   ifeq ($(BD_MODTYPE$(BDID)),gadget)
1064     BD_MODDIR$(BDID)  := $(AROS_GADGETS)
1065   endif
1066   ifeq ($(BD_MODTYPE$(BDID)),datatype)
1067     BD_MODDIR$(BDID)  := $(AROS_DATATYPES)
1068   endif
1069   ifeq ($(BD_MODTYPE$(BDID)),handler)
1070     BD_MODDIR$(BDID)  := $(AROS_FS)
1071   endif
1072   ifeq ($(BD_MODTYPE$(BDID)),device)
1073     BD_MODDIR$(BDID)  := $(AROS_DEVS)
1074   endif
1075   ifeq ($(BD_MODTYPE$(BDID)),resource)
1076     BD_MODDIR$(BDID)  := $(AROS_RESOURCES)
1077   endif
1078   ifeq ($(BD_MODTYPE$(BDID)),mui)
1079     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1080   endif
1081   ifeq ($(BD_MODTYPE$(BDID)),mcc)
1082     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1083   endif
1084   ifeq ($(BD_MODTYPE$(BDID)),mcp)
1085     BD_MODDIR$(BDID)  := $(AROS_CLASSES)/Zune
1086   endif
1087   ifeq ($(BD_MODTYPE$(BDID)),hidd)
1088     BD_MODDIR$(BDID)  := $(AROS_DRIVERS)
1089   endif
1090 endif
1092 BD_MODULE$(BDID)    := $(BD_MODDIR$(BDID))/$(BD_MODNAME$(BDID)).$(BD_MODTYPE$(BDID))
1093 BD_GENFILES$(BDID)  := $(BD_MODULE$(BDID))
1094 BD_DEPS$(BDID)      += $(BD_LINKLIBDEPS$(BDID))
1096 #MM- includes-all : %(mmake)-includes
1097 #MM %(mmake) : %(mmake)-includes %(mmake)-setup
1098 #MM %(mmake)-includes : %(mmake)-setup
1101 %(mmake)-quick : %(mmake)
1103 %(mmake) : $(BD_GENFILES$(BDID))
1106 %(mmake)-clean ::
1107         @$(ECHO) "Cleaning up for module $(BD_MODNAME$(BDID))"
1108         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID)) $(BD_REFFILE$(BDID)) \
1109             $(BD_REFFILES$(BDID))\
1110             $(addprefix $(BD_OBJDIR$(BDID))/,$(addsuffix .c,$(BD_GENFILES$(BDID)))) \
1111             $(addprefix $(GENINCDIR)/,$(BD_GENINCS$(BDID))) \
1112             $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID))) \
1113             $(BD_LINKLIBFILES$(BDID)) $(BD_LINKLIBOBJS$(BDID)) $(BD_LIBDEFSINC$(BDID)) \
1114             $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h \
1115             $(BD_ENDFILE$(BDID)).c $(BD_ENDOBJ$(BDID))
1118 %(mmake)-setup : setup-module$(BDID)
1120 #MM %(mmake)-includes : setup-clib
1122 TMP_DEPS := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1123 ifneq ($(BD_GENINCS$(BDID)),)
1124 TMP_DEPS += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp \
1125   $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID)))
1126 endif
1128 %(mmake)-includes : $(TMP_DEPS)
1129   
1130 $(TMP_DEPS) : $(BD_LIBDEFSINC$(BDID))
1132 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-linklib %(mmake)-quick %(mmake)-kobj),) # Avoid conflicts
1133 ifneq ($(dir $(BD_FILES$(BDID))),./)
1134 vpath %.c $(filter-out ./,$(dir $(BD_FUNCS$(BDID)) $(BD_FILES$(BDID))))
1135 endif
1137 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1138               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1139               compiler=%(compiler)
1140 %rule_compile basename=$(BD_ENDFILE$(BDID)) targetdir=$(BD_OBJDIR$(BDID)) \
1141               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1142               compiler=%(compiler)
1143 %rule_compile basename=$(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_functable targetdir=$(BD_OBJDIR$(BDID)) \
1144               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID)) \
1145               compiler=%(compiler)
1146 endif
1148 BD_DFILE_DEPS$(BDID) := $(BD_LIBDEFSINC$(BDID)) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h
1150 # Some include files need to be generated before the .c can be parsed.
1151 ifneq ($(filter $(TARGET),%(mmake) %(mmake)-quick %(mmake)-linklib) %(mmake)-kobj,) # Only for this target these deps are wanted
1152 $(BD_DEPS$(BDID)) : $(BD_DFILE_DEPS$(BDID))
1153 endif
1155 # Generation of the autogenerated .c and .h files.
1156 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h :
1157         @$(ECHO) "generating $@"
1158         @$(ECHO) "#define LC_LIBDEFS_FILE \"$(notdir $(BD_LIBDEFSINC$(BDID)))\"" >$@
1160 %libdefs_rule conffile=$(BD_CONFFILE$(BDID)) dest=$(BD_LIBDEFSINC$(BDID))
1162 ifneq ($(BD_ENDFILE$(BDID)),)
1163 $(BD_ENDFILE$(BDID)).c :
1164         @$(ECHO) "generating $@"
1165         @$(ECHO) "#include <libcore/libtail.c>" >$@
1166 endif
1168 %rule_genfunctable name=$(BD_MODNAME$(BDID))_functable files=$(BD_FUNCS$(BDID)) dir=$(BD_OBJDIR$(BDID)) \
1169   libdefs=$(BD_LIBDEFSINC$(BDID))
1171 # The module is linked from all the compiled .o files
1172 %rule_linkmodule module=$(BD_MODULE$(BDID)) objs="$(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID))" \
1173                  endobj=$(BD_ENDOBJ$(BDID)) err=$(BD_MODNAME).err uselibs="%(uselibs)" \
1174                  usehostlibs="%(usehostlibs)"
1176 BD_HEADER_DEPS$(BDID) := $(wildcard headers.tmpl) $(BD_LIBDEFSINC$(BDID)) \
1177             $(BD_FUNCSRCS$(BDID)) \
1178             $(SCRIPTDIR)/genshared \
1179             $(SCRIPTDIR)/genclib.awk $(SCRIPTDIR)/genpclib.awk \
1180             $(SCRIPTDIR)/gendefines.awk $(SCRIPTDIR)/genpdefines.awk
1182 # Regenerate the includes when some of the dependencies are changed
1183 $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp : $(BD_HEADER_DEPS$(BDID))
1184         @$(SCRIPTDIR)/genshared -clib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1185         @$(SCRIPTDIR)/genshared -defines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1186         @$(SCRIPTDIR)/genshared -proto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1187         @$(SCRIPTDIR)/genshared -pclib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1188         @$(SCRIPTDIR)/genshared -pdefines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1189         @$(SCRIPTDIR)/genshared -pproto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1190         @$(TOUCH) $@
1192 # Generate includes the first time they are needed
1193 $(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_private_protos.h \
1194 $(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_protos.h \
1195 $(GENINCDIR)/defines/$(BD_MODNAME$(BDID)).h \
1196 $(GENINCDIR)/proto/$(BD_MODNAME$(BDID)).h :
1197         @$(SCRIPTDIR)/genshared -clib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1198         @$(SCRIPTDIR)/genshared -proto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1199         @$(SCRIPTDIR)/genshared -pclib -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1200         @$(SCRIPTDIR)/genshared -pdefines -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1201         @$(SCRIPTDIR)/genshared -pproto -libdefsfile $(BD_LIBDEFSINC$(BDID)) -prefix $(GENINCDIR) $(BD_FUNCSRCS$(BDID))
1202         @$(TOUCH) $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp
1204 # The include files generated in $(GENINCDIR) have to be mirrored in the AROS include directory
1205 %rule_copy from=$(GENINCDIR)/clib/$(BD_MODNAME$(BDID))_protos.h to=$(AROS_INCLUDES)/clib/$(BD_MODNAME$(BDID))_protos.h
1206 %rule_copy from=$(GENINCDIR)/defines/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/defines/$(BD_MODNAME$(BDID)).h
1207 #%rule_copy from=$(GENINCDIR)/pragmas/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/pragmas/$(BD_MODNAME$(BDID)).h
1208 %rule_copy from=$(GENINCDIR)/proto/$(BD_MODNAME$(BDID)).h to=$(AROS_INCLUDES)/proto/$(BD_MODNAME$(BDID)).h
1210 MYDIRS$(BDID) := $(BD_OBJDIR$(BDID)) $(GENINCDIR) $(GENINCDIR)/clib \
1211   $(GENINCDIR)/proto $(GENINCDIR)/defines \
1212   $(GENINCDIR)/pragmas $(AROS_INCLUDES) $(AROS_INCLUDES)/clib $(AROS_INCLUDES)/proto \
1213   $(AROS_INCLUDES)/defines $(AROS_INCLUDES)/pragmas \
1214   $(BD_MODDIR$(BDID)) $(KOBJSDIR)
1216 %rule_makedirs dirs=$(MYDIRS$(BDID)) setuptarget=setup-module$(BDID)
1218 #MM %(mmake)-linklib : %(mmake)-setup setup-clib
1219 #MM %(mmake)-kobj : %(mmake)-setup setup-clib
1221 TMP_DEPS := $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_deflibdefs.h \
1222   $(BD_LIBDEFSINC$(BDID))
1223 ifneq ($(BD_GENINCS$(BDID)),)
1224 TMP_DEPS += $(BD_OBJDIR$(BDID))/$(BD_MODNAME$(BDID))_includes.stamp \
1225   $(addprefix $(AROS_INCLUDES)/,$(BD_GENINCS$(BDID)))
1226 endif
1228 %(mmake)-linklib : $(TMP_DEPS)
1229 %(mmake)-kobj : $(TMP_DEPS)
1231 # Link only when target %(mmake)-linklib otherwise for example jpeg.datatype
1232 # that depend on the jpeg library can cause to get this rule executed unwanted
1233 ifneq ($(filter $(TARGET),%(mmake)-linklib %(mmake)-kobj),)
1234 %(mmake)-linklib : $(LIBDIR)/lib$(BD_MODNAME$(BDID)).a
1235 %(mmake)-kobj : $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODTYPE$(BDID)).o
1237 %rule_link_linklib libname=$(BD_MODNAME$(BDID)) libdir=$(LIBDIR) \
1238   objs="$(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID)) $(BD_ENDOBJ$(BDID))"
1240 $(KOBJSDIR)/$(BD_MODNAME$(BDID))_$(BD_MODTYPE$(BDID)).o : \
1241 $(BD_INITOBJ$(BDID)) $(BD_OBJS$(BDID)) $(BD_ENDOBJ$(BDID))
1242         @$(ECHO) "Linking $@"
1243         $(AROS_LD) -Ur -o $@ $^
1244         $(OBJCOPY) $@ `$(NM_PLAIN) $@ | $(AWK) '$$3 ~ /^__.*_(LIST|END)__$$/ {print "-L " $$3;}'`
1245 endif
1247 %include_deps depstargets="%(mmake) %(mmake)-quick %(mmake)-linklib %(mmake)-kobj" deps=$(BD_DEPS$(BDID))
1248 %end
1249 #------------------------------------------------------------------------------
1252 #------------------------------------------------------------------------------
1253 # Build a linklib.
1254 # - mmake is the mmaketarget
1255 # - libname is the baselibname e.g. lib%(libname).a will be created
1256 # - files are the C source files to include in the lib. The list of files
1257 #   has to be given without the .c suffix
1258 # - asmfiles are the asm files to include in the lib. The list of files has to
1259 #   be given with the .s suffix
1260 # - cflags are the flags to compile the source (default $(CFLAGS))
1261 # - dflags are the flags use during makedepend (default equal to cflags)
1262 # - aflags are the flags use during assembling (default $(AFLAGS))
1263 # - objdir is where the .o are generated
1264 # - libdir is the directory where the linklib will be placed (default $(LIBDIR))
1265 %define build_linklib mmake=/A libname=/A files="$(basename $(wildcard *.c))" \
1266   asmfiles= cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) objdir=$(OBJDIR) libdir=$(LIBDIR)
1268 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean"
1270 # assign and generate the local variables used in this macro
1271 BD_LIBNAME$(BDID)    := %(libname)
1272 OBJDIR               ?= $(GENDIR)/$(CURDIR)
1273 BD_OBJDIR$(BDID)     := %(objdir)
1274 BD_LIBDIR$(BDID)     := %(libdir)
1276 BD_FILES$(BDID)      := %(files)
1277 BD_ASMFILES$(BDID)   := %(asmfiles)
1278 BD_SRCS$(BDID)       := $(addsuffix .c,$(BD_FILES$(BDID)))
1279 BD_OBJS$(BDID)       := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir $(BD_FILES$(BDID)) $(BD_ASMFILES$(BDID)))))
1280 BD_DEPS$(BDID)       := $(patsubst %.o,%.d,$(BD_OBJS$(BDID)))
1282 BD_CFLAGS$(BDID)     := %(cflags)
1283 ifeq (%(dflags),)
1284 BD_DFLAGS$(BDID)     := $(BD_CFLAGS$(BDID))
1285 else
1286 BD_DFLAGS$(BDID)     := %(dflags)
1287 endif
1288 BD_AFLAGS$(BDID)     := %(aflags)
1290 BD_LINKLIB$(BDID)    := $(BD_LIBDIR$(BDID))/lib$(BD_LIBNAME$(BDID)).a
1292 .PHONY : setup-linklib$(BDID)
1294 #MM %(mmake) : %(mmake)-setup
1296 %(mmake) : $(BD_LINKLIB$(BDID))
1299 %(mmake)-setup : setup-linklib$(BDID)
1302 %(mmake)-clean ::
1303         @$(RM) $(BD_OBJS$(BDID)) $(BD_DEPS$(BDID))
1305 %rule_makedirs dirs="$(BD_OBJDIR$(BDID)) $(BD_LIBDIR$(BDID))" \
1306                setuptarget=setup-linklib$(BDID)
1308 ifeq ($(TARGET),%(mmake))
1309 ifneq ($(dir $(BD_FILES$(BDID))),./)
1310 vpath %.c $(filter-out ./,$(dir $(BD_FILES$(BDID))))
1311 endif
1313 %rule_compile basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1314               cflags=$(BD_CFLAGS$(BDID)) dflags=$(BD_DFLAGS$(BDID))
1315 %rule_assemble basename=% targetdir=$(BD_OBJDIR$(BDID)) \
1316                flags=$(BD_AFLAGS$(BDID))
1317 endif
1319 %rule_link_linklib libname=%(libname) objs=$(BD_OBJS$(BDID)) libdir=$(BD_LIBDIR$(BDID))
1321 %include_deps depstargets=%(mmake) deps=$(BD_DEPS$(BDID))
1322 %end
1323 #------------------------------------------------------------------------------
1326 #------------------------------------------------------------------------------
1327 # Build catalogs.
1328 # - mmake is the mmaketarget
1329 # - catalogs is the list of catalogs, without the .ct suffix (default *.ct)
1330 # - description is the catalog description file (.cd) (default *.cd)
1331 # - subdir is the destination subdir of the catalogs
1332 # - name is the name of the destination catalog, without the .catalog suffix
1333 # - source is the path to the generated source code file
1334 # - dir is the base destination directory (default $(AROS_CATALOGS))
1335 # - sourcedescription is the path to the FlexCat's source description file, without the .sd suffix
1337 %define build_catalogs mmake=/A name=/A subdir=/A \
1338  catalogs="$(basename $(wildcard *.ct))" source="../strings.h" \
1339  description="$(basename $(wildcard *.cd))" dir=$(AROS_CATALOGS) \
1340  sourcedescription="$(TOOLDIR)/C_h_orig"
1342 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean"
1344 BD_SRCS$(BDID) := $(foreach name, %(catalogs), $(name).ct)
1345 BD_OBJS$(BDID) := $(foreach name, %(catalogs), %(dir)/$(name)/%(subdir)/%(name).catalog)
1346 BD_DIRS$(BDID) := $(foreach name, %(catalogs), %(dir)/$(name)/%(subdir))
1348 #MM %(mmake) : %(mmake)-setup
1350 %(mmake) : $(BD_OBJS$(BDID)) %(source)
1352 #MM %(mmake)-setup
1353 %rule_makedirs dirs=$(BD_DIRS$(BDID)) setuptarget=%(mmake)-setup
1355 %(dir)/%/%(subdir)/%(name).catalog : %.ct %(description).cd
1356         @$(ECHO) "Creating %(name) catalog for language $*."
1357         @$(FLEXCAT) %(description).cd $*.ct CATALOG=%(dir)/$*/%(subdir)/%(name).catalog || [ $$? -lt 10 ]
1359 ifneq (%(source),)
1360 %(source) : %(description).cd
1361         @$(ECHO) "Creating %(name) catalog source file %(source)"
1362         @$(FLEXCAT) %(description).cd %(source)=%(sourcedescription).sd
1363 endif
1366 %(mmake)-clean ::
1367         $(RM) $(BD_OBJS$(BDID)) %(source)
1369 .PHONY: %(mmake) %(mmake-setup) %(mmake-clean)
1371 %end
1373 #-----------------------------------------------------------------------------
1375 #-----------------------------------------------------------------------------
1376 # Build icons.
1377 # - mmake is the mmaketarget
1378 # - icons is a list of icon base names (ie. without the .info suffix)
1379 # - dir is the destination directory
1380 #-----------------------------------------------------------------------------
1382 %define build_icons mmake=/A icons=/A dir=/A
1384 %buildid targets="%(mmake) %(mmake)-setup %(mmake)-clean"
1386 BD_OBJS$(BDID) := $(foreach icon, %(icons), %(dir)/$(icon).info)
1388 #MM %(mmake) : %(mmake)-setup
1390 %(mmake) : $(BD_OBJS$(BDID))
1392 %(dir)/%.info : %.info.src %.png
1393         @$(ECHO) Creating $(notdir $@)...
1394         @$(ILBMTOICON) $+ $@
1396 #MM %(mmake)-setup
1397 %rule_makedirs dirs=%(dir) setuptarget=%(mmake)-setup
1400 %(mmake)-clean ::
1401         @$(RM) $(BD_OBJS$(BDID))
1403 .PHONY: %(mmake)
1405 %end
1407 #-----------------------------------------------------------------------------
1409 #------------------------------------------------------------------------------
1410 # Compile files for a arch specific replacement of code for a module
1411 # - files: the basename of the C files to compile.
1412 # - asmfiles: the basename of the asm file to assemble.
1413 # - mainmmake: the mmake of the module in the main directory to compile these
1414 #   arch specific files for.
1415 # - maindir: the object directory for the main module
1416 # - arch: the arch for which to compile these files. It can has to have the form
1417 #   of ARCH, CPU or ARCH-CPU, e.g. linux, i386 or linux-i386
1418 # - cflags (default $(CFLAGS)): the C flags to use for compilation
1419 # - dflags: the flags used during creation of dependency file. If not specified
1420 #   the same value as cflags will be used
1421 # - aflags: the flags used during assembling
1422 # - compiler: (host or target) specifies which compiler to use. By default
1423 #   the target compiler is used
1424 %define build_archspecific files= asmfiles= mainmmake=/A maindir=/A arch=/A \
1425 cflags=$(CFLAGS) dflags= aflags=$(AFLAGS) compiler=target modulename=
1427 ifeq (%(files) %(asmfiles),)
1428   $(error no files or asmfiles given)
1429 endif
1431 %buildid targets="%(mainmmake)-%(arch) %(mainmmake)-%(arch)-setup"
1433 #MM- %(mainmmake) : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1434 #MM- %(mainmmake)-linklib : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1435 #MM- %(mainmmake)-kobj : %(mainmmake)-$(ARCH)-$(CPU) %(mainmmake)-$(ARCH) %(mainmmake)-$(CPU)
1437 #MM %(mainmmake)-%(arch) : %(mainmmake)-%(arch)-setup %(mainmmake)-includes
1439 ifeq (%(arch),)
1440   $(error argument arch has to be non empty for the rule_compile_archspecific macro)
1441 endif
1443 BD_OBJDIR$(BDID)  := $(GENDIR)/%(maindir)/arch
1444 BD_COBJS$(BDID)   := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1445 BD_ASMOBJS$(BDID) := $(addsuffix .o,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(asmfiles))))
1446 BD_OBJS$(BDID)    := $(BD_COBJS$(BDID)) $(BD_ASMOBJS$(BDID))
1447 BD_DEPS$(BDID)    := $(addsuffix .d,$(addprefix $(BD_OBJDIR$(BDID))/,$(notdir %(files))))
1449 ifeq ($(TARGET),%(mainmmake)-%(arch))
1450 vpath %.c $(filter-out ./,$(dir %(files)))
1451 vpath %.s $(filter-out ./,$(dir %(asmfiles)))
1452 vpath %.S $(filter-out ./,$(dir %(asmfiles)))
1453 endif
1455 #MM %(mainmmake)-%(arch)-setup
1456 %rule_makedirs dirs=$(BD_OBJDIR$(BDID)) setuptarget=%(mainmmake)-%(arch)-setup
1459 %(mainmmake)-%(arch) :: $(BD_OBJS$(BDID))
1461 #MM %(mainmmake)-%(arch)-setup
1462 %rule_makedirs dirs=$(BD_OBJDIR$(BDID)) setuptarget=%(mainmmake)-%(arch)-setup
1464 ifeq ($(findstring %(compiler),host target),)
1465   $(error unknown compiler %(compiler))
1466 endif
1467 ifeq (%(compiler),target)
1468 $(BD_COBJS$(BDID)) : TMP_CMD:=$(TARGET_CC)
1469 endif
1470 ifeq (%(compiler),host)
1471 $(BD_COBJS$(BDID)) : TMP_CMD:=$(HOST_CC)
1472 endif
1473 ifneq (%(modulename),)
1474 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags) -I$(GENDIR)/%(maindir) \
1475                      --include $(GENDIR)/%(maindir)/%(modulename)_deflibdefs.h
1476 else
1477 $(BD_COBJS$(BDID)) : TMP_CFLAGS:=%(cflags)
1478 endif
1479 ifeq ($(TARGET),%(mainmmake)-%(arch))
1480 $(BD_OBJDIR$(BDID))/%.o : %.c
1481         %compile_q opt=$(TMP_CFLAGS) cmd=$(TMP_CMD)
1482 endif
1484 ifeq (%(dflags),)
1485 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(cflags)
1486 else
1487 $(BD_DEPS$(BDID)) : TMP_DFLAGS:=%(dflags)
1488 endif
1489 ifeq ($(TARGET),%(mainmmake)-%(arch))
1490 $(BD_OBJDIR$(BDID))/%.d : %.c
1491         %mkdepend_q flags=$(TMP_DFLAGS)
1492 endif
1494 $(BD_ASMOBJS$(BDID)) : AFLAGS:=%(aflags)
1496 ifeq ($(TARGET),%(mainmmake)-%(arch))
1497 $(BD_OBJDIR$(BDID))/%.o : %.s
1498         %assemble_q opt=$(AFLAGS)
1499 $(BD_OBJDIR$(BDID))/%.o : %.S
1500         %assemble_q opt=$(AFLAGS)
1501 endif
1503 %include_deps depstargets=%(mainmmake)-%(arch) deps=$(BD_DEPS$(BDID))
1504 %end
1505 #------------------------------------------------------------------------------
1513 # ======================
1514 # Old stuff, will probably be removed in the future
1519 # GNU Make automatic variables
1520 # $@ current target
1521 # $< First dependency
1522 # $? All newer dependencies
1523 # $^ All dependencies
1524 # $* The stem (ie. target is dir/a.foo.b and the pattern is
1525 #    a.%.b, then the stem is dir/foo)
1527 #------------------------------------------------------------------------------
1528 # rule to generate libdefs.h with archtool (options may go away!)
1529 %define libdefs_rule conffile=lib.conf genlibdefstool=$(ARCHTOOL) dest=libdefs.h
1530 %(dest) : %(conffile) %(genlibdefstool)
1531         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1532         @%(genlibdefstool) -c -o $@ %(conffile)
1533 %end
1536 #------------------------------------------------------------------------------
1537 # generate asm files from c files (for debugging purposes)
1538 %define ctoasm_q
1539 %.s : %.c
1540         @$(ECHO) "Generating $(CURDIR)/$(notdir $@)..."
1541         @$(TARGET_CC) -S $(CFLAGS) $< -c -o $@
1542 %end
1544 #------------------------------------------------------------------------------
1545 # Convert two png images to an Amiga icon file based on the description
1546 # file %(from), with outputfile going to %(to).
1547 %define makeicon2 from=$< to=$@ img1="$(basename $(basename $<))_N.png" img2="$(basename $(basename $<))_S.png"
1548         @$(ECHO) "Creating icon %(to)..."
1549         @$(PNGTOPNM) %(img1) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon1.iff
1550         @$(PNGTOPNM) %(img2) | $(PPMTOILBM) -maxplanes 8 >$(GENDIR)/genicon2.iff
1551         @$(ILBMTOICON) %(from) $(GENDIR)/genicon1.iff $(GENDIR)/genicon2.iff %(to)
1552 %end
1554 #------------------------------------------------------------------------------
1555 # NOTE: The following are all part of Iain's build changes, please don't use
1556 # or change anything below this line until you know what you are doing. This
1557 # is so that I don't conflict with the semantics of any of the above macros.
1558 #------------------------------------------------------------------------------
1560 #------------------------------------------------------------------------------
1561 # Copy files from one directory to another.
1563 %define copy_files_q files=$(FILES) src=. dst=/A maketarget=files-copy
1565 SRC_FILES := $(foreach f, %(files), %(src)/$(f))
1566 DST_FILES := $(foreach f, %(files), %(dst)/$(f))
1568 %(maketarget) : setup $(DST_FILES)
1570 $(DST_FILES) : %(dst)/% : %(src)/%
1571         @$(CP) $< $@
1572         
1573 setup ::
1574         %mkdirs_q %(dst)
1576 %end
1578 #----------------------------------------------------------------------------------
1579 # Copy a diretory recursively to another place, preserving the original 
1580 # hierarchical structure
1582 # src: the source directory whose content will be copied
1583 # dst: the directory where to copy src's content. If not existing, it will be made.
1585 %define copy_dir_recursive mmake=/A src=$(TOP)/$(CURDIR) dst=/A
1587 %(mmake)_FILES := $(shell cd %(src); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune -o -type f -print)
1588 %(mmake)_DIRS  := $(sort $(foreach f,$(%(mmake)_FILES),$(dir $(f))))
1590 define %(mmake)_mkdir
1591 $(1):
1592         $(MKDIR) $$@
1593 endef
1595 define %(mmake)_copy
1596 $(3)/$(1): $(2)/$(1) | $(dir $(3)/$(1))
1597         $(CP) $$< $$@
1598 endef
1600 .PHONY : %(mmake)
1603 %(mmake): | $(GENDIR)/$(CURDIR)
1604         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";        \
1605         $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m 
1606         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";    \
1607         for d in $(%(mmake)_DIRS); do                      \
1608             $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m;  \
1609         done
1610         @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak";                           \
1611         for f in $(%(mmake)_FILES); do                                            \
1612             $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$\$$(@D); $(CP) \$$< \$$@" >> $$m; \
1613         done;  \
1614         for dst in %(dst); do \
1615             $(MAKE) -f $$m DST=$$dst SRC=%(src) all; \
1616         done
1618 $(GENDIR)/$(CURDIR):
1619         $(MKDIR) $@
1621 %end
1623 #------------------------------------------------------------------------------
1624 #   Copy include files into the includes directories. There are currently
1625 #   two include directories. One for building AROS $(AROS_INCLUDES) and one
1626 #   for building tools that need to run on the host system $(GENINCDIR). The
1627 #   $(GENINCDIR) path must not contain any references to the C runtime
1628 #   library header files.
1630 %define copy_includes mmake= includes=$(INCLUDE_FILES) path=. dir=include
1632 ifneq (%(dir),)
1633 INCL_FILES_1 := $(subst %(dir),$(AROS_INCLUDES)/%(path),%(includes))
1634 INCL_FILES_2 := $(subst %(dir),$(GENINCDIR)/%(path),%(includes))
1635 _INC_PATH := %(dir)/
1636 else
1637 INCL_FILES_1 := $(foreach f,%(includes),$(AROS_INCLUDES)/%(path)/$(f))
1638 INCL_FILES_2 := $(foreach f,%(includes),$(GENINCDIR)/%(path)/$(f))
1639 _INC_PATH :=
1640 endif
1642 ifneq (%(mmake),)
1643 #MM 
1644 includes-copy : %(mmake)
1647 %(mmake) : %(mmake)-includes-setup $(INCL_FILES_1) $(INCL_FILES_2)
1649 .PHONY: %(mmake)
1651 else
1653 includes-copy : includes-setup $(INCL_FILES_1) $(INCL_FILES_2)
1654 endif
1657 $(AROS_INCLUDES)/%(path)/%.h : $(_INC_PATH)%.h
1658         @$(CP) $< $@
1660 $(GENINCDIR)/%(path)/%.h : $(_INC_PATH)%.h
1661         @$(CP) $< $@
1663 ifneq (%(mmake),)
1664 %(mmake)-includes-setup : $(AROS_INCLUDES)/%(path) $(GENINCDIR)/%(path)
1666 .PHONY: %(mmake)-includes-setup
1667 else
1668 includes-setup : $(AROS_INCLUDES)/%(path) $(GENINCDIR)/%(path)
1669 endif
1671 $(AROS_INCLUDES)/%(path) $(GENINCDIR)/%(path) :
1672         %mkdir_q dir=$@
1674 ,PHONY: includes-copy includes-setup
1676 %end
1678 %define make_hidd_stubs hidd=/A cflags=$(CFLAGS) dflags=$(CFLAGS) parenttarget=linklibs
1679 STUBS_SRC := $(foreach f,$(STUBS),$(f).c)
1680 STUBS_OBJ := $(foreach f,$(STUBS),$(OBJDIR)/$(f).o)
1681 STUBS_MEM := $(foreach f,$(STUBS),$(f).o)
1682 STUBS_DEP := $(foreach f,$(STUBS),$(OBJDIR)/$(f).d)
1683 HIDD_LIB := $(AROS_LIB)/libhiddstubs.a
1685 #MM- linklibs : hidd-%(hidd)-stubs
1686 #MM- %(parenttarget): hidd-%(hidd)-stubs
1687 #MM hidd-%(hidd)-stubs : includes includes-copy
1688 hidd-%(hidd)-stubs : setup $(HIDD_LIB)($(STUBS_MEM))
1690 $(HIDD_LIB)($(STUBS_MEM)) : $(STUBS_OBJ)
1691         %mklib_q from=$^
1693 $(STUBS_OBJ) : $(STUBS_SRC) 
1694         %compile_q cmd=$(TARGET_CC) opt=%(cflags)
1696 $(STUBS_DEP) : $(STUBS_SRC)
1697         %mkdepend_q flags=%(dflags)
1699 setup ::
1700         %mkdirs_q $(OBJDIR) $(LIBDIR)
1703 clean ::
1704         -@$(RM) $(HIDD_LIB) $(OBJDIR)
1706 DEPS := $(DEPS) $(STUBS_DEP)
1708 %end
1709       
1710 #------------------------------------------------------------------------------
1711 # Build an imported source tree which uses the configure script from the
1712 # autoconf package.  This rule will try to "integrate" the produced files as
1713 # much as possible in the AROS build, for exampley by putting libraries in the
1714 # standard library directory, includes in the standard include directory, and
1715 # so on. You can however override this behaviour.
1717 # As a special "bonus" for you, the PROGDIR environment variable is defined to
1718 # be %(bindir) (or its deduced value) when running "make install", and
1719 # "PROGDIR:" when running "make" alone; you can use this feature to pass the
1720 # configure script some more parameters whose value depends upon the PROGDIR
1721 # env var, so that the program gets all its stuff installed in the proper place
1722 # when building it, but when running it from inside AROS it can also find that
1723 # stuff by simply opening PROGDIR:, which it will do automatically if it uses
1724 # the configuration parameters set when running ./configure
1726 # *NOTICE*: DO NOT put a trailing '/' (slash) after $PROGDIR, as the variable
1727 # already contains either a '/' (slash) or a ':' (colon), thus simply attach it
1728 # to the name which has to follow it.
1731 %define build_with_configure mmake=/A srcdir=$(TOP)/$(CURDIR) prefix= aros_prefix= \
1732     extraoptions= nix_dir_layout= nix=no host=no \
1733     install_target=install postconfigure= postinstall=
1735 ifneq (%(prefix),)
1736     %(mmake)-prefix := %(prefix)
1737 else
1738     %(mmake)-prefix := $(AROS_CONTRIB)
1739 endif
1741 ifneq (%(aros_prefix),)
1742     %(mmake)-aros_prefix := %(aros_prefix)
1743 else
1744     %(mmake)-aros_prefix := $(%(mmake)-prefix)
1745 endif
1747 ifeq (%(nix),yes)
1748     %(mmake)-nix    := -nix
1749     %(mmake)-volpfx := /
1750     %(mmake)-volsfx := /
1751     
1752     ifeq (%(nix_dir_layout),)
1753         %(mmake)-nix_dir_layout := yes
1754     endif
1755 else
1756     %(mmake)-volsfx := :
1757     
1758     ifeq (%(nix_dir_layout),)
1759         %(mmake)-nix_dir_layout := no
1760     endif
1761 endif
1763 %(mmake)-volfunc = $(%(mmake)-volpfx)$(notdir $1)$(%(mmake)-volsfx)
1765 %(mmake)-install_opts := prefix=$(%(mmake)-prefix) exec_prefix=$(%(mmake)-prefix)
1767 ifeq ($(filter yes, $(%(mmake)-nix_dir_layout) %(host)),yes)
1768     %(mmake)-PROGDIR      := $(%(mmake)-aros_prefix)/bin
1769     %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1770 else
1771     ifeq (%(nix),yes)
1772         %(mmake)-config_opts := --prefix=/PROGDIR  --bindir=/PROGDIR --sbindir=/PROGDIR \
1773         --libdir=/LIB --includedir=/INCLUDE --oldincludedir=/INCLUDE   
1774     else
1775         %(mmake)-config_opts  := --prefix=$(%(mmake)-aros_prefix)
1776     endif
1778     %(mmake)-PROGDIR := $(%(mmake)-aros_prefix)
1779     
1780     %(mmake)-install_opts := bindir=$(%(mmake)-prefix) sbindir=$(%(mmake)-prefix) \
1781     libdir=$(AROS_LIB) includedir=$(AROS_INCLUDES) oldincludedir=$(AROS_INCLUDES)
1782 endif
1785 .PHONY : %(mmake) %(mmake)-setup %(mmake)-clean %(mmake)-build_and_install-quick
1787 #MM- %(mmake) : setup includes linklibs-core %(mmake)-quick
1789 ifneq (%(install_target),)
1790     %(mmake)-install_command = \
1791         $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1792         -C $(GENDIR)/$(CURDIR) %(install_target) && \
1793         $(TOUCH) $(GENDIR)/$(CURDIR)/.installed
1795     %(mmake)-uninstall_command = \
1796     $(RM) $(GENDIR)/$(CURDIR)/.installed && \
1797     $(MAKE) PROGDIR="$(%(mmake)-PROGDIR)/" $(%(mmake)-install_opts) \
1798     -C $(GENDIR)/$(CURDIR) uninstall
1799 else
1800     %(mmake)-install_command   := true
1801     %(mmake)-uninstall_command := true
1802 endif
1804 #MM- %(mmake)-quick : %(mmake)-configure %(postconfigure) %(mmake)-build_and_install-quick %(postinstall)
1807 %(mmake)-build_and_install-quick :  $(GENDIR)/$(CURDIR)/.configured
1808         if ! $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -q -C $(GENDIR)/$(CURDIR); then \
1809             $(RM)  $(GENDIR)/$(CURDIR)/.installed && \
1810             $(MAKE) PROGDIR="$(call %(mmake)-volfunc, PROGDIR)" -C $(GENDIR)/$(CURDIR) && \
1811             $(%(mmake)-install_command); \
1812         fi
1814 %(srcdir)/.files-touched:
1815         find %(srcdir) -exec $(TOUCH) -r %(srcdir)/configure '{}' \; && \
1816         $(TOUCH) $@
1819 %(mmake)-uninstall :
1820         $(%(mmake)-uninstall_command)
1822 ifneq ($(DEBUG),yes)
1823     %(mmake)-s_flag = -s
1824 endif
1827 %(mmake)-configure : $(GENDIR)/$(CURDIR)/.configured
1829 ifeq (%(host),yes)
1830 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
1831         $(RM) $@ 
1832         %mkdirs_q $(GENDIR)/$(CURDIR)
1833         cd $(GENDIR)/$(CURDIR) && \
1834         find . -name config.cache -exec $(RM) '{}' \; && \
1835         CC="$(HOST_CC)" \
1836             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) && \
1837             $(TOUCH) $@
1838 else
1839 $(GENDIR)/$(CURDIR)/.configured : %(srcdir)/.files-touched $(TOP)/$(CURDIR)/mmakefile
1840         $(RM) $@
1841         %mkdirs_q $(GENDIR)/$(CURDIR)
1842         cd $(GENDIR)/$(CURDIR) && \
1843         find . -name config.cache -exec $(RM) '{}' \; && \
1844         CC="$(TARGET_CC) $(%(mmake)-nix) $(%(mmake)-s_flag)" CC_FOR_BUILD="$(HOST_CC)" \
1845             %(srcdir)/configure $(%(mmake)-config_opts) %(extraoptions) --host=$(AROS_TARGET_CPU)-aros \
1846             --target=$(AROS_TARGET_CPU)-aros --build=local --disable-nls --without-x \
1847             --without-pic --disable-shared && \
1848             $(TOUCH) $@
1849 endif
1850         
1852 %(mmake)-clean : %(mmake)-uninstall
1853         @$(RM) $(GENDIR)/$(CURDIR)
1854 %end
1856 #############################################################################
1857 #############################################################################
1858 ##                                                                         ##
1859 ## Misciellanous macros. Everying that doesn't fin above should be put     ##
1860 ## here.                                                                   ##
1861 ##                                                                         ##
1862 #############################################################################
1863 #############################################################################
1865 #----------------------------------------------------------------------------------
1866 # Given an archive name, patches names and locations where to find them, fetch
1867 # the archive and the patches from any of those locations, unpack the archive
1868 # and then apply the patches.
1870 # Locations currently supported are http and ftp sites, plus local filesystem
1871 # directories. Supported archives are .tar.bz2 and .tar.gz. To modify this,
1872 # the fetch.sh script needs to be modified, since this macro relies on that script.
1874 # Arguments:
1876 #     - archive_origins = list of locations where to find the archive. They are tried
1877 #                         in sequence, until the archive is found and fetching it 
1878 #                         succeeded. If not specified, the current directory is assumed.
1879 #     - archive         = the archive name. Mandatory.
1880 #     - destination     = the local directory where to put the archive and patches.
1881 #                         If not specified, the current directory is assumed.
1882 #     - patches_origins = list of locations where to find the patches. They are tried
1883 #                         in sequence, until a patch is found and fetching it 
1884 #                         succeeded. If not specified, the current directory is assumed.
1885 #     - patches_specs   = list of "patch specs". A patch spec is of the form
1886 #                         patch_name[:[patch_subdir][:patch_opt]].
1887 #                         
1888 #                             - patch_name   = the name of the patch file
1889 #                             - patch_subdir = the directory within \destination\ where to
1890 #                                              apply the patch.
1891 #                             - patch_opt    = any options to pass to the `patch' command
1892 #                                              when applying the patch.
1893 #                         
1894 #                         The patch_subdir and patch_opt fields are optional.
1896 %define fetch archive_origins=. archive=/A suffixes= destination=. patches_origins=. patches_specs=::
1897         $(FETCH) -ao "%(archive_origins)" -a %(archive) -as "%(suffixes)" -d %(destination) \
1898         -po "%(patches_origins)" -p %(patches_specs)
1899 %end
1901 #-----------------------------------------------------------------------------------------
1902 # Joins the features of %fetch and %build_with_configure, taking advantage of
1903 # the naming scheme of GNU packages. GNU packages names are in the form
1905 #     <package name>-<version number>.<archive format suffix>
1907 # If a patch is provided, it *must* be named the following way:
1909 #    <package name>-<version number>-aros.diff
1911 # Moreover, it *must* be appliable with the -p1 option of the `patch' command after
1912 # CD'ing into the archive's extracted directory.
1914 # Note that whilst the %fetch macro accepts a list of patches for any given archive,
1915 # the %fetch_and_build macro only accept *one* patch for each package. It's up to you
1916 # to make that patch fully comprehensive.
1918 # NOTE: GNU packages are always compiled with *nix semantics turned on.
1920 # Arguments:
1922 #    - mmake        = the meta make target, as would be supplied to the %build_with_configure
1923 #                     macro.
1924 #    - package      = the GNU package name, sans version and archive format suffixes.
1925 #    - version      = the package's version number, or otherwise any other version string.
1926 #                     It gets appended to the package name to form the basename of the archive.
1927 #    - suffixes     = a list of suffixes to apped to the the package name plus the
1928 #                     version. Each one of them is tried until a matching archive is found.
1929 #                     Defaults to "tat.bz2 tar.gz".
1930 #    - destination  = same meaning as the one for the %fetch macro
1931 #    - package_repo = same meaning as the one of the %fetch macro's %(archive_origins) argument
1932 #    - patch        = "yes" or "no", depending on whether a patch for this package needs to be
1933 #                     fetched or not
1934 #    - patch_repo   = same meaning as the one of the %fetch macro's %(patches_origins) argument
1935 #    - prefix       = same meaning as the one for the %build_with_configure macro. Defaults to
1936 #                     $(GNUDIR).
1937 #    - aros_prefix  = same meaning as the one for the %build_with_configure macro. Defaults to
1938 #                     /GNU.
1939 #    - extraoptions = same meaning as the one for the %build_with_configure macro.
1940 #    - postinstall  = same meaning as the one for the %build_with_configure macro.
1942 %define fetch_and_build mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
1943     srcdir= package_repo= patch=no patch_repo= prefix= \
1944     aros_prefix= extraoptions= postconfigure= postinstall= nix=no nix_dir_layout=
1946 #MM- %(mmake)-quick : %(mmake)-%(subpackage)-quick
1947 #MM- %(mmake)-%(subpackage)-quick : %(mmake)-%(subpackage)-fetch
1949 %(mmake)-archbase  := %(package)-%(version)
1951 ifeq (%(prefix),)
1952     %(mmake)-prefix := $(CONTRIB_DIR)/%(package)
1953 else
1954     %(mmake)-prefix := %(prefix)
1955 endif
1957 ifneq (%(subpackage),)
1958     %(mmake)-%(subpackage)-archbase  := %(package)-%(subpackage)-%(version)
1959 else
1960     %(mmake)-%(subpackage)-archbase  := %(package)-%(version)
1961 endif
1963 ifneq (%(srcdir),)
1964     %(mmake)-%(subpackage)-srcdir  := %(srcdir)
1965 else
1966     %(mmake)-%(subpackage)-srcdir  := $(%(mmake)-archbase)
1967 endif
1969 ifeq (%(patch),yes)
1970     %(mmake)-%(subpackage)-patches_specs := $(%(mmake)-%(subpackage)-archbase)-aros.diff:$(%(mmake)-%(subpackage)-srcdir):-p1    
1971 else
1972     %(mmake)-%(subpackage)-patches_specs := ::
1973 endif
1975 #MM- %(mmake)-fetch : %(mmake)-%(subpackage)-fetch
1977 .PHONY : %(mmake)-%(subpackage)-fetch
1979 %(mmake)-%(subpackage)-fetch :
1980         %fetch archive=$(%(mmake)-%(subpackage)-archbase) suffixes="%(suffixes)" \
1981             destination=$(PORTSDIR)/%(package) \
1982             archive_origins=". %(package_repo)" \
1983             patches_specs="$(%(mmake)-%(subpackage)-patches_specs)" patches_origins=". %(patch_repo)"
1985 #MM- %(mmake) : %(mmake)-%(subpackage)
1987 PACKAGES_DIR := $(AROSDIR)/../Packages
1989 %(mmake)-%(subpackage)-package-dir := $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)
1991 %(mmake)-%(subpackage)-package-basename := \
1992     $(PACKAGES_DIR)/$(%(mmake)-%(subpackage)-archbase)-aros-bin.$(AROS_TARGET_CPU)
1994 %build_with_configure mmake=%(mmake)-%(subpackage) \
1995      srcdir=$(PORTSDIR)/%(package)/$(%(mmake)-%(subpackage)-srcdir) \
1996      nix=%(nix) nix_dir_layout=%(nix_dir_layout) prefix="$(%(mmake)-%(subpackage)-package-dir)" \
1997      aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall) \
1998      %(mmake)-%(subpackage)-make-package"  extraoptions="%(extraoptions)"
2000 .PHONY : %(mmake)-%(subpackage)-make-package
2001 #MM %(mmake)-%(subpackage)-make-package : %(mmake)-%(subpackage)-quick
2004 %(mmake)-%(subpackage)-make-package : $(%(mmake)-%(subpackage)-package-basename).tar.bz2
2006 #There seems to be a bug, either with my clock or with make, 'cause it may happen
2007 #that $^ and $@ have exactly the same mtime, and in that case make tries
2008 #to rebuild $@ again, which would fail because the directory where
2009 #the package got installed would not exist anymore. 
2010 #We work this around by using an if statement to manually check the mtimes.
2011 $(%(mmake)-%(subpackage)-package-basename).tar.bz2 :
2012         @if test $(GENDIR)/$(CURDIR)/.installed -nt $@ || ! test -f $@; then \
2013             $(RM) $@ && \
2014             $(ECHO) "Building \`$(%(mmake)-%(subpackage)-package-basename).tar.bz2'" && \
2015             cd $(%(mmake)-%(subpackage)-package-dir) && \
2016             tar --remove-files -cvf $(%(mmake)-%(subpackage)-package-basename).tar * && \
2017             mkdir -p "$(%(mmake)-prefix)" && \
2018             tar -xf $(%(mmake)-%(subpackage)-package-basename).tar -C "%(prefix)"/ && \
2019             bzip2 -9 -f $(%(mmake)-%(subpackage)-package-basename).tar && \
2020             cd .. && $(RM) $(%(mmake)-%(subpackage)-archbase); \
2021         fi
2022 %end
2024 %define fetch_and_build_gnu mmake=/A package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2025     srcdir= package_repo= patch=no patch_repo= prefix=$(GNUDIR) \
2026     aros_prefix=/GNU extraoptions= postconfigure= postinstall= 
2028 GNU_REPOSITORY := http://ftp.gnu.org/pub/gnu
2030 %fetch_and_build mmake="%(mmake)" package="%(package)" subpackage="%(subpackage)" version="%(version)" \
2031     suffixes="%(suffixes)" srcdir="%(srcdir)" \
2032     package_repo="%(package_repo) $(GNU_REPOSITORY)/%(package)" \
2033     patch="%(patch)" patch_repo="%(patch_repo)" \
2034     prefix="%(prefix)" aros_prefix="%(aros_prefix)" extraoptions="%(extraoptions)" \
2035     postconfigure="%(postconfigure)" postinstall="%(postinstall)" nix=yes
2037 %end
2039 #-----------------------------------------------------------------------------------------
2040 # Same job as the one of %fetch_and_build_gnu, except that this one assumes
2041 # that the package is a "Development" package, and as such it needs to be placed
2042 # under the $(AROS_DEVELOPMENT) directory, as a default. 
2044 # All the arguments have the same meaning as the ones of the %fetch_and_build_gnu 
2045 # macro, but notice that %fetch_and_build_gnu_development *doesn't* have a
2046 # "mmake" argument, because the metatarget is implicitely defined as
2048 #     #MM- development-%(package)
2050 %define fetch_and_build_gnu_development package=/A subpackage= version=/A suffixes="tar.bz2 tar.gz" \
2051     srcdir= package_repo= patch=no patch_repo= prefix=$(AROS_DEVELOPMENT) \
2052     aros_prefix=/Development postconfigure= postinstall=  extraoptions= 
2054 #MM- development : development-%(package)
2057 %fetch_and_build_gnu mmake=development-%(package) package=%(package) subpackage="%(subpackage)" \
2058    version=%(version) suffixes="%(suffixes)" srcdir="%(srcdir)"  \
2059    package_repo="%(package_repo)" patch="%(patch)" patch_repo="%(patch_repo)" prefix=%(prefix) \
2060    aros_prefix="%(aros_prefix)" postconfigure="%(postconfigure)" postinstall="%(postinstall)" \
2061    extraoptions="%(extraoptions)"
2062     
2063 %end