You are inside a passionate computer engineer's lab...
Proceed at your own risk...

Look for something inside my Lab...

Loading...

Install the latest stable version of GNU Debugger (GDB) on Debian/Ubuntu

I extensively use the GNU Debugger GDB on my Debian stable development machine, either directly or via front ends such as the Eclipse IDE. I love the stability of Debian, but I need to make some exceptions sometimes for some software. This is why I build some software from source, such as the GNU debugger. However, I had an issue with the gdb source. There is a "make install", but no "make uninstall". It means that once installed, you cannot automatically uninstall, you must go remove things manually, which is highly error-prone. If I need to install a new version, I need to make it override the old files, which can result in weird problems...

I found a way to deal with this, create a Debian binary package. I compile the way I want (with my favorite configure options), then I produce the files my system needs, I put that on a Debian package (.deb), then I install using aptitude. This way, aptitude also takes care of uninstalling gdb files automatically. It also lets me move to a repository-based version of gdb any moment I want.

Because I am lazy, I created a shell script that automates the thing to me, I just need to download the corresponding source package I want (yes, you can automate that also...).


#!/bin/bash

SOURCEARCHIVE=$1

NAME=gdb
VERSION=7.6
ARCH=i386

WORKDIR=$HOME/$NAME-$VERSION-$ARCH-debian-package
SOURCE=$WORKDIR/$NAME-$VERSION.tar.bz2
BUILD=$WORKDIR/$NAME-$VERSION
PREFIX=$WORKDIR/$NAME-$VERSION-$ARCH

CONFIGUREOPT=--enable-lto
MAKEPARALLEL=4

CONFIGURELOG=$WORKDIR/configure.log
MAKELOG=$WORKDIR/make.log
INSTALLLOG=$WORKDIR/install.log

echo "Copying source archive to working directory..."
rm -rf "$WORKDIR"
mkdir -p "$WORKDIR" "$PREFIX/usr" "$PREFIX/DEBIAN"
cp "$SOURCEARCHIVE" "$SOURCE"

echo "Extracting source archive..."
cd "$WORKDIR"
tar -xf "$SOURCE"

echo "Building..."
cd "$BUILD"
./configure --prefix=$PREFIX $CONFIGUREOPT >$CONFIGURELOG 2>&1 && make -j$MAKEPARALLEL >$MAKELOG 2>&1 && make install >$INSTALLLOG 2>&1
BUILDSTATUS=$?
if [ "$BUILDSTATUS" -ne "0" ]; then
  echo "Building failed. Checks logs."
  exit $BUILDSTATUS
fi;

INSTALLEDSIZE=$(du -ks "$PREFIX" | cut -d $'\t' -f 1)
echo "Software installed size: $INSTALLEDSIZE Kilobytes"

echo "Configuring Debian package..."
cat <<EOF> "$PREFIX/DEBIAN/control"
Package: $NAME
Version: $VERSION
Architecture: $ARCH
Maintainer: Koutheir Attouchi <koutheir@gmail.com>
Installed-Size: $INSTALLEDSIZE
Depends: libc6 (>= 2.11), libexpat1 (>= 2.0.1), libncurses5 (>= 5.5-5~), libpython2.7 (>= 2.7), libreadline6 (>= 6.0), libtinfo5, zlib1g (>= 1:1.2.0)
Section: devel
Priority: optional
Homepage: http://www.gnu.org/s/gdb/
Description: Custom build of the GNU Debugger
 GDB is a source-level debugger, capable of breaking programs at
 any specific line, displaying variable values, and determining
 where errors occurred. Currently, gdb supports C, C++, D,
 Objective-C, Fortran, Java, OpenCL C, Pascal, assembly, Modula-2,
 and Ada. A must-have for any serious programmer.
EOF

echo "Building Debian package..."
cd "$WORKDIR"
fakeroot dpkg-deb --build "$PREFIX"