Misc fixes and a few additional features added
Moved all helper functions in front of the generic ones
This commit is contained in:
parent
df081b7907
commit
8a2bd4a614
@ -43,7 +43,7 @@ SED=/usr/bin/sed
|
||||
|
||||
# Define defaults
|
||||
buildpkgbase=${HOME}/buildpkg
|
||||
stagedir=$buildpkgbase/$topdir/build
|
||||
stagedir=$buildpkgbase/$topdir/stage
|
||||
srcdir=$buildpkgbase/$topdir/src
|
||||
metadir=$buildpkgbase/$topdir/meta
|
||||
distdir=$buildpkgbase/distfiles
|
||||
@ -60,7 +60,7 @@ os=sol`$UNAME -r`
|
||||
pkgdirdesig=${topinstalldir##/*/} # topinstalldir suffix
|
||||
|
||||
# Distfiles should be named like this
|
||||
# <name>-<version>-<pkgver>-sb-<os>-<cpu>-<pkgdirdesig>
|
||||
# <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
|
||||
|
||||
@ -76,6 +76,7 @@ E_BAD_CONFIG=37
|
||||
E_BAD_MAKE=38
|
||||
E_BAD_CLEANOPTIONS=39
|
||||
E_BAD_STRIP=40
|
||||
E_BAD_ARGS=41
|
||||
|
||||
error_txt[$E_BAD_FILE]="File not found"
|
||||
error_txt[$E_PATCH_FAILED]="Patch failed"
|
||||
@ -85,11 +86,12 @@ 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"
|
||||
|
||||
#
|
||||
#####################################################
|
||||
# Helper functions
|
||||
#
|
||||
#
|
||||
#####################################################
|
||||
|
||||
# error(): exit with errorcode and possibly a message
|
||||
# params: $1 = errorcode $2 = name of caller
|
||||
error()
|
||||
@ -130,8 +132,8 @@ setdir()
|
||||
patch()
|
||||
{
|
||||
local pnum=$1
|
||||
local p2=$2
|
||||
local pparam=${p2:-"-p1"}
|
||||
local arg2=$2
|
||||
local pparam=${arg2:-"-p1"}
|
||||
|
||||
setdir source
|
||||
|
||||
@ -191,7 +193,7 @@ unpack()
|
||||
}
|
||||
|
||||
# clean(): Scrub build environment
|
||||
# params: $1=stage|source
|
||||
# params: $1=stage|source|distclean
|
||||
clean()
|
||||
{
|
||||
case $1 in
|
||||
@ -208,6 +210,15 @@ clean()
|
||||
error $E_BAD_DIR clean
|
||||
fi
|
||||
;;
|
||||
'meta') $RM -f $metadir/prototype*
|
||||
$RM -f $metadir/pkginfo
|
||||
$RM -rf $buildpkgbase/$topdir/$pkgname
|
||||
;;
|
||||
|
||||
'distclean') clean source
|
||||
clean stage
|
||||
clean meta
|
||||
;;
|
||||
*) error $E_BAD_CLEANOPTION clean
|
||||
esac
|
||||
}
|
||||
@ -225,9 +236,85 @@ strip()
|
||||
# if
|
||||
}
|
||||
|
||||
|
||||
# make_pkg(): Create the final package
|
||||
# params: none
|
||||
#
|
||||
make_pkg()
|
||||
{
|
||||
$PKGMK -r `pwd` -d $buildpkgbase/$topdir -o -f $metadir/prototype
|
||||
$PKGTRANS -o -s $buildpkgbase/$topdir $distdir/$distfile $pkgname
|
||||
}
|
||||
|
||||
# pack_info(): Create the pkginfo file
|
||||
# params: none
|
||||
# Will create the pkginfo file with pkginfo.in as a template
|
||||
# Both the template and the result will be in $metadir
|
||||
# Substitutions will be done on pkgname,version & pkgver
|
||||
# they will be replaced with the value of their variable counterparts
|
||||
pack_info()
|
||||
{
|
||||
$SED -e "s#%%pkgname%%#$pkgname#g" \
|
||||
-e "s#%%version%%#$version#g" \
|
||||
-e "s#%%pkgver%%#$pkgver#g" \
|
||||
$metadir/pkginfo.in > $metadir/pkginfo
|
||||
}
|
||||
|
||||
# prototype(): Create a prototype file for pkgmk
|
||||
# params: $1 = owner $2 = group $3 = [script|noscript]
|
||||
# $1 & $2 will list the owner and group that is to be applied to all files
|
||||
# pkginfo and depend (if it exists) will automatically be added to prototype file
|
||||
# $3 will define whether or not to automatically include any post/pre scripts found
|
||||
# in $topdir/meta. Pr. default postinstall,preinstall,postremove,preremove are the filenames
|
||||
# it will look for.
|
||||
# $3 can be omitted and in that case prototype will behave as if $3=noscript
|
||||
prototype()
|
||||
{
|
||||
local owner=$1
|
||||
local group=$2
|
||||
|
||||
$FIND . -print|$PKGPROTO > $metadir/prototype.in
|
||||
$CAT $metadir/prototype.in | $AWK -v owner="$owner" -v group="$group" \
|
||||
'{ $5=owner; $6=group; print; }' > $metadir/prototype
|
||||
|
||||
add_meta_file pkginfo "$metadir/pkginfo"
|
||||
|
||||
# If a dependency file is available then use it
|
||||
[ -r $metadir/depend ] && add_meta_file depend "$metadir/depend"
|
||||
|
||||
case $3 in
|
||||
'script') [ -r $metadir/preinstall ] && add_meta_file preinstall "$metadir/preinstall"
|
||||
[ -r $metadir/postinstall ] && add_meta_file postinstall "$metadir/postinstall"
|
||||
[ -r $metadir/preremove ] && add_meta_file preremove "$metadir/preremove"
|
||||
[ -r $metadir/postremove ] && add_meta_file postremove "$metadir/postremove"
|
||||
;;
|
||||
'noscript') ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# add_meta_file(): add a metafile entry to the prototype file
|
||||
# params: $1 = keyword $2 = filename
|
||||
# Additions will be done to the file $metadir/prototype
|
||||
add_meta_file()
|
||||
{
|
||||
local arg1=${1-'x'}
|
||||
if [ "$arg1" == "x" ]; then
|
||||
error $E_MISSING_ARGS add_meta_file
|
||||
fi
|
||||
local arg2=${2-'x'}
|
||||
if [ "$arg2" == "x" ]; then
|
||||
error $E_MISSING_ARGS add_meta_file
|
||||
fi
|
||||
if [ -r "$arg2" ]; then
|
||||
echo "i $arg1=$arg2" >> $metadir/prototype
|
||||
else
|
||||
error $E_BAD_FILE add_meta_file
|
||||
fi
|
||||
}
|
||||
|
||||
#####################################################
|
||||
# Define generic functions for different build stages
|
||||
#
|
||||
#####################################################
|
||||
|
||||
# generic_prep(): Unpack source and apply any patches
|
||||
# params: none
|
||||
@ -274,12 +361,19 @@ generic_build()
|
||||
}
|
||||
|
||||
# generic_install(): Install already built source
|
||||
# params: none
|
||||
# params: $1 = destvar
|
||||
# destvar is the variable that make should override to install into the staging
|
||||
# area. default is DESTDIR, possible common alternatives are prefix and PREFIX
|
||||
generic_install()
|
||||
{
|
||||
local destvar=DESTDIR
|
||||
local arg1=${1-'x'}
|
||||
if [ "$arg1" != "x" ]; then
|
||||
destvar=$arg1 # $1 was defined
|
||||
fi
|
||||
clean stage
|
||||
setdir source
|
||||
$MAKE_PROG DESTDIR=$stagedir install
|
||||
$MAKE_PROG $destvar=$stagedir install
|
||||
if [ $? -ne 0 ]; then
|
||||
error $E_BAD_MAKE generic_install
|
||||
fi
|
||||
@ -293,84 +387,17 @@ generic_install()
|
||||
# just bin) *unless* $1=shortroot.
|
||||
generic_pack()
|
||||
{
|
||||
clean meta
|
||||
# Verify if $1 is defined
|
||||
local arg1=${1-'x'}
|
||||
if [ "$arg1" == "x" ]; then
|
||||
setdir "$stagedir$prefix" # it was undefined
|
||||
else
|
||||
setdir "$stagedir"
|
||||
fi
|
||||
case $arg1 in
|
||||
'x') setdir "$stagedir$prefix" # arg1 was undefined
|
||||
;;
|
||||
'shortroot') setdir "$stagedir"
|
||||
;;
|
||||
'*') error $E_BAD_ARGS generic_pack
|
||||
esac
|
||||
pack_info
|
||||
prototype root bin
|
||||
prototype root bin script
|
||||
make_pkg
|
||||
}
|
||||
|
||||
# make_pkg(): Create the final package
|
||||
# params: none
|
||||
#
|
||||
make_pkg()
|
||||
{
|
||||
$PKGMK -r `pwd` -d $buildpkgbase/$topdir -o -f $metadir/prototype
|
||||
$PKGTRANS -o -s $buildpkgbase/$topdir $distdir/$distfile $pkgname
|
||||
}
|
||||
|
||||
# pack_info(): Create the pkginfo file
|
||||
# params: none
|
||||
# Will create the pkginfo file with pkginfo.in as a template
|
||||
# Both the template and the result will be in $metadir
|
||||
# Substitutions will be done on pkgname,version & pkgver
|
||||
# they will be replaced with the value of their variable counterparts
|
||||
pack_info()
|
||||
{
|
||||
$SED -e "s#%%pkgname%%#$pkgname#g" \
|
||||
-e "s#%%version%%#$version#g" \
|
||||
-e "s#%%pkgver%%#$pkgver#g" \
|
||||
$metadir/pkginfo.in > $metadir/pkginfo
|
||||
}
|
||||
|
||||
# prototype(): Create a prototype file for pkgmk
|
||||
# params: $1 = owner $2 = group $3 = [script|noscript]
|
||||
# $1 & $2 will list the owner and group that is to be applied to all files
|
||||
# $3 will define whether or not to automatically include any post/pre scripts found
|
||||
# in $topdir/meta. Pr. default postinstall,preinstall,postremove,preremove are the filenames
|
||||
# it will look for.
|
||||
prototype()
|
||||
{
|
||||
local owner=$1
|
||||
local group=$2
|
||||
|
||||
$FIND . -print|$PKGPROTO > $metadir/prototype.in
|
||||
$CAT $metadir/prototype.in | $AWK -v owner="$owner" -v group="$group" \
|
||||
'{ $5=owner; $6=group; print; }' > $metadir/prototype
|
||||
|
||||
add_meta_file pkginfo "$metadir/pkginfo"
|
||||
|
||||
case $3 in
|
||||
'script') [ -r $metadir/preinstall ] && add_meta_file preinstall "$metadir/preinstall"
|
||||
[ -r $metadir/postinstall ] && add_meta_file postinstall "$metadir/postinstall"
|
||||
[ -r $metadir/preremove ] && add_meta_file preremove "$metadir/preremove"
|
||||
[ -r $metadir/postremove ] && add_meta_file postremove "$metadir/postremove"
|
||||
;;
|
||||
'noscript') ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# add_meta_file(): add a metafile entry to the prototype file
|
||||
# params: $1 = keyword $2 = filename
|
||||
# Additions will be done to the file $metadir/prototype
|
||||
add_meta_file()
|
||||
{
|
||||
local arg1=${1-'x'}
|
||||
if [ "$arg1" == "x" ]; then
|
||||
error $E_MISSING_ARGS add_meta_file
|
||||
fi
|
||||
local arg2=${2-'x'}
|
||||
if [ "$arg2" == "x" ]; then
|
||||
error $E_MISSING_ARGS add_meta_file
|
||||
fi
|
||||
if [ -r "$arg2" ]; then
|
||||
echo "i $arg1=$arg2" >> $metadir/prototype
|
||||
else
|
||||
error $E_BAD_FILE add_meta_file
|
||||
fi
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user