Debian Codegraph @

build/m4/ax_ext_have_static_lib.m4

raw
1 # ===========================================================================
2 #
3 # SYNOPSIS
4 #
5 # AX_EXT_HAVE_STATIC_LIB(VARIABLE-PREFIX, SEARCH-PATHS, LIBRARY-NAMES,
6 # FUNCTION-NAME, [EXTRA-LIBRARIES])
7 #
8 # DESCRIPTION
9 #
10 # Provides a generic test for locating an appropriate static library
11 # to force link against, even when one's application is dynamically
12 # linked. The macro was inspired by the PKG_CHECK_MODULES macro.
13 #
14 # If the library is found, [VARIABLE-PREFIX]_FOUND is defined, and
15 # in all cases [VARIABLE-PREFIX]_LIBS is substituted.
16 #
17 # Example:
18 #
19 # AX_EXT_HAVE_STATIC_LIB_DETECT
20 # AX_EXT_HAVE_STATIC_LIB(ZLIB, [${DEFAULT_STATIC_LIB_SEARCH_PATHS}],
21 # z libz, compress)
22 #
23 # LICENSE
24 #
25 # Copyright (c) 2018 Joseph Benden <[email protected]>
26 #
27 # This program is free software: you can redistribute it and/or modify it
28 # under the terms of the GNU General Public License as published by the
29 # Free Software Foundation, either version 3 of the License, or (at your
30 # option) any later version.
31 #
32 # This program is distributed in the hope that it will be useful, but
33 # WITHOUT ANY WARRANTY; without even the implied warranty of
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
35 # Public License for more details.
36 #
37 # You should have received a copy of the GNU General Public License along
38 # with this program. If not, see <https://www.gnu.org/licenses/>.
39 #
40 # As a special exception, the respective Autoconf Macro's copyright owner
41 # gives unlimited permission to copy, distribute and modify the configure
42 # scripts that are the output of Autoconf when processing the Macro. You
43 # need not follow the terms of the GNU General Public License when using
44 # or distributing such scripts, even though portions of the text of the
45 # Macro appear in them. The GNU General Public License (GPL) does govern
46 # all other use of the material that constitutes the Autoconf Macro.
47 #
48 # This special exception to the GPL applies to versions of the Autoconf
49 # Macro released by the Autoconf Archive. When you make and distribute a
50 # modified version of the Autoconf Macro, you may extend this special
51 # exception to the GPL to apply to your modified version as well.
52
53 #serial 1
54
55 AC_DEFUN([AX_EXT_HAVE_STATIC_LIB_DETECT],
56 [
57 AC_REQUIRE([AC_CANONICAL_HOST])
58 AC_ARG_VAR([STATIC_HOST_ALIAS], [The alias name for host, default @<:@HOST@:>@.])dnl
59 AC_ARG_VAR([STATIC_LIBDIR_NAME], [The libdir name for host, default @<:@lib@:>@.])dnl
60
61 AC_CACHE_VAL([ext_cv_static_libdir_name], [
62 ext_cv_static_libdir_name="${STATIC_LIBDIR_NAME:-lib}"
63 ])
64
65 AC_CACHE_VAL([ext_cv_default_static_lib_search_paths], [
66 AC_MSG_CHECKING([Default static library search path])
67
68 static_extpath=""
69 if test -n "${STATIC_HOST_ALIAS}"
70 then
71 static_host="${STATIC_HOST_ALIAS}"
72 else
73 if test "${GCC}" = "yes"
74 then
75 static_host=`${CC} -dumpmachine 2>/dev/null`
76 static_extpath=`${CC} -print-search-dirs 2> /dev/null | grep '^libraries' | sed -e 's/@<:@^=@:>@*=//' -e 's/:/ /g'`
77 else
78 static_host="${host}"
79 fi
80 fi
81
82 ext_cv_default_static_lib_search_paths=" \
83 ${static_extpath} \
84 /opt/${ext_cv_static_libdir_name}/${static_host} \
85 /opt/${ext_cv_static_libdir_name} \
86 /usr/local/${ext_cv_static_libdir_name}/${static_host} \
87 /usr/local/${ext_cv_static_libdir_name} \
88 /usr/${ext_cv_static_libdir_name}/${static_host} \
89 /usr/${ext_cv_static_libdir_name} \
90 /${ext_cv_static_libdir_name} \
91 /opt/lib/${static_host} \
92 /opt/lib \
93 "
94 AC_MSG_RESULT([${ext_cv_default_static_lib_search_paths}])
95 ])
96 DEFAULT_STATIC_LIB_SEARCH_PATHS="${ext_cv_default_static_lib_search_paths}"
97 STATIC_LIBDIR_NAME="${ext_cv_static_libdir_name}"
98 ])
99
100 AC_DEFUN([AX_EXT_HAVE_STATIC_LIB],
101 [
102 AC_ARG_VAR([$1][_FOUND], [set if the static library $1 is available, already.])dnl
103 AC_ARG_VAR([$1][_LIBS], [static library linker flags for $1.])dnl
104
105 for dir in m4_normalize($2)
106 do
107 ext_haslib_cvdir=`echo $dir | $as_tr_sh`
108 ext_haslib_cvname=`echo $3 | $as_tr_sh`
109
110 AC_CACHE_VAL([ext_cv${ext_haslib_cvdir}_haslib_${ext_haslib_cvname}], [
111 for name in $3
112 do
113 dnl Does an archive file exists in our current path?
114 AC_CHECK_FILE("${dir}/${name}.a", [
115 dnl If so, can we link a simple program with it?
116
117 ext_func_search_save_LIBS=$LIBS
118 ext_func_save_ldflags=${LDFLAGS}
119 LIBS="${dir}/${name}.a $5 ${ext_func_search_save_LIBS}"
120 LDFLAGS="${ext_func_save_ldflags}"
121
122 AC_LINK_IFELSE([AC_LANG_CALL([], [$4])], [
123 eval "ext_cv${ext_haslib_cvdir}_haslib_${ext_haslib_cvname}"="${dir}/${name}.a"
124 AC_MSG_NOTICE([Found static library: ${dir}/${name}.a])
125 ], [
126 eval "ext_cv${ext_haslib_cvdir}_haslib_${ext_haslib_cvname}"=""
127 ])
128
129 LIBS=$ext_func_search_save_LIBS
130 LDFLAGS=$ext_func_save_ldflags
131 ])
132 done
133 ])
134
135 if eval `echo 'test x${'ext_cv${ext_haslib_cvdir}_haslib_${ext_haslib_cvname}'}' != "x"`; then
136 $1[]_LIBS="`eval echo '\${'ext_cv${ext_haslib_cvdir}_haslib_${ext_haslib_cvname}'}'`"
137 $1[]_FOUND=yes
138 ext_lib_found="yes"
139
140 AC_SUBST($1[]_LIBS)
141 AC_SUBST($1[]_FOUND)
142 fi
143 done
144 ])