1dnl Nesting safe macros for saving variables
2dnl Usage: PAC_PUSH_FLAG(CFLAGS)
3AC_DEFUN([PAC_PUSH_FLAG],[
4	if test -z "${pac_save_$1_nesting}" ; then
5	   pac_save_$1_nesting=0
6	fi
7	eval pac_save_$1_${pac_save_$1_nesting}='"$$1"'
8	pac_save_$1_nesting=`expr ${pac_save_$1_nesting} + 1`
9])
10
11dnl Usage: PAC_POP_FLAG(CFLAGS)
12AC_DEFUN([PAC_POP_FLAG],[
13	pac_save_$1_nesting=`expr ${pac_save_$1_nesting} - 1`
14	eval $1="\$pac_save_$1_${pac_save_$1_nesting}"
15	eval pac_save_$1_${pac_save_$1_nesting}=""
16])
17
18dnl Usage: PAC_PUSH_ALL_FLAGS
19AC_DEFUN([PAC_PUSH_ALL_FLAGS],[
20	PAC_PUSH_FLAG(CFLAGS)
21	PAC_PUSH_FLAG(CPPFLAGS)
22	PAC_PUSH_FLAG(CXXFLAGS)
23	PAC_PUSH_FLAG(FFLAGS)
24	PAC_PUSH_FLAG(FCFLAGS)
25	PAC_PUSH_FLAG(LDFLAGS)
26	PAC_PUSH_FLAG(LIBS)
27])
28
29dnl Usage: PAC_POP_ALL_FLAGS
30AC_DEFUN([PAC_POP_ALL_FLAGS],[
31	PAC_POP_FLAG(CFLAGS)
32	PAC_POP_FLAG(CPPFLAGS)
33	PAC_POP_FLAG(CXXFLAGS)
34	PAC_POP_FLAG(FFLAGS)
35	PAC_POP_FLAG(FCFLAGS)
36	PAC_POP_FLAG(LDFLAGS)
37	PAC_POP_FLAG(LIBS)
38])
39
40dnl PAC_PREFIX_FLAG - Save flag with a prefix
41dnl Usage: PAC_PREFIX_FLAG(PREFIX, FLAG)
42AC_DEFUN([PAC_PREFIX_FLAG],[
43	$1_$2=$$2
44	export $1_$2
45	AC_SUBST($1_$2)
46])
47
48dnl PAC_PREFIX_ALL_FLAGS - Save flags with a prefix
49dnl Usage: PAC_PREFIX_ALL_FLAGS(PREFIX)
50AC_DEFUN([PAC_PREFIX_ALL_FLAGS],[
51	PAC_PREFIX_FLAG($1, CFLAGS)
52	PAC_PREFIX_FLAG($1, CPPFLAGS)
53	PAC_PREFIX_FLAG($1, CXXFLAGS)
54	PAC_PREFIX_FLAG($1, FFLAGS)
55	PAC_PREFIX_FLAG($1, FCFLAGS)
56	PAC_PREFIX_FLAG($1, LDFLAGS)
57	PAC_PREFIX_FLAG($1, LIBS)
58])
59
60dnl Usage: PAC_APPEND_FLAG([-02], [CFLAGS])
61dnl appends the given argument to the specified shell variable unless the
62dnl argument is already present in the variable
63AC_DEFUN([PAC_APPEND_FLAG],[
64	AC_REQUIRE([AC_PROG_FGREP])
65	AS_IF(
66		[echo "$$2" | $FGREP -e '$1' >/dev/null 2>&1],
67		[echo "$2(='$$2') contains '$1', not appending" >&AS_MESSAGE_LOG_FD],
68		[echo "$2(='$$2') does not contain '$1', appending" >&AS_MESSAGE_LOG_FD
69		$2="$$2 $1"]
70	)
71])
72
73dnl Usage: PAC_PREPEND_FLAG([-lpthread], [LIBS])
74dnl Prepends the given argument to the specified shell variable unless the
75dnl argument is already present in the variable.
76dnl
77dnl This is typically used for LIBS and similar variables because libraries
78dnl should be added in reverse order.
79AC_DEFUN([PAC_PREPEND_FLAG],[
80        AC_REQUIRE([AC_PROG_FGREP])
81        AS_IF(
82                [echo "$$2" | $FGREP -e '$1' >/dev/null 2>&1],
83                [echo "$2(='$$2') contains '$1', not prepending" >&AS_MESSAGE_LOG_FD],
84                [echo "$2(='$$2') does not contain '$1', prepending" >&AS_MESSAGE_LOG_FD
85                $2="$1 $$2"]
86        )
87])
88
89
90dnl PAC_MKDIRS(path)
91dnl Create any missing directories in the path
92AC_DEFUN([PAC_MKDIRS],[
93# Build any intermediate directories
94for dir in $1 ; do
95    PAC_PUSH_FLAG([IFS])
96    IFS="/"
97    tmp_curdir=""
98    for tmp_subdir in $dir ; do
99	tmp_curdir="${tmp_curdir}$tmp_subdir"
100	if test ! -d "$tmp_curdir" ; then mkdir "$tmp_curdir" ; fi
101        tmp_curdir="${tmp_curdir}/"
102    done
103    PAC_POP_FLAG([IFS])
104done
105])
106
107# Find something to use for mkdir -p.  Eventually, this will have a
108# script for backup. As of autoconf-2.63, AC_PROG_MKDIR_P was broken;
109# it was checking to see if it recognized the "version" of mkdir and
110# was deciding based on that. This should always be a feature test.
111AC_DEFUN([PAC_PROG_MKDIR_P],[
112AC_CACHE_CHECK([whether mkdir -p works],
113pac_cv_mkdir_p,[
114pac_cv_mkdir_p=no
115rm -rf .tmp
116if mkdir -p .tmp/.foo 1>/dev/null 2>&1 ; then
117    if test -d .tmp/.foo ; then
118        pac_cv_mkdir_p=yes
119    fi
120fi
121rm -rf .tmp
122])
123if test "$pac_cv_mkdir_p" = "yes" ; then
124   MKDIR_P="mkdir -p"
125   export MKDIR_P
126else
127   AC_MSG_WARN([mkdir -p does not work; the install step may fail])
128fi
129AC_SUBST(MKDIR_P)
130])
131
132dnl Test for a clean VPATH directory.  Provide this command with the names
133dnl of all of the generated files that might cause problems
134dnl (Makefiles won't cause problems because there's no VPATH usage for them)
135dnl
136dnl Synopsis
137dnl PAC_VPATH_CHECK([file-names],[directory-names])
138dnl  file-names should be files other than config.status and any header (e.g.,
139dnl fooconf.h) file that should be removed.  It is optional
140AC_DEFUN([PAC_VPATH_CHECK],[
141# This is needed for Mac OSX 10.5
142rm -rf conftest.dSYM
143rm -f conftest*
144date >conftest$$
145# If creating a file in the current directory does not show up in the srcdir
146# then we're doing a VPATH build (or something is very wrong)
147if test ! -s $srcdir/conftest$$ ; then
148    pac_dirtyfiles=""
149    pac_dirtydirs=""
150    pac_header=""
151    ifdef([AC_LIST_HEADER],[pac_header=AC_LIST_HEADER])
152    for file in config.status $pac_header $1 ; do
153        if test -f $srcdir/$file ; then
154	    pac_dirtyfiles="$pac_dirtyfiles $file"
155	fi
156    done
157    ifelse($2,,,[
158 	for dir in $2 ; do
159            if test -d $srcdir/$dir ; then
160                pac_dirtydirs="$pac_dirtydirs $dir"
161	    fi
162	done
163    ])
164
165    if test -n "$pac_dirtyfiles" -o -n "$pac_dirtydirs" ; then
166	# Create a nice message about what to remove
167	rmmsg=""
168	if test -n "$pac_dirtyfiles" ; then
169	    rmmsg="files $pac_dirtyfiles"
170        fi
171 	if test -n "$pac_dirtydirs" ; then
172	    if test -n "$rmmsg" ; then
173	        rmmsg="$rmmsg and directories $pac_dirtydirs"
174            else
175                rmmsg="directories $pac_dirtydirs"
176            fi
177        fi
178        if test -f $srcdir/Makefile ; then
179            AC_MSG_ERROR([You cannot do a VPATH build if the source directory has been
180    configured.  Run "make distclean" in $srcdir first and make sure that the
181    $rmmsg have been removed.])
182        else
183            AC_MSG_ERROR([You cannot do a VPATH build if the source directory has been
184    configured.  Remove the $rmmsg in $srcdir.])
185        fi
186    fi
187fi
188# This is needed for Mac OSX 10.5
189rm -rf conftest.dSYM
190rm -f conftest*
191])
192