What are Makefile.am and Makefile.in?
Asked Answered
N

4

445

These two files are mostly seen in open source projects.

What are they for, and how do they work?

Nomology answered 28/3, 2010 at 3:47 Comment(1)
See Autotools Mythbuster ( autotools.info ).Gastongastralgia
C
478

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.

Coldshoulder answered 28/3, 2010 at 3:53 Comment(4)
What does .in stand for?Bueschel
The .in extension means that it's input for configure to massage, not a final file that should be used (e.g. with make). If you're curious as to why this seems "ridiculously" complicated, try reading: https://mcmap.net/q/81712/-confused-about-configure-script-and-makefile-in These days with GitHub, etc. becoming a common distribution channel some of autoconf's assumptions are breaking down: people are obtaining the source directly from the source code control tool, rather than using a source distribution tarball created by maintainers.Nightstick
This seems at odds with the emacs source; it has Makefile.in which generates Makefile using "configure".Alizaalizarin
@Alizaalizarin I think Makefile.am is used to generate Makefile.in, which is used as input to generate Makefile.Oosphere
I
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.

Idzik answered 28/5, 2015 at 16:17 Comment(3)
Why should one keep generated files under VCS (this can be not only Git BTW)?Beem
@VictorYarema I forgot why I reached that conclusion! Let me know if you find out.Idzik
Shouldn't autotools_hello_world instead of autoconf_hello_world? in your Usage section?Torsibility
S
47

DEVELOPER runs autoconf and automake:

  1. autoconf -- creates shippable configure script
    (which the installer will later run to make the Makefile)
  1. automake - creates shippable Makefile.in data file
    (which configure will later read to make the Makefile)

INSTALLER runs configure, make and sudo make install:

./configure       # Creates  Makefile        (from     Makefile.in).  
make              # Creates  the application (from the Makefile just created).  

sudo make install # Installs the application 
                  #   Often, by default its files are installed into /usr/local


INPUT/OUTPUT MAP

Notation below is roughly: inputs --> programs --> outputs

DEVELOPER runs these:

configure.ac -> autoconf -> configure (script) --- (*.ac = autoconf)
configure.in --> autoconf -> configure (script) --- (configure.in depreciated. Use configure.ac)

Makefile.am -> automake -> Makefile.in ----------- (*.am = automake)

INSTALLER runs these:

Makefile.in -> configure -> Makefile (*.in = input file)

Makefile -> make ----------> (puts new software in your downloads or temporary directory)
Makefile -> make install -> (puts new software in system directories)


"autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention. Autoconf creates a configuration script for a package from a template file that lists the operating system features that the package can use, in the form of M4 macro calls."

"automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards. Automake requires the use of Autoconf."

Manuals:

Free online tutorials:


Example:

The main configure.ac used to build LibreOffice is over 12k lines of code, (but there are also 57 other configure.ac files in subfolders.)

From this my generated configure is over 41k lines of code.

And while the Makefile.in and Makefile are both only 493 lines of code. (But, there are also 768 more Makefile.in's in subfolders.)

Spidery answered 12/2, 2018 at 17:47 Comment(0)
D
21

reference :

Makefile.am -- a user input file to automake

configure.in -- a user input file to autoconf


autoconf generates configure from configure.in

automake gererates Makefile.in from Makefile.am

configure generates Makefile from Makefile.in

For ex:

$]
configure.in Makefile.in
$] sudo autoconf
configure configure.in Makefile.in ... 
$] sudo ./configure
Makefile Makefile.in
Danielledaniels answered 7/7, 2015 at 17:11 Comment(3)
So Makefile.in should be in the tar.gz file when you make dist, right?Allier
@KeminZhou Yes. Non-developers are not supposed to run automake. They should have Makefile.in in tarball.Pinhole
Usually developers use autotools to generate configure to be used by regular users.Allier

© 2022 - 2024 — McMap. All rights reserved.