Linux HOWTOs

About | Home | Search


HOWTO: pkg-config
Description: Helper tool used when compiling applications and libraries
Click here for ChangeLog
NOTE: I use GNU tar >= 1.13.25 so it's -j for .tar.bz2 files,
it's safe to assume that make, gcc, binutils, fileutils/coreutils, gawk, sed, and grep are prerequisites for almost everything


# pkg-config 0.29.2
# =================
# Slackware 13.37, 14.0, 14.1: pkg-config 0.25
# Slackware 14.2: pkg-config 0.29.1
#
# Older versions of Slackware called the package 'pkgconfig' (no hyphen)

# If you want to remove pkg-config, or uninstall an old version before
# installing this one, skip down to the bottom for instructions.

# Prerequisites:
# Glib - As of 0.27, a copy of glib2 is included

# Get the source
cd
test -f installed/pkg-config-0.29.2.tar.gz &&
 mv installed/pkg-config-0.29.2.tar.gz .
test ! -f pkg-config-0.29.2.tar.gz &&
 wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz

# Verify tarball w/ sha1sum:
echo "76e501663b29cb7580245720edfb6106164fad2b  pkg-config-0.29.2.tar.gz" | \
sha1sum -c

# Verify tarball w/ gpg:
( gpg --list-keys C7EC6914 > /dev/null 2>&1 || gpg --recv-keys C7EC6914 ) &&
 wget -nc https://pkg-config.freedesktop.org/releases/\
pkg-config-0.29.2.tar.gz.asc &&
  gpg --verify pkg-config-0.29.2.tar.gz.asc &&
   rm pkg-config-0.29.2.tar.gz.asc

# Extract the source
mkdir -p -m 0700 ~/src
cd ~/src
find -maxdepth 1 -type d -name "pkg-config-*" -exec rm -r {} \;
find -maxdepth 1 -type d -name "pkgconfig-*" -exec rm -r {} \;
tar xzvf ~/pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2
test $UID = 0 && chown -R root:root .

# Building pkg-config requires one of these options:
# a) itself (to find Glib)
# b) you to pass GLIB_CFLAGS and GLIB_LIBS
# c) you to pass --with-internal-glib

# If you want pkg-config to search through more than just the default .pc
# file directory (prefix/lib*/pkgconfig), you can pass a list to the
# --with-pc-path configure option.  You can also pass a list of additional
# directories to search to the PKG_CONFIG_PATH environment variable.  See
# the notes at the bottom for more information about this.

# Configure the build for 64-bit
test $(uname -m) = "x86_64" &&
./configure --prefix=/usr --docdir=/usr/doc/pkg-config \
--mandir=/usr/man --libdir=/usr/lib64

# Configure the build for anything else
test $(uname -m) != "x86_64" &&
./configure --prefix=/usr --docdir=/usr/doc/pkg-config --mandir=/usr/man

# Build it
make

# Become root to install it
su

# Remove Slackware package version of pkg-config
test -x /sbin/removepkg && /sbin/removepkg pkgconfig pkg-config

# Install the new version
make install

# In addition to passing --with-pc-path to configure as noted above, to
# cover packages that use pkg-config that install files under a prefix
# other than /usr (the pkg-config files won't end up in /usr/lib*/pkgconfig),
# you can either create a symlink pointing /usr/local/lib*/pkgconfig and any
# others you need to /usr/lib*/pkgconfig or you can specify additional
# directories to look in by setting the PKG_CONFIG_PATH environment
# variable.  Seperate multiple directories with a colon.
#
# Some apps like OpenSSL and Qt install everything under a prefix like
# /usr/local/ssl or /usr/lib/qt, so you end up with a pkgconfig directory
# in there that pkg-config isn't aware of.  To cover those, add that
# directory to PKG_CONFIG_PATH.  My howtos that cover apps that install
# pkg-config files (GraphViz, OpenSSL, Qt, etc.) have been or will be
# updated to create their own /etc/profile.d/* file that will update
# PKG_CONFIG_PATH.
#
# I rarely, if ever, use csh - see Slackware's source for a pkgconfig.csh
# example and don't forget to use lib64 if you use 64-bit Slackware.
#
# Run this to create a /etc/profile.d/pkgconfig.sh that will add several
# different directories to the PKG_CONFIG_PATH variable if they exist and
# are not a symlink:
cat << EOF > /etc/profile.d/pkgconfig.sh
#!/bin/sh
for dir in \\
/lib/pkgconfig \\
/usr/lib/pkgconfig \\
/usr/lib64/pkgconfig \\
/usr/local/lib/pkgconfig \\
/usr/local/lib64/pkgconfig \\
/usr/X11R6/lib/pkgconfig;
do
  if [ -d "\$dir" -a ! -L "\$dir" ]; then
    if [ -n "\$PKG_CONFIG_PATH" ]; then
      PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:\$dir"
    else
      PKG_CONFIG_PATH="\$dir"
    fi
  fi
done
export PKG_CONFIG_PATH
EOF
chmod +x /etc/profile.d/pkgconfig.sh

# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .

# Become yourself again
exit

# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/pkgconfig-*.tar.* installed/pkg-config-*.tar.*
mv pkg-config-0.29.2.tar.gz installed/


# If you ever want to uninstall pkg-config, this should do it:
cd
su
test -x /sbin/removepkg && /sbin/removepkg pkg-config pkgconfig
test -d src/pkg-config-* && ( cd src/pkg-config-* ; make uninstall )
rm -f /usr/bin/pkg-config /usr/man/man1/pkg-config.1* \
 /usr/share/aclocal/pkg.m4 /usr/share/man/man1/pkg-config.1*
test -d /usr/doc/pkg-config && rm -r /usr/doc/pkg-config
test ! -L /usr/share/doc &&
 test -d /usr/share/doc/pkg-config && rm -r /usr/share/doc/pkg-config
find /usr/doc -maxdepth 1 -type d -name "pkg-config-*" -exec rm -r {} \;
test ! -L /usr/share/doc &&
 find /usr/share/doc -maxdepth 1 -type d -name "pkg-config-*" \
  -exec rm -r {} \;
exit
find ~/src -maxdepth 1 -type d -name "pkg-config-*" -exec rm -r {} \;
find ~/src -maxdepth 1 -type d -name "pkgconfig-*" -exec rm -r {} \;
rm -f ~/installed/pkg-config-*.tar.* ~/installed/pkgconfig.*

Back to the list


Last updated: Wed, 29 Apr 2020 22:04:50 -0400
Jason Englander <jason at englanders dot us>