生成符合自由软件惯例的Makefile
2014-06-17 15:02
155 查看
生成符合自由软件惯例的Makefile
./configure 的生成过程
configure 是个shell 脚本文件,是自动产生的,不是手工编写的。
------------------------------------------------------------
过程简述:
------------------------------------------------------------
编写3个文件
test.c
configure.in
Makefile.am
然后执行:
aclocal
autoconf
automake --add-missing
而后可以编译,安装,发布
./configure 生成Makefile
make
make clean
make install
make clean
make dist
------------------------------------------------------------
1. 准备目录和文件,autoscan 生成 configure.in 的模板
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ls
test.c
[hjj@hjj ~/ctest]$ cat test.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello\n");
return 0;
}
[hjj@hjj ~/ctest]$ autoscan
[hjj@hjj ~/ctest]$ ls
autoscan.log configure.scan test.c
------------------------------------------------------------
2. 编写configure.in 文件
有一些宏的定义要慢慢积累
AM_INIT_AUTOMAKE 宏是必须的
------------------------------------------------------------
以configure.scan 为模板,添加修改AC_INIT, AM_INIT_AUTOMAKE,AC_OUTPUT, 删除不用部分
[hjj@hjj ~/ctest]$ diff configure.scan configure.in
5,7c5,6
< AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
< AC_CONFIG_SRCDIR([test.c])
< AC_CONFIG_HEADERS([config.h])
---
> AC_INIT(test, 1.0)
> AM_INIT_AUTOMAKE(test, 1.0)
20c19
< AC_OUTPUT
---
> AC_OUTPUT(Makefile)
------------------------------------------------------------
3. 运行aclocal autoconf 命令
aclocal 是一个perl脚本,将configure.in 变成 aclocal.m4
autoconf 生成configure. 它的输入是aclocal.m4
configure 是一个shell 脚本,它能检测系统特性,使支持各种平台
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ls
autoscan.log configure.in configure.scan test.c
[hjj@hjj ~/ctest]$ aclocal
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure.in configure.scan test.c
[hjj@hjj ~/ctest]$ autoconf
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in configure.scan test.c
------------------------------------------------------------
4. 编写Makefile.am
是makefile.in 的输入文件
AUTOMAKE_OPTIONS:检查目录下是否存在标准GNU软件包中应具备的各种文件,例如AUTHORS、ChangeLog、NEWS等文件。
我们将其设置成foreign时,automake会改用一般软件包的标准来检查。
bin_PROGRAMS 指定我们所要产生的可执行文件的文件名。
如果你要产生多个可执行文件,那么在各个名字间用空格隔开。
test_SOURCES 指定产生“test”时所需要的源代码。如果它用到了多个源文件,那么请使用空格符号将它们隔开。
比如需要test.h,test.c那么请写成 test_SOURCES= test.h test.c。
bin_PROGRAMS定义了多个可执行文件,则对应每个可执行文件都要定义相对的filename_SOURCES
------------------------------------------------------------
[hjj@hjj ~/ctest]$ cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test
test_SOURCES=test.c
------------------------------------------------------------
5. 运行 automake --add-missing
--add-missing 选项会让automake自动加入软件包所必须的一些文件。
------------------------------------------------------------
[hjj@hjj ~/ctest]$ automake --add-missing
configure.in:6: installing `./install-sh'
configure.in:6: installing `./missing'
Makefile.am: installing `./depcomp'
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in configure.scan depcomp install-sh Makefile.am Makefile.in missing test.c
生成的Makefile.in 是符合GNU 惯例的。
至此,源码发布文件已经全部生成。
------------------------------------------------------------
6. 运行 ./configure
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ./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... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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 for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
------------------------------------------------------------
7. make & clean & distribute & install
------------------------------------------------------------
[hjj@hjj ~/ctest]$ make
gcc -DPACKAGE_NAME=\"test\" -DPACKAGE_TARNAME=\"test\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"test\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"test\" -DVERSION=\"1.0\" -I. -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
gcc -g -O2 -o test test.o
[hjj@hjj ~/ctest]$ make dist
{ test ! -d "test-1.0" || { find "test-1.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr "test-1.0"; }; }
test -d "test-1.0" || mkdir "test-1.0"
test -n "" \
|| find "test-1.0" -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/sh /home/hjj/ctest/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "test-1.0"
tardir=test-1.0 && /bin/sh /home/hjj/ctest/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >test-1.0.tar.gz
{ test ! -d "test-1.0" || { find "test-1.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr "test-1.0"; }; }
[hjj@hjj ~/ctest]$ make clean
test -z "test" || rm -f test
rm -f *.o
[hjj@hjj ~/ctest]$ make
gcc -DPACKAGE_NAME=\"test\" -DPACKAGE_TARNAME=\"test\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"test\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"test\" -DVERSION=\"1.0\" -I. -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
gcc -g -O2 -o test test.o
[hjj@hjj ~/ctest]$ sudo make install
make[1]: Entering directory `/home/hjj/ctest'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
/usr/bin/install -c test '/usr/local/bin'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/home/hjj/ctest'
------------------------------------------------------------
调试信息的添加:
------------------------------------------------------------
不要在Makefile中用CFLAGS,CXXFLAGS,xxx_CFLAGS,xxx_CXXFLAGS来设置调试信息。这样每次发布前都要修改Makefile.am
执行configure,设置相关环境变量, 重新生成Makefile, 来决定是否需要调试信息
如果是 C 程序,就执行 ./configure "CFLAGS=..."
如果是 C++ 程序,就执行 ./configure "CXXFLAGS=..."
可执行 ./configure --help 查看帮助。
./configure 的生成过程
configure 是个shell 脚本文件,是自动产生的,不是手工编写的。
------------------------------------------------------------
过程简述:
------------------------------------------------------------
编写3个文件
test.c
configure.in
Makefile.am
然后执行:
aclocal
autoconf
automake --add-missing
而后可以编译,安装,发布
./configure 生成Makefile
make
make clean
make install
make clean
make dist
------------------------------------------------------------
1. 准备目录和文件,autoscan 生成 configure.in 的模板
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ls
test.c
[hjj@hjj ~/ctest]$ cat test.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello\n");
return 0;
}
[hjj@hjj ~/ctest]$ autoscan
[hjj@hjj ~/ctest]$ ls
autoscan.log configure.scan test.c
------------------------------------------------------------
2. 编写configure.in 文件
有一些宏的定义要慢慢积累
AM_INIT_AUTOMAKE 宏是必须的
------------------------------------------------------------
以configure.scan 为模板,添加修改AC_INIT, AM_INIT_AUTOMAKE,AC_OUTPUT, 删除不用部分
[hjj@hjj ~/ctest]$ diff configure.scan configure.in
5,7c5,6
< AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
< AC_CONFIG_SRCDIR([test.c])
< AC_CONFIG_HEADERS([config.h])
---
> AC_INIT(test, 1.0)
> AM_INIT_AUTOMAKE(test, 1.0)
20c19
< AC_OUTPUT
---
> AC_OUTPUT(Makefile)
------------------------------------------------------------
3. 运行aclocal autoconf 命令
aclocal 是一个perl脚本,将configure.in 变成 aclocal.m4
autoconf 生成configure. 它的输入是aclocal.m4
configure 是一个shell 脚本,它能检测系统特性,使支持各种平台
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ls
autoscan.log configure.in configure.scan test.c
[hjj@hjj ~/ctest]$ aclocal
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure.in configure.scan test.c
[hjj@hjj ~/ctest]$ autoconf
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in configure.scan test.c
------------------------------------------------------------
4. 编写Makefile.am
是makefile.in 的输入文件
AUTOMAKE_OPTIONS:检查目录下是否存在标准GNU软件包中应具备的各种文件,例如AUTHORS、ChangeLog、NEWS等文件。
我们将其设置成foreign时,automake会改用一般软件包的标准来检查。
bin_PROGRAMS 指定我们所要产生的可执行文件的文件名。
如果你要产生多个可执行文件,那么在各个名字间用空格隔开。
test_SOURCES 指定产生“test”时所需要的源代码。如果它用到了多个源文件,那么请使用空格符号将它们隔开。
比如需要test.h,test.c那么请写成 test_SOURCES= test.h test.c。
bin_PROGRAMS定义了多个可执行文件,则对应每个可执行文件都要定义相对的filename_SOURCES
------------------------------------------------------------
[hjj@hjj ~/ctest]$ cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test
test_SOURCES=test.c
------------------------------------------------------------
5. 运行 automake --add-missing
--add-missing 选项会让automake自动加入软件包所必须的一些文件。
------------------------------------------------------------
[hjj@hjj ~/ctest]$ automake --add-missing
configure.in:6: installing `./install-sh'
configure.in:6: installing `./missing'
Makefile.am: installing `./depcomp'
[hjj@hjj ~/ctest]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in configure.scan depcomp install-sh Makefile.am Makefile.in missing test.c
生成的Makefile.in 是符合GNU 惯例的。
至此,源码发布文件已经全部生成。
------------------------------------------------------------
6. 运行 ./configure
------------------------------------------------------------
[hjj@hjj ~/ctest]$ ./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... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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 for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
------------------------------------------------------------
7. make & clean & distribute & install
------------------------------------------------------------
[hjj@hjj ~/ctest]$ make
gcc -DPACKAGE_NAME=\"test\" -DPACKAGE_TARNAME=\"test\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"test\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"test\" -DVERSION=\"1.0\" -I. -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
gcc -g -O2 -o test test.o
[hjj@hjj ~/ctest]$ make dist
{ test ! -d "test-1.0" || { find "test-1.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr "test-1.0"; }; }
test -d "test-1.0" || mkdir "test-1.0"
test -n "" \
|| find "test-1.0" -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/sh /home/hjj/ctest/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "test-1.0"
tardir=test-1.0 && /bin/sh /home/hjj/ctest/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >test-1.0.tar.gz
{ test ! -d "test-1.0" || { find "test-1.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr "test-1.0"; }; }
[hjj@hjj ~/ctest]$ make clean
test -z "test" || rm -f test
rm -f *.o
[hjj@hjj ~/ctest]$ make
gcc -DPACKAGE_NAME=\"test\" -DPACKAGE_TARNAME=\"test\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"test\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"test\" -DVERSION=\"1.0\" -I. -g -O2 -MT test.o -MD -MP -MF .deps/test.Tpo -c -o test.o test.c
mv -f .deps/test.Tpo .deps/test.Po
gcc -g -O2 -o test test.o
[hjj@hjj ~/ctest]$ sudo make install
make[1]: Entering directory `/home/hjj/ctest'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
/usr/bin/install -c test '/usr/local/bin'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/home/hjj/ctest'
------------------------------------------------------------
调试信息的添加:
------------------------------------------------------------
不要在Makefile中用CFLAGS,CXXFLAGS,xxx_CFLAGS,xxx_CXXFLAGS来设置调试信息。这样每次发布前都要修改Makefile.am
执行configure,设置相关环境变量, 重新生成Makefile, 来决定是否需要调试信息
如果是 C 程序,就执行 ./configure "CFLAGS=..."
如果是 C++ 程序,就执行 ./configure "CXXFLAGS=..."
可执行 ./configure --help 查看帮助。
相关文章推荐
- 充分利用 GNU 工具开发符合自由软件惯例的应用程序
- 使用Automake生成符合GNU标准的makefile
- Linux Automake工具生成Makefile软件实现步骤
- 自由软件发布方法惯例
- 跨平台MakeFile生成的软件--PreMake
- 自由软件来生成纯粹的Win32可执行文件的编译环境
- about face 2.0——第二章(3):大部分的软件符合的是实现模型
- 自由软件,不只是开放源码
- Linux下Makefile的automake生成全攻略
- 自由软件的定义
- 做Talk!软件的知识点滴(2)--从命令行生成(msdn)
- 自由软件及非自由软件的种类
- 自动化生成软件(未测)
- 在Sun Solaris中导入自由软件
- UML工具推荐 Poseidon版本 可以免费下载,自动生成代码 C++ Java C# VB.NET等 (来自德国汉堡的国际性建模软件开发商Gentleware AG的)
- 贩售自由软件
- 自由Windows软件
- 各种类自由软件的许可证释义
- 联合国举办自由软件日 向亚洲用户推介开源软件
- 适合中小软件采用的矢量化地图的生成方法总结