美文网首页
automake学习

automake学习

作者: ashura_ | 来源:发表于2017-05-27 21:13 被阅读0次

创建源文件

新建文件夹Demo

新建源码文件夹src

新建main.c

初始目录:

main.c
➜  Demo ls -F src . 
.:
Makefile.am  src/

src:
main.c

执行命令

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

执行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

执行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

执行程序

➜  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

官方文档

相关文章

网友评论

      本文标题:automake学习

      本文链接:https://www.haomeiwen.com/subject/ruxcfxtx.html