How to build a Debian/Ubuntu package from source?
Asked Answered
P

10

123

I have the source of a program (taken from cvs/svn/git/...) and I'd like to build a Debian/Ubuntu package for it. The package is present in the repositories, but:

  • It is an older version (lacking features I need)
  • I need slightly different compile options than the default.

What is the easiest way of doing it? I am concerned about a couple of things

  • How can I check if I have listed all the dependencies correctly? (I can get some hints by looking on what the older version depended, but new dependencies may have been added.)
  • How I can I prevent the update system installing the older version in the repo on an update?
  • How I can prevent the system installing a newer version (when its out), overwriting my custom package?
Plourde answered 25/9, 2008 at 1:1 Comment(1)
Similar on AU: askubuntu.com/questions/28372/…Photofluorography
A
81

you can use the special package "checkinstall" for all packages which are not even in debian/ubuntu yet.

You can use "uupdate" (apt-get install devscripts) to build a package from source with existing debian sources:

Example for libdrm2:

apt-get build-dep libdrm2
apt-get source libdrm2
cd libdrm-2.3.1
uupdate ~/Downloads/libdrm-2.4.1.tar.gz
cd ../libdrm-2.4.1
dpkg-buildpackage -us -uc -nc
Amadis answered 21/11, 2008 at 14:40 Comment(3)
Thanks! I have just used this to port Subversion 1.6.6 to an Ubuntu install that only has 1.6.5 as its latest available version, and it worked flawlessly. Saved me quite a few hours of tinkering! :)Eufemiaeugen
Could you give a little more context around these commands? Where is libdrm-2.3.1 exactly? Also where did libdrm-2.4.1.tar.gz come from (my initial assumption is that is the compiled binary of the application that we want to package in a deb, but replacing the existing version, is that correct?)Recor
If you get the error You must put some 'source' URIs in your sources.list, uncomment the deb-src lines in your /etc/apt/sources.listDiabetes
C
30

First, the title question: Assuming the debian directory is already there, be in the source directory (the directory containing the debian directory) and invoke dpkg-buildpackage. I like to run it with these options:

dpkg-buildpackage -us -uc -nc

which mean don't sign the result and don't clean.

How can I check if I have listed all the dependencies correctly?

Getting the dependencies is a black art. The "official" way is to check build depends is if the package builds with only the base system, the "build-essential" packages, and the build dependencies you have specified. Don't know a general answer for regular Dependencies, just wade in :)

How I can I prevent the update system installing the older version in the repo on an update? How I can prevent the system installing a newer version (when its out), overwriting my custom package?

My knowledge might be out of date on this one, but to address both: Use dpkg --set-selections. Assuming nullidentd was the package you wanted to stay put, run as root

echo 'nullidentd hold' | dpkg --set-selections

Alternately, since you are building from source, you can use an epoch to set the version number artificially high and never be bothered again. To use an epoch, add a new entry to the debian/changelog file, and put a 99: in front of the version number. Given my nullidentd example, the first line of your updated changelog would read:

nullidentd (99:1.0-4) unstable; urgency=low

Bernard's link is good, especially if you have to create the debian directory yourself - also helpful are the developers reference and the general resource page. Adam's link also looks good but I'm not familiar with it.

Cargile answered 25/9, 2008 at 1:1 Comment(1)
"dpkg --set-selections" still works, but a better method these days would be "aptitude hold nullidentd".Bulley
B
7

Sample Ubuntu-based build for ccache:

sudo apt-get update
sudo apt-get build-dep ccache
apt-get -b source ccache
sudo dpkg -i ccache*.deb

More details: http://blog.aplikacja.info/2011/11/building-packages-from-sources-in-debianubuntu/

Baku answered 18/9, 2012 at 21:16 Comment(0)
B
6

For what you want to do, you probably want to use the debian source diff, so your package is similar to the official one apart from the upstream version used. You can download the source diff from packages.debian.org, or can get it along with the .dsc and the original source archive by using "apt-get source".

Then you unpack your new version of the upstream source, change into that directory, and apply the diff you downloaded by doing

zcat ~/downloaded.diff.gz | patch -p1
chmod +x debian/rules

Then make the changes you wanted to compile options, and build the package by doing

dpkg-buildpackage -rfakeroot -us -uc
Bulley answered 25/9, 2008 at 15:0 Comment(0)
L
3

I believe this is the Debian package 'bible'.

Well, it's the Debian new maintainer's guide, so a lot of it won't be applicable, but they do cover what goes where.

Loch answered 25/9, 2008 at 1:6 Comment(0)
M
3
  • put "debian" directory from original package to your source directory
  • use "dch" to update version of package
  • use "debuild" to build the package
Muckworm answered 29/7, 2009 at 3:55 Comment(0)
P
2

If you're using Ubuntu, check out the pkgcreator project: http://code.google.com/p/pkgcreator

Phyllisphylloclade answered 6/3, 2011 at 0:10 Comment(0)
A
1

Here is a tutorial for building a Debian package.

Basically, you need to:

  1. Set up your folder structure
  2. Create a control file
  3. Optionally create postinst or prerm scripts
  4. Run dpkg-deb

I usually do all of this in my Makefile so I can just type make to spit out the binary and package it in one go.

Anlace answered 25/9, 2008 at 1:27 Comment(0)
A
1

How can I check if I have listed all the dependencies correctly?

The pbuilder is an excellent tool for checking both build dependencies and dependencies by setting up a clean base system within a chroot environment. By compiling the package within pbuilder, you can easily check the build dependencies, and by testing it within a pbuilder environment, you can check the dependencies.

Allophane answered 3/11, 2011 at 14:29 Comment(0)
B
1

If you want a quick and dirty way of installing the build dependencies, use:

apt-get build-dep

This installs the dependencies. You need sources lines in your sources.list for this:

deb-src http://ftp.nl.debian.org/debian/ squeeze-updates main contrib non-free

If you are backporting packages from testing to stable, please be advised that the dependencies might have changed. The command apt-get build-deb installs dependencies for the source packages in your current repository.

But of course, dpkg-buildpackage -us -uc will show you any uninstalled dependencies.

If you want to compile more often, use cowbuilder.

apt-get install cowbuilder

Then create a build-area:

sudo DIST=squeeze ARCH=amd64 cowbuilder --create

Then compile a source package:

apt-get source cowsay

# do your magic editing
dpkg-source -b cowsay-3.03+dfsg1              # build the new source packages
cowbuilder --build cowsay_3.03+dfsg1-2.dsc    # build the packages from source

Watch where cowbuilder puts the resulting package.

Good luck!

Bristling answered 8/3, 2012 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.