Makefile.am is a programmer-defined file and is used by automake to generate the Makefile.in file (the .am stands for automake). The configure script typically seen in source tarballs will use the Makefile.in to generate a Makefile.

The configure script itself is generated from a programmer-defined file named either configure.ac or configure.in (deprecated). I prefer .ac (for autoconf) since it differentiates it from the generated Makefile.in files and that way I can have rules such as make dist-clean which runs rm -f *.in. Since it is a generated file, it is not typically stored in a revision system such as Git, SVN, Mercurial or CVS, rather the .ac file would be.

Read more on GNU Autotools. Read about make and Makefile first, then learn about automake, autoconf, libtool, etc.

Answer from Sean A.O. Harney on Stack Overflow
🌐
GNU
gnu.org › software › automake › manual › html_node › amhello_0027s-Makefile_002eam-Setup-Explained.html
amhello's Makefile.am Setup Explained (automake)
When automake processes a Makefile.am it copies the entire file into the output Makefile.in (that will be later turned into Makefile by configure) but will react to certain variable definitions by generating some build rules and other variables.
🌐
Makefile Tutorial
makefiletutorial.com
Makefile Tutorial by Example
If you want a string to have a dollar sign, you can use $$. This is how to use a shell variable in bash or sh. Note the differences between Makefile variables and Shell variables in this next example. make_var = I am a make variable all: # Same as running "sh_var='I am a shell variable'; echo $sh_var" in the shell sh_var='I am a shell variable'; echo $$sh_var # Same as running "echo I am a make variable" in the shell echo $(make_var)
🌐
Trinity Desktop Project
wiki.trinitydesktop.org › Makefile.am_HOWTO
Makefile.am HOWTO - Trinity Desktop Project Wiki
August 24, 2021 - Add tests to the SUBDIRS line in parent Makefile.am and create a Makefile.am in the new tests directory. Use create_makefile (from kdesdk/scripts) to create the new Makefile, and now when you type make check the test program will be compiled (due to check_PROGRAMS) and run (due to TESTS).
Top answer
1 of 4
490

Makefile.am is a programmer-defined file and is used by automake to generate the Makefile.in file (the .am stands for automake). The configure script typically seen in source tarballs will use the Makefile.in to generate a Makefile.

The configure script itself is generated from a programmer-defined file named either configure.ac or configure.in (deprecated). I prefer .ac (for autoconf) since it differentiates it from the generated Makefile.in files and that way I can have rules such as make dist-clean which runs rm -f *.in. Since it is a generated file, it is not typically stored in a revision system such as Git, SVN, Mercurial or CVS, rather the .ac file would be.

Read more on GNU Autotools. Read about make and Makefile first, then learn about automake, autoconf, libtool, etc.

2 of 4
81

Simple example

Shamelessly adapted from: http://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html and tested on Ubuntu 14.04 Automake 1.14.1.

Makefile.am

SUBDIRS = src
dist_doc_DATA = README.md

README.md

Some doc.

configure.ac

AC_INIT([automake_hello_world], [1.0], [[email protected]])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 src/Makefile
])
AC_OUTPUT

src/Makefile.am

bin_PROGRAMS = autotools_hello_world
autotools_hello_world_SOURCES = main.c

src/main.c

#include <config.h>
#include <stdio.h>

int main (void) {
  puts ("Hello world from " PACKAGE_STRING);
  return 0;
}

Usage

autoreconf --install
mkdir build
cd build
../configure
make
sudo make install
autotools_hello_world
sudo make uninstall

This outputs:

Hello world from automake_hello_world 1.0

Notes

  • autoreconf --install generates several template files which should be tracked by Git, including Makefile.in. It only needs to be run the first time.

  • make install installs:

    • the binary to /usr/local/bin
    • README.md to /usr/local/share/doc/automake_hello_world

On GitHub for you to try it out.

🌐
Colby College
cs.colby.edu › maxwell › courses › tutorials › maketutor
A Simple Makefile Tutorial
If you put this rule into a file called Makefile or makefile and then type make on the command line it will execute the compile command as you have written it in the makefile. Note that make with no arguments executes the first rule in the file. Furthermore, by putting the list of files on ...
🌐
KDE TechBase
techbase.kde.org › Development › Tutorials › KDE3 › Makefile.am
Development/Tutorials/KDE3/Makefile.am - KDE TechBase
June 29, 2011 - For programs you should also add $(KDE_RPATH), it helps to get installed programs to find their libraries without having to set LD_LIBRARY_PATH. These specify additional compilation flags. This must contain $(all_includes). This is also where other compile-time flags like -DWITHOUTBUGS and -I$(srcdir)/subdir go. ... Insert -I directives before $(all_includes). This ensures that your own headers will be used, not some older installed version. ... . (the build directory) are always included automatically. You may find that Makefile.am files in KDE still use INCLUDES (the old name for AM_CPPFLAGS), but AM_CPPFLAGS is the recommended way to add include paths and other compilation flags.
🌐
Ubuntu
manpages.ubuntu.com › manpages › trusty › man1 › automake-1.4.1.html
Ubuntu Manpage: automake - automatically create Makefile.in's from Makefile.am's
Note that automake has a rather ... holding a configure.in. You can optionally give automake an argument; .am is appended to the argument and the result is used as the name of the input file....
🌐
SourceForge
inti.sourceforge.net › tutorial › libinti › autotoolsproject.html
Inti Tutorial: Building a GNU Autotools Project
Create a new text file called Makefile.am in the <tests/project> directory. Add the following line to the file and save it: The SUBDIRS variable is used to list the subdirectories that must be built. Next, in the <tests/project/src> subdirectory create another text file called Makefile.am.
🌐
GNU Project
gnu.ist.utl.pt › software › automake › manual › html_mono › automake.html
automake
The variable definitions and targets in the Makefile.am are copied verbatim into the generated file. This allows you to add arbitrary code into the generated Makefile.in. For instance the Automake distribution includes a non-standard cvs-dist target, which the Automake maintainer uses to make distributions from his source control system.
Find elsewhere
🌐
Thoughtbot
thoughtbot.com › blog › the-magic-behind-configure-make-make-install
The magic behind configure, make, and make install
August 5, 2024 - # src/Makefile.am AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = helloworld helloworld_SOURCES = main.c · Now we’ve written our config files, we can run autotools and generate the finished configure script and Makefile.in template. First, we need to generate an m4 environment for autotools to use.
🌐
GitHub
gist.github.com › adammw › 3690227
Makefile.am · GitHub
Save adammw/3690227 to your computer and use it in GitHub Desktop.
🌐
Opensource.com
opensource.com › article › 18 › 8 › what-how-makefile
What is a Makefile and how does it work? | Opensource.com
Below is the rewrite of the above makefile, assuming it is placed in the directory having a single file foo.c: # Usage: # make # compile all binary # make clean # remove ALL binaries and objects .PHONY = all clean CC = gcc # compiler to use LINKERFLAG = -lm SRCS := foo.c BINS := foo all: foo foo: foo.o @echo "Checking.." gcc -lm foo.o -o foo foo.o: foo.c @echo "Creating object.." gcc -c foo.c clean: @echo "Cleaning up..." rm -rvf foo.o foo
Top answer
1 of 4
9

It's an automake script/makefile. You can learn everything about automake, autoconf, libtool and such through the called autobook.

Basically, the steps would be to run automake, then autoconf, then configure, then make to build the software you have. These steps are neccessary to build the configure script, that automatically search for needed libraries and such on your system.

The process is not easy, unless your software also includes an already generated "configure" file. If so, the only thing you have to do (mostly) is to just run ./configure, then make, then make install to install the software to a default location. If you want to change configure options, you can also look at ./configure --help.

2 of 4
2

You stumbled upon an automake file, which is used to create a Makefile from the source, in this case Makefile.am.

From http://developer.gnome.org/doc/GGAD/z70.html, they explain it as:

automake processes Makefile.am to produce a standards-compliant Makefile.in. automake does a lot of work for you: it keeps up with dependencies between source files, for example. It creates all the standard targets, such as install and clean. It also creates more complex targets: simply typing make dist creates a standard .tar.gz file if your Makefile.am is correct.

Basically, you should run 'automake' to make the Makefile, and you will probably run into the same situation with the configure script with 'autoconf'.

Automake: http://www.gnu.org/software/automake/ Wikipedia article on automake: http://en.wikipedia.org/wiki/Automake

🌐
BuildTools
coin-or-tools.github.io › BuildTools › make-main.html
The Main Directory Makefile.am File | BuildTools
Alternatively, one could have specified ... in src/Makefile.am. The pkgconfiglib_DATA variable specifies the pkg-config configuration files that should be installed in directory $(pkgconfiglibdir) (typically $prefix/lib/pkgconfig). The files specified here will be installed by make install and removed again by make uninstall. The pkg-config configuration files are used to communicate ...
🌐
GNU
gnu.org › software › automake › manual › html_node › General-Operation.html
General Operation (automake)
May 13, 2013 - Generally, Automake is not particularly smart in the parsing of unusual Makefile constructs, so you’re advised to avoid fancy constructs or “creative” use of whitespace. For example, TAB characters cannot be used between a target name and the following “:” character, and variable assignments shouldn’t be indented with TAB characters. Also, using more complex macros in target names can cause trouble: % cat Makefile.am $(FOO:=x): bar % automake Makefile.am:1: bad characters in variable name '$(FOO' Makefile.am:1: ':='-style assignments are not portable
🌐
Baeldung
baeldung.com › home › building › difference between makefile.am and makefile.in
Difference Between Makefile.am and Makefile.in | Baeldung on Linux
August 22, 2024 - Automake, or specifically autoconf, scans the configure.ac file and the Makefile.am files to understand the dependencies of the project. Then, it uses that information to generate the Makefile.in files, which contain the parameters required by the actual configuration process.
🌐
GNU
gnu.org › software › automake › manual › 1.7.9 › automake.html
GNU Automake
The variable definitions and targets in the Makefile.am are copied verbatim into the generated file. This allows you to add arbitrary code into the generated Makefile.in. For instance the Automake distribution includes a non-standard cvs-dist target, which the Automake maintainer uses to make distributions from his source control system.
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › how-to-modify-makefile-in-or-makefile-am-324373
How to modify makefile.in or makefile.am
Hi, guys: I need to modify some code of the GNU project, and add some new c++ programs(.h, .cc), but now I am confused of how to use 'make' to