What are Makefile.am and Makefile.in?

后端 未结 4 1802
慢半拍i
慢半拍i 2020-12-02 03:28

These two files are mostly seen in open source projects.

What are they for, and how do they work?

4条回答
  •  有刺的猬
    2020-12-02 04:08

    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], [bug-automake@gnu.org])
    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 
    #include 
    
    int main (void) {
      puts ("Hello world from " PACKAGE_STRING);
      return 0;
    }
    

    Usage

    autoreconf --install
    mkdir build
    cd build
    ../configure
    make
    sudo make install
    autoconf_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.

提交回复
热议问题