Att bygga om ett binärpaket krävs under flera olika omständigheter. I visa fall behöver administratören en programvarufunktion somkräver att programvaran kompileras från källkod, med en viss kompileringsflagga; i andra fall är programvara som paketerats och installerats av Debian inte uppdaterad. I det senare fallet kommer administratören vanligtvis bygga paketet från en senare version av Debian — så som
Testing eller till och med
Unstable — så att detta nya paket fungerar i deras distribution
Stable; denna åtgärd kallas ”bakportering”. Som vanligt ska man innan åtar sig en sådan uppgift kontrollera om det redan har gjorts — en snabb kontroll av i Debian Package Tracker för det paketet kan avslöja den informationen.
Rebuilding a Debian package starts with getting its source code. The easiest way is to use the
apt-get source source-package-name
command. This command requires a
deb-src
line in the
/etc/apt/sources.list
file, and up-to-date index files (i.e.
apt-get update
). These conditions should already be met if you followed the instructions from the chapter dealing with APT configuration (see
Avsnitt 6.1, ”Att fylla i filen sources.list
”). Note, however, that you will be downloading the source packages from the Debian version mentioned in the
deb-src
line. If you need another version, you may need to download it manually from a Debian mirror or from the web site. This involves fetching two or three files (with extensions
*.dsc
— for
Debian Source Control —
*.tar.comp
, and sometimes
*.diff.gz
or
*.debian.tar.comp
—
comp taking one value among
gz
,
bz2
or
xz
depending on the compression tool in use), then run the
dpkg-source -x file.dsc
command. If the
*.dsc
file is directly accessible at a given URL, there is an even simpler way to fetch it all, with the
dget URL
command. This command (which can be found in the
devscripts package) fetches the
*.dsc
file at the given address, then analyzes its contents, and automatically fetches the file or files referenced within. Once everything has been downloaded, it verifies the integrity of the downloaded source packages using
dscverify
, and it extracts the source package (unless the
-d
or
--download-only
option is used). The Debian keyring is needed, unless the option
-u
is supplied.
15.1.2. Att göra ändringar
Let us use the samba package as an example.
$
apt source samba
Reading package lists... Done
NOTICE: 'samba' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/samba-team/samba.git
Please use:
git clone https://salsa.debian.org/samba-team/samba.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 11.7 MB of source archives.
Get:1 http://security.debian.org/debian-security buster/updates/main samba 2:4.9.5+dfsg-5+deb10u1 (dsc) [4,316 B]
Get:2 http://security.debian.org/debian-security buster/updates/main samba 2:4.9.5+dfsg-5+deb10u1 (tar) [11.4 MB]
Get:3 http://security.debian.org/debian-security buster/updates/main samba 2:4.9.5+dfsg-5+deb10u1 (diff) [252 kB]
Fetched 11.7 MB in 1s (9,505 kB/s)
dpkg-source: info: extracting samba in samba-4.9.5+dfsg
dpkg-source: info: unpacking samba_4.9.5+dfsg.orig.tar.xz
dpkg-source: info: unpacking samba_4.9.5+dfsg-5+deb10u1.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying 07_private_lib
dpkg-source: info: applying bug_221618_precise-64bit-prototype.patch
[...]
The source of the package is now available in a directory named after the source package and its version (samba-4.9.5+dfsg); this is where we'll work on our local changes.
The first thing to do is to change the package version number, so that the rebuilt packages can be distinguished from the original packages provided by Debian. Assuming the current version is
2:4.9.5+dfsg-5
, we can create version
2:4.9.5+dfsg-5falcot1
, which clearly indicates the origin of the package. This makes the package version number higher than the one provided by Debian, so that the package will easily install as an update to the original package. Such a change is best effected with the
dch
command (
Debian CHangelog) from the
devscripts package.
$
cd samba-4.9.5+dfsg
$
dch --local falcot
The last command invokes a text editor (
sensible-editor
— this should be your favorite editor if it is mentioned in the
VISUAL
or
EDITOR
environment variables, and the default editor otherwise) to allow documenting the differences brought by this rebuild. This editor shows us that
dch
really did change the
debian/changelog
file.
När en ändring av byggflaggorna behövs, måste ändringarna göras i debian/rules
, vilket driver stegen i paketets byggprocess. I de enklaste fallen är raderna som rör inledande konfiguration (./configure …
) eller det faktiska bygget ($(MAKE) …
eller make …
) lätta att hitta. Om dessa kommandon inte är anropas uttryckligen så de troligtvis sidoeffekter av ett annat kommando som anropas uttryckligen, i vilket fall du bör läsa deras dokumentation för att få reda på hur du ändrar standardbeteendet. Med paket som använder dh
, kan du behöva lägga till en åsidosättning för kommandona dh_auto_configure
eller dh_auto_build
(se deras respektive manualsidor för förklaringar om hur du åstadkommer detta).
Beroende på de lokala ändringarna till paketen kan en uppdatering också krävas i filen debian/control
, vilken innehåller en beskrivning av de genererade paketen. I synnerhet innehåller denna filen Build-Depends
-rade som styr listan av beroenden som måste vara uppfyllda då paketet byggs. Dessa refererar ofta till versioner av paket som finns i distributionen som källkodspaketet kommer från men som kanske inte finns tillgängliga i distributionen som används för ombygget. Det finns inget automatiserat sätt att avgöra om ett beroenden är korrekt eller endast angivet för att garantera att man endast ska försöka sig på bygget med den senaste versionen av ett bibliotek — detta är det enda tillgängliga sättett att tvinga en autobyggare att använda en given paketversion under bygget, vilket är anledningen till att Debian-utvecklarna ofta använda strikt versionerade byggberoenden.
Om du är säker på att dessa byggberoenden är allt för strikta kan du känna dig fri att lösa upp dem lokalt. Att läsa filerna som dokumenterar standardsättet att bygga programvara — dessa filer kallas ofta INSTALL
— kommer att hjälpa dig att lista ut lämpliga beroenden. I idealfallet borde alla beroenden kunna gå att tillfredställa från distributionen som används för ombygget; om inte inleds en rekursiv process där paket som nämns i fältet Build-Depends
måste bakporteras innan målpaketet kan bakporteras. Vissa paket kanske inte kräver bakportering och kan installeras som de är under byggprocessen (ett exempel är debhelper). Notera att bakporteringsprocessen snabbt kan bli komplex om du inte är försiktig. Därför bör man försöka sig på bakportering endat då det är nödvändigt.
15.1.3. Starting the Rebuild
When all the needed changes have been applied to the sources, we can start generating the actual binary package (.deb
file). The whole process is managed by the dpkg-buildpackage
command.
Exempel 15.1. Rebuilding a package
$
dpkg-buildpackage -us -uc
[...]
The previous command can fail if the Build-Depends
fields have not been updated, or if the related packages are not installed. In such a case, it is possible to overrule this check by passing the -d
option to dpkg-buildpackage
. However, explicitly ignoring these dependencies runs the risk of the build process failing at a later stage. Worse, the package may seem to build correctly but fail to run properly: some programs automatically disable some of their features when a required library is not available at build time.
More often than not, Debian developers use a higher-level program such as debuild
; this runs dpkg-buildpackage
as usual, but it also adds an invocation of a program that runs many checks to validate the generated package against the Debian policy. This script also cleans up the environment so that local environment variables do not “pollute” the package build. The debuild
command is one of the tools in the devscripts suite, which share some consistency and configuration to make the maintainers' task easier.