acinclude.m4 (9439B)
1 dnl Helper macros for Tor configure.ac 2 dnl Copyright (c) 2001-2004, Roger Dingledine 3 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson 4 dnl Copyright (c) 2007-2008, Roger Dingledine, Nick Mathewson 5 dnl Copyright (c) 2007-2019, The Tor Project, Inc. 6 dnl See LICENSE for licensing information 7 8 AC_DEFUN([TOR_EXTEND_CODEPATH], 9 [ 10 if test -d "$1/lib"; then 11 LDFLAGS="-L$1/lib $LDFLAGS" 12 elif test -d "$1/lib64"; then 13 LDFLAGS="-L$1/lib64 $LDFLAGS" 14 else 15 LDFLAGS="-L$1 $LDFLAGS" 16 fi 17 if test -d "$1/include"; then 18 CPPFLAGS="-I$1/include $CPPFLAGS" 19 else 20 CPPFLAGS="-I$1 $CPPFLAGS" 21 fi 22 ]) 23 24 AC_DEFUN([TOR_DEFINE_CODEPATH], 25 [ 26 if test x$1 = "x(system)"; then 27 TOR_LDFLAGS_$2="" 28 TOR_CPPFLAGS_$2="" 29 else 30 if test -d "$1/lib"; then 31 TOR_LDFLAGS_$2="-L$1/lib" 32 TOR_LIBDIR_$2="$1/lib" 33 elif test -d "$1/lib64"; then 34 TOR_LDFLAGS_$2="-L$1/lib64" 35 TOR_LIBDIR_$2="$1/lib64" 36 else 37 TOR_LDFLAGS_$2="-L$1" 38 TOR_LIBDIR_$2="$1" 39 fi 40 if test -d "$1/include"; then 41 TOR_CPPFLAGS_$2="-I$1/include" 42 else 43 TOR_CPPFLAGS_$2="-I$1" 44 fi 45 fi 46 AC_SUBST(TOR_CPPFLAGS_$2) 47 AC_SUBST(TOR_LDFLAGS_$2) 48 ]) 49 50 dnl 1: flags 51 dnl 2: try to link too if this is nonempty. 52 dnl 3: what to do on success compiling 53 dnl 4: what to do on failure compiling 54 AC_DEFUN([TOR_TRY_COMPILE_WITH_CFLAGS], [ 55 AS_VAR_PUSHDEF([VAR],[tor_cv_cflags_$1]) 56 AC_CACHE_CHECK([whether the compiler accepts $1], VAR, [ 57 tor_saved_CFLAGS="$CFLAGS" 58 CFLAGS="$CFLAGS -pedantic -Werror $1" 59 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], 60 [AS_VAR_SET(VAR,yes)], 61 [AS_VAR_SET(VAR,no)]) 62 if test x$2 != x; then 63 AS_VAR_PUSHDEF([can_link],[tor_can_link_$1]) 64 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], 65 [AS_VAR_SET(can_link,yes)], 66 [AS_VAR_SET(can_link,no)]) 67 AS_VAR_POPDEF([can_link]) 68 fi 69 CFLAGS="$tor_saved_CFLAGS" 70 ]) 71 if test x$VAR = xyes; then 72 $3 73 else 74 $4 75 fi 76 AS_VAR_POPDEF([VAR]) 77 ]) 78 79 dnl 1:flags 80 dnl 2:also try to link (yes: non-empty string) 81 dnl will set yes or no in $tor_can_link_$1 (as modified by AS_VAR_PUSHDEF) 82 AC_DEFUN([TOR_CHECK_CFLAGS], [ 83 TOR_TRY_COMPILE_WITH_CFLAGS($1, $2, CFLAGS="$CFLAGS $1", true) 84 ]) 85 86 dnl 1:flags 87 dnl 2:extra ldflags 88 dnl 3:extra libraries 89 AC_DEFUN([TOR_CHECK_LDFLAGS], [ 90 AS_VAR_PUSHDEF([VAR],[tor_cv_ldflags_$1]) 91 AC_CACHE_CHECK([whether the linker accepts $1], VAR, [ 92 tor_saved_CFLAGS="$CFLAGS" 93 tor_saved_LDFLAGS="$LDFLAGS" 94 tor_saved_LIBS="$LIBS" 95 CFLAGS="$CFLAGS -pedantic -Werror" 96 LDFLAGS="$LDFLAGS $2 $1" 97 LIBS="$LIBS $3" 98 AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [fputs("", stdout)])], 99 [AS_VAR_SET(VAR,yes)], 100 [AS_VAR_SET(VAR,no)], 101 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], 102 [AS_VAR_SET(VAR,yes)], 103 [AS_VAR_SET(VAR,no)])]) 104 CFLAGS="$tor_saved_CFLAGS" 105 LDFLAGS="$tor_saved_LDFLAGS" 106 LIBS="$tor_saved_LIBS" 107 ]) 108 if test x$VAR = xyes; then 109 LDFLAGS="$LDFLAGS $1" 110 fi 111 AS_VAR_POPDEF([VAR]) 112 ]) 113 114 dnl 1:libname 115 AC_DEFUN([TOR_WARN_MISSING_LIB], [ 116 h="" 117 if test x$2 = xdevpkg; then 118 h=" headers for" 119 fi 120 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then 121 AC_MSG_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"]) 122 if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then 123 AC_MSG_WARN([ You will probably need $tor_$1_devpkg_debian too.]) 124 fi 125 fi 126 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then 127 AC_MSG_WARN([On Fedora, you can install$h $1 using "dnf install $tor_$1_$2_redhat"]) 128 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 129 AC_MSG_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.]) 130 fi 131 else 132 if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then 133 AC_MSG_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat RPM package]) 134 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 135 AC_MSG_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.]) 136 fi 137 fi 138 fi 139 ]) 140 141 dnl Look for a library, and its associated includes, and how to link 142 dnl against it. 143 dnl 144 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers, 145 dnl 5:prototype, 146 dnl 6:code, 7:IGNORED, 8:searchextra) 147 dnl 148 dnl Special variables: 149 dnl ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir. 150 dnl Used to support renaming --with-ssl-dir to --with-openssl-dir 151 dnl 152 AC_DEFUN([TOR_SEARCH_LIBRARY], [ 153 try$1dir="" 154 AC_ARG_WITH($1-dir, 155 AS_HELP_STRING(--with-$1-dir=PATH, [specify path to $1 installation]), 156 [ 157 if test x$withval != xno ; then 158 try$1dir="$withval" 159 fi 160 ]) 161 if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then 162 try$1dir="$ALT_$1_WITHVAL" 163 fi 164 165 tor_saved_LIBS="$LIBS" 166 tor_saved_LDFLAGS="$LDFLAGS" 167 tor_saved_CPPFLAGS="$CPPFLAGS" 168 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [ 169 tor_$1_dir_found=no 170 tor_$1_any_linkable=no 171 172 for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do 173 LDFLAGS="$tor_saved_LDFLAGS" 174 LIBS="$3 $tor_saved_LIBS" 175 CPPFLAGS="$tor_saved_CPPFLAGS" 176 177 if test -z "$tor_trydir" ; then 178 continue; 179 fi 180 181 # Skip the directory if it isn't there. 182 if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then 183 continue; 184 fi 185 186 # If this isn't blank, try adding the directory (or appropriate 187 # include/libs subdirectories) to the command line. 188 if test "$tor_trydir" != "(system)"; then 189 TOR_EXTEND_CODEPATH($tor_trydir) 190 fi 191 192 # Can we link against (but not necessarily run, or find the headers for) 193 # the binary? 194 AC_LINK_IFELSE([AC_LANG_PROGRAM([$5], [$6])], 195 [linkable=yes], [linkable=no]) 196 197 if test "$linkable" = yes; then 198 tor_$1_any_linkable=yes 199 # Okay, we can link against it. Can we find the headers? 200 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$4], [$6])], 201 [buildable=yes], [buildable=no]) 202 if test "$buildable" = yes; then 203 tor_cv_library_$1_dir=$tor_trydir 204 tor_$1_dir_found=yes 205 break 206 fi 207 fi 208 done 209 210 if test "$tor_$1_dir_found" = no; then 211 if test "$tor_$1_any_linkable" = no ; then 212 AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusual, you can specify an explicit path using --with-$1-dir]) 213 TOR_WARN_MISSING_LIB($1, pkg) 214 AC_MSG_ERROR([Missing libraries; unable to proceed.]) 215 else 216 AC_MSG_WARN([We found the libraries for $1, but we could not find the C header files. You may need to install a devel package.]) 217 TOR_WARN_MISSING_LIB($1, devpkg) 218 AC_MSG_ERROR([Missing headers; unable to proceed.]) 219 fi 220 fi 221 222 LDFLAGS="$tor_saved_LDFLAGS" 223 LIBS="$tor_saved_LIBS" 224 CPPFLAGS="$tor_saved_CPPFLAGS" 225 ]) dnl end cache check 226 227 LIBS="$3 $LIBS" 228 if test "$tor_cv_library_$1_dir" != "(system)"; then 229 TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir) 230 fi 231 232 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1) 233 234 if test "$cross_compiling" != yes; then 235 AC_CACHE_CHECK([whether we need extra options to link $1], 236 tor_cv_library_$1_linker_option, [ 237 orig_LDFLAGS="$LDFLAGS" 238 runs=no 239 linked_with=nothing 240 if test -d "$tor_cv_library_$1_dir/lib"; then 241 tor_trydir="$tor_cv_library_$1_dir/lib" 242 else 243 tor_trydir="$tor_cv_library_$1_dir" 244 fi 245 for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \ 246 "-Wl,-rpath,$tor_trydir" ; do 247 if test "$tor_tryextra" = "(none)"; then 248 LDFLAGS="$orig_LDFLAGS" 249 else 250 LDFLAGS="$tor_tryextra $orig_LDFLAGS" 251 fi 252 AC_RUN_IFELSE([AC_LANG_PROGRAM([$5], [$6])], 253 [runnable=yes], [runnable=no], 254 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], 255 [runnable=yes], 256 [runnable=no])]) 257 if test "$runnable" = yes; then 258 tor_cv_library_$1_linker_option=$tor_tryextra 259 break 260 fi 261 done 262 263 if test "$runnable" = no; then 264 AC_MSG_ERROR([Found linkable $1 in $tor_cv_library_$1_dir, but it does not seem to run, even with -R. Maybe specify another using --with-$1-dir}]) 265 fi 266 LDFLAGS="$orig_LDFLAGS" 267 ]) dnl end cache check check for extra options. 268 269 if test "$tor_cv_library_$1_linker_option" != "(none)" ; then 270 TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option" 271 fi 272 fi # cross-compile 273 274 LIBS="$tor_saved_LIBS" 275 LDFLAGS="$tor_saved_LDFLAGS" 276 CPPFLAGS="$tor_saved_CPPFLAGS" 277 278 ]) dnl end defun 279 280 dnl Check whether the prototype for a function is present or missing. 281 dnl Apple has a nasty habit of putting functions in their libraries (so that 282 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers. 283 dnl 284 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes) 285 AC_DEFUN([TOR_CHECK_PROTOTYPE], [ 286 AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [ 287 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$3],[void *ptr= $1 ;])], 288 tor_cv_$1_declared=yes,tor_cv_$1_declared=no)]) 289 if test x$tor_cv_$1_declared != xno ; then 290 AC_DEFINE($2, 1, 291 [Defined if the prototype for $1 seems to be present.]) 292 fi 293 ])