-
Idar Tollefsen authored
Fixes pkg-config usage and switches from AC_CHECK_LIB() to AC_SEARCH_LIBS() for libcrypto. This fixes the issue mentioned in pull request #176 of the crypto library being added multiple times when using OpenSSL. There are several details to note. If the user specifies a OpenSSL directory with --with-openssl-dir, then the relevant subdirectories need to end up in CFLAGS and LDFLAGS (as they already did), not in CFLAGS and LIBS as proposed by PR #176. Since AC_CHECK_LIB() prepends the library, putting the user supplied directory in LIBS before the call to AC_CHECK_LIB() would put -lcrypto before -L<dir>/lib, potentially picking up the wrong library or the system supplied library. If pkg-config is available and the user specifies a OpenSSL directory that contains lib/pkgconfig/libcrypto.pc, then PKG_CONFIG_PATH is set so that the custom location can be picked up by pkg-config. In this case, neither CFLAGS nor LDFLAGS are modified since the pkg-config check will do the right thing here. The original code would call $PKG_CONFIG unconditionally via a shell invocation regardless of whether pkg-config was available or not. This changes it to use the PKG_CHECK_MODULES_STATIC() macro only if pkg-config is available. Note that PKG_CHECK_MODULES_STATIC() requires pkg-config 0.29 or higher, hence the version argument to PKG_PROG_PKG_CONFIG(). Unlike PKG_CHECK_MODULES(), PKG_CHECK_MODULES_STATIC() includes Libs.private for static linking (corresponds to 'pkg-config --static'). For libcrypto, this will include libz and/or libdl as necessary/configured. For the case when pkg-config is not installed, the AC_CHECK_LIB() calls for libz and libdl are kept. If found, they'll be added unconditionally, as before. As mentioned in the comment for PR #176, even if pkg-config is available and used, it's still desirable to check for the presence of certain functions in the configured library, and the usability of the library itself (i.e. it's built for the correct platform). To do so, and also to check for libcrypto if pkg-config isn't installed, AC_SEARCH_LIBS() is used. This will check for the given function in the libraries listed, which is only libcrypto in this case. The way AC_SEARCH_LIBS() works is that it will try to find the function without adding any libraries and then start adding libraries from the given list until the function is found or the list exhausted. For the case when pkg-config is installed and libcrypto is found via PKG_CHECK_MODULES_STATIC(), these extra checks for specific functions will not add -lcrypto again because it doesn't need to - it's already in LIBS and the functions will be found. For the case when pkg-config is not installed, the first check will add -lcrypto to LIBS while subsequent checks will pass without adding it again. Should any of the checks fail, i.e. the function isn't found or the configured library isn't usable, then it will fail as intended.
333fa84e