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	PAC_PREFIX_FLAG($1, EXTRA_LIBS)
59])
60
61dnl Usage: PAC_APPEND_FLAG([-02], [CFLAGS])
62dnl appends the given argument to the specified shell variable unless the
63dnl argument is already present in the variable
64AC_DEFUN([PAC_APPEND_FLAG],[
65	AC_REQUIRE([AC_PROG_FGREP])
66	AS_IF(
67		[echo "$$2" | $FGREP -e "\<$1\>" >/dev/null 2>&1],
68		[echo "$2(='$$2') contains '$1', not appending" >&AS_MESSAGE_LOG_FD],
69		[echo "$2(='$$2') does not contain '$1', appending" >&AS_MESSAGE_LOG_FD
70		$2="$$2 $1"]
71	)
72])
73
74dnl Usage: PAC_PREPEND_FLAG([-lpthread], [LIBS])
75dnl Prepends the given argument to the specified shell variable unless the
76dnl argument is already present in the variable.
77dnl
78dnl This is typically used for LIBS and similar variables because libraries
79dnl should be added in reverse order.
80AC_DEFUN([PAC_PREPEND_FLAG],[
81        AC_REQUIRE([AC_PROG_FGREP])
82        AS_IF(
83                [echo "$$2" | $FGREP -e "\<$1\>" >/dev/null 2>&1],
84                [echo "$2(='$$2') contains '$1', not prepending" >&AS_MESSAGE_LOG_FD],
85                [echo "$2(='$$2') does not contain '$1', prepending" >&AS_MESSAGE_LOG_FD
86                $2="$1 $$2"]
87        )
88])
89
90
91dnl PAC_MKDIRS(path)
92dnl Create any missing directories in the path
93AC_DEFUN([PAC_MKDIRS],[
94# Build any intermediate directories
95for dir in $1 ; do
96    PAC_PUSH_FLAG([IFS])
97    IFS="/"
98    tmp_curdir=""
99    for tmp_subdir in $dir ; do
100	tmp_curdir="${tmp_curdir}$tmp_subdir"
101	if test ! -d "$tmp_curdir" ; then mkdir "$tmp_curdir" ; fi
102        tmp_curdir="${tmp_curdir}/"
103    done
104    PAC_POP_FLAG([IFS])
105done
106])
107
108# Find something to use for mkdir -p.  Eventually, this will have a
109# script for backup. As of autoconf-2.63, AC_PROG_MKDIR_P was broken;
110# it was checking to see if it recognized the "version" of mkdir and
111# was deciding based on that. This should always be a feature test.
112AC_DEFUN([PAC_PROG_MKDIR_P],[
113AC_CACHE_CHECK([whether mkdir -p works],
114pac_cv_mkdir_p,[
115pac_cv_mkdir_p=no
116rm -rf .tmp
117if mkdir -p .tmp/.foo 1>/dev/null 2>&1 ; then
118    if test -d .tmp/.foo ; then
119        pac_cv_mkdir_p=yes
120    fi
121fi
122rm -rf .tmp
123])
124if test "$pac_cv_mkdir_p" = "yes" ; then
125   MKDIR_P="mkdir -p"
126   export MKDIR_P
127else
128   AC_MSG_WARN([mkdir -p does not work; the install step may fail])
129fi
130AC_SUBST(MKDIR_P)
131])
132
133dnl Test for a clean VPATH directory.  Provide this command with the names
134dnl of all of the generated files that might cause problems
135dnl (Makefiles won't cause problems because there's no VPATH usage for them)
136dnl
137dnl Synopsis
138dnl PAC_VPATH_CHECK([file-names],[directory-names])
139dnl  file-names should be files other than config.status and any header (e.g.,
140dnl fooconf.h) file that should be removed.  It is optional
141AC_DEFUN([PAC_VPATH_CHECK],[
142# This is needed for Mac OSX 10.5
143rm -rf conftest.dSYM
144rm -f conftest*
145date >conftest$$
146# If creating a file in the current directory does not show up in the srcdir
147# then we're doing a VPATH build (or something is very wrong)
148if test ! -s $srcdir/conftest$$ ; then
149    pac_dirtyfiles=""
150    pac_dirtydirs=""
151    pac_header=""
152    ifdef([AC_LIST_HEADER],[pac_header=AC_LIST_HEADER])
153    for file in config.status $pac_header $1 ; do
154        if test -f $srcdir/$file ; then
155	    pac_dirtyfiles="$pac_dirtyfiles $file"
156	fi
157    done
158    ifelse($2,,,[
159 	for dir in $2 ; do
160            if test -d $srcdir/$dir ; then
161                pac_dirtydirs="$pac_dirtydirs $dir"
162	    fi
163	done
164    ])
165
166    if test -n "$pac_dirtyfiles" -o -n "$pac_dirtydirs" ; then
167	# Create a nice message about what to remove
168	rmmsg=""
169	if test -n "$pac_dirtyfiles" ; then
170	    rmmsg="files $pac_dirtyfiles"
171        fi
172 	if test -n "$pac_dirtydirs" ; then
173	    if test -n "$rmmsg" ; then
174	        rmmsg="$rmmsg and directories $pac_dirtydirs"
175            else
176                rmmsg="directories $pac_dirtydirs"
177            fi
178        fi
179        if test -f $srcdir/Makefile ; then
180            AC_MSG_ERROR([You cannot do a VPATH build if the source directory has been
181    configured.  Run "make distclean" in $srcdir first and make sure that the
182    $rmmsg have been removed.])
183        else
184            AC_MSG_ERROR([You cannot do a VPATH build if the source directory has been
185    configured.  Remove the $rmmsg in $srcdir.])
186        fi
187    fi
188fi
189# This is needed for Mac OSX 10.5
190rm -rf conftest.dSYM
191rm -f conftest*
192])
193
194dnl PAC_CONF_HEX_TO_DEC(value,out_var)
195dnl
196dnl Converts the given hexadecimal integer constant to an integer constant and
197dnl stores the result in the shell variable given by 'out_var'.
198dnl
199dnl I think that printf like this will be sufficiently portable, but I don't
200dnl have any guarantee of it.  If not, we can fall back to AS_VAR_ARITH
201dnl and/or AC_COMPUTE_INT (the latter will probably be slow)
202AC_DEFUN([PAC_CONV_HEX_TO_DEC],[AS_VAR_SET([$2],[`printf "%d" $1`])])
203
204dnl PAC_GET_EXENAME(exe_name, out_exe_name)
205dnl
206dnl Prepends and appends program prefix and suffix as supplied by --program_prefix
207dnl and --program-sufix
208AC_DEFUN([PAC_GET_EXENAME],[
209$2=$1
210if test "$program_prefix" != "NONE" ; then
211    $2="${program_prefix}$$2"
212fi
213if test "$program_suffix" != "NONE" ; then
214    $2="$$2$program_suffix"
215fi
216])
217