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.
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.
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.
]]>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.
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.
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.
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.
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.
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?
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])
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..
]]>