Linux|系统管理|WEB开发

关注Linux,系统管理,WEB开发以及开源世界

快速制作一个虚假deb格式软件包

| Comments

把上面的代码保存为dummy.c。而后使用autoscan命令来粗昂间一个configure模板文件,命令如下

$ autoscan 
$ ls
autoscan.log  configure.scan  dummy.c

将生成的configure.scan文件保存为configure.in,并进行修改,只用保留下面几行内容就行了,我在文件里注释说明

AC_PREREQ([2.67])
#定义包的名字,版本以及bug发布地址
AC_INIT(dummy, 2009-10, fake@example.com)
#传递给automake的参数
AM_INIT_AUTOMAKE(dummy,2009-10)
AC_CONFIG_SRCDIR([dummy.c])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
#输出文件名
AC_OUTPUT(Makefile)

上面的版本号可以随意定义,但是为了和我们当前系统获取的真实的texlive-base包版一致,我们取的一样。我们可以先通过下面的指令获得该包的版本

$ apt-cache show texlive-base |grep '^Version'
Version: 2009-10

执行aclocalheautoconf,生成confiugre文件

$ aclocal
$ autoconf 
$ ls
autom4te.cache  autoscan.log  configure  configure.in  dummy.c

新建Makefile.am文件,再由automake工具根据所写的Makefile.am文件来自动生成Makefile.in文件。 Makefile.am文件一般定义自己的软件最后生成的可执行程序名字、需要连接的库等,这里只有一个c文件,因此Makefile.am就相当简单了

$ cat Makefile.am 
bin_PROGRAMS=dummy
dummy_SOURCES=dummy.c

注意上面的最后一行,dummy是依赖第一行的设置,如果第一行最后设置为foo,那么第二行就应该是foo_SOURCES 好了,现在有了Makefile.am了,我们可以创建Makefile.in文件了,不过创建Makefile.in之前,我们还需要创建automake必须要的一些文件,然后再执行她

$ touch NEWS README AUTHORS ChangeLog
$ automake --add-missing
$ ls
aclocal.m4      ChangeLog      configure.in  INSTALL      missing
AUTHORS         config.log     COPYING       install-sh   NEWS
autom4te.cache  config.status  depcomp       Makefile.am  README
autoscan.log    configure      dummy.c       Makefile.in

以上会给出一些警告,因为我们缺少一个软件源代码一般都需要的INSTALL,README等文件。当然你可以touch这些,或者对这些直接飘过,反正我们这个包只是用来欺骗apt的。 接下来的步骤我们就很熟悉了,就是./configure && make 这个套路了,我们来执行它吧:

$ automake
$ ./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... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
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
$ make
gcc -DPACKAGE_NAME=\"dummy\" -DPACKAGE_TARNAME=\"dummy\" -DPACKAGE_VERSION=\"2009-10\" -DPACKAGE_STRING=\"dummy\ 2009-10\" -DPACKAGE_BUGREPORT=\"fake@example.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"dummy\" -DVERSION=\"2009-10\" -I.     -g -O2 -MT dummy.o -MD -MP -MF .deps/dummy.Tpo -c -o dummy.o dummy.c
mv -f .deps/dummy.Tpo .deps/dummy.Po
gcc  -g -O2   -o dummy dummy.o  
$ ls
aclocal.m4      ChangeLog      configure.in  dummy.c     Makefile     NEWS
AUTHORS         config.log     COPYING       dummy.o     Makefile.am  README
autom4te.cache  config.status  depcomp       INSTALL     Makefile.in
autoscan.log    configure      dummy         install-sh  missing

好了,make成功了,如果仅仅是安装,我们执行make install 就好了,但是我们的目的是创建一个deb包,虽然我们可以按照Debian的New Maintainer Guide一步一步制作deb包,详细的过程请参照: http://www.debian.org/doc/maint-guide/ 但是我们为了快速创建deb包,还是利用checkinstall这个工具好了。

$ checkinstall -D -y --install=no --pkgname=texlive-base --pkgversion=2009-10

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran

...... .....
*******************************************************

 Done. The new package has been saved to

 /var/tmp/texlive-base/texlive-base_2009-10-1_i386.deb
 You can install it in your system anytime using: 

      dpkg -i texlive-base_2009-10-1_i386.deb

***********************************************************

看到最好了吧,我们就得到了texlive-base_2009-10-1_i386.deb包了,这个包,没有任何依赖关系,你可以直接安装。安装后,再执行

$sudo apt-get install texworks

从列出的依赖关系中,你就发现少了texlive-base包了。 如果你依赖的包很多,那么我们可以将上述过程自动化,非常方便。

Comments