[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: First steps with autoconf and autotools - building an OpenSSL app
From: |
Ivan \"Rambius\" Ivanov |
Subject: |
Re: First steps with autoconf and autotools - building an OpenSSL app |
Date: |
Sat, 10 Jul 2010 09:58:11 +0300 |
Hello Peter,
Thank you very much for your responses.
On Sat, Jul 10, 2010 at 5:48 AM, Peter Johansson <address@hidden> wrote:
> Hi Rambius,
>
> On 7/9/10 9:54 PM, Ivan "Rambius" Ivanov wrote:
>>
>> $ cat configure.in
>
> The modern name is configure.ac. If this is a new project, I wold consider
> changing to configure.ac.
Yes, it is a new project and I renamed it to configure.ac.
>
>> # -*- Autoconf -*-
>> # Process this file with autoconf to produce a configure script.
>>
>> AC_INIT([cryptoexamples], [0.1], address@hidden)
>> AC_CONFIG_AUX_DIR(config)
>> AC_CONFIG_SRCDIR([src])
>> AC_CONFIG_HEADERS([config.h])
>> AM_INIT_AUTOMAKE(cryptoexamples, 0.1)
>
> You don't need to give PACKAGE and VERSION in AM_INIT_AUTOMAKE. automake is
> smart and can figure out that from the arguments in AC_INIT.
I fixed it - it is now AM_INIT_AUTOMAKE with no parameters.
>> # Checks for libraries.
>> AC_CHECK_LIB(ssl, SSL_library_init)
>>
>
> underquoted; I would use
>
> AC_CHECK_LIB([ssl], [SSL_library_init])
I fixed this one also.
>>
>> AC_OUTPUT(Makefile src/Makefile)
>>
> same here
>
> AC_OUTPUT([Makefile src/Makefile])
I quoted this one as well and incorporated Ralf's instruction to split it into
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
>
>> Now my questions are:
>>
>> 1) The default locations of openssl headers and libs are /usr/include
>> and /usr/libs on Mac OS X. However, I have newer version of openssl in
>> /opt/local with headers in /opt/local/include and libs in
>> /opt/local/lib. How to instruct autotools to use the version in
>> /opt/local on Mac OS X?
>
> One way is to call configure as
> ./configure CPPFLAGS=-I/opt/local/include LDFLAGS=-L/opt/local/lib
I tried this and it works!
>> 2) In configure.in I make a check for openssl availability using the macro
>>
>> AC_CHECK_LIB(ssl, SSL_library_init)
>>
>> Later, when I run ./configure I get the message
>>
>> checking for SSL_library_init in -lssl... yes
>>
>> How can I instruct autoconf to fail if openssl is not found (in
>> /opt/local)?
>
> You can write
>
> AC_CHECK_LIB([ssl], [SSL_library_init], [], [AC_MSG_FAILURE([could not find
> ssl])])
I tried this and it also works!
>
> and configure will fail if ssl was not found. If you wanna fail if an old
> ssl (in /usr) was found, I suggest you change the test to test for some
> function that was introduced after that old version, which will make the
> linker test fail when linking against that old version of ssl.
>>
>> 3) In src/Makefile.am I am trying to build libseedprng.a with
>>
>> lib_LIBRARIES = libseedprng.a
>> libseedprng_a_SOURCES = seed_prng.c
>>
>> How can I instruct it to link it against ssl and crypto libraries;
>> that is how can I pass -lssl and -lcrypto options to the linker?
>
> LIBADD = -lssl -lcrypto
>
> should make it although I think -lssl might not be needed as AC_CHECK_LIB
> probably has added -lssl to LIBS already.
Yes, you are right. It does not need -lssl explicitly in src/Makefile.am
My full configure.ac is:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT([cryptoexamples], [0.1], address@hidden)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([src])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
# Checks for libraries.
AC_CHECK_LIB([ssl], [SSL_library_init], [],
[AC_MSG_FAILURE([can't find openssl ssl lib])])
AC_CHECK_LIB([crypto], [EVP_EncryptInit], [],
[AC_MSG_FAILURE([can't find openssl crypto lib])])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
I am grateful to you and to Ralf for your help.
Regards
Rambius
--
Tangra Mega Rock: http://www.radiotangra.com