一. 手动写了一个工具类,生成现成的c或者cpp框架。
git路径:https://github.com/chuanshanjia/ccpp/blob/master/frame.sh
git说明:https://github.com/chuanshanjia/ccpp/blob/master/README.md
#makefile自动生成工具 frame.sh
##使用方式 sh frame.sh autotools
##目录结构
include为存放头文件目录 src 为存放cpp文件的位置
##模块名字 修改frame.sh文件中变量名APP的名字,就能得到你想要的文件名字。
使用方式
部署:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[[email protected] ~]$ wget https://github.com/chuanshanjia/ccpp/blob/master/frame.sh
[[email protected] ccpp]$ ls
frame.sh
[[email protected] ccpp]$ pwd
/home/jack/tool/ccpp
[[email protected] ccpp]$ sh frame.sh autotools
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
...
[[email protected] ccpp]$ ls
aclocal.m4 autom4te.cache ChangeLog config.h.in config.status configure.ac depcomp include install-sh Makefile.am missing README stamp-h1
AUTHORS autoscan.log config.h config.log configure COPYING frame.sh INSTALL Makefile Makefile.in NEWS src
|
清理:
愉快的操作吧^_^
头文件位置:
|
1
2
3
4
|
[[email protected] ccpp]$ ls
aclocal.m4 autom4te.cache ChangeLog config.h.in config.status configure.ac depcomp include install-sh Makefile.am missing README stamp-h1
AUTHORS autoscan.log config.h config.log configure COPYING frame.sh INSTALL Makefile Makefile.in NEWS src
[[email protected] ccpp]$ vim include/demo.h
|
main文件位置:
编译运行:
|
1
2
3
4
5
6
7
8
9
10
|
[[email protected] ccpp]$ make
make all-am
make[1]: Entering directory `/home/jack/tool/ccpp'
g++ -DHAVE_CONFIG_H -I. -I/home/jack/tool/ccpp/include -I/home/jack/tool/ccpp/src/include -g -O2 -MT demo.o -MD -MP -MF .deps/demo.Tpo -c -o demo.o `test -f 'src/demo.cpp' || echo './'`src/demo.cpp
mv -f .deps/demo.Tpo .deps/demo.Po
g++ -g -O2 -o demo demo.o
make[1]: Leaving directory `/home/jack/tool/ccpp'
[[email protected] ccpp]$ ./demo
hello,demo
[[email protected] ccpp]$
|
以下内容可作为参考学习,帮助理解工具产生的过程,如非必要,可不进行阅读。网上有很多类似内容,可以在百度搜索“autotools"就能看到整个过程。
工具准备(参考):autoscan、aclocal、autoheader 、automake、autoconf、automake

准备Makefile.am文件
|
1
2
3
4
|
INCLUDES=-I./include -I./src/include
UTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test
test_SOURCES=src/test.cpp
|
使用智能化工具(参考)
autoscan
当我们利用autoscan工具生成confiugre.scan文件时,我们需要将confiugre.scan重命名为confiugre.ac文件。confiugre.in调用一系列autoconf宏来测试程序需要的或用到的特性是否存在,以及这些特性的功能。
具体使用如下:
修改点:

一气呵成
|
1
2
3
4
5
6
7
8
|
aclocal
autoconf
autoheader
automake --add-missing
automake --add-missing
touch NEWS README AUTHORS ChangeLog
automake --add-missing
./configure
|
参考手册
confiugre.in文件的一般布局:
|
1
2
3
4
5
6
7
8
9
10
|
AC_INIT
测试程序
测试函数库
测试头文件
测试类型定义
测试结构
测试编译器特性
测试库函数
测试系统调用
AC_OUTPUT
|
表 1Makefile.am一般格式

表 2 Makefile.am中可用的全局变量

在Makefile.am中尽量使用相对路径,系统预定义了两个基本路径:
表 3Makefile.am中可用的路径变量

参考文献
1、http://www.ibm.com/developerworks/cn/linux/l-makefile/
2、https://www.gnu.org/software/autoconf/manual/autoconf-2.61/html_node/Autoconf-Language.html#Autoconf-Language
3、http://www.gnu.org/software/automake/manual/automake.pdf