Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Makefile.am and Makefile.in?

These two files are mostly seen in open source projects.

What are they for, and how do they work?

like image 428
Mask Avatar asked Mar 28 '10 03:03

Mask


People also ask

What is $@ in Makefile?

The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.

What is Makefile in Linux?

Makefile is a program building tool which runs on Unix, Linux, and their flavors. It aids in simplifying building program executables that may need various modules. To determine how the modules need to be compiled or recompiled together, make takes the help of user-defined makefiles.

What is Autoreconf used for?

autoreconf is a Autotool which is used to create automatically buildable source code for Unix-like systems. Autotool is a common name for autoconf, automake, etc. These all together are termed as Autotools.


2 Answers

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.

like image 80
Sean A.O. Harney Avatar answered Oct 03 '22 23:10

Sean A.O. Harney


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.