1064 lines
30 KiB
Plaintext
1064 lines
30 KiB
Plaintext
# Global function library for buildpkg
|
|
# Copyright (C) 2003-2019 Tom G. Christensen <tgc@jupiterrise.com>
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# Written by Tom G. Christensen <tgc@jupiterrise.com>.
|
|
|
|
#
|
|
# This file is designed to be sourced by pr. package buildscripts
|
|
#
|
|
# We rely on an environment variable called BUILDPKG_BASE to
|
|
# define the root of the buildpkg tree
|
|
#
|
|
buildpkgbase=${BUILDPKG_BASE-'x'}
|
|
if [ "$buildpkgbase" == "x" ]; then
|
|
echo "You *must* define BUILDPKG_BASE environment variable"
|
|
exit 1
|
|
fi
|
|
|
|
# We rely on an environment variable called BUILDPKG_SCRIPTS to
|
|
# define where the buildpkg code is located
|
|
buildpkgscripts=${BUILDPKG_SCRIPTS-'x'}
|
|
if [ "$buildpkgscripts" == "x" ]; then
|
|
echo "You *must* define BUILDPKG_SCRIPTS environment variable"
|
|
exit 1
|
|
fi
|
|
|
|
# Variables that *must* be overridden pr. package
|
|
# They are used to construct paths and more so they
|
|
# must have sane values
|
|
# topdir= The default package dirname, it's used pr. default in pkgname
|
|
# and it is also used pr. default as the toplevel name inside the sourcetar ($topsrcdir)
|
|
# version= source version ie. 0.14.2b
|
|
# pkgver= the package revision, an increasing number is recommended but a date could be used instead
|
|
# source[0..x] = source filenames - source[0] *must* be defined and contain a legal filename
|
|
# pr. default we will look for source[0] relative to $srcfiles
|
|
# A filename that begin with / will be treated as absolute paths
|
|
# Note! only source[0] will be automatically unpacked
|
|
# patch[0..x] = patch filenames - if patch[0] is undefined then generic_prep won't attempt to patch the source
|
|
# pr. default we expect these to be listed relative to $patchdir (default $srcdir)
|
|
# filenames that begin with / will be treated as absolute paths
|
|
# All patching will be done from *within* $srcdir/$topsrcdir directory with patch -p1
|
|
# patches must be in uncompressed format
|
|
|
|
# Define tools programs in __ prefixed namespace
|
|
. $BUILDPKG_SCRIPTS/buildpkg.tools
|
|
|
|
# Define defaults
|
|
pkgdir=${PWD##*/} # topdir under $BUILDPKG_BASE
|
|
stagedir=$buildpkgbase/$pkgdir/stage
|
|
srcdir=$buildpkgbase/$pkgdir/src
|
|
patchdir=$srcdir # Allow the possibility of easily putting a load of patches in a different location
|
|
metadir=$buildpkgbase/$pkgdir/meta
|
|
distdir=$buildpkgbase/distfiles/beta
|
|
topsrcdir=$topdir-$version # it may be necessary to override this
|
|
|
|
srcfiles=$buildpkgbase/srcfiles
|
|
|
|
pkgdirdesig=tgcware # topinstalldir suffix
|
|
topinstalldir=/usr/$pkgdirdesig
|
|
prefix=$topinstalldir
|
|
metainstalldir=$topinstalldir
|
|
|
|
# The default configure args
|
|
configure_args=(--prefix=$prefix --disable-nls)
|
|
__configure="./configure"
|
|
|
|
# Docdir relative to $prefix
|
|
_docdir=share/doc
|
|
_vdocdir=${_docdir}/${topdir}-${version}
|
|
# Other relative dirs
|
|
_bindir=bin
|
|
_sbindir=sbin
|
|
_libdir=lib
|
|
_sharedir=share
|
|
_mandir=man
|
|
_infodir=info
|
|
_includedir=include
|
|
_sysconfdir=etc
|
|
_datadir=$_sharedir
|
|
|
|
tmpdir=/tmp
|
|
|
|
_os=$(${__uname} -sr|${__sed} -e 's/ //g' -e 's/\.//g'|${__tr} '[A-Z]' '[a-z]')
|
|
|
|
# pkg information.
|
|
# The following 3 vars can be used when constructing pkg metadata
|
|
# Override as necessary.
|
|
pkgprefix=SB
|
|
pkgname=$pkgprefix$topdir # overriding this will be common
|
|
name=$topdir # as will this ditto
|
|
|
|
# Functionality controls
|
|
symlinkman=0 # Don't replace .so linking with symlinks pr. default
|
|
symlinkman_verbose=0 # Be quiet
|
|
catman=0 # Don't fix manpages pr. default
|
|
gzman=0 # Don't gzip man pages pr. default
|
|
compressman=0 # Don't compress(1) man pages pr. default
|
|
packman=0 # Don't pack(1) man pages pr. default
|
|
gzinfo=1 # Compress infopages pr. default
|
|
dostrip=1
|
|
dostrip_elf=1 # default to stripping binaries during the install stage
|
|
dostrip_shared=1 # default to stripping shared objects during the install stage
|
|
dostrip_static=1 # default to stripping static archives during the install stage
|
|
shortroot=0 # Deep or shallow stagedir?
|
|
autonuke=1 # Automatically attempt to cleanout unwanted files after make install?
|
|
# eg. info/dir, lib/*.la
|
|
|
|
# This is meant to aid custom install functions that wants
|
|
# to skip the clean stage & make install parts of generic_install
|
|
custom_install=0
|
|
|
|
# We need to allow a pr. packaging function library to have it's own
|
|
# way of running configure. We default to using the generic version
|
|
# but if set to 0 it will try to use run_configure function instead
|
|
generic_configure=1
|
|
|
|
# Allow overriding the make target for building
|
|
# We default to an empty string so the default target will be built
|
|
make_build_target=""
|
|
|
|
# Allow overriding the make target for running the testsuite
|
|
# We default to 'check'
|
|
make_check_target="check"
|
|
|
|
# Allow overriding the make target for running the install
|
|
# We default to 'install'
|
|
make_install_target=install
|
|
|
|
# Allow skipping the configure run
|
|
no_configure=0
|
|
|
|
# When building perl modules should we run make test?
|
|
maketest=0
|
|
|
|
# When patching use -p1 as default prefix
|
|
patch_prefix="-p1"
|
|
|
|
# Settings for gnu_link
|
|
# GNU prefix
|
|
gnu_prefix=g
|
|
# GNU dir
|
|
_gnudir=gnu
|
|
# Add --program-prefix to configure if gnu_link is requested?
|
|
gnu_configure=1
|
|
|
|
# Distfiles should be named like this
|
|
# <name>-<version>-<pkgver>.sb-<os>-<cpu>-<pkgdirdesig>
|
|
# ie: libmad-0.14.2b-1.sb-sol5.8-sparcv9-local
|
|
#distfile=$topdir-$version-$pkgver.sb-$os-$cpu-$pkgdirdesig
|
|
# You must override the distfile var in the pr. packaging
|
|
# system function library
|
|
|
|
# Define error codes and texts
|
|
E_MISSING_STAGEDIR=30
|
|
E_MISSING_ARGS=31
|
|
E_BAD_FILE=32
|
|
E_PATCH_FAILED=33
|
|
E_BAD_DIR=34
|
|
E_BAD_UNPACK=35
|
|
E_BAD_COMPRESS=36
|
|
E_BAD_CONFIG=37
|
|
E_BAD_MAKE=38
|
|
E_BAD_CLEANOPTIONS=39
|
|
E_BAD_STRIP=40
|
|
E_BAD_ARGS=41
|
|
E_ARG_OBSO=42
|
|
E_BAD_SECTION_BEGIN=43
|
|
E_BAD_SECTION_END=44
|
|
E_UNPACKAGED_FILES=45
|
|
E_BAD_VERSION=46
|
|
E_BAD_LIBS=47
|
|
E_SVR4_PKG_OVERFLOW=48
|
|
E_SVR4_NAME_OVERFLOW=49
|
|
E_MISSING_EXE=50
|
|
E_MISSING_CHGLOG=51
|
|
E_MISSING_CHGLOGV=52
|
|
|
|
error_txt[$E_BAD_FILE]="File not found"
|
|
error_txt[$E_PATCH_FAILED]="Patch failed"
|
|
error_txt[$E_BAD_DIR]="Directory not found"
|
|
error_txt[$E_BAD_UNPACK]="Unable to decompress sourcearchive"
|
|
error_txt[$E_BAD_COMPRESS]="Unknown compression method"
|
|
#error_txt[$E_BAD_CONFIG]="configure failed"
|
|
#error_txt[$E_BAD_MAKE]="make failed"
|
|
error_txt[$E_MISSING_ARGS]="A required argument was missing"
|
|
error_txt[$E_BAD_ARGS]="An illegal argument was passed"
|
|
error_txt[$E_ARG_OBSO]="Function nolonger supports the argument you passed"
|
|
error_txt[$E_BAD_SECTION_BEGIN]="Section start marker found but we are already inside a section!"
|
|
error_txt[$E_BAD_SECTION_END]="Found end of section marker before section begin!"
|
|
error_txt[$E_UNPACKAGED_FILES]="Unpackaged files found in stage area!"
|
|
error_txt[$E_BAD_VERSION]="Version field overflow"
|
|
error_txt[$E_BAD_LIBS]="config.log defines obsolete libraries!"
|
|
error_txt[$E_SVR4_PKG_OVERFLOW]="PKG field exceeds 9 char limit"
|
|
error_txt[$E_SVR4_NAME_OVERFLOW]="NAME field exceeds 256 char limit"
|
|
error_txt[$E_MISSING_EXE]="Executable is missing"
|
|
error_txt[$E_MISSING_CHGLOG]="ChangeLog is missing"
|
|
error_txt[$E_MISSING_CHGLOGV]="Did not find ChangeLog entry for ${version}-${pkgver}"
|
|
|
|
#####################################################
|
|
# Helper functions
|
|
#####################################################
|
|
|
|
# Two very useful utility functions courtesy of the ABS guide (see Example A-22 & A-23)
|
|
# _pls will enclose a string in hard-quotes to avoid expansion
|
|
# _upls will remove hard-quotes from hard-quoted string thus allowing expansion
|
|
_pls() {
|
|
# local IFS=$'x1B' # \ESC character (not required)
|
|
echo $'\x27'$@$'\x27' # Hard quoted parameter glob
|
|
}
|
|
_upls() {
|
|
# local IFS=$'x1B' # \ESC character (not required)
|
|
eval echo $@ # Substitution on the glob.
|
|
}
|
|
|
|
# error(): exit with errorcode and possibly a message
|
|
# params: $1 = errorcode $2 = name of caller
|
|
error()
|
|
{
|
|
if [ -n "${error_txt[$1]}" ]; then
|
|
echo "$2: ${error_txt[$1]}"
|
|
fi
|
|
exit $1
|
|
}
|
|
|
|
# setdir(): switch to a directory, but check destination first
|
|
# params: $1=dir to cd to [source|stage] can be used as shortcuts
|
|
# Switches to the directory in $1 but first checks if the destination exists
|
|
setdir()
|
|
{
|
|
local dir=$1
|
|
case $dir in
|
|
'source') dir="$srcdir/$topsrcdir";;
|
|
'stage') dir="$stagedir";;
|
|
esac
|
|
echo "Switching to $dir"
|
|
if [ -z "$dir" ]; then
|
|
error $E_BAD_DIR setdir
|
|
fi
|
|
if [ -d "$dir" ]; then
|
|
cd "$dir"
|
|
else
|
|
error $E_BAD_DIR setdir
|
|
fi
|
|
}
|
|
|
|
# patch(): patch unpacked source
|
|
# params: $1 = patch number (arrayindex) $2 = patch params (defaults to -p1)
|
|
# It will verify the existence of the patch file passed to it and
|
|
# exit gracefully if it cannot be found.
|
|
# An empty $2 argument will be treated as undefined and mapped to -p1
|
|
patch()
|
|
{
|
|
local pnum=$1
|
|
local arg2=$2
|
|
local pparam=${arg2:-"-p1"}
|
|
|
|
setdir source
|
|
|
|
if [ ! -z ${patch[$pnum]} ]; then # They didn't give us an empty string
|
|
if [ "${patch[$pnum]:0:1}" != "/" ]; then # We have a relative pathname
|
|
# expand to absolute
|
|
patch[$pnum]=$(get_source_absfilename ${patch[$pnum]})
|
|
fi # We are now sure that $patch[$pnum] contains file with absolute path
|
|
echo "Processing patch[$pnum] - ${patch[$pnum]}"
|
|
if [ -r ${patch[$pnum]} ]; then # file is readable
|
|
${__patch} -Es $2 < ${patch[$pnum]}
|
|
if [ $? -ne 0 ]; then
|
|
error $E_PATCH_FAILED patch
|
|
fi
|
|
else
|
|
error $E_BAD_FILE patch
|
|
fi
|
|
else
|
|
echo "Patch $pnum has empty filename"
|
|
fi
|
|
}
|
|
|
|
# get_source_filename(): Find filename for given sourceid
|
|
# params: $1 = file to resolve (ie. source[x] or patch[x])
|
|
get_source_filename()
|
|
{
|
|
local source=$1
|
|
local file="${source##*/}" # Extract filename part
|
|
|
|
if [ -z "$file" ]; then
|
|
error $E_BAD_FILE get_source_filename
|
|
else
|
|
echo $file
|
|
fi
|
|
}
|
|
|
|
# get_source_path(): Find local path for given sourceid
|
|
# params: $1 = file to resolve (ie. source[x] or patch[x])
|
|
get_source_path()
|
|
{
|
|
local source=$1
|
|
local path_return=""
|
|
local path="${source%/*}" # Extract path part
|
|
local file=$(get_source_filename "$source") # Extract filename part
|
|
|
|
if [ -n "$path" ]; then
|
|
# We have a path component, could be relative, url or abs path
|
|
if [ "${path:0:1}" != "/" ]; then
|
|
# path is relative or contains an url
|
|
# If path contains an url
|
|
if [ -n "$(echo $path | grep '://')" ]; then
|
|
# let empty $path code handle it
|
|
path=""
|
|
else
|
|
# Not an url
|
|
[ -r "$srcdir/$file" ] && path_return="$srcdir"
|
|
[ -r "$srcfiles/$file" ] && path_return="$srcfiles"
|
|
fi
|
|
else # abs path
|
|
path_return=$path
|
|
fi
|
|
fi
|
|
# No path given
|
|
if [ -z "$path" ]; then
|
|
[ -r "$srcdir/$file" ] && path_return="$srcdir"
|
|
[ -r "$srcfiles/$file" ] && path_return="$srcfiles"
|
|
fi
|
|
|
|
[ -z "$path_return" ] && path_return="$srcfiles" # Best guess
|
|
|
|
echo $path_return
|
|
}
|
|
|
|
# get_source_absfilename(): Wrapper for get_source_filename and get_source_path
|
|
# params: $1 = file to resolve (ie. source[x] or patch[x])
|
|
# Note this wrapper will exit with $E_BAD_FILE if the absolute filename is not
|
|
# readable
|
|
get_source_absfilename()
|
|
{
|
|
local source=$1
|
|
local absfilename="$(get_source_path "$source")/$(get_source_filename $1)"
|
|
if [ -r "$absfilename" ]; then
|
|
echo "$absfilename"
|
|
else
|
|
# File is not readable
|
|
error $E_BAD_FILE get_source_absfilename
|
|
fi
|
|
}
|
|
|
|
# fetch_source(): Fetch a sourcefile from an url
|
|
# params: $1 = URL to fetch
|
|
fetch_source()
|
|
{
|
|
local url=$1
|
|
local file=$(get_source_filename "$url")
|
|
local path=$(get_source_path "$url")
|
|
|
|
if [ ! -r "$path/$file" ]; then
|
|
echo "fetch_source: Downloading $url"
|
|
if [ -x ${__curl} ]; then
|
|
${__curl} -R -# -L --retry 2 -C - -o $srcfiles/$file "$url"
|
|
else
|
|
error $E_MISSING_EXE fetch_source
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# get_files(): Fetch source files and patches from URLs
|
|
# params: none
|
|
# Any source or patch entries with URL's will be processed and downloaded
|
|
# as necessary.
|
|
get_files()
|
|
{
|
|
local numsource=${#source[@]}
|
|
local numpatch=${#patch[@]}
|
|
local src
|
|
local array
|
|
local counter
|
|
|
|
local idx=0
|
|
let counter=$numsource+$numpatch
|
|
array=( ${source[@]} ${patch[@]} )
|
|
while [ $idx -lt ${counter} ]
|
|
do
|
|
src=${array[$idx]}
|
|
[ -n "$(echo $src | grep '://')" ] && fetch_source $src
|
|
let idx=idx+1
|
|
done
|
|
}
|
|
|
|
# unpack(): Unpack source
|
|
# params: $1 = source number (arrayindex)
|
|
# It will detect filetype and unpack
|
|
# .tar, .tgz, .gz, .bz2, .xz, .zip and .Z supported
|
|
unpack()
|
|
{
|
|
local source=${source[$1]}
|
|
local filename
|
|
local suffix
|
|
local absfile
|
|
|
|
# Create the $srcdir if it is missing
|
|
if [ ! -d $srcdir ]; then
|
|
echo "Creating $srcdir"
|
|
${__mkdir} -p $srcdir
|
|
fi
|
|
setdir $srcdir
|
|
|
|
# If source contains an URL then first
|
|
# download the file to $srcfiles
|
|
if [ -n "$(echo $source | grep '://')" ]; then
|
|
# Yep it's an url
|
|
fetch_source "$source"
|
|
fi
|
|
|
|
filename="$(get_source_filename "$source")"
|
|
suffix=${filename##*.} # Strip down to filename suffix (strip down to the last .)
|
|
echo "Unpacking $filename"
|
|
# Note observe order here, since get_source_absfilename can exit with $E_BAD_FILE this
|
|
# provides context for resolving!
|
|
absfile="$(get_source_absfilename "$source")"
|
|
# Catch any badness from the get_source function stack
|
|
[ "$?" != "0" ] && error $E_BAD_FILE unpack
|
|
# Determine filetype and unpack
|
|
case $suffix in
|
|
'tar') ${__tar} -xf $absfile;;
|
|
'gz') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
|
'bz2') ${__bzip2} -dc $absfile | ${__tar} -xf -;;
|
|
'Z') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
|
'tgz') ${__gzip} -dc $absfile | ${__tar} -xf -;;
|
|
'xz') ${__xz} -dc $absfile | ${__tar} -xf -;;
|
|
'lz') ${__lzip} -dc $absfile | ${__tar} -xf -;;
|
|
'zip') ${__unzip} -q $absfile;;
|
|
*) error $E_BAD_COMPRESS unpack
|
|
esac
|
|
if [ $? -ne 0 ]; then
|
|
error $E_BAD_UNPACK unpack
|
|
fi
|
|
}
|
|
|
|
# clean(): Scrub build environment
|
|
# params: $1=stage|source|distclean
|
|
clean()
|
|
{
|
|
local i
|
|
local secname
|
|
local pkgname
|
|
case $1 in
|
|
'source') if [ -d "$srcdir/$topsrcdir" ]; then
|
|
echo "Removing $srcdir/$topsrcdir"
|
|
${__rm} -rf $srcdir/$topsrcdir
|
|
else
|
|
echo "No unpacked source to scrub"
|
|
fi
|
|
;;
|
|
'stage') if [ -d $stagedir -a "$stagedir" != "/" ]; then
|
|
echo "Emptying $stagedir"
|
|
${__rm} -rf $stagedir # This is very dangerous!
|
|
${__mkdir} $stagedir
|
|
fi
|
|
# Solaris only - We can't add this to meta since compver is usually created
|
|
# during install
|
|
${__rm} -f $metadir/compver.*
|
|
;;
|
|
'meta')
|
|
if [ "$(${__uname} -s)" == "SunOS" ]; then
|
|
for secname in $(list_pkgs)
|
|
do
|
|
META_CLEAN="$META_CLEAN prototype.$secname pkginfo.$secname"
|
|
pkgname=$(get_pkgname $secname)
|
|
echo "Removing $buildpkgbase/$pkgdir/$pkgname"
|
|
[ ! -z "$pkgname" ] && ${__rm} -rf $buildpkgbase/$pkgdir/$pkgname
|
|
done
|
|
fi
|
|
|
|
for i in $META_CLEAN
|
|
do
|
|
echo "Removing $metadir/$i"
|
|
${__rm} -f $metadir/$i
|
|
done
|
|
;;
|
|
|
|
'distclean') clean source
|
|
clean stage
|
|
clean meta
|
|
# Irix only - ugly hack
|
|
${__rm} -f $metadir/relnotes*.txt
|
|
;;
|
|
*) error $E_BAD_CLEANOPTION clean
|
|
esac
|
|
}
|
|
|
|
# do_strip(): strip binaries in stagedir
|
|
# params: none
|
|
# Automatically switches to $stagedir
|
|
# On exit cwd is $stagedir
|
|
do_strip()
|
|
{
|
|
local f
|
|
setdir stage
|
|
# Strip ELF binaries (see brp-strip from RPM)
|
|
if [ $dostrip_elf -eq 1 ]; then
|
|
do_strip_bin
|
|
fi
|
|
if [ $dostrip_shared -eq 1 ]; then
|
|
do_strip_shared
|
|
fi
|
|
if [ $dostrip_static -eq 1 ]; then
|
|
do_strip_static
|
|
fi
|
|
}
|
|
|
|
# do_autonuke(): Kill unwanted files after make install
|
|
# params: none
|
|
# Automatically switches to $stagedir/$prefix
|
|
# On exit cwd is $stagedir/$prefix
|
|
do_autonuke()
|
|
{
|
|
local i
|
|
local didnuke=0
|
|
echo "Autonuking..."
|
|
|
|
setdir ${stagedir}${prefix}
|
|
if [ -d "${_infodir}" ]; then
|
|
if [ -r ${_infodir}/dir ]; then
|
|
echo "Nuking ${_infodir}/dir"
|
|
${__rm} -f ${_infodir}/dir
|
|
didnuke=1
|
|
fi
|
|
fi
|
|
if [ -d "${_libdir}" ]; then
|
|
if [ -r ${_libdir}/charset.alias ]; then
|
|
echo "Nuking ${_libdir}/charset.alias"
|
|
${__rm} -f ${_libdir}/charset.alias
|
|
didnuke=1
|
|
fi
|
|
fi
|
|
if [ -d "${_libdir}" -a ! -z "$(${__ls} ${_libdir}/*.la 2>/dev/null)" ]; then
|
|
for i in ${_libdir}/*.la
|
|
do
|
|
echo "Nuking $i"
|
|
${__rm} -f "$i"
|
|
done
|
|
didnuke=1
|
|
fi
|
|
if [ $didnuke -eq 0 ]; then
|
|
echo "Found nothing to nuke"
|
|
fi
|
|
}
|
|
|
|
# symlink_man(): Convert .so style references to symlinks
|
|
# params: none
|
|
# Run from 'cwd' where 'cwd' contains manX subdirs
|
|
symlink_man()
|
|
{
|
|
local i
|
|
local manpage
|
|
local solink
|
|
local linkdest
|
|
local OIFS
|
|
local manpages
|
|
|
|
echo "Symlinking manpages"
|
|
for i in man?
|
|
do
|
|
if [ -d $i ]; then
|
|
OIFS="$IFS"
|
|
IFS="
|
|
"
|
|
manpages="$(${__ls} $i/* 2>/dev/null)"
|
|
for manpage in $manpages
|
|
do
|
|
solink="$(${__head} -n 1 $manpage)"
|
|
if [ "${solink:0:3}" = ".so" ]; then # .so style link to be converted
|
|
linkdest="${solink#.so*/}"
|
|
[ "$symlinkman_verbose" -eq 1 ] && echo "Symlinking $linkdest->$manpage"
|
|
${__ln} -sf "$linkdest" "$manpage"
|
|
fi
|
|
done
|
|
IFS="$OIFS"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# fix_man(): create compressed pre-formatted manpages from raw ones
|
|
# params: none
|
|
# Run from 'cwd' where 'cwd' contains manX subdirs
|
|
fix_man()
|
|
{
|
|
local i
|
|
local catdir
|
|
local manpage
|
|
local TARGET
|
|
|
|
echo "Formatting manpages"
|
|
for i in $(${__ls} -d man? 2>/dev/null)
|
|
do
|
|
if [ -d $i ]; then
|
|
catdir=cat${i##man}
|
|
${__mkdir} $catdir
|
|
cd $i
|
|
for manpage in $(${__ls} * 2>/dev/null)
|
|
do
|
|
if [ -L "$manpage" ]; then
|
|
TARGET=$(${__ls} -l "$manpage" | ${__awk} '{ print $NF }')
|
|
${__ln} -sf "$TARGET" "$manpage"
|
|
${__mv} "$manpage" "../$catdir"
|
|
${__rm} -f "$manpage"
|
|
else
|
|
${__nroff} $NROFFOPTS "$manpage" > "../$catdir/$manpage"
|
|
${__rm} -f $manpage
|
|
fi
|
|
done
|
|
cd ..
|
|
${__rmdir} $i
|
|
fi
|
|
done
|
|
}
|
|
|
|
# compress_man(): Compress manpages
|
|
# params: none
|
|
# Run from 'cwd' where 'cwd' contains catX/manX subdirs
|
|
compress_man()
|
|
{
|
|
if [ "$gzman" -eq 1 ]; then # Use gzip
|
|
local compsuffix=gz
|
|
local pack=${__gzip}
|
|
fi
|
|
if [ "$compressman" -eq 1 ]; then # Use compress(1)
|
|
local compsuffix=Z
|
|
local pack="${__compress} -f"
|
|
fi
|
|
if [ "$packman" -eq 1 ]; then # Use pack(1)
|
|
local compsuffix=z
|
|
local pack="${__pack} -f"
|
|
fi
|
|
|
|
echo "Compressing manpages"
|
|
for i in $(${__ls} -d [cm]a[nt]? 2>/dev/null)
|
|
do
|
|
if [ -d $i ]; then
|
|
cd $i
|
|
for manpage in $(${__ls} * 2>/dev/null)
|
|
do
|
|
suffix="${manpage##*.}"
|
|
if [ "$suffix" != "gz" -a "$suffix" != "Z" ]; then #probably uncompressed...
|
|
if [ -L "$manpage" ]; then
|
|
TARGET=$(${__ls} -l "$manpage" | ${__awk} '{ print $NF }')
|
|
${__ln} -sf "$TARGET".$compsuffix "$manpage".$compsuffix
|
|
${__rm} -f "$manpage"
|
|
else
|
|
$pack "$manpage"
|
|
fi
|
|
fi
|
|
done
|
|
cd ..
|
|
fi
|
|
done
|
|
}
|
|
|
|
# compress_info(): Compress GNU info pages
|
|
# params: none
|
|
# Run from 'cwd' where 'cwd' is the dir contains uncompressed info pages
|
|
compress_info()
|
|
{
|
|
echo "Compressing info pages"
|
|
for i in *
|
|
do
|
|
${__gzip} $i
|
|
done
|
|
}
|
|
|
|
# doc(): Add files from srcdir to 'docs' location
|
|
# params: $1..$x
|
|
# Copies files from $srcdir to $_docdir/$topdir-$version
|
|
doc()
|
|
{
|
|
local f
|
|
local ddir # Holds internal value of _docdir
|
|
|
|
if [ ! -z $# ]; then
|
|
setdir source
|
|
ddir=${stagedir}${prefix}/${_docdir}/${topdir}-${version}
|
|
${__mkdir} -p $ddir
|
|
echo "Adding docs"
|
|
until [ -z "$1" ]
|
|
do
|
|
for f in $(_upls $1)
|
|
do
|
|
(${__tar} -cf - "$f")|(cd $ddir; ${__tar} -xvBpf -)
|
|
done
|
|
shift
|
|
done
|
|
fi
|
|
}
|
|
|
|
# compute_octal()
|
|
# Description: Computes the octal value from a permission list (_rwxrwxrwx)
|
|
# param: $1=permission list
|
|
# Caveats: It won't pickup sticky bit and mandatory locking bit
|
|
compute_octal()
|
|
{
|
|
local perm=$1
|
|
local v=0; local d1=0; local d2=0; local d3=0; local d4=0
|
|
# User part
|
|
if [ "${perm:1:1}" == "r" ]; then
|
|
let "v = v + 4" # set read bit
|
|
fi
|
|
if [ "${perm:2:1}" == "w" ]; then
|
|
let "v = v + 2" # set write bit
|
|
fi
|
|
if [ "${perm:3:1}" == "x" ]; then
|
|
let "v = v + 1" # set executable bit
|
|
elif [ "${perm:3:1}" == "s" ]; then
|
|
let "v = v + 1" # set executable bit
|
|
let "d1 = d1 + 4" # Set setuid bit
|
|
fi
|
|
d2=$v; v=0
|
|
# Group part
|
|
if [ "${perm:4:1}" == "r" ]; then
|
|
let "v = v + 4" # set read bit
|
|
fi
|
|
if [ "${perm:5:1}" == "w" ]; then
|
|
let "v = v + 2" # set write bit
|
|
fi
|
|
if [ "${perm:6:1}" == "x" ]; then
|
|
let "v = v + 1" # set executable bit
|
|
elif [ "${perm:6:1}" == "s" ]; then
|
|
let "v = v + 1" # set executable bit
|
|
let "d1 = d1 + 2" # Set setgid bit
|
|
fi
|
|
d3=$v; v=0;
|
|
# Other part
|
|
if [ "${perm:7:1}" == "r" ]; then
|
|
let "v = v + 4" # set read bit
|
|
fi
|
|
if [ "${perm:8:1}" == "w" ]; then
|
|
let "v = v + 2" # set write bit
|
|
fi
|
|
if [ "${perm:9:1}" == "x" ]; then
|
|
let "v = v + 1" # set executable bit
|
|
fi
|
|
d4=$v; v=0
|
|
echo $d1$d2$d3$d4
|
|
}
|
|
|
|
# check_changelog(): Verify that the ChangeLog is updated
|
|
# params: none
|
|
# Verify that the ChangeLog exists and contains an entry for the current
|
|
# version of the software
|
|
check_changelog()
|
|
{
|
|
if [ -r $metadir/ChangeLog ]; then
|
|
# See if we can find an entry for this build otherwise complain
|
|
if [ -z "$(${__grep} ${version}-${pkgver}$ $metadir/ChangeLog)" ]; then
|
|
error $E_MISSING_CHGLOGV check_changelog
|
|
fi
|
|
else
|
|
error $E_MISSING_CHGLOG check_changelog
|
|
fi
|
|
}
|
|
|
|
# do_gnu_link: Create symlinks in $prefix/$_gnudir
|
|
# params: list of programs to link
|
|
# For each program given, create a symlink from $prefix/${_bindir}/program to
|
|
# $prefix/gnu with the first character stripped from the name
|
|
do_gnu_link()
|
|
{
|
|
local program
|
|
|
|
${__mkdir} -p ${stagedir}${prefix}/$_gnudir
|
|
cd ${stagedir}${prefix}/$_gnudir
|
|
|
|
for program in $@
|
|
do
|
|
local dest=${program:1}
|
|
echo "Linking $prefix/${_bindir}/$program to $prefix/$_gnudir/$dest"
|
|
${__ln_s} ../${_bindir}/$program ${dest}
|
|
done
|
|
}
|
|
|
|
# gnu_link: Prepare for gnu symlink setup
|
|
# params: list of programs to link
|
|
# Each param is added to the internal gnu_link_progs array
|
|
# It will also add --program-prefix=$gnu_prefix to configure_args if requested
|
|
gnu_link()
|
|
{
|
|
local item
|
|
for item in "$@"
|
|
do
|
|
gnu_link_progs+=($item)
|
|
done
|
|
[ $gnu_configure -eq 1 ] && configure_args=(--program-prefix=$gnu_prefix "${configure_args[@]}")
|
|
}
|
|
|
|
#####################################################
|
|
# Define generic functions for different build stages
|
|
#####################################################
|
|
|
|
# generic_prep(): Unpack source and apply any patches
|
|
# params: none
|
|
generic_prep()
|
|
{
|
|
clean source
|
|
|
|
# Sweep ${#source[@]} and ${#patch[@]} for URL's and download any files
|
|
# needed
|
|
get_files
|
|
|
|
unpack 0
|
|
|
|
# Verify that ${patch[$pnum]} is defined
|
|
local pver=${patch[0]-'x'}
|
|
if [ "$pver" == "x" ]; then
|
|
return # it was undefined
|
|
else
|
|
local numpatch=${#patch[@]}
|
|
local i=0
|
|
# Argh! - The C-style for loop doesn't work in bash-2.0.3 as distributed
|
|
# with Solaris 8 :( (it works just fine on Redhat Linux 7.3, bash 2.0.5a)
|
|
# for ((i=0; i < numpatch; i++))
|
|
# do
|
|
# patch $i -p1
|
|
# done
|
|
while [ $i -lt $numpatch ]
|
|
do
|
|
patch $i $patch_prefix
|
|
let i=i+1
|
|
done
|
|
fi
|
|
}
|
|
|
|
# generic_build(): Take the necessary steps to build already prepared source
|
|
# params: $1 = dir to descend to *inside* "source" - optional
|
|
generic_build()
|
|
{
|
|
local my_ac_overrides="$platform_ac_overrides $ac_overrides"
|
|
setdir ${srcdir}/${topsrcdir}/$1
|
|
|
|
if [ $no_configure -eq 0 ]; then
|
|
if [ $generic_configure -eq 1 ]; then
|
|
local acvar
|
|
for acvar in $my_ac_overrides
|
|
do
|
|
export $acvar
|
|
done
|
|
echo $__configure "${configure_args[@]}"
|
|
$__configure "${configure_args[@]}"
|
|
else
|
|
# Platform specific configure run
|
|
run_configure
|
|
fi
|
|
fi
|
|
if [ $? -ne 0 ]; then
|
|
error $E_BAD_CONFIG generic_build
|
|
fi
|
|
${__make} ${make_build_opts} $(_upls $make_build_target)
|
|
if [ $? -ne 0 ]; then
|
|
error $E_BAD_MAKE generic_build
|
|
fi
|
|
}
|
|
|
|
# generic_check(): Run the check target
|
|
# params: $1 = dir to descend to *inside* "source" - optional
|
|
generic_check()
|
|
{
|
|
setdir ${srcdir}/${topsrcdir}/$1
|
|
${__make} -k $(_upls $make_check_target)
|
|
}
|
|
|
|
# generic_build_perl(): Build a perl module from source
|
|
# params: same as generic_build
|
|
# This is based on code ripped out of a RPM specfile generated
|
|
# by cpan2rpm. Someday perhaps cpan2inst will come to exist but
|
|
# until then this is a bit of shortcut for build.sh
|
|
#
|
|
generic_build_perl()
|
|
{
|
|
setdir source
|
|
${__ggrep} -rsl '^#!.*perl' . |
|
|
${__ggrep} -v '.bak$' |${__xargs} --no-run-if-empty \
|
|
${__perl} -MExtUtils::MakeMaker -e 'MY->fixin(@ARGV)'
|
|
${__perl} Makefile.PL `${__perl} -MExtUtils::MakeMaker -e " print qq|PREFIX=${stagedir}${prefix}| if \$ExtUtils::MakeMaker::VERSION =~ /5\.9[1-6]|6\.0[0-5]/ "`
|
|
# Now do the actual build using std. generic_build with no_configure=1
|
|
no_configure=1
|
|
generic_build
|
|
# And a little extra, this is a candidate for inclusion in plain generic_build
|
|
if [ "$maketest" -eq 1 ]; then
|
|
${__make} test
|
|
fi
|
|
}
|
|
|
|
# makeinstall(): Generic make install ripped from rpm
|
|
# params: $@ passed directly to make install
|
|
makeinstall()
|
|
{
|
|
${__make} \
|
|
prefix=${stagedir}${prefix} \
|
|
exec_prefix=${stagedir}${prefix} \
|
|
bindir=${stagedir}${prefix}/${_bindir} \
|
|
sbindir=${stagedir}${prefix}/${_sbindir} \
|
|
sysconfdir=${stagedir}${prefix}/${_sysconfdir} \
|
|
datadir=${stagedir}${prefix}/${_sharedir} \
|
|
includedir=${stagedir}${prefix}/${_includedir} \
|
|
libdir=${stagedir}${prefix}/${_libdir} \
|
|
libexecdir=${stagedir}${prefix}/libexec \
|
|
localstatedir=${stagedir}${prefix}/var \
|
|
sharedstatedir=${stagedir}${prefix}/com \
|
|
mandir=${stagedir}${prefix}/${_mandir} \
|
|
infodir=${stagedir}${prefix}/${_infodir} \
|
|
install $@
|
|
}
|
|
|
|
# generic_install(): Install already built source
|
|
# params: $1 = destvar [$2 = dir to descend to *inside* "source"]
|
|
# destvar is the variable that make should override to install into the staging
|
|
# area. default is DESTDIR, possible common alternatives are prefix and PREFIX
|
|
# If shortroot=1 then we know that the install won't automatically create
|
|
# $prefix inside the stagedir so we have to do it first and add $prefix
|
|
# to the $destvar= argument
|
|
# If $2 is specified then we will descend into that subdir before attempting the install
|
|
generic_install()
|
|
{
|
|
local dest="$stagedir"
|
|
local destvar=${1:-DESTDIR}
|
|
|
|
if [ "$custom_install" -eq 0 ]; then
|
|
clean stage
|
|
[ "$shortroot" -eq 1 ] && dest="${stagedir}${prefix}"
|
|
# Create $dest if it is missing
|
|
if [ ! -d $dest ]; then
|
|
echo "Creating $dest"
|
|
${__mkdir} -p $dest
|
|
fi
|
|
setdir ${srcdir}/${topsrcdir}/$2
|
|
${__make} $(_upls $make_install_target) $destvar=$dest
|
|
if [ $? -ne 0 ]; then
|
|
error $E_BAD_MAKE generic_install
|
|
fi
|
|
fi
|
|
if [ $dostrip -eq 1 ]; then
|
|
do_strip
|
|
fi
|
|
if [ $autonuke -eq 1 ]; then
|
|
do_autonuke
|
|
fi
|
|
# If there are programs that should be linked to $prefix/$_gnudir
|
|
local prog
|
|
for prog in "${gnu_link_progs[@]}"; do
|
|
do_gnu_link ${gnu_prefix}${prog}
|
|
done
|
|
}
|
|
|
|
# generic_install_perl(): Install already built perl module
|
|
# params: none
|
|
# This is based on code ripped out of a RPM specfile generated
|
|
# by cpan2rpm. Someday perhaps cpan2inst will come to exist but
|
|
# until then this is a bit of shortcut for build.sh
|
|
generic_install_perl()
|
|
{
|
|
clean stage
|
|
setdir source
|
|
makeinstall $(${__perl} -MExtUtils::MakeMaker -e " print \$ExtUtils::MakeMaker::VERSION <= 6.05 ? qq|PREFIX=${stagedir}${prefix}| : qq|DESTDIR=${stagedir}| ")
|
|
|
|
# remove special files
|
|
${__find} ${stagedir} -name "perllocal.pod" \
|
|
-o -name ".packlist" \
|
|
-o -name "*.bs" \
|
|
| ${__xargs} -i rm -f {}
|
|
|
|
# no empty directories
|
|
${__find} ${stagedir}${prefix} \
|
|
-type d -depth \
|
|
-exec rmdir {} \; 2>/dev/null
|
|
|
|
export BUILDROOT="$stagedir"
|
|
|
|
${__perl} -MFile::Find -le '
|
|
my $buildroot = $ENV{BUILDROOT};
|
|
find({ wanted => \&wanted, no_chdir => 1}, "$buildroot");
|
|
# No docs here, add them in the usual way but to pkgdef.template
|
|
#print "doc samples Parser Expat Changes README";
|
|
for my $x (sort @dirs, @files) {
|
|
push @ret, $x unless indirs($x);
|
|
}
|
|
print join "\n", sort @ret;
|
|
|
|
sub wanted {
|
|
return if /auto$/;
|
|
|
|
local $_ = $File::Find::name;
|
|
my $f = $_; s|^\Q$buildroot\E||;
|
|
return unless length;
|
|
return $files[@files] = $_ if -f $f;
|
|
|
|
$d = $_;
|
|
/\Q$d\E/ && return for reverse sort @INC;
|
|
# This will expand everything outside the "perl" paths
|
|
# to files. cpan2rpm includes the mandir in this list
|
|
# but that will break buildpkg since they are processed
|
|
# later and the names thus change leaving pkgdef broken
|
|
$d =~ /\Q$_\E/ && return
|
|
for qw|/etc /usr/tgcware/bin /usr/tgcware/share|;
|
|
|
|
$dirs[@dirs] = $_;
|
|
}
|
|
|
|
sub indirs {
|
|
my $x = shift;
|
|
$x =~ /^\Q$_\E\// && $x ne $_ && return 1 for @dirs;
|
|
}
|
|
' > filelist
|
|
|
|
[ -z filelist ] && {
|
|
echo "ERROR: empty %files listing"
|
|
exit -1
|
|
}
|
|
# For handling any doc lines in the filelist, disabled for now (see above)
|
|
#eval $(${__grep} '^doc' filelist)
|
|
|
|
# To get stripping etc we call the regular generic_install now but with custom_install=1
|
|
custom_install=1
|
|
generic_install
|
|
}
|
|
|
|
# generic_pack(): Build package using files from 'install' stage
|
|
# params: $1 - indicating whether or not the root is complete as described below
|
|
# We expect generic_install to have made $stagedir the "root" dir
|
|
# in that all paths below will be complete (ie. /usr/local/bin and not
|
|
# just bin).
|
|
#
|
|
# This function should be implemented in the pr. packaging system
|
|
# function library.
|
|
case $OSTYPE in
|
|
solaris*) . $buildpkgscripts/buildpkg.packaging.solaris
|
|
;;
|
|
irix*) . $buildpkgscripts/buildpkg.packaging.irix
|
|
;;
|
|
*) echo "No packaging system function library available for this OS"
|
|
;;
|
|
esac
|
|
|
|
# generic_pack_perl(): Package a perl module
|
|
# params: same as generic_pack
|
|
# This is just a small wrapper which generates the pkgdef file
|
|
# from pkgdef.template and the filelist in the sourcetree generated
|
|
# by generic_install_perl.
|
|
generic_pack_perl()
|
|
{
|
|
${__cat} $metadir/pkgdef.template $srcdir/$topsrcdir/filelist | ${__sed} -e "s;^$prefix/;;g" > $metadir/pkgdef
|
|
generic_pack "$@"
|
|
}
|
|
|
|
# vim: set filetype=sh : #
|
|
# vim: set sts=4 : #
|
|
# vim: set shiftwidth=4 : #
|