Topic: Slackware Buildscript Template Resvised
I have separated into two the original template as decribed previously:
http://minimalinux.org/forum/viewtopic.php?id=229
Most of the comments and instruction will also apply here.
With the redundant portions removed the main body of the buildscript should
now be much easier to follow, especially when comparing other scripts.
The elements which are unlikely to change for most scripts have been
removed and included as functions in the file: boilerplate_functions
This will be most managable when placed somewhere in your path which in my
case is "/root/bin".
All should be easy to follow, but the only function that will probably need
tuning is the first: fn_init. Here you may want to make some modifications to
suit yourself, in particular: $TMP, $ARCH, $mtune, $cpoCFLAGS
boilerplate_functions
#-------- begin buildscript_functions --------#
#! /bin/bash
# buildscript_functions
# Paul Westell 2005 - 2009
## list of functions
# fn_init # set initial variables
# fn_unpack #
# fn_sanity # chown & chmod source
# fn_configure # default ./configure options
# fn_mitzy # the stripper
# fn_obligations # misc documentation and licence
# fn_package # buildscript & pacxkage
# set initial variables
fn_init() {
CWD=`pwd`
stamp=cpo`date +%y%m%d${HMS}`
prefix=/usr
TEMP=/usr/tmp ; mkdir -p ${TEMP}
PKG=${TEMP}/pkg-${PROGRAM}
mandir=${prefix}/man
infodir=${prefix}/info
docdir=${prefix}/doc/${PROGRAM}-${VERSION}
htmldir=${prefix}/html/${PROGRAM}-${VERSION}
sharedir=${prefix}share/${PROGRAM}-${VERSION}
scriptdir=${prefix}/share/buildscripts
ARCH=`uname -m` # will detect local CPU:
# ARCH=i386 # for generic 32 bit architectures
# ARCH=x86_64 # for generic 64 bit architectures
mtune=${cputype}
cpoCFLAGS=" -mtune="${mtune}" -g -O2 -m64 "
cpoTARGET=${ARCH}-cpo-linux-gnu
PACKAGE=${PROGRAM}-${VERSION}-${ARCH}-${stamp}
}
# fn_unpack
fn_unpack() {
# a simple "case" should navigate the different compression types with no difficulty,
# however there may be too many variations in the naming conventions used by source
# code authors and distributors to make this exercise worthwhile.
echo " fn_unpack is unimplimented "
}
# set ownership and permissions for the source.
fn_sanity() {
chown -hRc root:root .
find . -type d -exec chmod 755 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 500 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 777 -exec chmod 755 {} \;
}
# set default ./configure options
fn_configure() {
CONFIG=" \
--prefix=${prefix} \
--sysconfdir=/etc \
--localstatedir=/var \
--bindir=${prefix}/bin \
--libdir=${prefix}/lib \
--mandir=${mandir} \
--infodir=${infodir} \
--program-suffix="" \
--program-prefix="" \
--cache-file=/dev/null \
"
}
# strip binaries and libs
fn_mitzy() {
( cd ${PKG}
find . -name "*.a" -exec strip --strip-debug {} \;
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 {} \;
)
}
# install docs to $docdir
fn_obligations() {
mkdir -p ${PKG}${docdir}
cp -a ${DOCS} ${PKG}${docdir}
# finalise and build the package
fn_package() {
mkdir -p ${PKG}${scriptdir}
cat ${CWD}/${PROGRAM}.cpoBuild > ${PKG}${scriptdir}/${PROGRAM}.cpoBuild
cd ${PKG}
makepkg -l y -c n ${TEMP}/${PACKAGE}.tgz
cd ../
}
#--------- end buildscript_functions ---------#Buildscript Template
#--------------- begin cpoBuild ---------------#
#! /bin/bash
# a Slackware compatable buildscript
# Paul Westell 2005 - 2009
PROGRAM=
VERSION=
cputype=
# $cputype must reflect the capabilities of your version of gcc for "--march" or "--mcpu"
# for i386 eg: cputype= i386, i686, ... | for x86_64 cputype= nocona, Core, Core2 ...
source boilerplate.functions
# fn_init sets most initial variables
fn_init
# $DOCS must be handled case by case
DOCS=" ANNOUNCE AUTHORS COPYING INSTALL NEWS README* TODO "
# fn_unpack: too much variation to be an efficient replacement.
rm -rf ${PKG}
mkdir -p ${PKG}
cd ${TEMP}
rm -rf ${PROGRAM}-${VERSION}
tar -jxvf ${CWD}/${PROGRAM}-${VERSION}.tar.bz2
cd ${PROGRAM}-${VERSION}
SRC=`pwd`
fn_sanity
# sed source files or add patches here
# zcat $CWD/<file.diff.gz> | patch -p1 --verbose
fn_configure
# ./configure --help | less
# some 64bit builds work better with: CFLAGS/CXXFLAGS = "${cpoCFLAGS} -fPIC"
CXXFLAGS="${cpoCFLAGS}" \
CFLAGS="${cpoCFLAGS}" \
./configure ${CONFIG} \
--with-gnu-ld \
--disable-libtool-lock \
--docdir=${docdir} \
--htmldir=${htmldir} \
${cpoTARGET}
# --disable-nls \
# --libexecdir=${prefix}/lib \
make -j4
make html
# make check
make install DESTDIR=${PKG}
### binaries, libs, & scripts
# fn_mitzy strips binaries and libs.
fn_mitzy
#### headers:
#### config, init, data:
#### man, info, html
compressdoc -g -9 -F -S -v ${PKG}${mandir}
rm -fr ${PKG}${infodir}
mkdir -p ${PKG}${htmldir}
cp -a doc/*.html ${PKG}${htmldir}
### misc docs & licencing:
fn_obligations
#### slack-desc and install:
mkdir -p ${PKG}/install
cat ${CWD}/slack-desc > ${PKG}/install/slack-desc
# cat ${CWD}/doinst.sh > ${PKG}/install/doinst.sh
# finalise and make the the package
fn_package
#---------------- end cpoBuild ----------------#fin
Last edited by gilligan (2009-06-12 19:44:57)