autoconf – openSUSE Lizards https://lizards.opensuse.org Blogs and Ramblings of the openSUSE Members Fri, 06 Mar 2020 11:29:40 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.5 openSUSE and GCC part 7: autotools and how I do it https://lizards.opensuse.org/2013/11/19/opensuse-and-gcc-part-7/ Tue, 19 Nov 2013 08:54:05 +0000 http://lizards.opensuse.org/?p=10147 Last time I was little bit too hard to autotools. Okay they are not easy but they work. I also let last time people to figure how to get a long with autotools. Now I show how I do it.

Let’s dance

First put some good music on and relax. Starting new project and trying to get it compile is very unpleasant experience. Then read blog about autotools and then also see example that I’ve been using. Now you should have files: ‘configure.ac’, ‘Makefile.am’, ‘SDL_DisplayBitmap.c’, ‘LICENSE.TXT’ and ‘image.bmp’ in same directory/folder also you should have rpm libSDL_image-devel installed. Then we zypper needed autotools in.

zypper install libtool automake autoconf

after that we need to make directory contain needed scripts and M4-macros. You don’t need to copy them manually just make like this in console:

aclocal --force
libtoolize -c
automake --copy --add-missing
autoconf --force

So we run ‘aclocal’ to copy those M4-macros after that we ‘libtoolize’ our directory and then ‘automake’ creates needed ‘Makefile.in’ files from ‘Makefile.am’. Last ‘autoconf’ creates configure-script from configure.ac. If everything went fine you ca continue:

./configure
make
./SDL_DisplayBitmap

Okay now it should work as expected. If you are interested you can try also

make dist

and you should have ‘SDL_DisplayBitmap-1.0.tar.gz’ and ‘SDL_DisplayBitmap-1.0.tar.bz2’ to distribute you application.

Let’s dig further

I’ll explain what these sentences mean in ‘configure.ac’:

AC_PREREQ([2.57])
AC_CONFIG_MACRO_DIR([m4])

Just tell what Autoconf is needed at least 2.57 and what is M4-macro directory (in this case it’s ‘m4’)

AC_INIT([SDL_DisplayBitmap], [1.0], [http://lizards.opensuse.org])

Let’s have application named SDL_DisplayBitmap which version is 1.0 and URL to see something more is http://lizards.opensuse.org

AM_INIT_AUTOMAKE([foreign dist-bzip2])

Initialize automake. We want ‘tar.bz2’ package also made.

AC_LANG_C
AC_PROG_CC
AM_PROG_LIBTOOL

Make sure we have C++ and C-compiler and Libtools.

C_OPTIONS="-ansi -Wall -Werror -std=c99 -fno-strict-aliasing"

I use these C-Flags in my applications. You should use yours.

AC_SUBST(C_OPTIONS)

Make them available in Makefile.in/.am

PKG_CHECK_MODULES(SDL, SDL_image)

Check SDL_image from pkg-config and store it in SDL-prefix (SDL_LIBS and SDL_CFLAGS) variable.

AC_OUTPUT([Makefile])

Configure these files from configure here. In our case only use formulate Makefile.in file.

Makefile.am

Now it’s time to listen Scorpions Still loving you if don’t already listening it.

INCLUDES = $(SDL_CFLAGS) $(C_OPTIONS)

This actually old school way of doing it but it compatible downwards. We but our C_OPTIONS from configure.ac and SDL needed build flags in build.

EXTRA_DIST = LICENSE.TXT image.bmp

We also pack these files in distribution tar-ball.

noinst_PROGRAMS = SDL_DisplayBitmap

This tell we want to have binary named: ‘SDL_DisplayBitmap’ that ain’t installed anywhere. If you but bin_PROGRAMS application will be installed to ‘/usr/local/bin’ or ‘prefix/bin’ you mentioned in ‘./configure –prefix=/prefix’ (sbin_PROGRAMS will install it to ‘/usr/local/sbin’).

SDL_DisplayBitmap_SOURCES = SDL_DisplayBitmap.c
SDL_DisplayBitmap_LDFLAGS = $(SDL_LIBS)

Actually tell what sources belongs to SDL_DisplayBitmap and what libs are need to build this.

Yes that was so easy and nice. Next time is time to make RPM from our example application.

]]>
openSUSE and GCC part 6: Introduction to autotools https://lizards.opensuse.org/2013/11/12/opensuse-and-gcc-part-6/ https://lizards.opensuse.org/2013/11/12/opensuse-and-gcc-part-6/#comments Tue, 12 Nov 2013 06:47:56 +0000 http://lizards.opensuse.org/?p=10114 Autotools, autotools and once again autotools. Years ago I started with autotools I thought, ‘Hey someone has really get into linking and compiling’. I was sold for a while and tried to learn it inside out. Then I understood that I will never be good at autotools (So I started to go to gym instead). M4 macro language it is not my thing.
It’s just something that should be put on one way Mars shuttle and send to gray ones to figure out. I think mr. Spock’s brains functioned with M4 but mine won’t. If there is some M4 specialist. Send me e-mail or post comment about it and tell why M4 is best macro language on earth. If nobody stands up for poor M4-macro language I’ll keep unloving it. I can start liking it because I was so wrong with Rexx.

Autotools

Autotools are designed to work with GNU GCC (GNU Compiler Collection) and visa versa. You can use Autotools with any C-compiler or with any language but it works best when compiling GNU C or C++ applications. Autotools are actually four tools aclocal, libtool, autoconf and automake.

GNU aclocal

It’s easier to tell what aclocal is not than what it is. Aclocal checks your needed M4 macros and copies or symlinks them to your project. I hope you never need to tackle with this or write your own M4 macro for find you great library (use pkg-config I say it once more use pkg-config) or new something that other M4 macros sucks to do. I don’t have anything else to say about this.

GNU libtool

If you like to make Share Objects (.so), Windows DLL or something your operating system supports libtool is your friend. You’ll need this anyways wanted or not.

GNU autoconf

This one is also strange tool. I compiles from M4 macros an ‘configure’-named bash script. So you have ‘configure.ac’ M4 based script that is formulated to ‘configure’-named bash script and autoconf does that.

GNU automake

Last time we talked about Makefiles and how to use them with compiling. Autotools is make based. You can probably use other build tools but I never have seen them in use. Automake seeks for ‘Makefile.am’ files and turns macros and stuff inside them to ‘Makefile.in’ that is usable with ‘configure’-script from autoconf. Actually its not that simple but with this you can live you life happilly ever after.
Because everyone wants to know everything these days read more here.

And this was complicated you moron!

Yes I can admit it! I’m not very clever guy. When I was young I though hell there ain’t nobody that I better than me. Now I can admin there is and I’m just a ordinary guy from Finland. So you think you are more clever than me okay let’s test it. I’ll just throw you a bone and you tackle with by yourself and search machine (I won’t use that G-word there is so many other ones also). Example is the same that have been use in other posts and all the needed info is here so you should be able to figure this out by yourself and ask from mr. NSA the rest. Here are configure.ac and Makefile.am but how to utilize them? Good question.. hmm.. use zypper to install automake.. maybe.. maybe?

configure.ac

AC_PREREQ([2.57])
AC_CONFIG_MACRO_DIR([m4])
AC_INIT([SDL_DisplayBitmap], [1.0], [http://lizards.opensuse.org])
AM_INIT_AUTOMAKE([foreign dist-bzip2])

EXTRA_DIST = LICENSE.TXT image.bmp

AC_LANG_C
AC_PROG_CC
AM_PROG_LIBTOOL

C_OPTIONS="-ansi -Wall -Werror -std=c99 -fno-strict-aliasing"

AC_SUBST(C_OPTIONS)

PKG_CHECK_MODULES(SDL, SDL_image)

AC_OUTPUT([Makefile])

Makefile.am

INCLUDES = $(SDL_CFLAGS) $(C_OPTIONS)

EXTRA_DIST = LICENSE.TXT image.bmp

noinst_PROGRAMS = SDL_DisplayBitmap

SDL_DisplayBitmap_SOURCES = SDL_DisplayBitmap.c
SDL_DisplayBitmap_LDFLAGS = $(SDL_LIBS)

Now you have everything and go for the bad thing. Next time I’ll tell how I do it..

]]>
https://lizards.opensuse.org/2013/11/12/opensuse-and-gcc-part-6/feed/ 2