[ powrót ] [ Spis treści ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ dalej ]


APT HOWTO
Część 5 - Building from source


5.1 Pobieranie pakietów źródłowych

W świecie wolnego oprogramowania jest rzeczą powszechną studiować kod źródłowy programów, a nawet dokonywać w nim zmian, aby wyeliminować błędy. Aby to zrobić, musisz pobrać źródło programu. APT dostarcza Ci łatwego sposobu uzyskiwania kodów źródłowych wielu programów zawartych w dystrybucji, włączając w to wszystkie pliki potrzebne do stworzenia pakietu .deb dla danego programu.

Innym powszechnym zastosowaniem źródeł Debiana jest przystosowanie nowszej wersji programu, pochodzącej np. z niestabilnej dystrybucji, aby użyć go w wersji stabilnej. Zamiast pakietu stabilnego można skompilować źródła i wygenerować pakiety .deb z zależnościami przystosowanymi do pakietów dostępnych w tej dystrybucji.

Aby to osiągnąć, wpis ze słowem deb-src na początku linii w Twoim pliku /etc/apt/sources.list powinien wskazywać na archiwum niestabilne. Oczywiście powinien on być także włączony (tzn. odkomentowany). Zobacz sekcję Plik /etc/apt/sources.list, Rozdział 3.1, aby dowiedzieć się więcej szczegółów.

Aptitude, the Debian Package Manager is mainly targeted at binary packages. To use source packages we'll need to use apt-get instead. To download a source package, you would use the following command:

     $ apt-get source pakiet

Komenda ta pobierze trzy pliki: .orig.tar.gz, .dsc i .diff.gz. W przypadku pakietów tworzonych specjalnie dla Debiana nie będzie pobierany ostatni plik, a pierwszy zwykle nie ma w nazwie słowa "orig".

Plik .dsc jest używany przez program dpkg-source do rozpakowania źródeł pakietu w katalogu pakiet-wersja. Wewnątrz każdego pobranego pakietu istnieje katalog debian/, zawierający pliki niezbędne do stworzenia pakietu .deb.

Aby automatycznie zbudować pakiet w czasie pobierania jego źródeł, po prostu dodaj do komendy opcję -b tak, jak pokazano to poniżej:

     $ apt-get -b source pakiet

Jeśli nie zdecydowałeś się tworzyć pakietu .deb w czasie pobierania jego źródeł, możesz zrobić to później za pomocą polecenia:

     $ dpkg-buildpackage -rfakeroot -uc -b

Notice that to build most packages you'll need at least the following packages: devscripts, dpkg-dev, debhelper, fakeroot, take a look at Instalacja pakietów, Rozdział 4.4 and install them before proceeding. Most packages will also depend on compilation tools, so it may be useful to install the build-essential package as well. Other packages may be needed, take a look at Pakiety potrzebne do kompilowania pakietów źródłowych, Rozdział 5.2 for more information.

To install the package built by the commands above one must use the package manager directly. Take a look at Installing manually downloaded or locally created debian packages, Rozdział 4.5. A useful tool is provided by the devscripts package: debi. If you run debi from inside the source package directory it will look for the .changes file at the parent directory to discover what are the binary packages the package produces and will run dpkg to install all of them. While this is not very useful if your source package produces conflicting packages, it might be in most circunstances. Of course you need root powers in order to perform this.

Istnieje różnica pomiędzy metodą source programu apt-get, a jego innymi metodami. Metoda source może być używana przez zwykłych użytkowników, nie posiadających uprawnień roota. Pliki są pobierane do katalogu z którego wywołano komendę apt-get source pakiet.


5.2 Pakiety potrzebne do kompilowania pakietów źródłowych

Zwykle specyficzne pliki nagłówkowe i biblioteki współdzielone muszą być obecne, aby można było skompilować pakiet źródłowy. Wszystkie pakiety źródłowe mają pole w plikach kontrolujących, które nazywa się 'Build-Depends:'. Pole te wskazuje, które dodatkowe pakiety są niezbędne, aby można było zbudować pakiet z jego źródeł.

APT jest wyposażony w łatwy sposób pobierania tych pakietów. Po prostu uruchom komendę apt-get build-dep pakiet, gdzie `pakiet' jest nazwą pakietu, który zamierzasz zbudować. Na przykład:

     # apt-get build-dep gmc
     Reading Package Lists... Done
     Building Dependency Tree... Done
     The following NEW packages will be installed:
       comerr-dev e2fslibs-dev gdk-imlib-dev imlib-progs libgnome-dev libgnorba-dev
       libgpmg1-dev 
     0 packages upgraded, 7 newly installed, 0 to remove and 1  not upgraded.
     Need to get 1069kB of archives. After unpacking 3514kB will be used.
     Do you want to continue? [Y/n]

Pakiety, które zostaną zainstalowane są pakietami potrzebnymi do prawidłowego zbudowania pakietu gmc. Bardzo ważną rzeczą do zauważenia jest fakt, że komenda nie szuka pakietu ze źródłami programu, który ma być skompilowany. Dlatego musisz wcześniej uruchomić polecenie apt-get source, aby osobno je pobrać.

Jeśli chcesz sprawdzić, które pakiety są potrzebne do zbudowania powyższej paczki, możesz użyć wariantu polecenia apt-cache show (zobacz sekcję Pobieranie informacji o pakietach, Część 6), pokazującego oprócz innych informacji także linię Build-Depends z listą pakietów niezbędnych do zbudowania pakietu.

     # apt-cache showsrc package

5.3 Zarządzanie pakietami

If you want to build a package for debuging purposes to, for example, report a bug -- or fix one, you can use simple environment variables that are supported by most Debian packages.

To build a package which contains unstriped binaries[6] all you need to do is prefix it with DEB_BUILD_OPTIONS=nostrip. Optimizations can also make debuging harder, so you can disable them by adding the noopt string to the DEB_BUILD_OPTIONS variable too. Example:

     $ dpkg-buildpackage -rfakeroot -uc -b

5.4 Customizing package build options

If what you want is to customize the way the package is built you'll have to go about editing the debian/rules file. This means: inside the main directory created when the source package is extracted there will be a debian directory, which contains many files. One of them is special: the rules file.

This file is usually a Makefile that has targets to configure, build, install and create the package. For example, if I want to have the luola[7] built without sound I can, after downloading and extracting its source edit the debian/rules file that looks like this:

     [...]
     configure: configure-stamp
     configure-stamp:
     	dh_testdir
     	# Add here commands to configure the package.
     	./configure $(confflags) \
     		--prefix=/usr \
     		--mandir=share/man \
     		--infodir=share/info \
     		--datadir=share/games \
     		--bindir=games \
     		--enable-sound
     #		 --enable-sdl-gfx	
     
     	touch configure-stamp
     [...]

See the --enable-sound switch? If I remove it or replace it with --disable-sound and then rebuild the package using the technique described on Pobieranie pakietów źródłowych, Rozdział 5.1 I'll have a luola package that is built with no sound.

If you really want to work with source packages on a daily basis I would suggest reading the Debian New Maintainers Guide and the Debian Policy, mainly. Other documentation available from the Debian Developers Corner may be useful too.


5.5 But hey, I do not want to use the Debian stuff!

Sometimes, people want to use a specific version of a program available only on source code, with no Debian package. But the packaging system can be a trouble when doing this. Suppose you want to compile a new version of your email server. All is fine, but many packages in Debian depend on an MTA (Mail Transfer Agent). Since you installed something you compiled by yourself, the packaging system doesn't know about it.

W takich właśnie przypadkach z pomocą przychodzi nam pakiet equivs. Aby móc z niego skorzystać, należy zainstalować pakiet o takiej samej nazwie. Cóż on takiego robi? Tworzy pusty pakiet, który potrafi w pełni spełnić zależności i sprawia, że system pakietów jest przekonany o tym, iż zależności są spełnione.

Zanim pokażemy jak używać tego pakietu, należy jeszcze przypomnieć, że istnieją bezpieczniejsze sposoby kompilacji programu, który posiada już pakiet Debiana i że nie należy używać pakietu equivs do zastępowania zależności, gdy nie wiemy jak to zrobić. Więcej informacji na ten temat można znaleźć w sekcji Building from source, Część 5.

Kontynuujmy nasz przykład z agentem pocztowym MTA. Powiedzmy, że właśnie skompilowałeś i zainstalowałeś nową wersję serwera postfix, a teraz zamierzasz zainstalować pakiet mutt. Nagle okazuje się, że mutt chce zainstalować innego agenta MTA, a Ty już masz przecież swój.

Przejdź wtedy do jakiegoś katalogu (np. do /tmp) i wydaj komendę:

     # equivs-control nazwa

gdzie nazwa to nazwa pliku kontrolnego, który chcesz stworzyć. Plik ten będzie miał następującą zawartość:

     Section: misc
     Priority: optional
     Standards-Version: 3.0.1
     
     Package: <enter package name; defaults to equivs-dummy>
     Version: <enter version here; defaults to 1.0>
     Maintainer: <your name and email address; defaults to username>
     Pre-Depends: <packages>
     Depends: <packages>
     Recommends: <packages>
     Suggests: <package>
     Provides: <(virtual)package>
     Architecture: all
     Copyright: <copyright file; defaults to GPL2>
     Changelog: <changelog file; defaults to a generic changelog>
     Readme: <README.Debian file; defaults to a generic one>
     Extra-Files: <additional files for the doc directory, comma separated>
     Description: <short description; defaults to some wise words>
      long description and info
      .
      second paragraph

Teraz musimy tak go zmodyfikować, żeby robił to, co chcemy. Spójrzmy na format pól i ich opisy. Nie ma oczywiście potrzeby objaśniać każdego z nich. Zróbmy tylko to, co jest niezbędne:

     Section: misc
     Priority: optional
     Standards-Version: 3.0.1
     
     Package: mta-local
     Provides: mail-transport-agent

Tak, to naprawdę wszystko, czego nam potrzeba! Pakiet mutt zależy od pakietu wirtualnego mail-transport-agent, którego dostarczają wszystkie agenty MTA. Mogłem też nazwać pakiet po prostu mail-transport-agent, ale wolę używać schematu pakietów wirtualnych, który wykorzystuje pole `Provides'.

The Conflicts and Replaces fields are needed, too, so that APT and dpkg will understand they should remove the currently installed MTA package in favour of the new one you're installing.

Teraz tylko musimy zbudować pakiet:

     # equivs-build nazwa
     dh_testdir
     touch build-stamp
     dh_testdir
     dh_testroot
     dh_clean -k
     # Add here commands to install the package into debian/tmp.
     touch install-stamp
     dh_testdir
     dh_testroot
     dh_installdocs
     dh_installchangelogs
     dh_compress
     dh_fixperms
     dh_installdeb
     dh_gencontrol
     dh_md5sums
     dh_builddeb
     dpkg-deb: building package `nazwa' in `../nazwa_1.0_all.deb'.
     
     The package has been created.
     Attention, the package has been created in the current directory,

i zainstalować powstały pakiet .deb.

Jak widać, pakietu equivs można używać na różne sposoby. Za jego pomocą można nawet stworzyć pakiet moje-ulubione, który zależy od programów, które zwykle instalujesz. To jak go wykorzystasz zależy tylko od Twojej wyobraźni, ale bądź ostrożny!

Na koniec jeszcze jedna ważna uwaga: przykłady plików kontrolnych znajdują się w katalogu /usr/share/doc/equivs/examples. Przyjrzyj się im.


[ powrót ] [ Spis treści ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ dalej ]


APT HOWTO

2.0.2 - October 2006

Gustavo Noronha Silva kov@debian.org
polskie tłumaczenie: Paweł Tęcza ptecza@debianusers.pl