1 dnl /usr/share/aclocal/guidod-cvs/ax_enable_builddir_uname.m4
2 dnl @synopsis AX_ENABLE_BUILDDIR_UNAME [(dirstring-or-command [,Makefile.mk])]
4 dnl if the current configure was run within the srcdir then we move all
5 dnl configure-files into a subdir and let the configure steps continue
6 dnl there. We provide an option --disable-builddir to suppress the move
7 dnl into a separate builddir.
11 dnl $1 = $build (defaults to `uname -msr`.d)
15 dnl This macro must be called before AM_INIT_AUTOMAKE.
17 dnl it creates a default toplevel srcdir Makefile from the information
18 dnl found in the created toplevel builddir Makefile. It just copies the
19 dnl variables and rule-targets, each extended with a default
20 dnl rule-execution that recurses into the build directory of the
21 dnl current "BUILD". You can override the auto-dection through
22 dnl `uname -msr | tr " /" "__"`.d at build-time of course, as in
24 dnl make BUILD=i386-mingw-cross
26 dnl After the default has been created, additional rules can be
27 dnl appended that will not just recurse into the subdirectories and
28 dnl only ever exist in the srcdir toplevel makefile - these parts are
29 dnl read from the $2 = Makefile.mk file
31 dnl The automatic rules are usually scanning the toplevel Makefile for
32 dnl lines like '#### $build |$builddir' to recognize the place where to
33 dnl recurse into. Usually, the last one is the only one used. However,
34 dnl almost all targets have an additional "*-all" rule which makes the
35 dnl script to recurse into _all_ variants of the current BUILD (!!)
36 dnl setting. The "-all" suffix can be overriden for the macro as well.
38 dnl a special rule is only given for things like "dist" that will copy
39 dnl the tarball from the builddir to the sourcedir (or $(PUB)) for
40 dnl reason of convenience.
43 dnl @author Guido U. Draheim
44 dnl @version 2005-12-03
45 dnl @license GPLWithACException
47 AC_DEFUN([AX_ENABLE_BUILDDIR_UNAME],[
48 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
49 AC_REQUIRE([AX_CONFIGURE_ARGS])[]dnl
50 AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
51 AS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
52 AS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
54 AC_ARG_ENABLE([builddir], AC_HELP_STRING(
55 [--disable-builddir],[disable automatic build in subdir of sources])
56 ,[SUB="$enableval"], [SUB="yes"])
57 if test ".$ac_srcdir_defaulted" != ".no" ; then
58 if test ".$srcdir" = ".." ; then
59 if test -f config.status ; then
60 AC_MSG_NOTICE(toplevel srcdir already configured... skipping subdir build)
62 test ".$SUB" = "." && SUB="."
63 test ".$SUB" = ".no" && SUB="."
64 test ".$BUILD" = "." && BUILD=`uname -msr | tr " /" "__"`.d
65 test ".$SUB" = ".yes" && SUB="m4_ifval([$1], [$1],[$BUILD])"
66 if test ".$SUB" != ".." ; then # we know where to go and
68 echo __.$SUB.__ > $SUB/conftest.tmp
70 if grep __.$SUB.__ conftest.tmp >/dev/null 2>/dev/null ; then
72 AC_MSG_RESULT([continue configure in default builddir "./$SUB"])
74 AC_MSG_ERROR([could not change to default builddir "./$SUB"])
77 sed -e 's,^\./,,;s,[[^/]]$,&/,;s,[[^/]]*/,../,g;s,[[/]]$,,;'`
78 # going to restart from subdirectory location
79 test -f $srcdir/config.log && mv $srcdir/config.log .
80 test -f $srcdir/confdefs.h && mv $srcdir/confdefs.h .
81 test -f $srcdir/conftest.log && mv $srcdir/conftest.log .
82 test -f $srcdir/$cache_file && mv $srcdir/$cache_file .
83 AC_MSG_RESULT(....exec $SHELL "$srcdir/[$]0" "--srcdir=$srcdir" "--enable-builddir=$SUB" $ac_configure_args)
84 case "[$]0" in # restart
85 [/\\]*) eval $SHELL "'[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
86 *) eval $SHELL "'$srcdir/[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
91 dnl ac_path_prog uses "set dummy" to override $@ which would defeat the "exec"
92 AC_PATH_PROG(SED,gsed sed, sed)
93 AS_VAR_POPDEF([SED])dnl
94 AS_VAR_POPDEF([SUB])dnl
95 AC_CONFIG_COMMANDS([buildir],[dnl .............. config.status ..............
96 AS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
97 AS_VAR_PUSHDEF([TOP],[top_srcdir])dnl
98 AS_VAR_PUSHDEF([SRC],[ac_top_srcdir])dnl
99 AS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
100 pushdef([END],[Makefile.mk])dnl
101 SRC="$ax_enable_builddir_srcdir"
102 if test ".$SUB" = "." ; then
103 if test -f "$TOP/Makefile" ; then
104 AC_MSG_NOTICE([skipping TOP/Makefile - left untouched])
106 AC_MSG_NOTICE([skipping TOP/Makefile - not created])
109 AC_MSG_NOTICE([create TOP/Makefile guessed from local Makefile])
110 x='`' ; cat >$tmp/conftemp.sed <<_EOF
127 s/^srcdir *=.*/srcdir = ./
128 s/^top_srcdir *=.*/top_srcdir = ./
134 /^.*[[=]]/!s%\$% ; (cd \$(BUILD) \\&\\& \$(ISNOTSRCDIR) \\&\\& \$(MAKE) "\$\@") || exit ; \$(MAKE) done "RULE=\$\@"%
136 test ".$USE_MAINTAINER_MODE" = ".no" || \
137 cp "$tmp/conftemp.sed" "$SRC/makefile.sed~" ## DEBUGGING
138 echo 'BUILD=`uname -msr | tr " /" "__"`.d' >$SRC/Makefile
139 echo 'ISNOTSRCDIR=test ! -f configure' >>$SRC/Makefile
140 $SED -f $tmp/conftemp.sed Makefile >>$SRC/Makefile
141 echo 'done: ;@ if grep "$(RULE)-done .*:" Makefile > /dev/null; then dnl
142 echo $(MAKE) $(RULE)-done ; $(MAKE) $(RULE)-done ; else true ; fi' dnl
144 if test -f "$SRC/m4_ifval([$2],[$2],[END])" ; then
145 AC_MSG_NOTICE([extend TOP/Makefile with TOP/m4_ifval([$2],[$2],[END])])
146 cat $SRC/END >>$SRC/Makefile
148 AC_MSG_NOTICE([make uses BUILD=$SUB (on $ax_enable_builddir_host:)])
151 AS_VAR_POPDEF([SED])dnl
152 AS_VAR_POPDEF([SRC])dnl
153 AS_VAR_POPDEF([TOP])dnl
154 AS_VAR_POPDEF([SUB])dnl
156 ax_enable_builddir_srcdir="$srcdir" # $srcdir
157 ax_enable_builddir_host="$HOST" # $HOST / $host
158 ax_enable_builddir_version="$VERSION" # $VERSION
159 ax_enable_builddir_package="$PACKAGE" # $PACKAGE
160 ax_enable_builddir_sed="$ax_enable_builddir_sed" # $SED
161 ax_enable_builddir="$ax_enable_builddir" # $SUB