Skip to content

Check 3rd party features

tat edited this page Oct 3, 2012 · 1 revision

Use makl_compile to check special features in 3rd party deps

If you need to check for a particular feature in a third party dependency you can use makl_compile function together with a specifically crafted program in order to tell if the tracked dependency has the requested feature or not.

A real life case. I aimed at finding out if OpenSSL library found in $(prefix) had been patched with Nokia’s PSK code. So, in my configure script, after the makl_args_handle line I’ve placed the following lines:

# get $(prefix)
__dd=`makl_get_var_mk "DESTDIR"`

# myproj needs a PSK patched version of OpenSSL
makl_compile "build/psk.c" "-I${__dd}/include" "-L${__dd}/lib -lssl -lcrypto"
[ $? == 0 ] || \
      makl_err 1 "could not find a PSK patched version of OpenSSL in ${__dd}"

# if found, set openssl compiler/linker flags
makl_set_var_mk "OPENSSL_CFLAGS" "-I${__dd}/include"
makl_set_var_mk "OPENSSL_LDFLAGS" "-L${__dd}/lib -lssl -lcrypto"
makl_set_var_mk "OPENSSL_LDADD" "${__dd}/lib/libssl.a ${__dd}/lib/libcrypto.a"

Since I know that Nokia’s patches introduce for the first time into OpenSSL the SSL_CTX_set_psk_client_callback API, the build/psk.c program can be as simple as that:

#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>

int main (void)
{
    SSL_CTX ctx;

    /* check PSK */
    SSL_CTX_set_psk_client_callback(&ctx, NULL);

    return 0;   
}

In case I were trying to use an unpatched OpenSSL 0.9.8x, I’d get a:

checking dependencies
ld: Undefined symbols:
_SSL_CTX_set_psk_client_callback
[err] could not find a PSK patched version of OpenSSL in /usr/local

which would stop the autoconfiguration step.