xref: /aosp_15_r20/external/libffi/m4/ax_enable_builddir.m4 (revision 1fd5a2e1d639cd1ddf29dd0c484c123bbd850c21)
1*1fd5a2e1SPrashanth Swaminathan# ===========================================================================
2*1fd5a2e1SPrashanth Swaminathan#    https://www.gnu.org/software/autoconf-archive/ax_enable_builddir.html
3*1fd5a2e1SPrashanth Swaminathan# ===========================================================================
4*1fd5a2e1SPrashanth Swaminathan#
5*1fd5a2e1SPrashanth Swaminathan# SYNOPSIS
6*1fd5a2e1SPrashanth Swaminathan#
7*1fd5a2e1SPrashanth Swaminathan#   AX_ENABLE_BUILDDIR [(dirstring-or-command [,Makefile.mk [,-all]])]
8*1fd5a2e1SPrashanth Swaminathan#
9*1fd5a2e1SPrashanth Swaminathan# DESCRIPTION
10*1fd5a2e1SPrashanth Swaminathan#
11*1fd5a2e1SPrashanth Swaminathan#   If the current configure was run within the srcdir then we move all
12*1fd5a2e1SPrashanth Swaminathan#   configure-files into a subdir and let the configure steps continue
13*1fd5a2e1SPrashanth Swaminathan#   there. We provide an option --disable-builddir to suppress the move into
14*1fd5a2e1SPrashanth Swaminathan#   a separate builddir.
15*1fd5a2e1SPrashanth Swaminathan#
16*1fd5a2e1SPrashanth Swaminathan#   Defaults:
17*1fd5a2e1SPrashanth Swaminathan#
18*1fd5a2e1SPrashanth Swaminathan#     $1 = $host (overridden with $HOST)
19*1fd5a2e1SPrashanth Swaminathan#     $2 = Makefile.mk
20*1fd5a2e1SPrashanth Swaminathan#     $3 = -all
21*1fd5a2e1SPrashanth Swaminathan#
22*1fd5a2e1SPrashanth Swaminathan#   This macro must be called before AM_INIT_AUTOMAKE. It creates a default
23*1fd5a2e1SPrashanth Swaminathan#   toplevel srcdir Makefile from the information found in the created
24*1fd5a2e1SPrashanth Swaminathan#   toplevel builddir Makefile. It just copies the variables and
25*1fd5a2e1SPrashanth Swaminathan#   rule-targets, each extended with a default rule-execution that recurses
26*1fd5a2e1SPrashanth Swaminathan#   into the build directory of the current "HOST". You can override the
27*1fd5a2e1SPrashanth Swaminathan#   auto-detection through `config.guess` and build-time of course, as in
28*1fd5a2e1SPrashanth Swaminathan#
29*1fd5a2e1SPrashanth Swaminathan#     make HOST=i386-mingw-cross
30*1fd5a2e1SPrashanth Swaminathan#
31*1fd5a2e1SPrashanth Swaminathan#   which can of course set at configure time as well using
32*1fd5a2e1SPrashanth Swaminathan#
33*1fd5a2e1SPrashanth Swaminathan#     configure --host=i386-mingw-cross
34*1fd5a2e1SPrashanth Swaminathan#
35*1fd5a2e1SPrashanth Swaminathan#   After the default has been created, additional rules can be appended
36*1fd5a2e1SPrashanth Swaminathan#   that will not just recurse into the subdirectories and only ever exist
37*1fd5a2e1SPrashanth Swaminathan#   in the srcdir toplevel makefile - these parts are read from the $2 =
38*1fd5a2e1SPrashanth Swaminathan#   Makefile.mk file
39*1fd5a2e1SPrashanth Swaminathan#
40*1fd5a2e1SPrashanth Swaminathan#   The automatic rules are usually scanning the toplevel Makefile for lines
41*1fd5a2e1SPrashanth Swaminathan#   like '#### $host |$builddir' to recognize the place where to recurse
42*1fd5a2e1SPrashanth Swaminathan#   into. Usually, the last one is the only one used. However, almost all
43*1fd5a2e1SPrashanth Swaminathan#   targets have an additional "*-all" rule which makes the script to
44*1fd5a2e1SPrashanth Swaminathan#   recurse into _all_ variants of the current HOST (!!) setting. The "-all"
45*1fd5a2e1SPrashanth Swaminathan#   suffix can be overridden for the macro as well.
46*1fd5a2e1SPrashanth Swaminathan#
47*1fd5a2e1SPrashanth Swaminathan#   a special rule is only given for things like "dist" that will copy the
48*1fd5a2e1SPrashanth Swaminathan#   tarball from the builddir to the sourcedir (or $(PUB)) for reason of
49*1fd5a2e1SPrashanth Swaminathan#   convenience.
50*1fd5a2e1SPrashanth Swaminathan#
51*1fd5a2e1SPrashanth Swaminathan# LICENSE
52*1fd5a2e1SPrashanth Swaminathan#
53*1fd5a2e1SPrashanth Swaminathan#   Copyright (c) 2009 Guido U. Draheim <[email protected]>
54*1fd5a2e1SPrashanth Swaminathan#   Copyright (c) 2009 Alan Jenkins <[email protected]>
55*1fd5a2e1SPrashanth Swaminathan#
56*1fd5a2e1SPrashanth Swaminathan#   This program is free software; you can redistribute it and/or modify it
57*1fd5a2e1SPrashanth Swaminathan#   under the terms of the GNU General Public License as published by the
58*1fd5a2e1SPrashanth Swaminathan#   Free Software Foundation; either version 3 of the License, or (at your
59*1fd5a2e1SPrashanth Swaminathan#   option) any later version.
60*1fd5a2e1SPrashanth Swaminathan#
61*1fd5a2e1SPrashanth Swaminathan#   This program is distributed in the hope that it will be useful, but
62*1fd5a2e1SPrashanth Swaminathan#   WITHOUT ANY WARRANTY; without even the implied warranty of
63*1fd5a2e1SPrashanth Swaminathan#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
64*1fd5a2e1SPrashanth Swaminathan#   Public License for more details.
65*1fd5a2e1SPrashanth Swaminathan#
66*1fd5a2e1SPrashanth Swaminathan#   You should have received a copy of the GNU General Public License along
67*1fd5a2e1SPrashanth Swaminathan#   with this program. If not, see <https://www.gnu.org/licenses/>.
68*1fd5a2e1SPrashanth Swaminathan#
69*1fd5a2e1SPrashanth Swaminathan#   As a special exception, the respective Autoconf Macro's copyright owner
70*1fd5a2e1SPrashanth Swaminathan#   gives unlimited permission to copy, distribute and modify the configure
71*1fd5a2e1SPrashanth Swaminathan#   scripts that are the output of Autoconf when processing the Macro. You
72*1fd5a2e1SPrashanth Swaminathan#   need not follow the terms of the GNU General Public License when using
73*1fd5a2e1SPrashanth Swaminathan#   or distributing such scripts, even though portions of the text of the
74*1fd5a2e1SPrashanth Swaminathan#   Macro appear in them. The GNU General Public License (GPL) does govern
75*1fd5a2e1SPrashanth Swaminathan#   all other use of the material that constitutes the Autoconf Macro.
76*1fd5a2e1SPrashanth Swaminathan#
77*1fd5a2e1SPrashanth Swaminathan#   This special exception to the GPL applies to versions of the Autoconf
78*1fd5a2e1SPrashanth Swaminathan#   Macro released by the Autoconf Archive. When you make and distribute a
79*1fd5a2e1SPrashanth Swaminathan#   modified version of the Autoconf Macro, you may extend this special
80*1fd5a2e1SPrashanth Swaminathan#   exception to the GPL to apply to your modified version as well.
81*1fd5a2e1SPrashanth Swaminathan
82*1fd5a2e1SPrashanth Swaminathan#serial 30
83*1fd5a2e1SPrashanth Swaminathan
84*1fd5a2e1SPrashanth SwaminathanAC_DEFUN([AX_ENABLE_BUILDDIR],[
85*1fd5a2e1SPrashanth SwaminathanAC_REQUIRE([AC_CANONICAL_HOST])[]dnl
86*1fd5a2e1SPrashanth SwaminathanAC_REQUIRE([AC_CANONICAL_TARGET])[]dnl
87*1fd5a2e1SPrashanth SwaminathanAC_REQUIRE([AX_CONFIGURE_ARGS])[]dnl
88*1fd5a2e1SPrashanth SwaminathanAC_REQUIRE([AM_AUX_DIR_EXPAND])[]dnl
89*1fd5a2e1SPrashanth SwaminathanAC_BEFORE([$0],[AM_INIT_AUTOMAKE])dnl
90*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
91*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([AUX],[ax_enable_builddir_auxdir])dnl
92*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
93*1fd5a2e1SPrashanth SwaminathanSUB="."
94*1fd5a2e1SPrashanth SwaminathanAC_ARG_ENABLE([builddir], AS_HELP_STRING(
95*1fd5a2e1SPrashanth Swaminathan  [--disable-builddir],[disable automatic build in subdir of sources])
96*1fd5a2e1SPrashanth Swaminathan  ,[SUB="$enableval"], [SUB="auto"])
97*1fd5a2e1SPrashanth Swaminathanif test ".$ac_srcdir_defaulted" != ".no" ; then
98*1fd5a2e1SPrashanth Swaminathanif test ".$srcdir" = ".." ; then
99*1fd5a2e1SPrashanth Swaminathan  if test -f config.status ; then
100*1fd5a2e1SPrashanth Swaminathan    AC_MSG_NOTICE(toplevel srcdir already configured... skipping subdir build)
101*1fd5a2e1SPrashanth Swaminathan  else
102*1fd5a2e1SPrashanth Swaminathan    test ".$SUB" = "."  && SUB="."
103*1fd5a2e1SPrashanth Swaminathan    test ".$SUB" = ".no"  && SUB="."
104*1fd5a2e1SPrashanth Swaminathan    test ".$TARGET" = "." && TARGET="$target"
105*1fd5a2e1SPrashanth Swaminathan    test ".$SUB" = ".auto" && SUB="m4_ifval([$1], [$1],[$TARGET])"
106*1fd5a2e1SPrashanth Swaminathan    if test ".$SUB" != ".." ; then    # we know where to go and
107*1fd5a2e1SPrashanth Swaminathan      AS_MKDIR_P([$SUB])
108*1fd5a2e1SPrashanth Swaminathan      echo __.$SUB.__ > $SUB/conftest.tmp
109*1fd5a2e1SPrashanth Swaminathan      cd $SUB
110*1fd5a2e1SPrashanth Swaminathan      if grep __.$SUB.__ conftest.tmp >/dev/null 2>/dev/null ; then
111*1fd5a2e1SPrashanth Swaminathan        rm conftest.tmp
112*1fd5a2e1SPrashanth Swaminathan        AC_MSG_RESULT([continue configure in default builddir "./$SUB"])
113*1fd5a2e1SPrashanth Swaminathan      else
114*1fd5a2e1SPrashanth Swaminathan        AC_MSG_ERROR([could not change to default builddir "./$SUB"])
115*1fd5a2e1SPrashanth Swaminathan      fi
116*1fd5a2e1SPrashanth Swaminathan      srcdir=`echo "$SUB" |
117*1fd5a2e1SPrashanth Swaminathan              sed -e 's,^\./,,;s,[[^/]]$,&/,;s,[[^/]]*/,../,g;s,[[/]]$,,;'`
118*1fd5a2e1SPrashanth Swaminathan      # going to restart from subdirectory location
119*1fd5a2e1SPrashanth Swaminathan      test -f $srcdir/config.log   && mv $srcdir/config.log   .
120*1fd5a2e1SPrashanth Swaminathan      test -f $srcdir/confdefs.h   && mv $srcdir/confdefs.h   .
121*1fd5a2e1SPrashanth Swaminathan      test -f $srcdir/conftest.log && mv $srcdir/conftest.log .
122*1fd5a2e1SPrashanth Swaminathan      test -f $srcdir/$cache_file  && mv $srcdir/$cache_file  .
123*1fd5a2e1SPrashanth Swaminathan      AC_MSG_RESULT(....exec $SHELL $srcdir/[$]0 "--srcdir=$srcdir" "--enable-builddir=$SUB" ${1+"[$]@"})
124*1fd5a2e1SPrashanth Swaminathan      case "[$]0" in # restart
125*1fd5a2e1SPrashanth Swaminathan       [[\\/]]* | ?:[[\\/]]*) # Absolute name
126*1fd5a2e1SPrashanth Swaminathan         eval $SHELL "'[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
127*1fd5a2e1SPrashanth Swaminathan       *) eval $SHELL "'$srcdir/[$]0'" "'--srcdir=$srcdir'" "'--enable-builddir=$SUB'" $ac_configure_args ;;
128*1fd5a2e1SPrashanth Swaminathan      esac ; exit $?
129*1fd5a2e1SPrashanth Swaminathan    fi
130*1fd5a2e1SPrashanth Swaminathan  fi
131*1fd5a2e1SPrashanth Swaminathanfi fi
132*1fd5a2e1SPrashanth Swaminathantest ".$SUB" = ".auto" && SUB="."
133*1fd5a2e1SPrashanth Swaminathandnl ac_path_prog uses "set dummy" to override $@ which would defeat the "exec"
134*1fd5a2e1SPrashanth SwaminathanAC_PATH_PROG(SED,gsed sed, sed)
135*1fd5a2e1SPrashanth SwaminathanAUX="$am_aux_dir"
136*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([SED])dnl
137*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([AUX])dnl
138*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([SUB])dnl
139*1fd5a2e1SPrashanth SwaminathanAC_CONFIG_COMMANDS([buildir],[dnl .............. config.status ..............
140*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([SUB],[ax_enable_builddir])dnl
141*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([TOP],[top_srcdir])dnl
142*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([SRC],[ac_top_srcdir])dnl
143*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([AUX],[ax_enable_builddir_auxdir])dnl
144*1fd5a2e1SPrashanth SwaminathanAS_VAR_PUSHDEF([SED],[ax_enable_builddir_sed])dnl
145*1fd5a2e1SPrashanth Swaminathanpushdef([END],[Makefile.mk])dnl
146*1fd5a2e1SPrashanth Swaminathanpushdef([_ALL],[ifelse([$3],,[-all],[$3])])dnl
147*1fd5a2e1SPrashanth Swaminathan  SRC="$ax_enable_builddir_srcdir"
148*1fd5a2e1SPrashanth Swaminathan  if test ".$SUB" = ".." ; then
149*1fd5a2e1SPrashanth Swaminathan    if test -f "$TOP/Makefile" ; then
150*1fd5a2e1SPrashanth Swaminathan      AC_MSG_NOTICE([skipping TOP/Makefile - left untouched])
151*1fd5a2e1SPrashanth Swaminathan    else
152*1fd5a2e1SPrashanth Swaminathan      AC_MSG_NOTICE([skipping TOP/Makefile - not created])
153*1fd5a2e1SPrashanth Swaminathan    fi
154*1fd5a2e1SPrashanth Swaminathan  else
155*1fd5a2e1SPrashanth Swaminathan    if test -f "$SRC/Makefile" ; then
156*1fd5a2e1SPrashanth Swaminathan      a=`grep "^VERSION " "$SRC/Makefile"` ; b=`grep "^VERSION " Makefile`
157*1fd5a2e1SPrashanth Swaminathan      test "$a" != "$b" && rm "$SRC/Makefile"
158*1fd5a2e1SPrashanth Swaminathan    fi
159*1fd5a2e1SPrashanth Swaminathan    if test -f "$SRC/Makefile" ; then
160*1fd5a2e1SPrashanth Swaminathan	echo "$SRC/Makefile : $SRC/Makefile.in" > $tmp/conftemp.mk
161*1fd5a2e1SPrashanth Swaminathan	echo "	[]@ echo 'REMOVED,,,' >\$[]@" >> $tmp/conftemp.mk
162*1fd5a2e1SPrashanth Swaminathan      eval "${MAKE-make} -f $tmp/conftemp.mk 2>/dev/null >/dev/null"
163*1fd5a2e1SPrashanth Swaminathan      if grep '^REMOVED,,,' "$SRC/Makefile" >/dev/null
164*1fd5a2e1SPrashanth Swaminathan      then rm $SRC/Makefile ; fi
165*1fd5a2e1SPrashanth Swaminathan      cp $tmp/conftemp.mk $SRC/makefiles.mk~      ## DEBUGGING
166*1fd5a2e1SPrashanth Swaminathan    fi
167*1fd5a2e1SPrashanth Swaminathan    if test ! -f "$SRC/Makefile" ; then
168*1fd5a2e1SPrashanth Swaminathan      AC_MSG_NOTICE([create TOP/Makefile guessed from local Makefile])
169*1fd5a2e1SPrashanth Swaminathan      x='`' ; cat >$tmp/conftemp.sed <<_EOF
170*1fd5a2e1SPrashanth Swaminathan/^\$/n
171*1fd5a2e1SPrashanth Swaminathanx
172*1fd5a2e1SPrashanth Swaminathan/^\$/bS
173*1fd5a2e1SPrashanth Swaminathanx
174*1fd5a2e1SPrashanth Swaminathan/\\\\\$/{H;d;}
175*1fd5a2e1SPrashanth Swaminathan{H;s/.*//;x;}
176*1fd5a2e1SPrashanth SwaminathanbM
177*1fd5a2e1SPrashanth Swaminathan:S
178*1fd5a2e1SPrashanth Swaminathanx
179*1fd5a2e1SPrashanth Swaminathan/\\\\\$/{h;d;}
180*1fd5a2e1SPrashanth Swaminathan{h;s/.*//;x;}
181*1fd5a2e1SPrashanth Swaminathan:M
182*1fd5a2e1SPrashanth Swaminathans/\\(\\n\\)	/\\1 /g
183*1fd5a2e1SPrashanth Swaminathan/^	/d
184*1fd5a2e1SPrashanth Swaminathan/^[[	 ]]*[[\\#]]/d
185*1fd5a2e1SPrashanth Swaminathan/^VPATH *=/d
186*1fd5a2e1SPrashanth Swaminathans/^srcdir *=.*/srcdir = ./
187*1fd5a2e1SPrashanth Swaminathans/^top_srcdir *=.*/top_srcdir = ./
188*1fd5a2e1SPrashanth Swaminathan/[[:=]]/!d
189*1fd5a2e1SPrashanth Swaminathan/^\\./d
190*1fd5a2e1SPrashanth Swaminathandnl Now handle rules (i.e. lines containing ":" but not " = ").
191*1fd5a2e1SPrashanth Swaminathan/ = /b
192*1fd5a2e1SPrashanth Swaminathan/ .= /b
193*1fd5a2e1SPrashanth Swaminathan/:/!b
194*1fd5a2e1SPrashanth Swaminathans/:.*/:/
195*1fd5a2e1SPrashanth Swaminathans/ /  /g
196*1fd5a2e1SPrashanth Swaminathans/ \\([[a-z]][[a-z-]]*[[a-zA-Z0-9]]\\)\\([[ :]]\\)/ \\1 \\1[]_ALL\\2/g
197*1fd5a2e1SPrashanth Swaminathans/^\\([[a-z]][[a-z-]]*[[a-zA-Z0-9]]\\)\\([[ :]]\\)/\\1 \\1[]_ALL\\2/
198*1fd5a2e1SPrashanth Swaminathans/  / /g
199*1fd5a2e1SPrashanth Swaminathan/^all all[]_ALL[[ :]]/i\\
200*1fd5a2e1SPrashanth Swaminathanall-configured : all[]_ALL
201*1fd5a2e1SPrashanth Swaminathandnl dist-all exists... and would make for dist-all-all
202*1fd5a2e1SPrashanth Swaminathans/ [[a-zA-Z0-9-]]*[]_ALL [[a-zA-Z0-9-]]*[]_ALL[]_ALL//g
203*1fd5a2e1SPrashanth Swaminathan/[]_ALL[]_ALL/d
204*1fd5a2e1SPrashanth Swaminathana\\
205*1fd5a2e1SPrashanth Swaminathan	@ HOST="\$(HOST)\" \\\\\\
206*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
207*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### \$\$HOST " Makefile | sed -e 's/.*|//' $x \\\\\\
208*1fd5a2e1SPrashanth Swaminathan	; use=$x basename "\$\@" _ALL $x; n=$x echo \$\$BUILD | wc -w $x \\\\\\
209*1fd5a2e1SPrashanth Swaminathan	; echo "MAKE \$\$HOST : \$\$n * \$\@"; if test "\$\$n" -eq "0" ; then : \\\\\\
210*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^####.*|" Makefile |tail -1| sed -e 's/.*|//' $x ; fi \\\\\\
211*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$BUILD" = "." && BUILD="." \\\\\\
212*1fd5a2e1SPrashanth Swaminathan	; test "\$\$use" = "\$\@" && BUILD=$x echo "\$\$BUILD" | tail -1 $x \\\\\\
213*1fd5a2e1SPrashanth Swaminathan	; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
214*1fd5a2e1SPrashanth Swaminathan	; (cd "\$\$i" && test ! -f configure && \$(MAKE) \$\$use) || exit; done
215*1fd5a2e1SPrashanth Swaminathandnl special rule add-on: "dist" copies the tarball to $(PUB). (source tree)
216*1fd5a2e1SPrashanth Swaminathan/dist[]_ALL *:/a\\
217*1fd5a2e1SPrashanth Swaminathan	@ HOST="\$(HOST)\" \\\\\\
218*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
219*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### \$\$HOST " Makefile | sed -e 's/.*|//' $x \\\\\\
220*1fd5a2e1SPrashanth Swaminathan	; found=$x echo \$\$BUILD | wc -w $x \\\\\\
221*1fd5a2e1SPrashanth Swaminathan	; echo "MAKE \$\$HOST : \$\$found \$(PACKAGE)-\$(VERSION).tar.*" \\\\\\
222*1fd5a2e1SPrashanth Swaminathan	; if test "\$\$found" -eq "0" ; then : \\\\\\
223*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### .*|" Makefile |tail -1| sed -e 's/.*|//' $x \\\\\\
224*1fd5a2e1SPrashanth Swaminathan	; fi ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
225*1fd5a2e1SPrashanth Swaminathan	; for f in \$\$i/\$(PACKAGE)-\$(VERSION).tar.* \\\\\\
226*1fd5a2e1SPrashanth Swaminathan	; do test -f "\$\$f" && mv "\$\$f" \$(PUB). ; done ; break ; done
227*1fd5a2e1SPrashanth Swaminathandnl special rule add-on: "dist-foo" copies all the archives to $(PUB). (source tree)
228*1fd5a2e1SPrashanth Swaminathan/dist-[[a-zA-Z0-9]]*[]_ALL *:/a\\
229*1fd5a2e1SPrashanth Swaminathan	@ HOST="\$(HOST)\" \\\\\\
230*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$HOST" = "." && HOST=$x sh ./config.guess $x \\\\\\
231*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### \$\$HOST " Makefile | sed -e 's/.*|//' $x \\\\\\
232*1fd5a2e1SPrashanth Swaminathan	; found=$x echo \$\$BUILD | wc -w $x \\\\\\
233*1fd5a2e1SPrashanth Swaminathan	; echo "MAKE \$\$HOST : \$\$found \$(PACKAGE)-\$(VERSION).*" \\\\\\
234*1fd5a2e1SPrashanth Swaminathan	; if test "\$\$found" -eq "0" ; then : \\\\\\
235*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### .*|" Makefile |tail -1| sed -e 's/.*|//' $x \\\\\\
236*1fd5a2e1SPrashanth Swaminathan	; fi ; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
237*1fd5a2e1SPrashanth Swaminathan	; for f in \$\$i/\$(PACKAGE)-\$(VERSION).* \\\\\\
238*1fd5a2e1SPrashanth Swaminathan	; do test -f "\$\$f" && mv "\$\$f" \$(PUB). ; done ; break ; done
239*1fd5a2e1SPrashanth Swaminathandnl special rule add-on: "distclean" removes all local builddirs completely
240*1fd5a2e1SPrashanth Swaminathan/distclean[]_ALL *:/a\\
241*1fd5a2e1SPrashanth Swaminathan	@ HOST="\$(HOST)\" \\\\\\
242*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$HOST" = "." && HOST=$x sh $AUX/config.guess $x \\\\\\
243*1fd5a2e1SPrashanth Swaminathan	; BUILD=$x grep "^#### .*|" Makefile | sed -e 's/.*|//' $x \\\\\\
244*1fd5a2e1SPrashanth Swaminathan	; use=$x basename "\$\@" _ALL $x; n=$x echo \$\$BUILD | wc -w $x \\\\\\
245*1fd5a2e1SPrashanth Swaminathan	; echo "MAKE \$\$HOST : \$\$n * \$\@ (all local builds)" \\\\\\
246*1fd5a2e1SPrashanth Swaminathan	; test ".\$\$BUILD" = "." && BUILD="." \\\\\\
247*1fd5a2e1SPrashanth Swaminathan	; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
248*1fd5a2e1SPrashanth Swaminathan	; echo "# rm -r \$\$i"; done ; echo "# (sleep 3)" ; sleep 3 \\\\\\
249*1fd5a2e1SPrashanth Swaminathan	; for i in \$\$BUILD ; do test ".\$\$i" = "." && continue \\\\\\
250*1fd5a2e1SPrashanth Swaminathan	; echo "\$\$i" | grep "^/" > /dev/null && continue \\\\\\
251*1fd5a2e1SPrashanth Swaminathan	; echo "\$\$i" | grep "^../" > /dev/null && continue \\\\\\
252*1fd5a2e1SPrashanth Swaminathan	; echo "rm -r \$\$i"; (rm -r "\$\$i") ; done ; rm Makefile
253*1fd5a2e1SPrashanth Swaminathan_EOF
254*1fd5a2e1SPrashanth Swaminathan      cp "$tmp/conftemp.sed" "$SRC/makefile.sed~"            ## DEBUGGING
255*1fd5a2e1SPrashanth Swaminathan      $SED -f $tmp/conftemp.sed Makefile >$SRC/Makefile
256*1fd5a2e1SPrashanth Swaminathan      if test -f "$SRC/m4_ifval([$2],[$2],[END])" ; then
257*1fd5a2e1SPrashanth Swaminathan        AC_MSG_NOTICE([extend TOP/Makefile with TOP/m4_ifval([$2],[$2],[END])])
258*1fd5a2e1SPrashanth Swaminathan        cat $SRC/END >>$SRC/Makefile
259*1fd5a2e1SPrashanth Swaminathan      fi ; xxxx="####"
260*1fd5a2e1SPrashanth Swaminathan      echo "$xxxx CONFIGURATIONS FOR TOPLEVEL MAKEFILE: " >>$SRC/Makefile
261*1fd5a2e1SPrashanth Swaminathan      # sanity check
262*1fd5a2e1SPrashanth Swaminathan      if grep '^; echo "MAKE ' $SRC/Makefile >/dev/null ; then
263*1fd5a2e1SPrashanth Swaminathan        AC_MSG_NOTICE([buggy sed found - it deletes tab in "a" text parts])
264*1fd5a2e1SPrashanth Swaminathan        $SED -e '/^@ HOST=/s/^/	/' -e '/^; /s/^/	/' $SRC/Makefile \
265*1fd5a2e1SPrashanth Swaminathan          >$SRC/Makefile~
266*1fd5a2e1SPrashanth Swaminathan        (test -s $SRC/Makefile~ && mv $SRC/Makefile~ $SRC/Makefile) 2>/dev/null
267*1fd5a2e1SPrashanth Swaminathan      fi
268*1fd5a2e1SPrashanth Swaminathan    else
269*1fd5a2e1SPrashanth Swaminathan      xxxx="\\#\\#\\#\\#"
270*1fd5a2e1SPrashanth Swaminathan      # echo "/^$xxxx *$ax_enable_builddir_host /d" >$tmp/conftemp.sed
271*1fd5a2e1SPrashanth Swaminathan      echo "s!^$xxxx [[^|]]* | *$SUB *\$!$xxxx ...... $SUB!" >$tmp/conftemp.sed
272*1fd5a2e1SPrashanth Swaminathan      $SED -f "$tmp/conftemp.sed" "$SRC/Makefile" >$tmp/mkfile.tmp
273*1fd5a2e1SPrashanth Swaminathan        cp "$tmp/conftemp.sed" "$SRC/makefiles.sed~"         ## DEBUGGING
274*1fd5a2e1SPrashanth Swaminathan        cp "$tmp/mkfile.tmp"   "$SRC/makefiles.out~"         ## DEBUGGING
275*1fd5a2e1SPrashanth Swaminathan      if cmp -s "$SRC/Makefile" "$tmp/mkfile.tmp" 2>/dev/null ; then
276*1fd5a2e1SPrashanth Swaminathan        AC_MSG_NOTICE([keeping TOP/Makefile from earlier configure])
277*1fd5a2e1SPrashanth Swaminathan        rm "$tmp/mkfile.tmp"
278*1fd5a2e1SPrashanth Swaminathan      else
279*1fd5a2e1SPrashanth Swaminathan        AC_MSG_NOTICE([reusing TOP/Makefile from earlier configure])
280*1fd5a2e1SPrashanth Swaminathan        mv "$tmp/mkfile.tmp" "$SRC/Makefile"
281*1fd5a2e1SPrashanth Swaminathan      fi
282*1fd5a2e1SPrashanth Swaminathan    fi
283*1fd5a2e1SPrashanth Swaminathan    AC_MSG_NOTICE([build in $SUB (HOST=$ax_enable_builddir_host)])
284*1fd5a2e1SPrashanth Swaminathan    xxxx="####"
285*1fd5a2e1SPrashanth Swaminathan    echo "$xxxx" "$ax_enable_builddir_host" "|$SUB" >>$SRC/Makefile
286*1fd5a2e1SPrashanth Swaminathan  fi
287*1fd5a2e1SPrashanth Swaminathanpopdef([END])dnl
288*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([SED])dnl
289*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([AUX])dnl
290*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([SRC])dnl
291*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([TOP])dnl
292*1fd5a2e1SPrashanth SwaminathanAS_VAR_POPDEF([SUB])dnl
293*1fd5a2e1SPrashanth Swaminathan],[dnl
294*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_srcdir="$srcdir"                    # $srcdir
295*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_host="$HOST"                        # $HOST / $host
296*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_version="$VERSION"                  # $VERSION
297*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_package="$PACKAGE"                  # $PACKAGE
298*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_auxdir="$ax_enable_builddir_auxdir" # $AUX
299*1fd5a2e1SPrashanth Swaminathanax_enable_builddir_sed="$ax_enable_builddir_sed"       # $SED
300*1fd5a2e1SPrashanth Swaminathanax_enable_builddir="$ax_enable_builddir"               # $SUB
301*1fd5a2e1SPrashanth Swaminathan])dnl
302*1fd5a2e1SPrashanth Swaminathan])
303