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)

on an island ... somewhere in the Pacific

Re: Slackware Buildscript Template Resvised

how do I query gcc to report what it believes the cpu is before compile-time ?

I had originally wanted to define the package name in this form:
    PACKAGE=${PROGRAM}-${VERSION}-${mtune}-${stamp}

- where it was intended that $mtune report the selection gcc had made at compile-time (given mtune=native).
This was a really stupid oversight for several reasons.

I have now reset the script so that $mtune must be set externally via the variable $cputype from within the build script.

This leaves me at a loss though. How do I query gcc before compile-time, and have it report what it will use if given the compile-time option mtune=native. It is not always safe to assume the correct choice will be made without intervention. Certain AMD CPUs of fatally different characteristics have been known to identify incorrectly for example.

on an island ... somewhere in the Pacific

Re: Slackware Buildscript Template Resvised

gilligan wrote:

how do I query gcc to report what it believes the cpu is before compile-time ?

I am totally clueless, but maybe this helps:

http://www.pixelbeat.org/scripts/gcccpuopt

- Jeff

Last edited by Jeff (2009-06-13 00:42:57)

Re: Slackware Buildscript Template Resvised

Thanks Jeff,

I've had a brief look at that script now, and it is very much along the lines of what I wanted to accomplish.
The drawbacks: size, and it is limited to 32bit information, even with 64bit CPUs.
I will treat it at least as an instructive document.

It may be better that this option be set manually in any case, whether in the build script or the functions. I seem to remember source that would not accept anything better than -march=pentiumpro without exploratoty surgery, after which it compiled without effort.

on an island ... somewhere in the Pacific

Re: Slackware Buildscript Template Resvised

Hey gilligan!

> that would not accept anything better than -march=pentiumpro without exploratoty surgery

I have yet to see -march=i486 fail.  There is a very good reason that it is part and parcel of the enviroment for the chrootable i386 development thingy here.  I seem to lean towards the brute force method for whatever reason.

Life is good,
Maurice