SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sometimes, I want to build a package from source. I like to make a Slackware package, so that it is easy to upgrade/remove the package in the future. checkinstall works for this most of the time, but not always. I have found it easier to create a SlackBuild for the package.
Since most software compiles fairly similar, I decided to create a SlackBuild template. I have tried to keep it as simliar to the SlackBuild scripts that the official packages use as possible.
Please feel free to use this if it is useful to you.
Any recommended changes/critiques are welcome.
Code:
#!/bin/sh
########################
# NOTES:
#
########################
#
#
#
#
#
#
#
########################
# Set initial variables:
NAME= # Program name
PNAME= # Package name (Useful for changing case, removing "-"s, etc.)
VERSION= # Program version
PVERSION= # Package version (Useful for removing "-"s, CVS builds, etc.)
ARCH=${ARCH:-i686} # Package architecture
BUILD=${BUILD:-1seb} # Build number plus packager initials (use your own)
CWD=`pwd`
TMP=${TMP:-/tmp} # Location to compile the source
PKG=$TMP/package-$NAME # Location to build the package (use "package-$NAME" to avoid poss. conflicts)
# Define compiler flags based on intended architecture:
# Can easily expand this for alternate compilations
if [ "$ARCH" = "i386" ]; then
SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
SLKCFLAGS="-O2 -march=i486 -mcpu=i686"
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mcpu=i686"
elif [ "$ARCH" = "s390" ]; then
SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2"
fi
rm -rf $PKG # Get rid of any leftovers
mkdir -p $PKG # Make sure $PKG and $TMP (-p switch) exist
########################
#
# Why use this? Already covered above, right?
#
########################
#
#if [ ! -d $TMP ]; then
# mkdir -p $TMP # location to build the source
#fi
#
########################
########################
#
# Why use this? Already covered above, right?
#
########################
#
#if [ ! -d $PKG ]; then
# mkdir -p $PKG # place for the package to be built
#fi
#
########################
cd $TMP
rm -rf $NAME-$VERSION
tar xvzf $CWD/$NAME-$VERSION.tar.gz # Should consider changing to check for tar.gz or tar.bz2
cd $NAME-$VERSION
# Correct general permissions/ownership:
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
# Classic "./configure && make && make install":
CFLAGS="$SLKCFLAGS" \
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var/lib \
$ARCH-slackware-linux
make -j3
make install DESTDIR=$PKG
# Correct binaries ownership:
if ls $PKG/bin &> /dev/null; then
chown -R root.bin $PKG/bin
fi
if ls $PKG/usr/bin &> /dev/null; then
chown -R root.bin $PKG/usr/bin
fi
if ls $PKG/sbin &> /dev/null; then
chown -R root.bin $PKG/sbin
fi
if ls $PKG/usr/sbin &> /dev/null; then
chown -R root.bin $PKG/usr/sbin
fi
if ls $PKG/usr/X11R6/bin &> /dev/null; then
chown -R root.bin $PKG/usr/X11R6/bin
fi
# Strip binaries and libs:
( 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:
find $PKG/usr/man -type f -exec gzip -9 {} \;
# Create package docs:
# Probably should define the package documentation with
# a variable ($PDOCS) up top and replace the names with it
mkdir -p $PKG/usr/doc/$PNAME-$PVERSION
cp -a \
AUTHORS BUGS COPYING ChangeLog INSTALL NEWS README TODO TROUBLESHOOTING \
$PKG/usr/doc/$PNAME-$PVERSION
chmod 644 $PKG/usr/doc/$PNAME-$PVERSION/*
# Add package description:
if [ -e $CWD/slack-desc ]; then
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
fi
# Add install script:
if [ -e $CWD/doinst.sh ]; then
cat $CWD/doinst.sh > $PKG/install/doinst.sh
fi
# Add desktop file:
if [ -e $CWD/$PNAME.desktop ]; then
mkdir -p $PKG/usr/share/applications
cat $CWD/$PNAME.desktop > $PKG/usr/share/applications/$PNAME.desktop
fi
# Build the package:
cd $PKG
makepkg -l y -c n $TMP/$PNAME-$PVERSION-$ARCH-$BUILD.tgz
# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
rm -rf $PKG
fi
########################
#
# Why use this? Already covered above, right?
#
########################
#
#if [ ! -d $TMP ]; then
# mkdir -p $TMP # location to build the source
#fi
#
########################
The first line is just the definition of the environment variable "TMP", but that does not mean it exists as a directory already. If I run the SlackBuild script as
Code:
TMP=/home/alien/temp ./template.SlackBuild
then execution would fail if the directory /home/alien/temp does not exist.
So the commented-out lines really should be uncommented.
Quote:
# Correct binaries ownership:
if ls $PKG/bin &> /dev/null; then
chown -R root.bin $PKG/bin
fi
To be complete, you should add a check for $PKG/opt/kde/bin too in case someone builds a KDE package.
Quote:
# Add package description:
if [ -e $CWD/slack-desc ]; then
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
fi
# Add install script:
if [ -e $CWD/doinst.sh ]; then
cat $CWD/doinst.sh > $PKG/install/doinst.sh
fi
Now, if the "$CWD/slack-desc" file is not found, then the "$PKG/install" directory is not created and the "cat $CWD/doinst.sh" command will fail.
this would gzip man pages even if they were already gzipped, no?? i think something like this would be better (no need to use find):
Code:
gzip -9 $PKG/usr/man/man?/*.?
No not really. You would not catch all possible man pages without a "find", since there could be internationalized man pages too, that will be installed into $PKG/usr/jp/man/ for instance (japanese).
No not really. You would not catch all possible man pages without a "find", since there could be internationalized man pages too, that will be installed into $PKG/usr/jp/man/ for instance (japanese).
the original find command wouldn't find the japanese man pages either, since it doesn't look in /usr/*/man... then again, being a *generic* script perhaps it doesn't need to cover any international possibilities... either way, the method i posted is what patrick usually uses, which is something to keep in mind...
maybe you could post a find command that would search through all the possible locations??
Seems sensible to me. Some programs have internationalized manual pages, and the number will probably only increase. So I don't see a problem with doing things the right way . You may want to take out the redirections of stderr to /dev/null.
Seems sensible to me. Some programs have internationalized manual pages, and the number will probably only increase. So I don't see a problem with doing things the right way . You may want to take out the redirections of stderr to /dev/null.
yeah that looks much better... kinda like a hybrid of the find and the direct gzip...
so i take it that the internationalized man pages are stored in the /usr/man directory and not in a directory such as the /usr/jp/man/ example above, right?? cool...
so i take it that the internationalized man pages are stored in the /usr/man directory and not in a directory such as the /usr/jp/man/ example above, right??
#####--------Common Overrides and Options----------------------
# PRE_FIX=""
# EXTRA_CONFIGS=""
# DOCLIST=""
# GROUP_NAME=""
#######----------------Processing------------------------------
# Get functions and read in configuration files
source /usr/share/Amigo/PkgBuild/FUNCTIONS ;
# This template calls each process individually so you can add
# extra instructions between processes, or even leave out steps.
All the code for these functions are in the FUNCTIONS file. A couple of config files let you set up global prefs as to where to unpack, build and leave the created packages.
The first example works for anything that will compile using autoconf and make:
./configure
make
make install
The second example can be made to work for anything -multi-packages from one source, no configure, imake compiles, noarch packages, etc.
The point is that the build script only has information about what is unique to compiling and building only that package. All other information is either part of the functions, or is a variable which can be always be easily overridden.
It supports source/package grouping and regrouping, never actually installs the package unless you tell it to, works for suid programs. It also has a lot of extar features for generating dependency information and package reports, or for creating 'non-standard' packages with extra compression, culling of language files and other features.
It's not perfect, but I turned it loose the other day on 83 source packages. A few hours later I had 83 binary packages, with temp directories all cleaned up.
The really nice thing is that someone who can't code BASH at all, can write a build script for probably 80% of the stuff they want compile.
The long form gives me an excellent way to *easily* see the details of anything that needs custonization.
I have a similar script that I use when packaging programs. When I use it to package mplayer, gzipping the man pages will break a symlink. It looks like this script will have the same problem.
If I remember correctly...
mencoder.1 -> mplayer.1
After gzipping mplayer.1, the mencoder.1 symlink is broken (it should point to mplayer.1.gz instead). Does anyone have a good solution for detecting and fixing this type of problem, rather than explicitly removing and recreating that specific symlink?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.