Makefile file makes compiling work more efficient, especially when it turns to solve some jobs with a complex structure. But
it depends on the building environment so hard that we can't use it portably. So that a tools called automake assist us to generate makefile
automatically.
Brief
autoscan
vim configure.scan
andmv configure.scan configure.ac
aclocal
autoconf
vim Makefile.am
automake --add-missing
./configure
make
Example
Project Layout
- First of all, create a source code in C:
/* hello.c */
#include <stdio.h>
int main(int argc, char *argv[])
{
fprintf(stdout, "Hello Auto Makefile
");
return 0;
}
then autoscan
it, you will find a file named configure.scan
$ autoscan
$ ls
hello.c configure.scan
- edit configure.scan and rename it as configure.ac
$ vim configure.scan
$ cat configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT( hello.c)
AM_INIT_AUTOMAKE(hello, 1.0)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile)
$ mv configure.scan configure.ac
- use
aclocal
to create aclocal.m4. m4 is a kind of marco processor.
$ aclocal
$ ls
aclocal.m4 configure.ac hello.c
- use
autoconf
to generate configure
$ autoconfig
$ ls
aclocal.m4 autom4te.cache configure configure.ac hello.c
- edit makefile.am
$ vim makefile.am
$ cat makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
helloworld_SOURCE=hello.c
./configure
./make
Copyright © 2021 Gsharp. All Rights Reserved.