Below, you have a small tutorial on how to use pkgbuild to build packages.
As I said, pkgbuild isn't a tool for novice users, but is a tool for medium to advanced users who want to build correct packages in a simple way. However, its scripting language is not ... Chinese Simplified, only RPM simplified, like one of yours said.
We decided to build the package Xdialog respecting all Slackware standards for architectures
i486,
i586,
i686 and
x86_64. Pkgbuild can help us? Let's see how.
Latest version of Xdialog is
http://xdialog.free.fr/Xdialog-2.3.1.tar.bz2.
We download the source file into a directory and will extract the archive. Studying sources, we see that Xdialog uses automake tools and running "./configure --help", that has the option of using GTK2 (--with-gtk2).
Therefore, we use a template pkgspec for automake:
Code:
# PkgBuild Spec for <foo> package(s)
# Build headers
Name: foo
Version: 1.0
Release: 1
# Sources
Source: %{__name}-%{__version}.tar.gz
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
foo (cool application)
Write a nice description here.
%begin
%setup
%configure
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
%files
%defattr(-,root,root,-)
/*
We change the name, version and we will complete description.
Code:
# PkgBuild Spec for <Xdialog> package(s)
# Build headers
Name: Xdialog
Version: 2.3.1
Release: 1
# Sources
Source: %{__name}-%{__version}.tar.bz2
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
Xdialog (A X11 drop in replacement for cdialog)
Xdialog is designed to be a drop in replacement for the cdialog
program. It converts any terminal based program into a program with an
X-windows interface.
The dialogs are easier to see and use and Xdialog adds even more
functionalities (help button+box, treeview, editbox, file selector,
range box, and much more).
%begin
%setup
%configure
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
%files
%defattr(-,root,root,-)
/*
The question arises: what are the commands that begin with a
%?
pkgbuild interpret its pkgspec, which is divided into sections, using definitions.
Some definitions are simple, eg
%{__name} will be replaced with the value of the line "Name:" others are more complex, such as
%configure, which will call
configure with several parameters, after entering in the sources directory.
Another example. What is
%{__make}? This definition will be replaced with direct path to
make (ie /usr/bin/make). It is more appropriate to use these definitions to write a portable build because these paths may be different depending on the system.
Another important definition is
%{_smp_mflags} which will be replaced with the auto-detected value for the make jobs. It's the $NUMJOBS's equivalent.
We will complete our definitions as follows:
Code:
# PkgBuild Spec for <Xdialog> package(s)
# Build headers
Name: Xdialog
Version: 2.3.1
Release: 1
# Sources
Source: %{__name}-%{__version}.tar.bz2
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
Xdialog (A X11 drop in replacement for cdialog)
Xdialog is designed to be a drop in replacement for the cdialog
program. It converts any terminal based program into a program with an
X-windows interface.
The dialogs are easier to see and use and Xdialog adds even more
functionalities (help button+box, treeview, editbox, file selector,
range box, and much more).
%begin
%setup
%configure --with-gtk2
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
%files
%defattr(-,root,root,-)
/*
It is time to test the build. We run command:
Code:
pkgbuild Xdialog.pkgspec
If everything is correct, pkgbuild will generate in /tmp directory the package
Xdialog-2.3.1-i486-1.txz and source package
Xdialog-2.3.1-1.src.txz.
Inspecting the package, we will notice that the docs directory is currently in
/usr/share/doc/Xdialog-2.3.1. What is wrong. He ought to be
/usr/doc/Xdialog-2.3.1.
We might add
--docdir=%{_docdir} to
configure, but it does not support this command. We use brute force.
Code:
# PkgBuild Spec for <Xdialog> package(s)
# Build headers
Name: Xdialog
Version: 2.3.1
Release: 1
# Sources
Source: %{__name}-%{__version}.tar.bz2
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
Xdialog (A X11 drop in replacement for cdialog)
Xdialog is designed to be a drop in replacement for the cdialog
program. It converts any terminal based program into a program with an
X-windows interface.
The dialogs are easier to see and use and Xdialog adds even more
functionalities (help button+box, treeview, editbox, file selector,
range box, and much more).
%begin
%setup
%configure --with-gtk2
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
# Move doc files in a properly place:
%{__mv} -f $__installdir%{_datadir}/doc $__installdir%{_prefix}
%files
%defattr(-,root,root,-)
/*
As suspected,
$__installdir is the directory where pkgbuild temporary installed the package,
%{_datadir} is
/usr/share and
%{_prefix} is
/usr
The new build is perfect. It's time to add other elements.
pkgbuild know how to download the required sources. We will use this feature and we use SHA1 checksums.
We get the checksum of the source with sha1sum and we add:
Code:
# PkgBuild Spec for <Xdialog> package(s)
# Build headers
Name: Xdialog
Version: 2.3.1
Release: 1
# Sources
Source: http://xdialog.free.fr/%{__name}-%{__version}.tar.bz2
# Sources checksum
Source-SHA1: 292c552506633c54a28d51aa290277b7b5c0c708
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
Xdialog (A X11 drop in replacement for cdialog)
Xdialog is designed to be a drop in replacement for the cdialog
program. It converts any terminal based program into a program with an
X-windows interface.
The dialogs are easier to see and use and Xdialog adds even more
functionalities (help button+box, treeview, editbox, file selector,
range box, and much more).
%begin
%setup
%configure --with-gtk2
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
# Move doc files in a properly place:
%{__mv} -f $__installdir%{_datadir}/doc $__installdir%{_prefix}
%files
%defattr(-,root,root,-)
/*
In our new build, pkgbuild will download the tarball and will check its checksum before extraction.
It's time to add the last element. pkgbuild known to use several build architectures. Usually is used to get the
noarch packages, but we speculate this feature.
We add:
Code:
# PkgBuild Spec for <Xdialog> package(s)
# Build headers
Name: Xdialog
Version: 2.3.1
Release: 1
%if %{!=__arch: x86_64}
BuildArch: i486 i586 i686
%endif
# Sources
Source: http://xdialog.free.fr/%{__name}-%{__version}.tar.bz2
# Sources checksum
Source-SHA1: 292c552506633c54a28d51aa290277b7b5c0c708
%package
# Package specific headers
%description
# The "handy ruler" below makes it easier to edit a package description. The second
# '#' on the right side marks the last column you can put a character in. It's also
# customary to make exactly 11 lines for the formatting to be correct.
#-----handy-ruler-----------------------------------------------------#
Xdialog (A X11 drop in replacement for cdialog)
Xdialog is designed to be a drop in replacement for the cdialog
program. It converts any terminal based program into a program with an
X-windows interface.
The dialogs are easier to see and use and Xdialog adds even more
functionalities (help button+box, treeview, editbox, file selector,
range box, and much more).
%begin
%setup
%configure --with-gtk2
%begin build
%{__make} %{_smp_mflags}
%begin install
%{__make} install DESTDIR=$__installdir
# Move doc files in a properly place:
%{__mv} -f $__installdir%{_datadir}/doc $__installdir%{_prefix}
%files
%defattr(-,root,root,-)
/*
In our new build, pkgbuild will run package building for every architecture and we get
Xdialog-2.3.1-i486-1.txz,
Xdialog-2.3.1-i586-1.txz and
Xdialog-2.3.1-i686-1.txz. We just need to rebuild the source package on a x86_64 machine, and we achieved also the fourth package. Voila!
PS. If you enjoyed this tutorial, the following tutorial will be called "building a package for a KDE4 application, which uses CMake". I let you to choose the application.