beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / m4 / ax_enable_builddir_uname.m4
blobdf5e2639c172c6feb427bf92431ee6b2007cc9eb
1 dnl /usr/share/aclocal/guidod-cvs/ax_enable_builddir_uname.m4
2 dnl @synopsis AX_ENABLE_BUILDDIR_UNAME [(dirstring-or-command [,Makefile.mk])]
3 dnl
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.
8 dnl
9 dnl Defaults:
10 dnl
11 dnl   $1 = $build (defaults to `uname -msr`.d)
12 dnl   $2 = Makefile.mk
13 dnl   $3 = -all
14 dnl
15 dnl This macro must be called before AM_INIT_AUTOMAKE.
16 dnl
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
23 dnl
24 dnl   make BUILD=i386-mingw-cross
25 dnl
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
30 dnl
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.
37 dnl
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.
41 dnl
42 dnl @category Misc
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
53 SUB="."
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)
61   else
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
67       AS_MKDIR_P([$SUB])
68       echo __.$SUB.__ > $SUB/conftest.tmp
69       cd $SUB
70       if grep __.$SUB.__ conftest.tmp >/dev/null 2>/dev/null ; then
71         rm conftest.tmp
72         AC_MSG_RESULT([continue configure in default builddir "./$SUB"])
73       else
74         AC_MSG_ERROR([could not change to default builddir "./$SUB"])
75       fi
76       srcdir=`echo "$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 ;;
87       esac ; exit $?
88     fi
89   fi
90 fi fi
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])
105     else
106       AC_MSG_NOTICE([skipping TOP/Makefile - not created])
107     fi
108   else
109     AC_MSG_NOTICE([create TOP/Makefile guessed from local Makefile])
110      x='`' ; cat >$tmp/conftemp.sed <<_EOF
111 /^\$/n
113 /^\$/bS
115 /\\\\\$/{H;d;}
116 {H;s/.*//;x;}
120 /\\\\\$/{h;d;}
121 {h;s/.*//;x;}
123 s/\\(\\n\\)     /\\1 /g
124 /^      /d
125 /^[[    ]]*[[\\#]]/d
126 /^VPATH *=/d
127 s/^srcdir *=.*/srcdir = ./
128 s/^top_srcdir *=.*/top_srcdir = ./
129 /[[:=]]/!d
130 /^\\./d
131 s/:.*/:/
132 /:\$/s/ /  /g
133 /:\$/s/  / /g
134 /^.*[[=]]/!s%\$% ; (cd \$(BUILD) \\&\\& \$(ISNOTSRCDIR) \\&\\& \$(MAKE) "\$\@") || exit ; \$(MAKE) done "RULE=\$\@"%
135 _EOF
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
143     >> $SRC/Makefile
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
147     fi 
148     AC_MSG_NOTICE([make uses BUILD=$SUB (on $ax_enable_builddir_host:)])
149   fi
150 popdef([END])dnl
151 AS_VAR_POPDEF([SED])dnl
152 AS_VAR_POPDEF([SRC])dnl
153 AS_VAR_POPDEF([TOP])dnl
154 AS_VAR_POPDEF([SUB])dnl
155 ],[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
162 ])dnl