13 Ağustos 2009 Perşembe

GNU Autobuild system

Working with big projects, I have realized the importance of makefile systems. It's really needed to handle the whole project and the dependency tree. But writing whole makefile was very difficult for me. For this reason, I looked for some tools to do it and I found the answer: GNU Autobuild system.

GNU Autobuild system is actually a bunch of programs which inspect your code, make dependency checks, control these dependencies and create makefiles for your project. It takes the burden to create makefiles from the developer, and it puts it on the maintainers of GNU Autobuild system.

In order to understand the workflow of the system, one should have a good understanding of what program does what. Let's see:

a) autoscan : This program inspects the directory structure and source codes and tries to create configure.ac input file for autoconf. It creates a candidate file named configure.scan, with just a little modification, you can rename configure.scan to configure.ac and use it as the configuration input file. (For my specific case, I only needed to change two things. First, i changed the package name, version exc. And second, I added the line AM_INIT_AUTOMAKE. This macro is needed for automake program and I will explain it later.)

b) autoconf : This program takes an input file named configure.ac and creates a configuration script named configure. This script will be used later to make the dependency check on user's computer and create the makefile for the project. I prefer running this program at the very end step after creating every file.

c) automake : This program takes an input file named makefile.am and according to configure.ac file, tries to create a pre-makefile, named makefile.in. It uses aclocal.m4 to know the macros, you can create aclocal.m4 with aclocal command in terminal. It also needs "install-sh" and "missing" scripts, they can be created by "automake --add-missing" command in terminal. It also needs for additional file to be present; NEWS, README, AUTHORS, Changelog. You can create and fill inside of them as you wish. I'll explain how to create makefile.am later.

d) aclocal : Creates "aclocal.m4" file needed for automake to understand macros.

e) autoheader: Creates a file named "config.h.in" which is needed to run "configure" script. No action needs to be taken.

Now, let's check which files needs to be created:
makefile.am (You have to fill it yourself)
configure.ac (autoscan mostly fills it)
aclocal.m4 (aclocal does the work)
install-sh and missing (automake --add-missing does the work)
config.h.in (autoheader does the work)
NEWS, README, AUTHORS, Changelog (I don't even know why they are needed, I think they are GNU standarts for a package)

Creating "makefile.am" file: Don't worry, creating this file is way easy compared
to the creating makefile itself. First of all, you have to create a different makefile.am for every direction which you want to include in your project (and tarball of course). The structure is always almost the same, there are some syntactic elements you should know. Basic ones are like these:
"SUBDIR = ... ... ..." : declaration of subdirs
"bin_PROGRAMS = ... ..." : name of the binary files
"x_SOURCES = .... ..." : sources needed for binary file x
"x_LDADD = ... ...", : special linkings for binary file x
"noinst_LIBRARIES = ... ..." : create libraries but do not install them.
"lib_LTLIBRARIES = ... ..." create shared libraries for the project. The program libtool might be very useful here.

And much more, there are various many options. But with the options listed above, you can mostly do your work.

After doing everything, we can run configure script on the terminal. It will make checks and if succeeds, will create makefiles for the project. After makefiles have been created, users can use "make" command to build,install,uninstall the project. And there are many more options for maintainers.
"make install-check" : checks if installation succeeds.
"make uninstall-check" : checks if uninstall process succeeds.
"make dist-gzip" : creates a tar.gz tarball for your project.

And at that step you're done. Now you can create the tarball of your project and archive or publish it.

References:
http://www.delorie.com/gnu/docs/automake/automake_toc.html#SEC_Contents (You can find a very good documentation here in detail.)
http://en.wikipedia.org/wiki/GNU_build_system
http://www.gnu.org/software/automake/
http://www.gnu.org/software/autoconf/
http://www.lrde.epita.fr/~adl/autotools.html (Autotools tutorial)

Hiç yorum yok:

Yorum Gönder