source: trunk/third/gpdf/acinclude.m4 @ 21033

Revision 21033, 10.2 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21032, which included commits to RCS files with non-trunk default branches.
Line 
1# <<< smr.m4 from smr_macros 0.2.4 >>>
2
3dnl ####################### -*- Mode: M4 -*- ###########################
4dnl smr.m4 --
5dnl
6dnl Copyright (C) 1999 Matthew D. Langston <langston@SLAC.Stanford.EDU>
7dnl Copyright (C) 1998 Steve Robbins <stever@cs.mcgill.ca>
8dnl
9dnl This file is free software; you can redistribute it and/or modify it
10dnl under the terms of the GNU General Public License as published by
11dnl the Free Software Foundation; either version 2 of the License, or
12dnl (at your option) any later version.
13dnl
14dnl This file is distributed in the hope that it will be useful, but
15dnl WITHOUT ANY WARRANTY; without even the implied warranty of
16dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17dnl General Public License for more details.
18dnl
19dnl You should have received a copy of the GNU General Public License
20dnl along with this file; if not, write to:
21dnl
22dnl   Free Software Foundation, Inc.
23dnl   Suite 330
24dnl   59 Temple Place
25dnl   Boston, MA 02111-1307, USA.
26dnl ####################################################################
27
28
29dnl NOTE: The macros in this file are extensively documented in the
30dnl       accompanying `smr_macros.texi' Texinfo file.  Please see the
31dnl       Texinfo documentation for the definitive specification of how
32dnl       these macros are supposed to work.  If the macros work
33dnl       differently than the Texinfo documentation says they should,
34dnl       then the macros (and not the Texinfo documentation) has the
35dnl       bug(s).
36
37dnl This is a convenient macro which translates illegal characters for
38dnl bourne shell variables into legal characters.  It has the same
39dnl functionality as sed 'y%./+-:%__p__%'.
40AC_DEFUN([smr_safe_translation], [patsubst(patsubst([$1], [+], [p]), [./-:], [_])])
41
42AC_DEFUN([smr_SWITCH],
43[
44  dnl Define convenient aliases for the arguments since there are so
45  dnl many of them and I keep confusing myself whenever I have to edit
46  dnl this macro.
47  pushdef([smr_name],        $1)
48  pushdef([smr_help_string], $2)
49  pushdef([smr_default],     $3)
50  pushdef([smr_yes_define],  $4)
51  pushdef([smr_no_define],   $5)
52
53  dnl Do some sanity checking of the arguments.
54  ifelse([regexp(smr_default, [^\(yes\|no\)$])], -1, [AC_MSG_ERROR($0: third arg must be either yes or no)])
55
56  dnl Create the help string
57  pushdef([smr_lhs], [--ifelse(smr_default, yes, disable, enable)-smr_name])dnl
58  pushdef([smr_rhs], [ifelse(smr_default, yes, disable, enable) smr_help_string (default is smr_default)])dnl
59
60  dnl Add the option to `configure --help'.  We don't need to supply the
61  dnl 4th argument to AC_ARG_ENABLE (i.e. the code to set the default
62  dnl value) because that is done below by AC_CACHE_CHECK.
63  AC_ARG_ENABLE([smr_name],
64                AC_HELP_STRING([smr_lhs], [smr_rhs]),
65                smr_cv_enable_[]smr_name=$enableval)
66
67  dnl We cache the result so that the user doesn't have to remember
68  dnl which flags they passed to `configure'.
69  AC_CACHE_CHECK([whether to enable smr_help_string],
70                 smr_cv_enable_[]smr_name,
71                 smr_cv_enable_[]smr_name=smr_default)
72
73    ifelse(smr_yes_define, , , test x"[$]smr_cv_enable_[]smr_name" = xyes && AC_DEFINE(smr_yes_define))
74    ifelse(smr_no_define, , ,  test x"[$]smr_cv_enable_[]smr_name" = xno  && AC_DEFINE(smr_no_define))
75
76  dnl Sanity check the value assigned to smr_cv_enable_$1 to force it to
77  dnl be either `yes' or `no'.
78  if test ! x"[$]smr_cv_enable_[]smr_name" = xyes; then
79    if test ! x"[$]smr_cv_enable_[]smr_name" = xno; then
80      AC_MSG_ERROR([smr_lhs must be either yes or no])
81    fi
82  fi
83
84  popdef([smr_name])
85  popdef([smr_help_string])
86  popdef([smr_default])
87  popdef([smr_yes_define])
88  popdef([smr_no_define])
89  popdef([smr_lhs])
90  popdef([smr_rhs])
91])
92
93
94AC_DEFUN([smr_ARG_WITHLIB],
95[
96  dnl Define convenient aliases for the arguments since there are so
97  dnl many of them and I keep confusing myself whenever I have to edit
98  dnl this macro.
99  pushdef([smr_name],        $1)
100  pushdef([smr_libname],     ifelse($2, , smr_name, $2))
101  pushdef([smr_help_string], $3)
102  pushdef([smr_safe_name],   smr_safe_translation(smr_name))
103
104  dnl Add the option to `configure --help'.  We don't need to supply the
105  dnl 4th argument to AC_ARG_WITH (i.e. the code to set the default
106  dnl value) because that is done below by AC_CACHE_CHECK.
107  AC_ARG_WITH(smr_safe_name-library,
108              AC_HELP_STRING([--with-smr_safe_name-library[[=PATH]]],
109                             [use smr_name library ifelse(smr_help_string, , , (smr_help_string))]),
110              smr_cv_with_[]smr_safe_name[]_library=$withval)
111
112  dnl We cache the result so that the user doesn't have to remember
113  dnl which flags they passed to `configure'.
114  AC_CACHE_CHECK([whether to use smr_name library],
115                 smr_cv_with_[]smr_safe_name[]_library,
116                 smr_cv_with_[]smr_safe_name[]_library=maybe)
117
118
119  case x"[$]smr_cv_with_[]smr_safe_name[]_library" in
120      xyes | xmaybe)
121          smr_safe_name[]_LIBS="-l[]smr_libname"
122          with_[]smr_safe_name=[$]smr_cv_with_[]smr_safe_name[]_library
123          ;;
124      xno)
125          smr_safe_name[]_LIBS=
126          with_[]smr_safe_name=no
127          ;;
128      *)
129          if test -f "[$]smr_cv_with_[]smr_safe_name[]_library"; then
130            smr_safe_name[]_LIBS=[$]smr_cv_with_[]smr_safe_name[]_library
131          elif test -d "[$]smr_cv_with_[]smr_safe_name[]_library"; then
132            smr_safe_name[]_LIBS="-L[$]smr_cv_with_[]smr_safe_name[]_library -l[]smr_libname"
133          else
134            AC_MSG_ERROR([argument must be boolean, file, or directory])
135          fi
136          with_[]smr_safe_name=yes
137          ;;
138  esac
139
140  popdef([smr_name])
141  popdef([smr_libname])
142  popdef([smr_help_string])
143  popdef([smr_safe_name])
144])
145
146
147AC_DEFUN([smr_ARG_WITHINCLUDES],
148[
149  dnl Define convenient aliases for the arguments since there are so
150  dnl many of them and I keep confusing myself whenever I have to edit
151  dnl this macro.
152  pushdef([smr_name],        $1)
153  pushdef([smr_header],      $2)
154  pushdef([smr_extra_flags], $3)
155  pushdef([smr_safe_name],   smr_safe_translation(smr_name))
156
157  dnl Add the option to `configure --help'.  We don't need to supply the
158  dnl 4th argument to AC_ARG_WITH (i.e. the code to set the default
159  dnl value) because that is done below by AC_CACHE_CHECK.
160  AC_ARG_WITH(smr_safe_name-includes,
161              AC_HELP_STRING([--with-smr_safe_name-includes[[=DIR]]],
162                             [set directory for smr_name headers]),
163              smr_cv_with_[]smr_safe_name[]_includes=$withval)
164
165  dnl We cache the result so that the user doesn't have to remember
166  dnl which flags they passed to `configure'.
167  AC_CACHE_CHECK([where to find the smr_name header files],
168                 smr_cv_with_[]smr_safe_name[]_includes,
169                 smr_cv_with_[]smr_safe_name[]_includes=)
170
171  if test ! x"[$]smr_cv_with_[]smr_safe_name[]_includes" = x; then
172    if test -d "[$]smr_cv_with_[]smr_safe_name[]_includes"; then
173      smr_safe_name[]_CFLAGS="-I[$]smr_cv_with_[]smr_safe_name[]_includes"
174    else
175      AC_MSG_ERROR([argument must be a directory])
176    fi
177  else
178    smr_safe_name[]_CFLAGS=
179  fi
180
181  dnl This bit of logic comes from the autoconf AC_PROG_CC macro.  We
182  dnl need to put the given include directory into CPPFLAGS temporarily,
183  dnl but then restore CPPFLAGS to its old value.
184  smr_test_CPPFLAGS="${CPPFLAGS+set}"
185  smr_save_CPPFLAGS="$CPPFLAGS"
186  CPPFLAGS="$CPPFLAGS [$]smr_safe_name[]_CFLAGS smr_extra_flags"
187
188  dnl If the header file smr_header exists, then define
189  dnl HAVE_[]smr_header (in all capitals).
190  AC_CHECK_HEADERS([smr_header],
191                   smr_have_[]smr_safe_name[]_header=yes,
192                   smr_have_[]smr_safe_name[]_header=no)
193
194  if test x"$smr_test_CPPFLAGS" = xset; then
195    CPPFLAGS=$smr_save_CPPFLAGS
196  else
197    unset CPPFLAGS
198  fi
199
200  popdef([smr_name])
201  popdef([smr_header])
202  popdef([smr_extra_flags])
203  popdef([smr_safe_name])
204])
205
206
207AC_DEFUN([smr_CHECK_LIB],
208[
209  dnl Define convenient aliases for the arguments since there are so
210  dnl many of them and I keep confusing myself whenever I have to edit
211  dnl this macro.
212  pushdef([smr_name],        $1)
213  pushdef([smr_libname],     ifelse($2, , smr_name, $2))
214  pushdef([smr_help_string], $3)
215  pushdef([smr_function],    $4)
216  pushdef([smr_header],      $5)
217  pushdef([smr_extra_libs],  $6)
218  pushdef([smr_extra_flags], $7)
219  pushdef([smr_prototype],   $8)
220  pushdef([smr_safe_name],   smr_safe_translation(smr_name))
221
222  dnl Give the user (via "configure --help") an interface to specify
223  dnl whether we should use the library or not, and possibly where we
224  dnl should find it.
225  smr_ARG_WITHLIB([smr_name], [smr_libname], [smr_help_string])
226
227  if test ! x"$with_[]smr_safe_name" = xno; then
228
229    # If we got this far, then the user didn't explicitly ask not to use
230    # the library.
231
232    dnl If the caller of smr_CHECK_LIB specified a header file for this
233    dnl library, then give the user (via "configure --help") an
234    dnl interface to specify where this header file can be found (if it
235    dnl isn't found by the compiler by default).
236    ifelse(smr_header, , , [smr_ARG_WITHINCLUDES(smr_name, smr_header, smr_extra_flags)])
237
238    # We need only look for the library if the header has been found
239    # (or no header is needed).
240    if test [$]smr_have_[]smr_safe_name[]_header != no; then
241
242       AC_CHECK_LIB(smr_libname,
243                    smr_function,
244                    smr_have_[]smr_safe_name[]_library=yes,
245                    smr_have_[]smr_safe_name[]_library=no,
246                    [$]smr_safe_name[]_CFLAGS [smr_extra_flags] [$]smr_safe_name[]_LIBS [smr_extra_libs],
247                    [ifelse(smr_prototype, , , [[#]include <smr_header>])],
248                    smr_prototype)
249    fi
250
251    if test x"[$]smr_have_[]smr_safe_name[]_library" = xyes; then
252      AC_MSG_RESULT([using smr_name library])
253    else
254      smr_safe_name[]_LIBS=
255      smr_safe_name[]_CFLAGS=
256
257      if test x"$with_[]smr_safe_name" = xmaybe; then
258        AC_MSG_RESULT([not using smr_name library])
259      else
260        AC_MSG_WARN([requested smr_name library not found!])
261      fi
262    fi
263  fi
264
265  popdef([smr_name])
266  popdef([smr_libname])
267  popdef([smr_help_string])
268  popdef([smr_function])
269  popdef([smr_header])
270  popdef([smr_extra_libs])
271  popdef([smr_extra_flags])
272  popdef([smr_prototype])
273  popdef([smr_safe_name])
274])
Note: See TracBrowser for help on using the repository browser.