1dnl PAC_RESET_ALL_FLAGS - Reset precious flags to those set by the user
2AC_DEFUN([PAC_RESET_ALL_FLAGS],[
3	if test "$FROM_MPICH2" = "yes" ; then
4	   CFLAGS="$USER_CFLAGS"
5	   CPPFLAGS="$USER_CPPFLAGS"
6	   CXXFLAGS="$USER_CXXFLAGS"
7	   FFLAGS="$USER_FFLAGS"
8	   FCFLAGS="$USER_FCFLAGS"
9	   LDFLAGS="$USER_LDFLAGS"
10	   LIBS="$USER_LIBS"
11	fi
12])
13
14dnl PAC_RESET_LINK_FLAGS - Reset precious link flags to those set by the user
15AC_DEFUN([PAC_RESET_LINK_FLAGS],[
16	if test "$FROM_MPICH2" = "yes" ; then
17	   LDFLAGS="$USER_LDFLAGS"
18	   LIBS="$USER_LIBS"
19	fi
20])
21
22dnl Sandbox configure with additional arguments
23dnl Usage: PAC_CONFIG_SUBDIR_ARGS(subdir,configure-args,action-if-success,action-if-failure)
24dnl
25dnl The subconfigure argument list is created based on "ac_precious_vars"
26dnl instead of explicitly use of well-known Makefile variables, like
27dnl CC/CFLAGS/CPPFLAGS..., this generalization is effective as long as
28dnl calling configure.ac declares the needed variables to be passed down
29dnl to subconfigure as "precious" appropriately.  The precious variable
30dnl can be created in the following ways:
31dnl 1) implicit declaration through use of autoconf macros, like
32dnl    AC_PROG_CC (declares CC/CFLAGS/CPPFLAGS/LIBS/LDFLAGS), or
33dnl    AC_PROG_F77 (declares F77/FFLAGS/FLIBS) ...
34dnl    which are in turns invoked by other subconfigure.
35dnl    When in doubt, check "ac_precious_var" in the calling configure.
36dnl 2) explicit "precious" declaration through AC_ARG_VAR.
37dnl Without correct "precious" declaration in the calling configure.ac,
38dnl there would be variables not being included in the subconfigure
39dnl argument list.
40dnl
41dnl Note: I suspect this DEFUN body is underquoted in places, but it does not
42dnl seem to cause problems in practice yet. [goodell@ 2010-05-18]
43AC_DEFUN([PAC_CONFIG_SUBDIR_ARGS],[
44        pac_dir="$1"
45        AC_MSG_NOTICE([===== configuring $1 =====])
46
47	pac_abs_srcdir=`(cd $srcdir && pwd)`
48
49	if test -f $pac_abs_srcdir/$1/setup ; then
50           AC_MSG_NOTICE([sourcing $pac_abs_srcdir/$1/setup])
51	   . $pac_abs_srcdir/$1/setup
52	fi
53
54        # Adapted for MPICH2 from the autoconf-2.67 implementation of
55        # AC_CONFIG_SUBDIRS.  Search for "MPICH2 note:" for relevant commentary and
56        # local modifications.
57
58        # Remove --cache-file, --srcdir, and --disable-option-checking arguments
59        # so they do not pile up.  Otherwise relative paths (like --srcdir=.. from
60        # make distcheck) will be incorrect.
61        pac_sub_configure_args="$2"
62        pac_prev=
63        eval "set x $ac_configure_args"
64        shift
65        for pac_arg
66        do
67          if test -n "$pac_prev"; then
68            pac_prev=
69            continue
70          fi
71          case $pac_arg in
72          -cache-file | --cache-file | --cache-fil | --cache-fi \
73          | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
74            pac_prev=cache_file ;;
75          -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
76          | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \
77          | --c=*)
78            ;;
79          --config-cache | -C)
80            ;;
81          -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
82            pac_prev=srcdir ;;
83          -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
84            ;;
85          -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
86            pac_prev=prefix ;;
87          -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
88            ;;
89          --disable-option-checking)
90            ;;
91          *)
92            # MPICH2 note: this is a more robust version of the "precious
93            # variable" propagation code that was present in the previous
94            # incarnation of this macro
95            for pac_pvar in $ac_precious_vars ; do
96                # check if configure argument token contains the
97                # precious variable, i.e. "name_of_prec_var=".
98                if ( echo $pac_arg | grep "^$pac_pvar=" >/dev/null 2>&1 ) ; then
99                    # check if current precious variable is set in env
100                    eval pvar_set=\${$pac_pvar+set}
101                    if test "$pvar_set" = "set" ; then
102                        # Append 'name_of_prec_var=value_of_prec_var'
103                        # to the subconfigure arguments list, where
104                        # value_of_prec_var is fetched from the env.
105                        # this also overrides any value set on the command line
106                        eval pac_pval=\${$pac_pvar}
107                        pac_arg="$pac_pvar=$pac_pval"
108                        break
109                    fi
110                fi
111            done
112            case $pac_arg in
113            *\'*) pac_arg=`AS_ECHO(["$pac_arg"]) | sed "s/'/'\\\\\\\\''/g"` ;;
114            esac
115            AS_VAR_APPEND([pac_sub_configure_args], [" '$pac_arg'"]) ;;
116          esac
117        done
118
119        # Always prepend --prefix to ensure using the same prefix
120        # in subdir configurations.
121        # MPICH2 note: see tt#983 for an example of why this is necessary
122        pac_arg="--prefix=$prefix"
123        case $pac_arg in
124        *\'*) pac_arg=`AS_ECHO(["$pac_arg"]) | sed "s/'/'\\\\\\\\''/g"` ;;
125        esac
126        pac_sub_configure_args="'$pac_arg' $pac_sub_configure_args"
127
128        # Pass --silent
129        if test "$silent" = yes; then
130          pac_sub_configure_args="--silent $pac_sub_configure_args"
131        fi
132
133        # Always prepend --disable-option-checking to silence warnings, since
134        # different subdirs can have different --enable and --with options.
135        pac_sub_configure_args="--disable-option-checking $pac_sub_configure_args"
136
137        pac_popdir=`pwd`
138
139        # Do not complain, so a configure script can configure whichever
140        # parts of a large source tree are present.
141        test -d "$srcdir/$pac_dir" || continue
142
143        # MPICH2 note: modified to remove the internal "_AS_*" macro usage, also
144        # msg is already printed at top
145dnl        _AS_ECHO_LOG([$pac_msg])
146dnl        _AS_ECHO([$pac_msg])
147        AS_MKDIR_P(["$pac_dir"])
148        # MPICH2 note: we leave this internal macro reference for now.  We can clone
149        # the macro locally if this turns out to be non-portable across several autoconf
150        # versions.  It sets the following variables: ac_builddir,
151        # ac_top_builddir_sub, ac_top_build_prefix, ac_srcdir, ac_top_srcdir,
152        # ac_abs_top_builddir, ac_abs_builddir, ac_abs_top_srcdir, ac_abs_srcdir
153        _AC_SRCDIRS(["$pac_dir"])
154
155        cd "$pac_dir"
156
157        # Check for guested configure; otherwise get Cygnus style configure.
158        if test -f "$ac_srcdir/configure.gnu"; then
159          pac_sub_configure=$ac_srcdir/configure.gnu
160        elif test -f "$ac_srcdir/configure"; then
161          pac_sub_configure=$ac_srcdir/configure
162        elif test -f "$ac_srcdir/configure.ac"; then
163          # This should be Cygnus configure.
164          pac_sub_configure=$ac_aux_dir/configure
165        else
166          AC_MSG_WARN([no configuration information is in $pac_dir])
167          pac_sub_configure=
168        fi
169
170        # The recursion is here.
171        if test -n "$pac_sub_configure"; then
172          # MPICH2 note: overriding the cache file on purpose to prevent strange
173          # issues resulting from inter-dir caching
174dnl          # Make the cache file name correct relative to the subdirectory.
175dnl          case $cache_file in
176dnl          [[\\/]]* | ?:[[\\/]]* ) pac_sub_cache_file=$cache_file ;;
177dnl          *) # Relative name.
178dnl            pac_sub_cache_file=$ac_top_build_prefix$cache_file ;;
179dnl          esac
180          pac_sub_cache_file="/dev/null"
181
182          AC_MSG_NOTICE([running $SHELL $pac_sub_configure $pac_sub_configure_args --cache-file=$pac_sub_cache_file --srcdir=$ac_srcdir])
183          # The eval makes quoting arguments work.
184          # MPICH2 note: we want to execute the provided actions, not be silent
185          # or error out if the subconfigure succeeded/failed
186dnl          eval "\$SHELL \"\$pac_sub_configure\" $pac_sub_configure_args \
187dnl               --cache-file=\"\$pac_sub_cache_file\" --srcdir=\"\$ac_srcdir\"" ||
188dnl            AC_MSG_ERROR([$pac_sub_configure failed for $pac_dir])
189          if eval "\$SHELL \"\$pac_sub_configure\" $pac_sub_configure_args \
190               --cache-file=\"\$pac_sub_cache_file\" --srcdir=\"\$ac_srcdir\""
191          then
192            # restore the current dir for the provided actions
193            cd "$pac_popdir"
194            $3
195          else
196            # restore the current dir for the provided actions
197            cd "$pac_popdir"
198            $4
199          fi
200        fi
201
202        cd "$pac_popdir"
203
204        AC_MSG_NOTICE([===== done with $1 configure =====])
205
206	# Check for any localdefs files.  These may be created, so we
207	# look in the local directory first.
208	if test -f $1/localdefs ; then
209           AC_MSG_NOTICE([sourcing $1/localdefs])
210	   . $1/localdefs
211	elif test -f $pac_abs_srcdir/$1/localdefs ; then
212           AC_MSG_NOTICE([sourcing $pac_abs_srcdir/$1/localdefs])
213	   . $pac_abs_srcdir/$1/localdefs
214	fi
215])
216
217dnl Sandbox configure
218dnl Usage: PAC_CONFIG_SUBDIR(subdir,action-if-success,action-if-failure)
219AC_DEFUN([PAC_CONFIG_SUBDIR],[PAC_CONFIG_SUBDIR_ARGS([$1],[],[$2],[$3])])
220
221dnl PAC_SUBCFG_EXPAND_SUFFIX_MACRO(MACRO_PREFIX,MACRO_PATH_SUFFIX)
222dnl converts the path given by MACRO_PATH_SUFFIX (with '/' chars in it) to one
223dnl with '_' chars in it and then appends that to MACRO_PREFIX with '_' in
224dnl between.  The resulting macro name is then expanded, but with informative
225dnl "##" comments before and after the expansion.
226dnl
227dnl This is intended to be an internal helper macro for the PAC_SUBCFG
228dnl implementation.
229dnl
230dnl XXX DJG FIXME: need to be able to deal with PREREQ macros that potentially
231dnl aren't present while having safety for BODY macros when there are
232dnl misspellings
233AC_DEFUN([PAC_SUBCFG_EXPAND_PATH_SUFFIX_MACRO],[
234dnl convert path separators into '_', the m4_translit is intentionally unquoted
235m4_pushdef([subsys_uscore_name],[$1_]m4_translit([$2],[\/],[__]))dnl
236m4_ifdef(m4_defn([subsys_uscore_name]),[],[m4_fatal([macro ]m4_defn([subsys_uscore_name])[ is undefined])])dnl
237[##] begin expansion of m4_defn([subsys_uscore_name])
238dnl call the computed routine name with the remaining args
239m4_indir(m4_defn([subsys_uscore_name]),m4_shift($@))
240dnl there is intentionally no "dnl" on the previous line to reduce the chance of
241dnl a "fi## end expansion" bug when the BODY macro doesn't end in a newline
242[##] end expansion of m4_defn([subsys_uscore_name])
243])
244
245dnl invokes the PAC_SUBCFG_BODY_foo macro for the "foo" subsys, when "foo" is
246dnl passed as the only argument to this macro.  The first arg may be the '/'
247dnl path version instead of having underscores.
248AC_DEFUN([PAC_SUBCFG_CONFIGURE_SUBSYS],[PAC_SUBCFG_EXPAND_PATH_SUFFIX_MACRO([PAC_SUBCFG_BODY],[$1])])
249
250dnl invokes the PAC_SUBCFG_PREREQ_foo macro for the "foo" subsys, when "foo" is
251dnl passed as the only argument to this macro.  The first arg may be the '/'
252dnl path version instead of having underscores.
253AC_DEFUN([PAC_SUBCFG_DO_PREREQ],[PAC_SUBCFG_EXPAND_PATH_SUFFIX_MACRO([PAC_SUBCFG_PREREQ],[$1])])
254
255dnl takes no arguments, expands to "foo_bar_baz" when invoked in a file named
256dnl "foo/bar/baz/subconfigure.m4"
257dnl
258dnl This is useful for reducing copy-paste errors when defining PREREQ and BODY
259dnl macros.  If you tinker with this macro, watch the quoting carefully.
260AC_DEFUN([PAC_SUBCFG_AUTO_SUFFIX],[m4_translit(m4_bpatsubst(m4_dquote(__file__),[/[^/]+.m4],[]),[/],[_])])
261
262