Advertisement

Autoconf

Started by October 17, 2005 07:57 AM
6 comments, last by kadaf 19 years, 1 month ago
Hi! I have written a program under Linux. Now I want to make a tar.gz package using autoconf, automake, so I can distribute the program. But the autoconf man page is difficult for me to understand, because I am new to Linux. Where should I start? Is there any userfriendly program for this purpose? Can Kdevelop do this? Lutyo
The template files generated by KDevelop can help but they are a bit outdated. I suggest googling for configure.ac and Makefile.am. You will find both tutorials and examples of real projects. The script to run autotools in the right order is often called autogen.sh or bootstrap.

OGRE is one good example but be sure to look at others as well.

Btw. if you see a configure.in file then it is probably written for an older version of autoconf. The practice of naming the autoconf script configure.ac is fairly new.
Advertisement
No, there is nothing user-friendly about autoconf/automake. The system does, however, allow your program to run on a large variety of differently broken UNIX implementations, which is considered friendly by the users of your package.
enum Bool { True, False, FileNotFound };
Thank you. Finally I have found the solution. Anjuta can create a distribution. Now I can distribute my program. [cool]
I believe that Anjuta just calls "make dist". Maybe should you look into that, in case you don't want to be tied to a particular IDE.

Hope this helps.
Here is a tutorial about autoconf, automake, etc. that will hopefully be easier to understand than the man page.
Advertisement
You can always read the autobook [smile]
autoconf/automake in 7 easy steps:

1. Create a Makefile.am file in your source directory. It should look something like this:

CXXFLAGS = -O2 -w -DGAMEDATADIR=\"$(datadir)/@PACKAGE@\"SUBDIRS = binbin_PROGRAMS = mycoolgamemycoolgame_SOURCES = mycoolgame.cpp mycoolgame.h mycoolfoobar.cpp   mycoolfoobar.h something.cpp bar.cppuninstall-hook:  rm -r $(datadir)/@PACKAGE@


mycoolgame is the name of the desired exectable. The GAMEDATADIR define is useful for telling your game where to find the data files. The 'uninstall-hook' is useful for letting the user type 'make uninstall' to remove your game.

2. I usually keep my game data files in a /bin sub-directory in the tar-ball. That directory also need a Makefile.am: (bin/Makefile.am)

pkgdatadir = $(datadir)/@PACKAGE@pkgdata_DATA = mydatafile.dat ugly_horse.jpg foobar.pngEXTRA_DIST = $(pkgdata_DATA)


Note that 'SUBDIRS = bin' line in the main Makefile.am - it specifies where to find extra Makefiles.

3. Now we need to make a configure.in file for autoconf:
AC_INIT(mycoolgame.cpp)AC_INIT_AUTOMAKE(mycoolgame,1.0.0)AC_PROG_CXXAC_PROG_INSTALLAC_CHECK_LIB(jpeg,jpeg_CreateCompress, [], [        echo "libjpeg required!"        exit -1        ])AC_CHECK_LIB(png,png_read_image, [], [        echo "libpng required!"        exit -1        ])AC_CHECK_LIB(SDL,SDL_Init, [], [        echo "SDL required!"        exit -1        ])AC_OUTPUT(Makefile bin/Makefile)


You'll need a AC_CHECK_LIB for each library you use. The first argument is the library name (for instance SDL equals a -lSDL argument for gcc). The next argument is a function in the library you use. The rest is pretty self-explaining I think.

4. Run 'aclocal'. It will do some magical stuff.

5. Run 'autoconf'. It translates your configure.in file.

6. Run 'automake -i -a'. More magical stuff, including generation of various standard files like INSTALL, COPYING, etc. It will also prompt you to supply README, ChangeLog, and similar files.

7. Voila. Theoretically you should now be able to run './configure && make' to build your game. You can also run 'make install' as root, and the game will install itself magically. 'make dist' will produce a distributable 'mycoolgame-1.0.0.tar.gz' file.

This is from my memory only, and it's probably not totally correct :)

-- Rasmus Neckelmann

This topic is closed to new replies.

Advertisement