Creating packages (Italiano)

From ArchWiki
Revision as of 23:59, 22 December 2010 by Morbin (talk | contribs) (In allineamento con la pag inglese)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Creating packages (Italiano)#)
Note: Pagina in via di aggiornamento e traduzione, consultare per favore la pagina internazionale

Questo articolo si propone di assistere gli utenti nella creazione dei propri pacchetti con il sistema di compilazione "ports-like" di Arch Linux. It covers creation of a PKGBUILD – a package build description file sourced by Template:Codeline to create a binary package from source. If already in possession of a Template:Filename, see makepkg.


I pacchetti in Arch Linux sono compilati utilizzando l'utilità makepkg e le informazioni memorizzate in un file PKGBUILD. When Template:Codeline is run, it searches for a Template:Filename in the current directory and follows the instructions therein to either compile or otherwise acquire the required files to be packaged within a package file (Template:Filename). The resulting package contains binary files and installation instructions; readily installed with pacman.

Un pacchetto di Arch non è altro che un archivio tar compresso utilizzando "xz", o "tarball", che contiene:

  • I file binari per l'installazione
  • Template:Filename: contiene tutti i metadati necessari a pacman per gestire i pacchetti, le dipendenze, ecc.
  • Template:Filename: an optional file kept by the package maintainer documenting the changes of the package. (It is not present in all packages.)


Prerequisiti software

First ensure that the necessary tools are installed. The package group "base-devel" should be sufficient; it includes make and additional tools needed for compiling from source.

# pacman -S base-devel

One of the key tools for building packages is makepkg (provided by Template:Package Official) which does the following:

  1. Checks if package dependencies are installed.
  2. Downloads the source file(s) from the specified server(s).
  3. Unpacks the source file(s).
  4. Compiles the software and installs it under a fakeroot environment.
  5. Strips symbols from binaries and libraries.
  6. Generates the package meta file which is included with each package.
  7. Compress the fakeroot environment into a package file.
  8. Stores the package file in the configured destination directory, which is the present working directory by default.

Scaricamento e test dell'installazione

Download the source tarball of the software you want to package, extract it, and follow the author's steps to install the program. Make a note of all commands and/or steps needed to compile and install it. You will be repeating those same commands in the PKGBUILD file.

Most software authors stick to the 3-step build cycle:

make install

This is a good time to make sure the program is working correctly.

Creazione di un PKGBUILD

When you run Template:Codeline, it will look for a Template:Filename file in the present working directory. If a Template:Filename file is found it will download the software's source code and compile it according to the instructions specified in the Template:Filename file. The instructions must be fully interpretable by the Bash shell. After successful completion, the resulting binaries and metadata of the package, i.e. package version and dependencies, are packed in a Template:Filename package file that can be installed with Template:Codeline.

To begin with a new package, you should first create an empty working directory, (preferably Template:Filename), change into that directory, and create a Template:Filename file. You can either copy the prototype PKGBUILD Template:Filename to your working directory or copy a Template:Filename from a similar package. The latter may be useful if you only need to change a few options.

Definizione delle variabili PKGBUILD

The Template:Filename file contains metadata about a package. It is a plain text file. The following is a prototype Template:Filename. It can be found in Template:Filename along with other templates.


makepkg defines three variables that you should use as part of the build and install process:

This contains the absolute path to the directory where the Template:Filename file is located. This variable used to be used in combination with Template:Filename or Template:Filename postfixes, but the use of Template:Codeline and Template:Codeline variables is the modern method. Template:Codeline is not guaranteed to be the same as Template:Codeline, and likewise for Template:Codeline. Use of this variable is deprecated and strongly discouraged.
This points to the directory where makepkg extracts or copies all source files.
This points to the directory where makepkg bundles the installed package, which becomes the root directory of your built package.
Note: makepkg, and thus the Template:Codeline and Template:Codeline functions, are intended to be non-interactive. Interactive utilities or scripts called in those functions may break makepkg, particularly if it is invoked with build-logging enabled (Template:Codeline). (See Arch Linux Bug #13214.)

Note: apart from the current package Maintainer, there may be previous maintainers listed above as Contributors.

An explanation of possible Template:Filename variables can be found in the PKGBUILD article.

La funzione Template:Codeline

Now you need to implement the Template:Codeline function in the Template:Filename file. This function uses common shell commands in Bash syntax to automatically compile software and create a Template:Filename directory to install the software to. This allows makepkg to package files without having to sift through your filesystem.

The first step in the Template:Codeline function is to change into the directory created by uncompressing the source tarball. In most common cases the first command will look like this:

cd $srcdir/$pkgname-$pkgver

Now, you need to list the same commands you used when you manually compiled the software. The Template:Codeline function in essence automates everything you did by hand and compiles the software in the fakeroot build environment. If the software you are packaging uses a configure script, it is good practice to use Template:Codeline when building packages for pacman. A lot of software installs files relative to the Template:Filename directory, which should only be done if you are manually building from source. All Arch Linux packages should use the Template:Filename directory. As seen in the Template:Filename file, the next two lines often look like this:

./configure --prefix=/usr

La funzione Template:Codeline

The final step is to put the compiled files in a directory where makepkg can retrieve them to create a package. This by default is the Template:Filename directory — a simple fakeroot environment. The Template:Filename directory replicates the hierarchy of the root file system of the software's installation paths. If you have to manually place files under the root of your filesystem, you should install them in the Template:Filename directory under the same directory structure. For example, if you want to install a file to Template:Filename, it should instead be placed under Template:Filename. Very few install procedures require the user to copy dozens of files manually. Instead, for most software, calling Template:Codeline will do so. The final line should look like the following in order to correctly install the software in the Template:Filename directory:

make DESTDIR=$pkgdir install
Note: It is sometimes the case where Template:Codeline is not used in the Template:Filename; you may need to use Template:Codeline instead. If the package is built with autoconf/automake, use Template:Codeline; this is what is documented in the manuals. If Template:Codeline does not work, try building with Template:Codeline. If that does not work, you'll have to look further into the install commands that are executed by "Template:Codeline".

In some odd cases, the software expects to be run from a single directory. In such cases, it is wise to simply copy these to Template:Filename.

More often than not, the installation process of the software will create any subdirectories below the Template:Filename directory. If it does not, however, makepkg will generate a lot of errors and you will need to manually create subdirectories by adding the appropriate Template:Codeline commands in the Template:Codeline function before the installation procedure is run.

In old packages, there was no Template:Codeline function. So, putting compiled files was done at the end of the Template:Codeline function. If Template:Codeline is not present, Template:Codeline runs via fakeroot. If Template:Codeline is present, Template:Codeline runs as the user calling makepkg, Template:Codeline runs via fakeroot.

Template:Codeline runs only the Template:Codeline function, so it creates a Template:Codeline file without compiling the package. This may save time e.g. if you just have changed the Template:Codeline variable of the package.

Informazioni aggiuntive

Please read Arch Packaging Standards thoroughly for best practices and additional considerations.

Testare il PKGBUILD

Mentre si scrive la funzione Template:Codeline, si vorrà collaudare frequentemente i cambiamenti, per essere sicuri che non ci siano bug. Questo si può fare usando il comando Template:Codeline nella directory contenente il Template:Filename. Con un Template:Filename, propriamente formattato, makepkg creerà un pacchetto; ma con uno errato o non finito, restituirà un errore.

Se il processo di makepkg è finito correttamente, creerà un nuovo file chiamato Template:Filename in your working directory. nella directory attuale. Questo è un pacchetto di pacman e può essere installato con Template:Codeline. Notare che il fatto che il pacchetto sia stato costruito non significa che funzioni! E' plausibile che contenga solo la struttura di directory e nessun file se, per esempio, un prefix è stato specificato impropriamente. Si possono usare le funzioni di ricerca di pacman per visualizzare una lista di file contenuti nel pacchetto e le dipendenze da esso richieste con Template:Codeline e Template:Codeline.

Se il pacchetto sembra essere valido, è tutto. Comunque, se si pensa di rilasciare il Template:Filename, è obbligatorio controllare e ricontrollare e ricontrollare ancora i contenuti dell'array Template:Codeline.

Also ensure that the package binaries actually run flawlessly! It is annoying to release a package that contains all necessary files, but crashes because of some obscure configuration option that doesn't quite work well with the rest of the system. If you're only going to compile packages for your own system, though, you don't need to worry too much about this quality assurance step, as you're the only person suffering from mistakes, after all.

Template:Codeline e Template:Codeline

Dependencies are the most common packaging error. There are two excellent tools you can use to check dependencies. The first one is ldd, which will show you the shared library dependencies of dynamic executables:

$ ldd gcc =>  (0xb7f33000) => /lib/ (0xb7de0000)
/lib/ (0xb7f34000)

The other tool is namcap, which not only checks for dependencies but the overall sanity of your package. Please read the namcap article for a detailed description.

Submitting packages to the AUR

Please read AUR User Guidelines#Submitting Packages to UNSUPPORTED for a detailed description of the submission process.

Per ricapitolare

  1. Scaricare i tarball sorgenti del programma che si vuole impacchettare.
  2. Provare a compilare il pacchetto e installarlo in una directory arbitraria.
  3. Copiare il prototipo Template:Filename e rinominarlo in Template:Filename in una directory di lavoro temporanea -- preferibilmente Template:Filename.
  4. Modificare il Template:Filename secondo le necessità del proprio pacchetto.
  5. Lanciare Template:Codeline e vedere se il pacchetto risultante è costruito correttamente.
  6. In caso contrario, ripetere gli ultimi due passi.


  • Prima di poter automatizzare il processo di compilazione di un pacchetto, bisognerebbe averlo fatto manualmente almeno una volta a meno di non conoscere esattamente cosa si sta facendo a priori, nel qual caso non si starebbe leggendo questo articolo come primo. Sfortunatamente, nonostante un buon gruppo di programmatori si attengano al ciclo di compilazione in tre passi di "Template:Codeline; Template:Codeline; Template:Codeline", questo non accade sempre, e le cose possono diventare davvero pessime se bisogna applicare patch per far funzionare tutto. Regola empirica: se non si riesce a compilare il programma dal tarball sorgente e farlo installare da sè in una sottodirectory temporanea definita, non bisogna neanche provare a impacchettarlo. Non c'è nessuna polvere magica in Template:Codeline che risolva i problemi dei sorgenti.
  • In qualche caso, i pacchetti non sono nemmeno disponibili come sorgenti e bisogna usare qualcosa come Template:Codeline per farli funzionare. Si dovrà fare un po' di lavoro di ricerca (leggere i README, le istruzioni di INSTALL, pagine man, magari ebuild da Gentoo o altri gestori di pacchetti, eventualmente persino i MAKEFILE o il codice sorgente) per metterli a posto. In certi casi davvero brutti, bisogna modificare i file sorgenti per far funzionare tutto bene. Comunque, Template:Codeline deve essere completamente autonomo, senza alcun input da utente. Perciò se si devono modificare i Makefile, si potrebbe dover creare una patch personalizzata con il Template:Filename ed installarla da dentro la funzione Template:Codeline, o si potrebbe dover inserire alcuni comandi Template:Codeline da dentro la stessa funzione.

Consultare inoltre