使用make命令
产生了makefile后我们就要使用make工程管理器去实现makefile的制定。
1、make
make默认执行make all命令,其执行情况如下所示:
[root@localhosthello]# make
make all-am
make[1]: Entering directory `/root/hello'
if gcc -DHAVE_CONFIG_H -I.-I.-I.-g -O2 -MT hello.o -MD-MP -MF ".deps/hello.Tpo" -c -o hello.o hello.c; then mv -f".deps/hello.Tpo" ".deps/hello.Po"; else rm -f".deps/hello.Tpo"; exit 1; fi
gcc -g -O2 -o hello hello.o
make[1]: Leaving directory `/root/hello'
如果之前makefile操作无误,那么执行make命令会出现上面这段执行内容,而且会在目录下生成hello可执行文件,运行hello程序:
[root@localhosthello]# ./hello
Hello,Make!
2、make install
把hello程序安装到系统目录中去:
[root@localhosthello]# make install
make[1]: Entering directory `/root/hello'
test -z "/usr/local/bin" || mkdir -p --"/usr/local/bin"
/usr/bin/install-c 'hello' '/usr/local/bin/hello'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/root/hello'
此时,若直接运行hello能出现如下结果就说明操作正确:
[root@localhosthello]# hello
Hello,Make!
3、make clean
此命令是清除之前所编译的可执行文件及目标文件(object file, *.o):
[root@localhosthello]# make clean
test -z "hello" || rm -f hello
rm -f *.orm -f*.o
4、make dist
当我们做好了一切工作,最后一步是压缩文档以供发布:
[root@localhost hello]# make dist
[root@localhosthello]# ls hello-1.0.tar.gz
hello-1.0.tar.gz
hello-1.0-tar.gz就是我们最终要发布的压缩文件。autoTools的整个流程都介绍完毕,现实中更多会用到autoTools来为我们生成makefile文档。
小结
本章介绍了make工程管理器的命令、作用和怎样编写简单实用的makefile,并且还讨论了make规则和make的一些有用的命令行选项。通过学习本章,同学们应该已经能够使用make来管理软件项目的的创建和维护过程了。
