3.5、 执行autoheader和aclocal命令
autoheader是用来映射头文件,aclocal用来设置所有的宏(执行aclocal会产生aclocal.m4文件,如果没有特别的要求,无需修改它。用 aclocal产生的宏将会提示automake如何动作。)。
zhouyl@zhouyl:/tmp/hello$ ls
autoscan.log configure.in hello.c Makefile.am
zhouyl@zhouyl:/tmp/hello$autoheader
zhouyl@zhouyl:/tmp/hello$ ls
autom4te.cache autoscan.log config.h.in configure.in hello.c Makefile.am
zhouyl@zhouyl:/tmp/hello$ aclocal
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autom4te.cache autoscan.log config.h.in configure.in hello.c Makefile.am
zhouyl@zhouyl:/tmp/hello$
3.6、使用automake命令了:
zhouyl@zhouyl:/tmp/hello$ automake
configure.in:8: required file `./install-sh' not found
configure.in:8: `automake --add-missing' can install `install-sh'
configure.in:8: required file `./missing' not found
configure.in:8: `automake --add-missing' can install `missing'
Makefile.am: required file `./INSTALL' not found
Makefile.am: `automake --add-missing' can install `INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: required file `./COPYING' not found
Makefile.am: `automake --add-missing' can install `COPYING'
所以,根据提示,我们缺少 NEWS、README、AUTHORS、ChangeLog和COPYING,而使用automake --add-missing会生成COPYING,所以在此之前我们需要手动添加这几个文件:
zhouyl@zhouyl:/tmp/hello$ touch NEWS README AUTHORS ChangeLog
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autom4te.cache ChangeLog configure.in Makefile.am README
AUTHORS autoscan.log config.h.in hello.c NEWS
注:这是我在演示如何使用autotools,如果是你真得要发布软件,请仔细填写这几个文件,而不是使用touch生成一个空文件。
现在我们可以使用automake --add-missing:
zhouyl@zhouyl:/tmp/hello$ automake --add-missing
configure.in:8: installing `./install-sh'
configure.in:8: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: installing `./COPYING' using GNU General Public License v3 file
Makefile.am: Consider adding the COPYING file to the version control system
Makefile.am: for your code, to avoid questions about which license your project uses.
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autom4te.cache ChangeLog configure.in hello.c install-sh Makefile.in NEWS
AUTHORS autoscan.log config.h.in COPYING INSTALL Makefile.am missing README
会发现,现在使用automake很顺利,而且生成了INSTALL、COPYING等文件。
3.7、使用autoconf
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autom4te.cache ChangeLog configure.in hello.c install-sh Makefile.in NEWS
AUTHORS autoscan.log config.h.in COPYING INSTALL Makefile.am missing README
zhouyl@zhouyl:/tmp/hello$autoconf
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autom4te.cache ChangeLog configure COPYING INSTALL Makefile.am missing README
AUTHORS autoscan.log config.h.in configure.in hello.c install-sh Makefile.in NEWS
所以,我们可以看到,使用autoconf命令生成了configure。
3.8、./configure , make
接下来的工作无非就是使用configure,生成make文件:
zhouyl@zhouyl:/tmp/hello$./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
……(a lot of cheaking)
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
zhouyl@zhouyl:/tmp/hello$ls
aclocal.m4 autoscan.log config.h.in configure depcomp install-sh Makefile.in README
AUTHORS ChangeLog config.log configure.in hello.c Makefile missing stamp-h1
autom4te.cache config.h config.status COPYING INSTALL Makefile.am NEWS
所以,使用./configure生成了Makefile、config.h和其他一些文件。
因为此时Makefile文件已经生成,所以我们可以使用make命令了:
zhouyl@zhouyl:/tmp/hello$ make
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /tmp/hello/missing --run autoheader)
rm -f stamp-h1
touch config.h.in
cd . && /bin/bash ./config.status config.h
config.status: creating config.h
make all-am
make[1]: 正在进入目录 `/tmp/hello'
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc -g -O2 -o beep hello.o
make[1]:正在离开目录 `/tmp/hello'
zhouyl@zhouyl:/tmp/hello$ ls // 使用make命令后,生成了二进制可执行文件,因为我们在上面已经指定,所以生成的可执行文件名不是hello而是beep
aclocal.m4 autoscan.log config.h config.log configure.in hello.c install-sh Makefile.in README
AUTHORS beep config.h.in config.status COPYING hello.o Makefile missing stamp-h1
autom4te.cache ChangeLog config.h.in~ configure depcomp INSTALL Makefile.am NEWS
dslab@Raring-Ringtail:/tmp/hello$ ./beep // 运行二进制可执行文件,得正确的执行结果
hello,world
分析一下可以发现,我们这一步的步骤大致是这样的:
Makefile.in -----+ +-> Makefile -----+-> make -> binary
src/Makefile.in -+-> ./configure -+-> src/Makefile -+
config.h.in -----+ +-> config.h -----+
其实此时,在当前目录下有Makefile文件,我们可以做的工作有:
* make all:产生设定的目标,即生成所有的可执行文件。使用make也可以达到此目的。
* make clean:删除之前编译时生成的可执行文件及目标文件(形如*.o的中间文件)。
* make distclean:除了删除可执行文件和目标文件以外,把configure所产生的 Makefile文件也清除掉。通常在发布软件前执行该命令。
* make install:将使用make all或make命令产生的可执行文件以软件的形式安装到系统中。若使用bin_PROGRAMS宏,程序将会被安装到 /usr/local/bin下,否则安装到预定义的目录下。
* make dist:将程序和相关的文档包装为一个压缩文档以供发布。执行完该命令,在当前目录下会产生一个名为PACKAGE-VERSION.tar.gz的文件。PACKAGE 和 VERSION 这两个参数是来自configure.in文件中的AM_INIT_AUTOMAKE(PACKAGE,
VERSION)。如在上个例子中执行make dist命令,会产生名为“hello-1.0.tar.gz”的文件。
* make distcheck:与make dist类似,但是加入了检查包装以后的压缩文件是否正常。
======================= 下面步骤是生成deb程序包,Debian系专属 ==================================
3.9、make dist 提取源程序包
下面,我们做的可是高端大气上档次的工作 -- 生成可发布的Debian应用包 -- deb文件。(Debian系Linux专属哦)
首先,我们使用“ make dist ”命令,make dist将程序和相关的文档包装为一个压缩文档以供发布。从此,你将再也不想手动写Makefile!!
zhouyl@zhouyl:/tmp/hello$ make dist
if test -d "beep-0.1"; then find "beep-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "beep-0.1" || { sleep 5 && rm -rf "beep-0.1"; }; else :; fi
test -d "beep-0.1" || mkdir "beep-0.1"
test -n "" \
|| find "beep-0.1" -type d ! -perm -755 \
-exec chmod u+rwx,go+rx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec /bin/bash /tmp/hello/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "beep-0.1"
tardir=beep-0.1 && ${TAR-tar} chof - "$tardir" | GZIP=--best gzip -c >beep-0.1.tar.gz
if test -d "beep-0.1"; then find "beep-0.1" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "beep-0.1" || { sleep 5 && rm -rf "beep-0.1"; }; else :; fi
zhouyl@zhouyl:/tmp/hello$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh Makefile.in README
AUTHORS beep-0.1.tar.gz config.h.in configure hello.c Makefile missing stamp-h1
autom4te.cache ChangeLog config.log configure.in INSTALL Makefile.am NEWS
我们可以看到,目录里多了个beep-0.1.tar.gz文件。这就是我们后续工作的核心