Use a common place to store downloads, extract archives and store build scripts.
/opt/source/
├── downloads/
| ├── package01.tar.gz
| └── ...
├── package01/
| └── Makefile
| └── ...
├── package02_from_git/
| └── Makefile
| └── ...
├── configure-package01.sh
├── configure-package02.sh
├── package-package01.sh
├── package-package02.sh
├── ...
└── README.md
The location normally requires root permission but we don't want to build as root so we chown to our user.
mkdir -p /opt/source/downloads
chown -R username /opt/source
Most packages are released as a tarball, so first download the original archive into downloads
and then extract into the source
directory. Sometime we build from a git
repo. so just clone the repo into the source
directory and check out the appropriate branch or tag.
Most packages use the configure program or possibly require environment variables to be set before compiling. Even if there are no commands to issue, it is still useful to keep notes about any pre-build steps that were completed. The convention is to create a file with the package name prefixed with "configure-".
NOTE: The important thing is that the configure file is in the parent sources
directory and not created within a directory extracted from an archive.
Most of the work has already been done with the "configure-" file and all that is needed is running make
. However, if there are any other steps they can be noted as comments in the "configure-" file.
Most packages are installed with make install
but it can be nice to build a binary package instead and then install through your package manager. There are a few options to use:
checkinstall
cpack
for projects usingcmake
with the CPackComponent module enabled
Create a "package-" file similar to the "configure-" file containing the exact command that is run to create the binary package.
The checkinstall
utility has a lot of options and can be automated so the best way to keep track of what options were used is to specify options on the command line instead of interactively.
fakeroot checkinstall --install=no --fstrans=yes \
--pkgname some-package \
--pkgversion 0.1.0
First, see if the project supporst cpack
by running make help
and looking to see if there is a package
target.
Next, you can specify the generator and other options by running cpack
manually.
cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -D CPACK_RPM_SPEC_INSTALL_POST="/bin/true" -G DEB
See https://gist.github.com/awesomebytes/196eab972a94dd8fcdd69adfe3bd1152
- With a
.deb
package:sudo dpkg -i packagefile.deb
- Without a package:
sudo make install
See http://unixwiz.net/techtips/building-source.html
cd /source/tarballs
wget ftp://postfix.cloud9.net/official/postfix-2.0.12.tar.gz
cd ..
gtar -xzvf tarballs/postfix-2.0.12.tar.gz
cd postfix-2.0.12
emacs ../configure-mysql
exec ./configure \
--prefix=/home/mysql \
--enable-assembler \
--enable-local-infile \
--without-innodb \
--with-mysqld-user=mysql \
--with-unix-socket-path=/var/run/mysql/mysqld.sock
sh ../configure-mysql
make -j12
sh ../package-mysql
sudo dpkg -i install source-app_version_amd64.deb