1.安装automake和autoconf
root@localhost]#yum install -y automake autoconf
2.进入需要被打包源码的目录
[root@localhost]# cd viscall
[root@localhost]# ls
base64.cpp crypto.h http.h io.cpp main.cpp network.cpp url.cpp ymdevice.cpp ymdocument.cpp ymlog.cpp ymlua.cpp ymparam.cpp ymtask.cpp
common.h http.cpp include io.h md5.cpp network.h url.h ymdevice.h ymdocument.h ymlog.h ymlua.h ymparam.h ymtask.h
3.利用autoconf工具生成makefile文件
[root@localhost]# autoscan
[root@localhost]# ls
autoscan.log common.h crypto.h http.h io.cpp main.cpp network.cpp url.cpp ymdevice.cpp ymdocument.cpp ymlog.cpp ymlua.cpp ymparam.cpp ymtask.cpp
base64.cpp configure.scan http.cpp include io.h md5.cpp network.h url.h ymdevice.h ymdocument.h ymlog.h ymlua.h ymparam.h ymtask.h
[root@localhost]# mv configure.scan configure.ac
[root@localhost]# vi configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
#将AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) 修改为
AC_INIT(viscall, 2.0, admin@support.com)
#添加AM_INIT_AUTOMAKE([FULL-PACKAGE-NAME], [VERSION])
AM_INIT_AUTOMAKE(viscall,2.0)
AC_CONFIG_SRCDIR([base64.cpp])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
...
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([floor gethostbyname gethostname gettimeofday inet_ntoa memchr memmove memset socket strchr strerror strrchr strstr strtoul])
#在AC_OUTPUT后面添加
AC_OUTPUT(Makefile)
·AC_PREREQ 宏声明本文件要求的autoconf版本,本例使用的版本为2.59。
·AC_INIT 宏用来定义软件的名称和版本等信息,”FULL-PACKAGE-NAME”为软件包名称,”VERSION”为软件版本号,”BUG-REPORT-ADDRESS”为BUG报告地址(一般为软件作者邮件地址)。
·AC_CONFIG_SRCDIR 宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性。
·AC_CONFIG_HEADER 宏用于生成config.h文件,以便autoheader使用。
·AC_PROG_CC 用来指定编译器,如果不指定,选用默认gcc。
·AC_OUTPUT 用来设定 configure 所要产生的文件,如果是makefile,configure会把它检查出来的结果带入makefile.in文件产生合适的makefile。使用Automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生。
修改完成后执行
[root@localhost]# aclocal
[root@localhost]# ls
autom4te.cache base64.cpp configure.ac http.cpp include io.h md5.cpp network.h url.h ymdevice.h ymdocument.h ymlog.h ymlua.h ymparam.h ymtask.h
autoscan.log common.h crypto.h http.h io.cpp main.cpp network.cpp url.cpp ymdevice.cpp ymdocument.cpp ymlog.cpp ymlua.cpp ymparam.cpp ymtask.cpp
[root@localhost]# autoconf
[root@localhost]# ls
autom4te.cache base64.cpp configure crypto.h http.h io.cpp main.cpp network.cpp url.cpp ymdevice.cpp ymdocument.cpp ymlog.cpp ymlua.cpp ymparam.cpp ymtask.cpp
autoscan.log common.h configure.ac http.cpp include io.h md5.cpp network.h url.h ymdevice.h ymdocument.h ymlog.h ymlua.h ymparam.h ymtask.h
此时可以看到已经生成了configure
[root@localhost]# autoheader
[root@localhost]# ls
autom4te.cache common.h configure.ac http.h io.h network.cpp url.h ymdocument.cpp ymlog.h ymparam.cpp ymtask.h
autoscan.log config.h.in crypto.h include main.cpp network.h ymdevice.cpp ymdocument.h ymlua.cpp ymparam.h
base64.cpp configure http.cpp io.cpp md5.cpp url.cpp ymdevice.h ymlog.cpp ymlua.h ymtask.cpp
autoheader生成了configure.h.in如果在configure.ac中定义了AC_CONFIG_HEADER,那么此文件就需要;
4.创建Makefile.am并编写内容
[root@localhost]# vi Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=viscall
viscall_SOURCES=./main.cpp \
./ymparam.cpp \
./ymdocument.cpp \
./ymlog.cpp \
./ymdevice.cpp \
./md5.cpp \
./base64.cpp \
./url.cpp \
./network.cpp \
./io.cpp \
./http.cpp \
./ymlua.cpp \
./ymtask.cpp
noinst_HEADERS=./common.h \
./ymparam.h \
./ymdocument.h \
./ymlog.h \
./ymdevice.h \
./crypto.h \
./url.h \
./network.h \
./io.h \
./http.h \
./ymlua.h \
./ymtask.h
viscall_CPPFLAGS=-I./include -std=gnu++11
viscall_LDFLAGS=-export-dynamic -lcurl -llua -lpthread
· AUTOMAKE_OPTIONS 为设置Automake的选项。由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则Automake执行时会报错。Automake提供了3种软件等级:foreign、gnu和gnits,供用户选择,默认等级为gnu。本例使需用foreign等级,它只检测必须的文件。
· bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。
· viscall_SOURCES 定义”viscall”这个执行程序所需要的原始文件。
5.利用automake 生成Makefile.in
[root@localhost]# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am:30: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
[root@localhost]# ls
aclocal.m4 base64.cpp configure depcomp include io.h Makefile.in network.cpp url.h ymdocument.cpp ymlog.h ymparam.cpp ymtask.h
autom4te.cache common.h configure.ac http.cpp install-sh main.cpp md5.cpp network.h ymdevice.cpp ymdocument.h ymlua.cpp ymparam.h
autoscan.log config.h.in crypto.h http.h io.cpp Makefile.am missing url.cpp ymdevice.h ymlog.cpp ymlua.h ymtask.cpp
6.进行程序安装
[root@localhost]#./configure
checking for a BSD-compatible install... /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 whether make supports nested variables... yes
...
...
...
checking for strtoul... yes
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
[root@localhost]# make
cd . && /bin/sh /root/viscall-yueme/missing automake-1.13 --foreign Makefile
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
cd . && /bin/sh ./config.status Makefile depfiles
config.status: creating Makefile
config.status: executing depfiles commands
make all-am
make[1]: Entering directory /root/viscall-yueme
g++ -DHAVE_CONFIG_H -I. -I./include -std=gnu++11 -g -O2 -MT viscall-main.o -MD -MP -MF .deps/viscall-main.Tpo -c -o viscall-main.o `test -f './main.cpp' || echo './'`./main.cpp
mv -f .deps/viscall-main.Tpo .deps/viscall-main.Po
g++ -DHAVE_CONFIG_H -I. -I./include -std=gnu++11 -g -O2 -MT viscall-ymparam.o -MD -MP -MF .deps/viscall-ymparam.Tpo -c -o viscall-ymparam.o `test -f './ymparam.cpp' || echo './'`./ymparam.cpp
mv -f .deps/viscall-ymparam.Tpo .deps/viscall-ymparam.Po
g++ -DHAVE_CONFIG_H -I. -I./include -std=gnu++11 -g -O2 -MT viscall-ymdocument.o -MD -MP -MF .deps/viscall-ymdocument.Tpo -c -o viscall-ymdocument.o `test -f './ymdocument.cpp' || echo './'`./ymdocument.cpp
mv -f .deps/viscall-ymdocument.Tpo .deps/viscall-ymdocument.Po
g++ -DHAVE_CONFIG_H -I. -I./include -std=gnu++11 -g -O2 -MT viscall-ymlog.o -MD -MP -MF .deps/viscall-ymlog.Tpo -c -o viscall-ymlog.o `test -f './ymlog.cpp' || echo './'`./ymlog.cpp
mv -f .deps/viscall-ymlog.Tpo .deps/viscall-ymlog.Po
g++ -DHAVE_CONFIG_H -I. -I./include -std=gnu++11 -g -O2 -MT viscall-ymdevice.o -MD -MP -MF .deps/viscall-ymdevice.Tpo -c -o viscall-ymdevice.o `test -f './ymdevice.cpp' || echo './'`./ymdevice.cpp
...
...
...
mv -f .deps/viscall-ymtask.Tpo .deps/viscall-ymtask.Po
g++ -g -O2 -export-dynamic -lcurl -llua -lpthread -o viscall viscall-main.o viscall-ymparam.o viscall-ymdocument.o viscall-ymlog.o viscall-ymdevice.o viscall-md5.o viscall-base64.o viscall-url.o viscall-network.o viscall-io.o viscall-http.o viscall-ymlua.o viscall-ymtask.o
make[1]: Leaving directory /root/viscall-yueme
[root@localhost]#ls
[root@localhost]# ls
aclocal.m4 config.h configure.ac include Makefile network.cpp viscall viscall-md5.o viscall-ymlog.o ymdevice.h ymlua.cpp ymtask.h
autom4te.cache config.h.in crypto.h install-sh Makefile.am network.h viscall-base64.o viscall-network.o viscall-ymlua.o ymdocument.cpp ymlua.h
autoscan.log config.log depcomp io.cpp Makefile.in stamp-h1 viscall-http.o viscall-url.o viscall-ymparam.o ymdocument.h ymparam.cpp
base64.cpp config.status http.cpp io.h md5.cpp url.cpp viscall-io.o viscall-ymdevice.o viscall-ymtask.o ymlog.cpp ymparam.h
common.h configure http.h main.cpp missing url.h viscall-main.o viscall-ymdocument.o ymdevice.cpp ymlog.h ymtask.cpp
在目录中生成viscall的执行文件
打包源码
[root@localhost]# make dist
make dist-gzip am__post_remove_distdir='@:'
make[1]: Entering directory /root/viscall-yueme
if test -d "viscall-2.0"; then find "viscall-2.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "viscall-2.0" || { sleep 5 && rm -rf "viscall-2.0"; }; else :; fi
test -d "viscall-2.0" || mkdir "viscall-2.0"
test -n "" \
|| find "viscall-2.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 /root/viscall-yueme/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "viscall-2.0"
tardir=viscall-2.0 && ${TAR-tar} chof - "$tardir" | GZIP=--best gzip -c >viscall-2.0.tar.gz
make[1]: Leaving directory /root/viscall-yueme
if test -d "viscall-2.0"; then find "viscall-2.0" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "viscall-2.0" || { sleep 5 && rm -rf "viscall-2.0"; }; else :; fi
[root@localhost]# ls
aclocal.m4 config.h configure.ac include Makefile network.cpp viscall viscall-main.o viscall-ymdocument.o ymdevice.cpp ymlog.h ymtask.cpp
autom4te.cache config.h.in crypto.h install-sh Makefile.am network.h viscall-2.0.tar.gz viscall-md5.o viscall-ymlog.o ymdevice.h ymlua.cpp ymtask.h
autoscan.log config.log depcomp io.cpp Makefile.in stamp-h1 viscall-base64.o viscall-network.o viscall-ymlua.o ymdocument.cpp ymlua.h
base64.cpp config.status http.cpp io.h md5.cpp url.cpp viscall-http.o viscall-url.o viscall-ymparam.o ymdocument.h ymparam.cpp
common.h configure http.h main.cpp missing url.h viscall-io.o viscall-ymdevice.o viscall-ymtask.o ymlog.cpp ymparam.h
执行命令后会生成viscall-2.0.tar.gz文件
网友评论