Setting up build environment
/home/slackware: The Slackware home directory which is owned by the "packger" group( which root and
user account are the members on the local system.
/home/slackware/source: which places the whole slackware-source.
/home/slackware/source/myslackware: This is where puts all packages.
/home/slackware/source/myslackware/<package> In this directory we build our package
/home/slackware/packages: where puts all built packages.
Getting started
Beginning the process of building package with SlackBuild script.
For this example, we will create a package of latex2html which made website home page.
creating the directory named <build_environment>/latex2html, getting the most
recent source code release of latex2html and placing it in this directory.
mkdir <build-environment>/latex2html
cd <build-environment>/latex2html
wget http://www.latex2html.org/~latex2ht/current/latex2html-2002-2-1.tar.gz
touch latex2html.SlackBuild
touch slack-desc
Extracting the source code, because we need to look at configure script and late to determine what options we need to pass to it.
Writing the SlackBuild script
Initial Setup
First specifying the interpreter
#!/bin/sh -e ('e' option tells shell exit on any error.
# <you name> revision date yyyy/mm/dd
# Set initial variables :
CWD=$(pwd)
if [ "$TMP" == " " ]; then
TMP = /tmp
fi
# The version which appears in the application's filename
VERSION = 2012-1-2
# If the version conflicts with the Slackware package standard
# The dash character ("-") is not allowed in the VERSION string
# You can set the PKG_VERSION to something else than VERSION
PKG_VERSION=2002.2.1 # the version which appears in the package name.
ARCH=${ARCH:-i486} #The architecture on where your package will biuld
#First digit is the build number. which specifies how many times it has been built,
#Second string is the short form of authors name, typically three initilas: w
BUILD=${BUILD: - 1_dvp}
#The Application's name
APP=latex2html
#The installation directory of the package
PKG=$TMP/package-$APP
#Set SLKCFLAGS, if use old version gcc less than 3.4.x, needing "-mcpu" instead of "mtune"
if [ "$ARCH" = "i486" ]; then
SLKCFLAGS = "-02 -match=i486 -mtune=i686"
elif [ "$ARCH = "x86_64" ]; then
SLCKFLAGS = "-02 -fPIC"
fi
#Exract the source file
#Deleting the leftover directories id there exists
rm -fr $PKG
mkdir -p $TMP $PKG
rm -fr $TMP/$APP-$VERSION
#Change to the $TMP directory
cd $TMP || exit 1
#Extract the application source file in TMP
tar -xzvf $CWD/$APP-$VERSION.tar.gz
# Change to the Application directory
cd $APP-$VERSION || exit 1
chown -R root:root .
chmod u+x, go+r-w, a-s .
#Set configure options
#If your app is writen in C++, you will also add line about CXXFLAGS
CFLAGS="$SLCKFLAGS" \
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--with-perl=/usr/bin/perl \
--enable-eps \
--enable-gif \
--enable-png \
--build=$ARCH-slackware-linux \
--host=$BUILD-slackware-linux \
#Compile the source and exit when go wrong
make || exit
#Installing everything into the package directory, but exit if go wrong
make install $PKG || exit
# Install software documentation
#Create the directory to stored the documentation
mkdir -p $PKG/usr/doc/$APP-$VERSION
#Copy documentation to docs directory and change the permission
cp -a BUGS Changes FAQ INSTALL LICENSE MAINFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION
find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;
#We can also place the *.SlackBuild script to the directory
cat $CWD/$APP.SlackBuild > $PKG/usr/doc/$APP.SlackBuild
#Create the ./install directory and place the slack-desc in this directory
mkdir -p $PKG/install
cp $CWD/slack-desc $PKG/install/slack-desc
#And doinst.sh to the directory if it exits
if [ -e doinst.sh.gz ]; then
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
fi
# Strip some libraries and binaries
( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
# Compress man pages if they exist
if [ -d $PKG/usr/man ]; then
( cd $PKG/usr/man
find . -type f -exec gzip -9 {} \;
for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done
)
fi
# Compress info pages if they exist (and remove the dir file)
if [ -d $PKG/usr/info ]; then
gzip -9 $PKG/usr/info/*.info
rm -f $PKG/usr/info/dir
fi
Build the Package
# Build the package
cd $PKG
/sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz