AUTOTOOLS-
automake,autoconfig,autogen,libtool
UNDERSTANDING BUILD
SYSTEMS
Autotools Purpose
The purpose of autotools :
◻ It serves the needs of your users (checking platform and
libraries; compiling and installing ).
◻ It makes your project incredibly portable for different system
platforms.
◻ Autotools is a set of tools for building, testing, and packaging
software projects.
◻ It's a popular choice for open-source projects, especially those
written in C and C++
What is Autotools?
◻ Autotools is a collection of tools that help automate the
process of building, testing, and packaging software
projects.
◻ It's designed to make it easy to create portable software
that can be built and run on different platforms, including
Linux, macOS, and Windows
Introduction to configure and build process
◻ GNU Autotools , also known as the GNU Build System , is a set of programming tools
designed to help make source code packages portable to many Unix systems.
◻ It can be difficult to make a software program portable: the C compiler differs from system
to system;Some library functions are missing on some systems;Header files may have
different names.
◻ One way to deal with this is to write conditional code, with code blocks selected using
preprocessor directives (#ifdef);But due to the wide variety of building environments, this
approach quickly becomes unmanageable.
◻ Autotools is designed to solve this problem more easily.
◻ GNU AutoTools is a set of tools (AutoMake, AutoConf, libtool, etc.) used to automate the
build process for software projects
Introduction to configure and build process
◻ Autotools is part of the GNU tool chain and is widely used in many open source
and open source packages. Its component tools are licensed by free software
under the GNU General Public License, with special license exceptions allowing
their use with proprietary software.
◻ The GNU Build System makes it possible to create many programs using a
two-step process: configure followed by make.
GNU packages for GNU build system
◻ 3 GNU packages for GNU build system
◻ Autoconf Generates a configure script that checks the build
environment and creates a Makefile. Automake Generates a
Makefile that can be used to build the project.
◻ Libtool helps manage shared libraries and creates a portable
way to link against them.
◻ Autoheader: generates a header file that contains definitions
for the project's configuration.
components of Autotools
◻ Autotools can help make your application more portable, give it the
versatility to be installed on many different systems, and can
automatically procure scripts to check where elements are, like the
compiler for your program.
◻ The primary components of Autotools are:
• automake
• autoconf
• make
components of Autotools (Contd)
◻ Using these tools, you will create two files, configure and Makefile.in. These files
are present in any project shipped using Autotools and are usually quite large and
complex.
◻ Luckily, you don’t have to write them yourself—instead you’ll be writing the
files configure.ac and Makefile.am, which will automatically generate the files
you need.
Autoconf
◻ Autoconf is written in M4sh, using m4 macros.
◻ m4sh provides some macros you can use when creating your configure.ac script
and are part of why you can generate a massive configure script without having to
write too much actual code.
◻ configure.ac script in which you define various settings like release name,
version, which compiler to use, and where it should output files.
◻ Once you’ve written your script, you run it through autoconf to create your
final configure script. The purpose of autoconf is to collect information from your
system to populate the Makefile.in template, which is created using automake
Automake
◻ The Makefile.am script creates Makefile.in.
◻ The principles behind this are the same as with configure.ac: write a
simple script in order to create a complex file.
◻ Automake is the component you’ll use to create the Makefile, a template
that can then be populated with autoconf.
Steps - autoconfig,automake
◻ The configure script is a shell script generated
from configure.ac by a program called autoconf
• configure.ac used to be named configure.in but this
name is now deprecated
• Written in shell script, augmented with numerous m4
macros
Steps - autoconfig,automake
◻ The Makefile.in are generated from Makefile.am files by a program
called automake
◻ Some auxilliary tools like autoheader or aclocal are also used
◻ autoheader is responsible for generating the configuration header
template, config.h.in
◻ Generated files (configure, Makefile.in, Makefile) should not be
modified. Reading them is also very difficult. Read the real source
instead!
Autoconf
Here is a diagram
showing how the files
that can be used in
configuration are
produced. Programs that
are executed are suffixed
by ‘*’. Optional files are
enclosed in square
brackets
(‘[]’). autoconf and autoh
eader also read the
installed Autoconf macro
files (by
reading autoconf.m4).
configure.ac language
◻ Really a shell script I Processed through the m4 preprocessor
◻ Shell script augmented with special constructs for portability:
◻ AS_IF instead of shell if ... then .. Fi
◻ AS_CASE instead of shell case ... esac etc…
◻ autoconf provides a large set of m4 macros to perform most of the usual
tests
◻ Make sure to quote macro arguments with []
configure.ac
◻ AC_INIT([hello], [1.0])
◻ AC_OUTPUT
❑ AC_INIT
• Every configure script must call AC_INIT before doing anything else that
produces output.
• Process any command-line arguments and perform initialization and
verification.
• Prototype: AC_INIT (package, version, [bug-report], [tarname], [url])
❑ AC_OUTPUT
▪ Every configure.ac, should finish by calling AC_OUTPUT.
▪ Generates and runs config.status, which in turn creates the makefiles and
any other files resulting from configuration.
Shared Libraries
◻ Shared libraries contain only a small table of functions that programs
require.
◻ Shared libraries make executable file smaller.
◻ It is easy to update shared libraries without recompiling projects.
◻ Shared libraries use dynamic linking, which provides chunks of
executable code that the operating system can load into a program's
address space and execute.
◻ GNU Libtool simplifies the developer job by encapsulating both platform
specific dependencies and user interface in a single script.
GNU LIBTOOL
◻ GNU Libtool is a software development tool, part of the GNU build system, consisting of
a shell script created to address the software portability problem when compiling shared
libraries from source code.
◻ It hides the differences between computing platforms for the commands which compile
shared libraries.
◻ It provides a command-line interface that is identical across platforms and it executes the
platform's native commands.
◻ Libtool is used by Autoconf and Automake, two other portability tools in the GNU build
system
◻ It can be used to compile, link, and install libraries.
Libtool
◻ Different operating systems handle shared libraries differently. Some platforms
do not use shared libraries at all.
◻ It can be difficult to make a software program portable: the C compiler differs
from system to system; certain library functions are missing on some systems;
header files may have different names.
◻ Libtool helps manage the creation of static and dynamic libraries on
various Unix-like operating systems.
◻ Libtool accomplishes this by abstracting the library-creation process, hiding
differences between various systems
Libtool Benefits:
◻ Simplified library management: Libtool simplifies the process of
creating, managing, and using shared libraries.
◻ Improved portability: Libtool enables developers to write code that can
be easily ported to different platforms and architectures.
◻ Easier dependency management: Libtool's dependency tracking feature
makes it easier to manage complex software projects with multiple
dependencies.
Building shared libraries-LIBTOOL
Libtool library example
Libtool
◻ libtool --mode=compile gcc -c mylib.c
◻ libtool --mode=link gcc -o libmylib.la mylib.lo
◻ libtool --mode=install install libmylib.la /usr/lib
Libtool commands in a Makefile:
Let's create “Hello, world!”
First, we'll write a standard “Hello, world!” program:
With a simple Makefile
Let's try making our binaries:
Let's add Autoconf
Creating this file by hand can be tedious, though. So
Now, we'll add autoconf to
Autoconf provides a program to create the file for
this program. First, we create a
you. This program is “autoscan”:
file called “configure.ac”. This
file instructs Autoconf how to
generate the "configure" script.
(Autoconf 2.13 users: Create
“configure.in” instead.)
Rename the file to “configure.ac”
▪ “autoscan” scans your sources and creates an appropriate
“configure.ac” file. But notice it doesn't create “configure.ac”
file directly. Instead, it creates a file called “configure.scan”.
We need to rename this file to “configure.ac”:
Rename the file to “configure.ac”
▪ Why doesn't “autoscan” create “configure.ac” directly? Well,
you don't know this at the moment, but you'll be customizing
“configure.ac” later. You don't want to accidentally overwrite
“configure.ac”, do you? So “autoscan” doesn't write to
“configure.ac” directly.
Run “autoconf” to generate “configure”
“autoconf” to generate “configure”
◻ Ignore all those extra files Autoconf creates. They are just
intermediary files we don't need. Don't erase them, though —
Autoconf may use them later.
◻ We could now type “./configure”, but not yet: “configure” is
supposed to generate a new Makefile. But “configure” uses a
file called “Makefile.in” to generate the new Makefile. So now
we need a “Makefile.in”.
Rename “Makefile” to “Makefile.in”
◻ “Makefile.in” is supposed to be a template for the new
“Makefile”. We'll simply rename “Makefile” to
“Makefile.in” and worry about writing the proper version
later:
Rename “Makefile” to “Makefile.in”
Review
◻ Create the sources, Makefile, etc.
◻ Run “autoscan” (“autoscan” creates “configure.scan”)
◻ Rename “configure.scan” to “configure.ac”
◻ Run “autoconf” (“autoconf” uses “configure.ac” to create
“configure”)
◻ Rename “Makefile” to “Makefile.in” (“configure” will use
“Makefile.in” to create “Makefile”)
◻ Run “./configure” and “make”
Introduction to autogen
◻ Automated text and program generated tool
◻ Autogen is a tool designed to simplify the creation and maintenance of programs that
contain large amounts of repetitious text.
◻ AutoGen will accept either its own definition format, or XML files as definition
input, in addition to CGI data (for producing dynamic and traditional
AutoGen definitions.
◻ Developers typically use Autogen in conjunction with other build tools to automate
repetitive coding tasks, reducing the likelihood of errors and saving time.
autogen
◻ Purpose: Autotools is a collection of programming tools
designed to assist in making source code packages
portable to different Unix-like systems.
The AutoGen
◻ A common example where this would be useful is in creating and maintaining the
code required for processing program options.
◻ Processing options requires multiple constructs to be maintained in parallel in
different places in your program.
◻ Options maintenance needs to be done countless times. So, AutoGen comes with an
add-on package named AutoOpts that simplifies the maintenance and documentation
of program options.
◻ AutoGen is known to work on GNU/Linux, BSD, Apple's OS/X, SVR4-5, HPUX,
SCO OpenServer and Solaris.
◻ It is expected that it will work on any reasonably modern UNIX system with an
ANSI-compliant C compiler.
◻ It also runs under WinNT, provided you have CygWin and Guile loaded.
Overall view of autotools
◻ Typically, Autotools are used in the following order:
◻ Developer writes the configuration templates (configure.ac,
Makefile.am, etc.).
◻ Autoconf generates the configure script based on configure.ac.
◻ Automake generates Makefile.in from Makefile.am.
◻ The end-user runs the configure script, which creates the final
Makefile tailored to their system.
◻ The user then runs make to build the software and make install to
install it.
Key Differences:
◻ Autogen is more about automating repetitive tasks in file
generation.
◻ Autotools is a suite focused on making software portable
across various environments by generating scripts and
makefiles that handle system-specific differences.
Reference for autogen
◻ http://www.linuxfromscratch.org/~thomasp/blfs-book-xsl/
general/autogen.html