Fix CVE-2017-6891 in minitasn1 code
[platform/upstream/gnutls.git] / m4 / guile.m4
1 ## Autoconf macros for working with Guile.
2 ##
3 ##   Copyright (C) 1998, 2001, 2006, 2010, 2012 Free Software
4 ##   Foundation, Inc.
5 ##
6 ## This library is free software; you can redistribute it and/or
7 ## modify it under the terms of the GNU Lesser General Public
8 ## License as published by the Free Software Foundation; either
9 ## version 2.1 of the License, or (at your option) any later version.
10 ## 
11 ## This library is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ## Lesser General Public License for more details.
15 ## 
16 ## You should have received a copy of the GNU Lesser General Public
17 ## License along with this library; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 ## Index
21 ## -----
22 ##
23 ## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
24 ## GUILE_FLAGS -- set flags for compiling and linking with Guile
25 ## GUILE_SITE_DIR -- find path to Guile "site" directory
26 ## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
27 ## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
28 ## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
29 ## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
30 ## GUILE_MODULE_EXPORTS -- check if a module exports a variable
31 ## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
32
33 ## Code
34 ## ----
35
36 ## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
37 ## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
38
39 # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
40 #
41 # Usage: GUILE_PROGS
42 #
43 # This macro looks for programs @code{guile}, @code{guile-config} and
44 # @code{guile-tools}, and sets variables @var{GUILE}, @var{GUILE_CONFIG} and
45 # @var{GUILE_TOOLS}, to their paths, respectively.  If either of the first two
46 # is not found, signal error.
47 #
48 # The variables are marked for substitution, as by @code{AC_SUBST}.
49 #
50 AC_DEFUN([GUILE_PROGS],
51  [AC_PATH_PROG(GUILE,guile)
52   if test "$GUILE" = "" ; then
53       AC_MSG_ERROR([guile required but not found])
54   fi
55   AC_SUBST(GUILE)
56   AC_PATH_PROG(GUILE_CONFIG,guile-config)
57   if test "$GUILE_CONFIG" = "" ; then
58       AC_MSG_ERROR([guile-config required but not found])
59   fi
60   AC_SUBST(GUILE_CONFIG)
61   AC_PATH_PROG(GUILE_TOOLS,guile-tools)
62   AC_SUBST(GUILE_TOOLS)
63  ])
64
65 # GUILE_FLAGS -- set flags for compiling and linking with Guile
66 #
67 # Usage: GUILE_FLAGS
68 #
69 # This macro runs the @code{guile-config} script, installed with Guile, to
70 # find out where Guile's header files and libraries are installed.  It sets
71 # two variables, @var{GUILE_CFLAGS} and @var{GUILE_LDFLAGS}.
72 #
73 # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
74 # uses Guile header files.  This is almost always just a @code{-I} flag.
75 #
76 # @var{GUILE_LDFLAGS}: flags to pass to the linker to link a program against
77 # Guile.  This includes @code{-lguile} for the Guile library itself, any
78 # libraries that Guile itself requires (like -lqthreads), and so on.  It may
79 # also include a @code{-L} flag to tell the compiler where to find the
80 # libraries.
81 #
82 # The variables are marked for substitution, as by @code{AC_SUBST}.
83 #
84 AC_DEFUN([GUILE_FLAGS],
85  [AC_REQUIRE([GUILE_PROGS])dnl
86   AC_MSG_CHECKING([libguile compile flags])
87   GUILE_CFLAGS="`$GUILE_CONFIG compile`"
88   AC_MSG_RESULT([$GUILE_CFLAGS])
89   AC_MSG_CHECKING([libguile link flags])
90   GUILE_LDFLAGS="`$GUILE_CONFIG link`"
91   AC_MSG_RESULT([$GUILE_LDFLAGS])
92   AC_SUBST(GUILE_CFLAGS)
93   AC_SUBST(GUILE_LDFLAGS)
94  ])
95
96 # GUILE_SITE_DIR -- find path to Guile "site" directory
97 #
98 # Usage: GUILE_SITE_DIR
99 #
100 # This looks for Guile's "site" directory, usually something like
101 # PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
102 # Note that the var name is different from the macro name.
103 #
104 # The variable is marked for substitution, as by @code{AC_SUBST}.
105 #
106 AC_DEFUN([GUILE_SITE_DIR],
107  [AC_REQUIRE([GUILE_PROGS])dnl
108   AC_MSG_CHECKING(for Guile site directory)
109   GUILE_SITE=`[$GUILE_CONFIG] info pkgdatadir`/site
110   AC_MSG_RESULT($GUILE_SITE)
111   AC_SUBST(GUILE_SITE)
112  ])
113
114 # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
115 #
116 # Usage: GUILE_CHECK_RETVAL(var,check)
117 #
118 # @var{var} is a shell variable name to be set to the return value.
119 # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
120 #    returning either 0 or non-#f to indicate the check passed.
121 #    Non-0 number or #f indicates failure.
122 #    Avoid using the character "#" since that confuses autoconf.
123 #
124 AC_DEFUN([GUILE_CHECK],
125  [AC_REQUIRE([GUILE_PROGS])
126   $GUILE -c "$2" > /dev/null 2>&1
127   $1=$?
128  ])
129
130 # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
131 #
132 # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
133 #
134 # @var{var} is a shell variable name to be set to "yes" or "no".
135 # @var{module} is a list of symbols, like: (ice-9 common-list).
136 # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
137 # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
138 #
139 AC_DEFUN([GUILE_MODULE_CHECK],
140          [AC_MSG_CHECKING([if $2 $4])
141           GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
142           if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
143           AC_MSG_RESULT($$1)
144          ])
145
146 # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
147 #
148 # Usage: GUILE_MODULE_AVAILABLE(var,module)
149 #
150 # @var{var} is a shell variable name to be set to "yes" or "no".
151 # @var{module} is a list of symbols, like: (ice-9 common-list).
152 #
153 AC_DEFUN([GUILE_MODULE_AVAILABLE],
154          [GUILE_MODULE_CHECK($1,$2,0,is available)
155          ])
156
157 # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
158 #
159 # Usage: GUILE_MODULE_REQUIRED(symlist)
160 #
161 # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
162 # like: ice-9 common-list.
163 #
164 AC_DEFUN([GUILE_MODULE_REQUIRED],
165          [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
166           if test "$ac_guile_module_required" = "no" ; then
167               AC_MSG_ERROR([required guile module not found: ($1)])
168           fi
169          ])
170
171 # GUILE_MODULE_EXPORTS -- check if a module exports a variable
172 #
173 # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
174 #
175 # @var{var} is a shell variable to be set to "yes" or "no".
176 # @var{module} is a list of symbols, like: (ice-9 common-list).
177 # @var{modvar} is the Guile Scheme variable to check.
178 #
179 AC_DEFUN([GUILE_MODULE_EXPORTS],
180  [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
181  ])
182
183 # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
184 #
185 # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
186 #
187 # @var{module} is a list of symbols, like: (ice-9 common-list).
188 # @var{modvar} is the Guile Scheme variable to check.
189 #
190 AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
191  [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
192   if test "$guile_module_required_export" = "no" ; then
193       AC_MSG_ERROR([module $1 does not export $2; required])
194   fi
195  ])
196
197 ## guile.m4 ends here