Automake Completed

This commit is contained in:
2026-07-27 00:14:09 +05:30
parent 91389315e1
commit 9de00ef098
+535 -22
View File
@@ -64,10 +64,10 @@ algorithm2e
\use_formatted_ref 0
\use_minted 0
\use_lineno 0
\backgroundcolor white
\backgroundcolor lightgray
\fontcolor black
\notefontcolor none
\boxbgcolor none
\notefontcolor darkgray
\boxbgcolor white
\table_border_color default
\table_odd_row_color default
\table_even_row_color default
@@ -946,7 +946,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1081,7 +1081,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1171,7 +1171,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1475,7 +1475,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1524,7 +1524,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1591,7 +1591,7 @@ height "1pt"
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1667,7 +1667,7 @@ height "1pt"
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1760,7 +1760,7 @@ height "1pt"
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1827,7 +1827,7 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
@@ -1918,16 +1918,16 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
bin_PROGRAMS = myprog
bin_PROGRAMS += myprog
\end_layout
\begin_layout Plain Layout
myprog_SOURCES = myprog.c
myprog_SOURCES += myprog.c
\end_layout
\begin_layout Plain Layout
@@ -1975,7 +1975,7 @@ CLEANFILES = greptest.sh @4
\begin_inset Caption Standard
\begin_layout Plain Layout
src/Makefile.am:
src/Makemodule.am:
Additional code required to support the check target
\end_layout
@@ -2079,12 +2079,12 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
noinst_LIBRARIES = libcommon.a
noinst_LIBRARIES += libcommon.a
\end_layout
\begin_layout Plain Layout
@@ -2092,7 +2092,7 @@ libcomman_a_SOURCES = common.h print.c
\begin_inset Caption Standard
\begin_layout Plain Layout
common/Makefile.am:
common/Makemodule.am:
To build the temporary library.
\end_layout
@@ -2168,12 +2168,12 @@ height "1pt"
\begin_layout Standard
\begin_inset listings
lstparams "basicstyle={\footnotesize\ttfamily},breaklines=true"
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
bin_PROGRAMS = myprog
bin_PROGRAMS += myprog
\end_layout
\begin_layout Plain Layout
@@ -2189,7 +2189,7 @@ myprog_LDADD = ../common/libcommon.a
\begin_inset Caption Standard
\begin_layout Plain Layout
src/Makefile.am:
src/Makemodule.am:
Adding compiler and linker directives to Makefile.am files.
\end_layout
@@ -2414,5 +2414,518 @@ ltlibrary_LIBADD
) to a Libtool static or shared library.
\end_layout
\begin_layout Standard
We can use the last three option variables in the list to pass lists of order-dependent static and shared library references to the linker.
These variable can also be used to pass -L and -l options.
\end_layout
\begin_layout Subsubsection
Per-Makefile Option Variables
\end_layout
\begin_layout Standard
Some of the preprocessor flags are common for all the products that is to be build by the Makefile.
So,
instead of repeatedly mentioning it on product variables in
\family typewriter
.am
\family default
files,
these can be mentioned in the per-makefile option variable as shown below:
\begin_inset Newline newline
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\end_layout
\begin_layout Standard
\begin_inset listings
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
AM_CFLAG = ...
some flags ...
\end_layout
\begin_layout Plain Layout
...
\end_layout
\begin_layout Plain Layout
prog1_CFLAGS = ...
more flags ...
$(AM_CFLAGS) @1
\begin_inset Caption Standard
\begin_layout Plain Layout
per-product and per-makefile flags.
\end_layout
\end_inset
\end_layout
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\begin_inset Newline newline
\end_inset
The first line above is a per-makefile flag while the next flag at
\family typewriter
(@1)
\family default
is a per-product flag.
Note,
that after adding the per-makefile flag it is appended as variable to the per-product flag because the per-product flags overrides the value of per-makefile flag.
In order to include both,
the former is added to the latter in order to include all the mentioned flags for the products.
\begin_inset Newline newline
\end_inset
\begin_inset Newline newline
\end_inset
Why then per-makefile are needed in the first place?
Can't we directly add to the per-products flag?
\begin_inset Newline newline
\end_inset
Per-makefile flags generates relatively compact Makefile as compare what per-product flag generates.
This is because per-product flags makes Automake to generate per-product rules instead of most of the redundant part which can be used as suffix.
\begin_inset Newline newline
\end_inset
Note that these variables specific to Automake don't modify the actual
\family typewriter
CFLAGS
\family default
of Makefiles.
These variables are exclusively reserved for the end user to tinker with.
All the flags are defined above are appended to these flags or to the Command when executed for building the product.
\end_layout
\begin_layout Subsection
Building the New Library
\end_layout
\begin_layout Standard
Now the newly added static library can be build by adding the
\family typewriter
SUBDIR
\family default
to the top-level makefile.
This is for the case when we opt for recursive Build system.
However,
our intention is to create a Non-Recursive Build system for reason we have already discussed.
For that we declare the PLVs on the top-level Makefile.am and we include the products list in the Makemodules.am which are in the sub-directories,
which we have been doing till now.
\begin_inset Newline newline
\end_inset
In the case of Recursive-Makfiles,
we would have to add the Makefiles of the sub-directories into the macro
\family typewriter
AC_CONFIG_FILES
\family default
in configure.ac:
\begin_inset Newline newline
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\end_layout
\begin_layout Standard
\begin_inset listings
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
...
\end_layout
\begin_layout Plain Layout
AC_CONFIG_FILES([Makefile
\end_layout
\begin_layout Plain Layout
common/Makefile
\end_layout
\begin_layout Plain Layout
src/Makefile])
\end_layout
\begin_layout Plain Layout
...
\begin_inset Caption Standard
\begin_layout Plain Layout
For the case of Recursive-Makefile build system.
\end_layout
\end_inset
\end_layout
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\begin_inset Newline newline
\end_inset
However,
for Non-recursive case we don't need such inclusion as there is only one Makefile which would be generated by the Automake,
i.e.
the top-level makefile.
\begin_inset Newline newline
\end_inset
On running the
\family typewriter
autoreconf -i
\family default
,
the updated build system will be checked and enhancements will be suggested by the Autotools scripts.
\begin_inset Newline newline
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\end_layout
\begin_layout Standard
\begin_inset listings
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
autoreconf -i
\end_layout
\begin_layout Plain Layout
configure.ac:6:
installing './install-sh'
\end_layout
\begin_layout Plain Layout
configure.ac:6:
installing './missing'
\end_layout
\begin_layout Plain Layout
Makefile.am:2:
error:
library used but 'RANLIB' is undefined
\end_layout
\begin_layout Plain Layout
Makefile.am:2:
The usual way to define 'RANLIB' is to add 'AC_PROG_RANLIB'
\end_layout
\begin_layout Plain Layout
Makefile.am:2:
to 'configure.ac' and run 'autoconf' again.
\end_layout
\begin_layout Plain Layout
Makefile.am:
installing './depcomp'
\end_layout
\begin_layout Plain Layout
autoreconf:
error:
automake failed with exit status:
1
\end_layout
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\begin_inset Newline newline
\end_inset
As we can see,
it install some scripts and mention one error where
\family typewriter
RANLIB
\family default
is not added in
\family typewriter
configure.ac
\family default
file to for building the project.
This error can be removed by adding
\family typewriter
AC_PROG_RANLIB
\family default
to
\family typewriter
configure.ac
\family default
.
The inclusion of
\family typewriter
RANLIB
\family default
is only for making the build system portable.
It is not usually not needed in modern systems.
\end_layout
\begin_layout Section
What Goes into a Distribution?
\end_layout
\begin_layout Standard
Automake is quite smart enough to know what are the roles of each file in the build process and hence determine which files and directory needs to be included in the distribution created by executing
\family typewriter
make dist
\family default
.
This is only possible because we have mentioned every file to Automake using PLV and PSV.
Be warned that don't try to use some bash shell shortcuts to write one line to include all the source files,
etc.
Thats not how Automake will behave properly.
Trying to hack a will be more pain than listing all the files.
\begin_inset Newline newline
\end_inset
Also,
Automake
\family typewriter
EXTRA_DIST
\family default
variable can be used to mention files or directories that also need to including while creating the distribution package.
\begin_inset Newline newline
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\end_layout
\begin_layout Standard
\begin_inset listings
lstparams "language=bash,basicstyle={\footnotesize\ttfamily},breaklines=true"
inline false
status open
\begin_layout Plain Layout
EXTRA_DIST = Config
\end_layout
\begin_layout Plain Layout
\begin_inset Caption Standard
\begin_layout Plain Layout
directory Config to be included in distribution package.
\end_layout
\end_inset
\end_layout
\end_inset
\begin_inset CommandInset line
LatexCommand rule
offset "0.5ex"
width "100col%"
height "1pt"
\end_inset
\begin_inset Newline newline
\end_inset
Note that the directories might have
\family typewriter
.git
\family default
,
\family typewriter
.svn
\family default
or
\family typewriter
.CVS
\family default
status directories and we don't want it to be installed with the distribution created.
Fortunately,
Automake handles this automatically.
\end_layout
\begin_layout Section
Maintainer Mode
\end_layout
\begin_layout Standard
This is where we make our project ready to use for our user.
One situation might be created that the timestamp of the source in the distribution package might be newer relative to the system clock.
Because of this,
when the end-user execute make command,
it might see that the configuration scripts and all the tools related to Autotools are modified and the entire build system needed to be build including these configuration script,
\family typewriter
Makefile.in
\family default
from
\family typewriter
Makefile.am
\family default
.
The problem is that the user might not have these Autotools.
But,
it doesn't meant that they cannot build the project.
To handle such situation,
Automake has a mode called Maintainer Mode where Makefile rules are generated conditionally on whether the Autotools related generated scripts need to be rebuild.
This is done via
\family typewriter
AM_MAINTAINER_MODE
\family default
macro in configure.ac which disable maintainer-level
\family typewriter
make
\family default
rules that we discussed just now.
\begin_inset Newline newline
\end_inset
For maintainer,
to rebuild the entire build-system including the Autotools related script,
it should use command-line option (--enable-maintainer-mode) with configure scripts that tells to generate Makefile.in templates that contains rules and commands to execute the Autotools as necessary.
This is to enable the end-user to not worry about Autotools behavior and can build the project without it.
\end_layout
\begin_layout Section
Suppressing Noise
\end_layout
\begin_layout Standard
Some user might want to print only relevant things while building the project and don't want entire command-line output for building the project.
This can be achieved by in two ways and either can be used:
\end_layout
\begin_layout Itemize
Add the silent-rules option to the argument of
\family typewriter
AM_INIT_AUTOMAKE
\family default
in configure.ac.
\end_layout
\begin_layout Itemize
Call the
\family typewriter
AM_SILENT_RULES
\family default
macro in configure.ac.
\end_layout
\begin_layout Standard
The user can set the verbosity by using argument
\family typewriter
--enable-silent-rules
\family default
or
\family typewriter
--disable-silent-rules
\family default
on the configure command line.
What it does it actually it set the
\family typewriter
V
\family default
(verbosity) of make output by setting it to either 1 or 0,
respectively.
\end_layout
\begin_layout Part*
Ending
\end_layout
\begin_layout Standard
And thats it,
we have covered hopefully enough to at least create a moderately good enough build-system using Autoconf and Automake.
Mostly,
we have discussed about Automake and very slightly about Autoconf.
But,
next write-up will be about Autoconf and how we can make the build-system configurable for end-user based on the requirement of the user and the capability of the user's system.
Farewell!
\end_layout
\end_body
\end_document