Debian Codegraph @

libs/zziplib/zziplib-src/m4/ax_enable_builddir.m4

raw
1 dnl @synopsis AX_ENABLE_BUILDDIR [(dirstring-or-command [,Makefile.mk [,-all]])]
2 dnl
3 dnl if the current configure was run within the srcdir then we move all
4 dnl configure-files into a subdir and let the configure steps continue
5 dnl there. We provide an option --disable-builddir to suppress the move
6 dnl into a separate builddir.
7 dnl
8 dnl Defaults:
9 dnl
10 dnl $1 = $host (overridden with $HOST)
11 dnl $2 = Makefile.mk
12 dnl $3 = -all
13 dnl
14 dnl This macro must be called before AM_INIT_AUTOMAKE.
15 dnl
16 dnl it creates a default toplevel srcdir Makefile from the information
17 dnl found in the created toplevel builddir Makefile. It just copies the
18 dnl variables and rule-targets, each extended with a default
19 dnl rule-execution that recurses into the build directory of the
20 dnl current "HOST". You can override the auto-dection through
21 dnl `config.guess` and build-time of course, as in
22 dnl
23 dnl make HOST=i386-mingw-cross
24 dnl
25 dnl which can of course set at configure time as well using
26 dnl
27 dnl configure --host=i386-mingw-cross
28 dnl
29 dnl After the default has been created, additional rules can be
30 dnl appended that will not just recurse into the subdirectories and
31 dnl only ever exist in the srcdir toplevel makefile - these parts are
32 dnl read from the $2 = Makefile.mk file
33 dnl
34 dnl The automatic rules are usually scanning the toplevel Makefile for
35 dnl lines like '#### $host |$builddir' to recognize the place where to
36 dnl recurse into. Usually, the last one is the only one used. However,
37 dnl almost all targets have an additional "*-all" rule which makes the
38 dnl script to recurse into _all_ variants of the current HOST (!!)
39 dnl setting. The "-all" suffix can be overridden for the macro as well.
40 dnl
41 dnl a special rule is only given for things like "dist" that will copy
42 dnl the tarball from the builddir to the sourcedir (or $(PUB)) for
43 dnl reason of convenience.
44 dnl
45 dnl @category Misc
46 dnl @author Guido Draheim
47 dnl @version 2007-02-01
48 dnl @license GPLWithACException
49
50 AC_DEFUN([AX_ENABLE_BUILDDIR],[
51 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
52 AC_REQUIRE([AX_CONFIGURE_ARGS])[]dnl
53 AC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
54 AS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
55 AS_VAR_PUSHDEF([AUX],[ax_enable_builddir_auxdir])dnl
56 AS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
57 SUB="."
58 AC_ARG_ENABLE([builddir], AC_HELP_STRING(
59 [--disable-builddir],[disable automatic build in subdir of sources])
60 ,[SUB="$enableval"], [SUB="yes"])
61 if test ".$ac_srcdir_defaulted" != ".no" ; then
62 if test ".$srcdir" = ".." ; then
63 if test -f config.status ; then
64 AC_MSG_NOTICE(toplevel srcdir already configured... skipping subdir build)
65 else
66 test ".$SUB" = "." && SUB="."
67 test ".$SUB" = ".no" && SUB="."
68 test ".$TARGET" = "." && TARGET="$target"
69 test ".$SUB" = ".yes" && SUB="m4_ifval([$1], [$1],[$TARGET])"
70 if test ".$SUB" != ".." ; then # we know where to go and
71 AS_MKDIR_P([$SUB])
72 echo __.$SUB.__ > $SUB/conftest.tmp
73 cd $SUB
74 if grep __.$SUB.__ conftest.tmp >/dev/null 2>/dev/null ; then
75 rm conftest.tmp
76 AC_MSG_RESULT([continue configure in default builddir "./$SUB"])
77 else
78 AC_MSG_ERROR([could not change to default builddir "./$SUB"])
79 fi
80 srcdir=`echo "$SUB" |
81 sed -e 's,^\./,,;s,[[^/]]$,&/,;s,[[^/]]*/,../,g;s,[[/]]$,,;'`
82 # going to restart from subdirectory location
83 test -f $srcdir/config.log && mv $srcdir/config.log .
84 test -f $srcdir/confdefs.h && mv $srcdir/confdefs.h .
85 test -f $srcdir/conftest.log && mv $srcdir/conftest.log .
86 test -f $srcdir/$cache_file && mv $srcdir/$cache_file .
87 AC_MSG_RESULT(....exec $SHELL $srcdir/[$]0 "--srcdir=$srcdir" "--enable-builddir=$SUB" ${1+"[$]@"})
88 case "[$]0" in # restart
89 [/\\]*) eval $SHELL "'[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
90 *) eval $SHELL "'$srcdir/[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
91 esac ; exit $?
92 fi
93 fi
94 fi fi
95 dnl ac_path_prog uses "set dummy" to override $@ which would defeat the "exec"
96 AC_PATH_PROG(SED,gsed sed, sed)
97 AUX="$ac_aux_dir"
98 AUX=`echo "$AUX" | $SED -e "s|$ac_top_srcdir|.|"`
99 test ".$AUX" = "." && AUX="$ac_aux_dir"
100 test ".$AUX" = "." && AUX="."
101 AS_VAR_POPDEF([SED])dnl
102 AS_VAR_POPDEF([AUX])dnl
103 AS_VAR_POPDEF([SUB])dnl
104 AC_CONFIG_COMMANDS([buildir],[dnl .............. config.status ..............
105 AS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
106 AS_VAR_PUSHDEF([TOP],[top_srcdir])dnl
107 AS_VAR_PUSHDEF([SRC],[ac_top_srcdir])dnl
108 AS_VAR_PUSHDEF([AUX],[ax_enable_builddir_auxdir])dnl
109 AS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
110 pushdef([END],[Makefile.mk])dnl
111 pushdef([_ALL],[ifelse([$3],,[-all],[$3])])dnl
112 SRC="$ax_enable_builddir_srcdir"
113 if test ".$SUB" = "." ; then
114 if test -f "$TOP/Makefile" ; then
115 AC_MSG_NOTICE([skipping TOP/Makefile - left untouched])
116 else
117 AC_MSG_NOTICE([skipping TOP/Makefile - not created])
118 fi
119 else
120 if test -f "$SRC/Makefile" ; then
121 a=`grep "^VERSION " "$SRC/Makefile"` ; b=`grep "^VERSION " Makefile`
122 test "$a" != "$b" && rm "$SRC/Makefile"
123 fi
124 if test -f "$SRC/Makefile" ; then
125 echo "$SRC/Makefile : $SRC/Makefile.in" > $tmp/conftemp.mk
126 echo " []@ echo 'REMOVED,,,' >\$[]@" >> $tmp/conftemp.mk
127 eval "${MAKE-make} -f $tmp/conftemp.mk 2>/dev/null >/dev/null"
128 if grep '^REMOVED,,,' "$SRC/Makefile" >/dev/null
129 then rm $SRC/Makefile ; fi
130 cp $tmp/conftemp.mk $SRC/makefiles.mk~ ## DEBUGGING
131 fi
132 if test ! -f "$SRC/Makefile" ; then
133 AC_MSG_NOTICE([create TOP/Makefile guessed from local Makefile])
134 x='`' ; cat >$tmp/conftemp.sed <<_EOF
135 /^\$/n
136 x
137 /^\$/bS
138 x
139 /\\\\\$/{H;d;}
140 {H;s/.*//;x;}
141 bM
142 :S
143 x
144 /\\\\\$/{h;d;}
145 {h;s/.*//;x;}
146 :M
147 s/\\(\\n\\) /\\1 /g
148 /^ /d
149 /^[[ ]]*[[\\#]]/d
150 /^VPATH *=/d
151 s/^srcdir *=.*/srcdir = ./
152 s/^top_srcdir *=.*/top_srcdir = ./
153 /[[:=]]/!d
154 /^\\./d
155 s/:.*/:/
156 /:\$/s/ / /g
157 /:\$/s/ \\([[a-z]][[a-z-]]*[[a-z]]\\) / \\1 \\1[]_ALL /g
158 /:\$/s/^\\([[a-z]][[a-z-]]*[[a-z]]\\)\\([[ :]]\\)/\\1 \\1[]_ALL\\2/
159 /:\$/s/ / /g
160 /^all all[]_ALL[[ :]]/i\\
161 all-configured : all[]_ALL
162 dnl dist-all exists... and would make for dist-all-all
163 /[]_ALL[]_ALL/d
164 /^.*[[=]]/!a\\
165 @ HOST="\$(HOST)\" \\\\\\
166 ; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
167 ; BUILD=$x grep "^#### \$\$HOST " Makefile | sed -e 's/.*|//' $x \\\\\\
168 ; use=$x basename "\$\@" _ALL $x; n=$x echo \$\$BUILD | wc -w $x \\\\\\
169 ; echo "MAKE \$\$HOST : \$\$n * \$\@"; if test "\$\$n" = "0" ; then : \\\\\\
170 ; BUILD=$x grep "^####.*|" Makefile |tail -1| sed -e 's/.*|//' $x ; fi \\\\\\
171 ; test ".\$\$BUILD" = "." && BUILD="." \\\\\\
172 ; test "\$\$use" = "\$\@" && BUILD=$x echo "\$\$BUILD" | tail -1 $x \\\\\\
173 ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
174 ; (cd "\$\$i" && test ! -f configure && \$(MAKE) \$\$use) || exit; done
175 dnl special rule add-on: "dist" copies the tarball to $(PUB). (source tree)
176 /dist[]_ALL *:/a\\
177 @ HOST="\$(HOST)\" \\\\\\
178 ; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
179 ; BUILD=$x grep "^#### \$\$HOST " Makefile | sed -e 's/.*|//' $x \\\\\\
180 ; found=$x echo \$\$BUILD | wc -w $x \\\\\\
181 ; echo "MAKE \$\$HOST : \$\$found \$(PACKAGE)-\$(VERSION).tar.*" \\\\\\
182 ; if test "\$\$found" = "0" ; then : \\\\\\
183 ; BUILD=$x grep "^#### .*|" Makefile |tail -1| sed -e 's/.*|//' $x \\\\\\
184 ; fi ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
185 ; for f in \$\$i/\$(PACKAGE)-\$(VERSION).tar.* \\\\\\
186 ; do test -f "\$\$f" && mv "\$\$f" \$(PUB). ; done ; break ; done
187 dnl special rule add-on: "distclean" removes all local builddirs completely
188 /distclean[]_ALL *:/a\\
189 @ HOST="\$(HOST)\" \\\\\\
190 ; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
191 ; BUILD=$x grep "^#### .*| *\\./" Makefile | sed -e 's/.*|//' $x \\\\\\
192 ; use=$x basename "\$\@" _ALL $x; n=$x echo \$\$BUILD | wc -w $x \\\\\\
193 ; echo "MAKE \$\$HOST : \$\$n * \$\@ (all local builds)" \\\\\\
194 ; test ".\$\$BUILD" = "." && BUILD="." \\\\\\
195 ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
196 ; echo "# rm -r \$\$i"; done ; echo "# (sleep 3)" ; sleep 3 \\\\\\
197 ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
198 ; echo "rm -r \$\$i"; (rm -r "\$\$i") ; done ; rm Makefile
199 _EOF
200 cp "$tmp/conftemp.sed" "$SRC/makefile.sed~" ## DEBUGGING
201 $SED -f $tmp/conftemp.sed Makefile >$SRC/Makefile
202 if test -f "$SRC/m4_ifval([$2],[$2],[END])" ; then
203 AC_MSG_NOTICE([extend TOP/Makefile with TOP/m4_ifval([$2],[$2],[END])])
204 cat $SRC/END >>$SRC/Makefile
205 fi ; xxxx="####"
206 echo "$xxxx CONFIGURATIONS FOR TOPLEVEL MAKEFILE: " >>$SRC/Makefile
207 # sanity check
208 if grep '^; echo "MAKE ' $SRC/Makefile >/dev/null ; then
209 AC_MSG_NOTICE([buggy sed found - it deletes tab in "a" text parts])
210 $SED -e '/^@ HOST=/s/^/ /' -e '/^; /s/^/ /' $SRC/Makefile \
211 >$SRC/Makefile~
212 (test -s $SRC/Makefile~ && mv $SRC/Makefile~ $SRC/Makefile) 2>/dev/null
213 fi
214 else
215 xxxx="\\#\\#\\#\\#"
216 # echo "/^$xxxx *$ax_enable_builddir_host /d" >$tmp/conftemp.sed
217 echo "s!^$xxxx [[^|]]* | *$SUB *\$!$xxxx ...... $SUB!" >$tmp/conftemp.sed
218 $SED -f "$tmp/conftemp.sed" "$SRC/Makefile" >$tmp/mkfile.tmp
219 cp "$tmp/conftemp.sed" "$SRC/makefiles.sed~" ## DEBUGGING
220 cp "$tmp/mkfile.tmp" "$SRC/makefiles.out~" ## DEBUGGING
221 if cmp -s "$SRC/Makefile" "$tmp/mkfile.tmp" 2>/dev/null ; then
222 AC_MSG_NOTICE([keeping TOP/Makefile from earlier configure])
223 rm "$tmp/mkfile.tmp"
224 else
225 AC_MSG_NOTICE([reusing TOP/Makefile from earlier configure])
226 mv "$tmp/mkfile.tmp" "$SRC/Makefile"
227 fi
228 fi
229 AC_MSG_NOTICE([build in $SUB (HOST=$ax_enable_builddir_host)])
230 xxxx="####"
231 echo "$xxxx" "$ax_enable_builddir_host" "|$SUB" >>$SRC/Makefile
232 fi
233 popdef([END])dnl
234 AS_VAR_POPDEF([SED])dnl
235 AS_VAR_POPDEF([AUX])dnl
236 AS_VAR_POPDEF([SRC])dnl
237 AS_VAR_POPDEF([TOP])dnl
238 AS_VAR_POPDEF([SUB])dnl
239 ],[dnl
240 ax_enable_builddir_srcdir="$srcdir" # $srcdir
241 ax_enable_builddir_host="$HOST" # $HOST / $host
242 ax_enable_builddir_version="$VERSION" # $VERSION
243 ax_enable_builddir_package="$PACKAGE" # $PACKAGE
244 ax_enable_builddir_auxdir="$ax_enable_builddir_auxdir" # $AUX
245 ax_enable_builddir_sed="$ax_enable_builddir_sed" # $SED
246 ax_enable_builddir="$ax_enable_builddir" # $SUB
247 ])dnl
248 ])