Skip to content

Instantly share code, notes, and snippets.

@zflat
Last active November 4, 2020 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zflat/5678a1d78d80e758301d9da3bc4fb4f1 to your computer and use it in GitHub Desktop.
Save zflat/5678a1d78d80e758301d9da3bc4fb4f1 to your computer and use it in GitHub Desktop.
Conventions for building packages from source
git clone https://gist.github.com/5678a1d78d80e758301d9da3bc4fb4f1.git /opt/source
## Ignore subdirectories
*/*
## Emacs stuff
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

Conventions for building packages from source

Overall Directory Structure

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

Steps to follow

Downloading sources

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.

Saving "./configure" parameters

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.

Building

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.

Packaging (optional)

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 using cmake 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.

Packaging with checkinstall

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

Packaging with cpack

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

Building a debian package from a ROS (catkin) package

See https://gist.github.com/awesomebytes/196eab972a94dd8fcdd69adfe3bd1152

Installing

  • With a .deb package: sudo dpkg -i packagefile.deb
  • Without a package: sudo make install

Examples and further reading:

See http://unixwiz.net/techtips/building-source.html

Downloading and extracting source files

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

Saving "./configure" parameters

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

Building and installing

sh ../configure-mysql
make -j12
sh ../package-mysql
sudo dpkg -i install source-app_version_amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment