`
thecloud
  • 浏览: 882572 次
文章分类
社区版块
存档分类
最新评论

从无到有搭建Ubuntu下的编译环境和制作debian包

 
阅读更多

1.环境准备:安装 gcc, autoconf, automake, libtool, gettext, dh-makedebhelper等包;

2./home/workroom/test目录下写一个简单的测试程序test.c:

#include <stdio.h>

void main()

{

printf("Hello world!\r\n");

}

3./home/workroom/test目录下运行 autoscan产生基本的 configure.scan文件,打开该文件,并添加红色的几行,然后另存为configure.ac

# -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_CONFIG_SRCDIR([test.c])

AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AC_CONFIG_HEADERS([config.h])

# Checks for programs.

AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([

Makefile

])

AC_OUTPUT

4.手工生成一个autogen.sh文件,内容如下:

#! /bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements. See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License. You may obtain a copy of the License at

#

# Regenerate the files autoconf / automake

rm -f configure

rm -f config.cache

rm -f config.log

aclocal -I .

autoheader

autoconf

automake -a -c

5.手工生成Makefile.am

sbin_PROGRAMS=testapp

testapp_SOURCES= test.c

6.执行./autogen.sh生成configure文件

root@Ubuntu:/home/workroom/test#./autogen.sh

7.执行./configure生成Makefile文件

root@Ubuntu:/home/workroom/test#./configure

8.执行 make编译

root@Ubuntu:/home/workroom/test#make

至此,第一阶段程序的自动编译环境已经完成,可以看到在当前目录下已经生成了 testapp可执行程序。执行 ./testapp会输出“Hello world!”

下面继续完成将当前程序打成deb包。

9.在当前目录下新建一个 debian目录,并进入该目录创建 control, rules, changlog,copyright,compat等几个必要的文件:

root@Ubuntu:/home/workroom/test# mkdir debian

root@Ubuntu:/home/workroom/test# cd debian

root@Ubuntu:/home/workroom/test# touch control

输入内容:

Source: testapp

Section: unknown

Priority: extra

Maintainer: aaa

Build-Depends: debhelper (>= 8.0.0), autotools-dev

Standards-Version: 3.9.2

Homepage: http://www.test.com

Package: testapp

Architecture: any

Depends: ${shlibs:Depends}, ${misc:Depends}

Description: testapp

testapp

root@Ubuntu:/home/workroom/test# touch copyright

输入内容:

Format: http://dep.debian.net/deps/dep5

Upstream-Name: testapp

Source: <url://example.com>

Files: *

Copyright: <years> <put author's name and email here>

<years> <likewise for another author>

License: <special license>

<Put the license of the package here indented by 1 space>

<This follows the format of Description: lines in control file>

.

<Including paragraphs>

root@Ubuntu:/home/workroom/test# touch changelog

输入内容:

testapp (1.0.0-1) stable; urgency=low

* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>

-- aaa <aaa@unknown> Thu, 28 Jun 2012 13:27:14 +0800

root@Ubuntu:/home/workroom/test# touch compat

输入内容:

8

root@Ubuntu:/home/workroom/test# touch rules

输入内容:

#!/usr/bin/make -f

# testApp debian/rules using debhelper

# Copyright (C) 2012 aaa <aaa@gmail.com>

CXXFLAGS += -g -O2

CFLAGS += -g -O2

build-arch: build

build-indep: build

build: build-stamp

build-stamp: build-test-stamp

touch build-stamp

build-test-stamp:

mkdir build_test

ls |grep -v debian|grep -v build_test|xargs -i cp -r {} build_test/

cd build_test && ./autogen.sh && ./configure

$(MAKE) -C build_test

touch build-test-stamp

clean: clean-patched

clean-patched:

dh_testdir

dh_testroot

[ ! -d $(CURDIR)/build_test ] || rm -rf $(CURDIR)/build_test

dh_clean

install: install-stamp

install-stamp: build-stamp

dh_testdir

dh_testroot

dh_prep

dh_installdirs

$(MAKE) -C $(CURDIR)/build_test install DESTDIR=$(CURDIR)/debian/tmp

dh_install --sourcedir=debian/tmp

touch install-stamp

binary-arch: build install

dh_testdir

dh_testroot

dh_install --list-missing

dh_installchangelogs

dh_installdocs

dh_installexamples

dh_installman

dh_python2 --no-guessing-versions

dh_link

dh_strip

dh_compress

dh_fixperms

dh_makeshlibs

dh_installdeb

dh_shlibdeps

dh_gencontrol

dh_md5sums

dh_builddeb

# Build architecture-independent files here.

binary-indep: build install

# We have nothing to do by default.

binary: binary-indep binary-arch

.PHONY: build clean binary-indep binary-arch binary install

10.因为我们编译出来的程序名叫 testapp,为了把它做进deb包,还需要创建一个testapp.install文件:

root@Ubuntu:/home/workroom/test# touch testapp.install

/usr/local/bin/testapp

至此,为制作deb包的所有环节已经准备好,在当前目录下执行:

root@Ubuntu:/home/workroom/test# ./debian/rules binary

11.成功之后,debian包生成在root@Ubuntu:/home/workroom/testapp_1.0.0-1.i386.deb

12.dpkg -i命令安装这个deb:

root@Ubuntu:/home/workroom#dpkg –i testapp_1.0.0-1.i386.deb

安装完后执行 testapp:

root@Ubuntu:/home/workroom# testapp

Hello world!

以上从无到有,介绍了在linux Ubuntu下基本的编译环境和debian包生成的基本步骤和框架,当然如果工程复杂的话,需要在上述步骤中添加相应的依赖包等,但总体的框架和步骤是一样的,更详细的说明可以参考:http://www.debian.org/doc/manuals/maint-guide/index.en.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics