Unit III
Unit III
Unit III
AUTOCONF
One of the major objectives of GNU software packages is that the software may
be distributed as source code and it should possible to make the executable
under various Posix-like systems. Normally, it would be a gigantic task for each
programmer to write makefiles for each conceivable environment. autoconf
makes this a straightforward task. The input to autoconf is a text file named
configure.ac, or configure.in (configure.in is the older name).
autoconf produces configure, which is a shell script to to create makefile(s),
customized to build the software executables as per the local environment. The
input file, configure.ac, contains macros to check a system for features that
a software package might use. autoconf invokes the m4 macro processor to
generate the configure script.
AC_INIT[hello],[1.0])
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS(config.h)
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_PROG_INSTALL
AC_OUTPUT
Each configure.ac must start with an AC_INIT. The parameters, here, are
the package name hello and version, 1.0. AC_CONFIG_HEADERS ensures that
–D(definitions) options to the compiler are not passed on the commandline.
A file config.h would be created, containing all the #defines that were being
passed as header files. AC_CONFIG_SRCDIR makes autoconf check for
the presence of given file, in this case hello.c. AC_PROG_CC determines the C
compiler to use. AC_CONFIG_FILES makes AC_OUTPUT create the given files.
AC_PROG_INSTALL checks for the presence of BSD compatible install
program in the current path. If it is found, its path is set to output variable
INSTALL. The last call in configure.ac is AC_OUTPUT. It performs all the
configuration actions, which includes writing all output files.
Constructing make files
You can use make with any programming language whose compiler
can be run with a shell command. Indeed, make is not limited to
programs. You can use it to describe any task where some files must
be updated automatically from others whenever the others change.
You need a file called a makefile to tell make what to do. Most often,
the makefile tells make how to compile and link a program. To prepare
to use make, you must write a file called the makefile that describes
the relationships among files in your program and provides commands
for updating each file. In a program, typically, the executable file is
updated from object files, which are in turn made by compiling source
files.
Once a suitable makefile exists, each time you change some source
files, this simple shell command:
make
When make recompiles the editor, each changed C source file must be
recompiled. If a header file has changed, each C source file that
includes the header file must be recompiled to be safe. Each
compilation produces an object file corresponding to the source file.
Finally, if any source file has been recompiled, all the object files,
whether newly made or saved from previous compilations, must be
linked together to produce the new executable editor.