創(chuàng)建源文件
新建文件夾Demo
新建源碼文件夾src
新建main.c
初始目錄:
main.c
? Demo ls -F src .
.:
Makefile.am src/
src:
main.c
執(zhí)行命令
cat /src/main.c
#include <config.h>
#include <stdio.h>
int
main (void)
{
puts ("Hello World!");
return 0;
}
autoscan
cat configure.ac
? Demo cat configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(hjwhello, 1.0, hjw@qq.com)
#AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile])
# 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
生成幾個占位文件
touch NEWS README AUTHORS ChangeLog
生成configure
autoreconf --install
執(zhí)行configure
? Demo ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./../install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
執(zhí)行make
? Demo make
/Users/huangjianwu/Documents/Xcode.app/Contents/Developer/usr/bin/make all-am
depbase=`echo src/main.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT src/main.o -MD -MP -MF $depbase.Tpo -c -o src/main.o src/main.c &&\
mv -f $depbase.Tpo $depbase.Po
gcc -g -O2 -o hello src/main.o
查看最終生成的文件
? Demo ls
AUTHORS ChangeLog Makefile Makefile.in README autom4te.cache config.h config.log configure hello stamp-h1
COPYING INSTALL Makefile.am NEWS aclocal.m4 autoscan.log config.h.in config.status configure.ac src
執(zhí)行程序
? Demo ./hello
Hello World!
參考文檔
下載地址
curl http://ftp.gnu.org/gnu/automake/automake-1.14.tar.xz | tar --strip-components=2 -xvJf - automake-1.14/doc/amhello-1.0.tar.gz
官方文檔