Changes to bldpkg:
-> Fixed identation in help() -> Fixed code in validatemakeflags function -> Added 'local' in several functions -> Moved randomnum inside compilertestfile function -> Removed return command in runtime function -> Added -f option to ln command and added code to unset OPTIND and OPTARG in preprunitservice function -> Removed $pkg in several test cases in mkfinalpkg because the PWD is already known -> Added a directory test before discarding libtool files -> Added code to discard lib/charset.alias and empty lib directory -> Added code to export MAKEFLAGS along with other compiler variables
This commit is contained in:
parent
cd0a82d4b1
commit
b4fea8960e
1 changed files with 60 additions and 52 deletions
112
bldpkg
112
bldpkg
|
@ -97,8 +97,8 @@ Usage:
|
|||
|
||||
-r Resume the build by skipping all commands in prepbuilddir and execute
|
||||
build() function. Presumes that the package was completely extracted
|
||||
in the build directory, and patches, if any, were applied and executes
|
||||
stuff inside build().
|
||||
in the build directory, and patches, if any, were applied and executes
|
||||
stuff inside build().
|
||||
|
||||
-s Display build summary. A summary is produced whenever a build is either
|
||||
interrupted, exits cleanly or aborts due to a build error
|
||||
|
@ -116,8 +116,7 @@ exit 0
|
|||
|
||||
# Function to validate the build file.
|
||||
validatebldfile() {
|
||||
local buildfile
|
||||
buildfile="$1"
|
||||
local buildfile="$1"
|
||||
|
||||
if [[ ! -f $buildfile ]] ; then
|
||||
err "No build file to validate from!"
|
||||
|
@ -165,15 +164,16 @@ Try -f <build_file> if your build file has a different name (Not recommended)"
|
|||
|
||||
validatemakeflags() {
|
||||
local makeflags="$1"
|
||||
if ! echo "$makeflags" | grep -E -q '^[0-9]+$' ; then
|
||||
err "Invalid MAKEFLAGS '$makeflags'!"
|
||||
local makeflags0="${makeflags/-j/}"
|
||||
if ! echo "$makeflags0" | grep -E -q '^[0-9]+$' ; then
|
||||
err "Invalid MAKEFLAGS '$makeflags0'!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function for applying patches to the build in a more efficient manner
|
||||
applypatch() {
|
||||
# Take patch file name as the first argument
|
||||
patchfile="$1"
|
||||
local patchfile="$1"
|
||||
|
||||
# Perform a simple check
|
||||
if [[ -z $patchfile ]] ; then
|
||||
|
@ -183,7 +183,7 @@ applypatch() {
|
|||
fi
|
||||
|
||||
# Get relative path of the patch file
|
||||
relativepath=${patchfile##*/}
|
||||
local relativepath=${patchfile##*/}
|
||||
info "Applying patch '$relativepath'.."
|
||||
# We use if/else to determine if the patch applied successfully
|
||||
if ! patch -p1 < "$patchfile" ; then
|
||||
|
@ -206,8 +206,8 @@ inarray() {
|
|||
compileonlyfor() {
|
||||
# usage: compileonlyfor <arch>
|
||||
# will cause compilation to exit with 0 if uname -m does not match <arch>
|
||||
archname="$(uname -m)"
|
||||
archargument="$1"
|
||||
local archname="$(uname -m)"
|
||||
local archargument="$1"
|
||||
|
||||
if [[ $archname != $archargument ]]; then
|
||||
info "'$app' not supported on '$archname' and hence not not being built. Exiting."
|
||||
|
@ -218,21 +218,28 @@ compileonlyfor() {
|
|||
# Function to validate compilers.
|
||||
# Usage: compilertestfile "$CC" "$CFLAGS" cc-test.c cc-test
|
||||
compilertestfile() {
|
||||
compileraddonflags="-O0 -Werror -static"
|
||||
compiler="$1"
|
||||
compilerflags="$2"
|
||||
compilerfile="$3"
|
||||
compileroutput="$4"
|
||||
local compileraddonflags="-O0 -Werror -static"
|
||||
local compiler="$1"
|
||||
local compilerflags="$2"
|
||||
local compilerfile="$3"
|
||||
local compileroutput="$4"
|
||||
|
||||
printf "[INFO] Validating compiler '$compiler'... "
|
||||
|
||||
# Inside a function, validate the compilers that have been set as CC and CXX in bldpkg.conf
|
||||
# A small C/CXX program is being used to print a random number
|
||||
|
||||
# Generate a random number using shuf. We'll output this same number inside the C/CXX program.
|
||||
# If the numbers match, the compiler looks sane, else error out.
|
||||
local randomnum="$(shuf -i 100-9999 -n1)"
|
||||
|
||||
cat << EOF > "$parenttmp/$compilerfile"
|
||||
#include <stdio.h>
|
||||
int main() { printf("$randomnum\n"); }
|
||||
EOF
|
||||
|
||||
$compiler $compilerflags -o "$parenttmp/$compileroutput" $compileraddonflags "$parenttmp/$compilerfile"
|
||||
finaloutput="$($parenttmp/$compileroutput)"
|
||||
local finaloutput="$($parenttmp/$compileroutput)"
|
||||
|
||||
# Error out if the outputs don't match
|
||||
if [[ $finaloutput != $randomnum ]] ;then
|
||||
|
@ -246,7 +253,7 @@ EOF
|
|||
# Function to start/stop sccache.
|
||||
# Usage: sccache start/stop
|
||||
sccacheprocess() {
|
||||
sccacheopt="$1"
|
||||
local sccacheopt="$1"
|
||||
if [[ $sccache = 1 ]]; then
|
||||
if [[ $sccacheopt = "start" ]] ; then
|
||||
# Check whether sccache is running on TCP port 4226 via nc
|
||||
|
@ -297,7 +304,6 @@ fixbuilddirpermissions() {
|
|||
# environment variable set by bash to show the number of whole seconds the shell has been running.
|
||||
runtime() {
|
||||
timer="$1"
|
||||
[[ -z $timer ]] && return 1
|
||||
|
||||
local day=$(( timer / 86400 ))
|
||||
local hour=$(( (timer - (day * 86400)) / 3600 ))
|
||||
|
@ -309,8 +315,6 @@ runtime() {
|
|||
else
|
||||
echo -n "${hour}h, ${mins}m ${secs}s"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
preprunitservice() {
|
||||
|
@ -327,18 +331,21 @@ preprunitservice() {
|
|||
install -Dm 755 "$srcdir/$servicefile.run" "$pkg/etc/service/$servicefile/run"
|
||||
(
|
||||
cd $pkg
|
||||
ln -s "../../etc/service/$servicefile" "var/service/$service"
|
||||
ln -sf "../../etc/service/$servicefile" "var/service/$service"
|
||||
)
|
||||
|
||||
[[ -n $downfile ]] && touch "$pkg/etc/service/$servicefile/down"
|
||||
[[ -n $finishfile ]] && touch "$pkg/etc/service/$servicefile/finish"
|
||||
|
||||
# Unset OPTIND and OPTARG to avoid problems if getopts is used again in the future
|
||||
unset OPTIND OPTARG
|
||||
}
|
||||
|
||||
# Function to validate symlinks.
|
||||
# Usage: checkcompilersymlink symlink symlink_target
|
||||
checkcompilersymlink() {
|
||||
symlinkdir="$1"
|
||||
symlinktgt="$2"
|
||||
local symlinkdir="$1"
|
||||
local symlinktgt="$2"
|
||||
|
||||
for compiler in gcc g++ cc c++ ; do
|
||||
if [[ -e $symlinkdir/$compiler ]] && [[ -L $symlinkdir/$compiler ]]; then
|
||||
|
@ -420,7 +427,7 @@ interruptoutput() {
|
|||
wasinterrupted="1"
|
||||
|
||||
# Restore terminal colours
|
||||
echo -e $colourd
|
||||
echo -e "$colourd"
|
||||
|
||||
# Terminate sccache
|
||||
sccacheprocess stop
|
||||
|
@ -453,7 +460,7 @@ mkfinalpkg() {
|
|||
info "Performing packaging tasks..."
|
||||
|
||||
# Check if /lib64 was created inside $pkg
|
||||
if [[ -d $pkg/lib64 ]] ; then
|
||||
if [[ -d lib64 ]] ; then
|
||||
err "'$app' has /lib64 directory within the staging directory. Musl does not support multilib.
|
||||
Please fix the build options and ensure the /lib64 is not created."
|
||||
fi
|
||||
|
@ -462,7 +469,7 @@ Please fix the build options and ensure the /lib64 is not created."
|
|||
# of its build file. Ignore their existence if $ignoreusr is set to 1 in the pkg build file
|
||||
if [[ -z $ignoreusr ]] ; then
|
||||
for directory in usr sbin ; do
|
||||
if [[ -d $pkg/$directory ]] ; then
|
||||
if [[ -d $directory ]] ; then
|
||||
err "'$app' has '$directory' directory within the staging directory which is a symlink to /bin on SMLinux.
|
||||
Please fix the build options and ensure '$directory' is not created"
|
||||
fi
|
||||
|
@ -471,29 +478,29 @@ Please fix the build options and ensure '$directory' is not created"
|
|||
|
||||
info "Copying post-install files..."
|
||||
|
||||
[[ -e $srcdir/doinst.sh ]] && cp "$srcdir/doinst.sh" "$pkg/install/"
|
||||
[[ -e $srcdir/doinst.sh ]] && cp "$srcdir/doinst.sh" "install/"
|
||||
|
||||
# If /share/applications directory exists but there is no doinst.sh in the source directory, create one using cat
|
||||
if [[ -d $pkg/share/applications ]] && [[ ! -e $srcdir/doinst.sh ]] ; then
|
||||
if [[ -d share/applications ]] && [[ ! -e $srcdir/doinst.sh ]] ; then
|
||||
info "Found /share/applications but couldn't find any doinst.sh in the source directory.
|
||||
Creating one automatically that refreshes GTK cache."
|
||||
cat << EOF >> "$pkg/install/doinst.sh"
|
||||
cat << EOF >> "install/doinst.sh"
|
||||
[[ -x /etc/rc.d/rc.gtk ]] && /etc/rc.d/rc.gtk
|
||||
EOF
|
||||
|
||||
# Or if /share/applications directory exists, and there is a doinst.sh file in the source directory, but there is no mention of rc.gtk, then too create one using cat
|
||||
elif [[ -d $pkg/share/applications ]] && [[ -e $srcdir/doinst.sh ]] && ! grep -q 'rc.gtk' "$srcdir/doinst.sh" ; then
|
||||
elif [[ -d share/applications ]] && [[ -e $srcdir/doinst.sh ]] && ! grep -q 'rc.gtk' "$srcdir/doinst.sh" ; then
|
||||
info "Found /share/applications but couldn't find any rc.gtk lines inside doinst.sh in the source directory.
|
||||
Creating one automatically that refreshes GTK cache."
|
||||
cat << EOF >> "$pkg/install/doinst.sh"
|
||||
cat << EOF >> "install/doinst.sh"
|
||||
[[ -x /etc/rc.d/rc.gtk ]] && /etc/rc.d/rc.gtk
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Compress and link manpages
|
||||
if [[ -d $pkg/share/man ]]; then
|
||||
if [[ -d share/man ]]; then
|
||||
info "Compressing and linking man pages..."
|
||||
( cd "$pkg/share/man"
|
||||
( cd "share/man"
|
||||
for manpagedir in $(find . -type d -name "man*") ; do
|
||||
( cd $manpagedir
|
||||
for eachpage in $( find . -type l -maxdepth 1) ; do
|
||||
|
@ -507,8 +514,10 @@ EOF
|
|||
fi
|
||||
|
||||
# Remove libtool archive files
|
||||
info "Discarding any libtool archive (.la) files..."
|
||||
find "$pkg" -type f -name "*.la" -exec rm -v {} \;
|
||||
if [[ -d lib ]] ; then
|
||||
info "Discarding any libtool archive (.la) files..."
|
||||
find "$pkg" -type f -name "*.la" -exec rm -v {} \;
|
||||
fi
|
||||
|
||||
# Provide a copy of the package build file as a source of reference for users
|
||||
if [[ -n $origbuildfile ]] && [[ -f $srcdir/$origbuildfile ]] ; then
|
||||
|
@ -565,6 +574,18 @@ EOF
|
|||
fi
|
||||
fi
|
||||
|
||||
# Discard install directory if it's empty but don't error out
|
||||
rmdir --ignore-fail-on-non-empty install
|
||||
|
||||
# Discard charset.alias
|
||||
if [[ -f lib/charset.alias ]] ; then
|
||||
info "Discarding charset.alias"
|
||||
rm lib/charset.alias
|
||||
fi
|
||||
|
||||
# Also discard the lib directory if it's empty but don't error out
|
||||
rmdir --ignore-fail-on-non-empty lib
|
||||
|
||||
tar cvf - . --format gnu \
|
||||
--xform 'sx^\./\(.\)x\1x' \
|
||||
--show-stored-names | "$compressor" "$compressoropts" > "$newpkglocation"
|
||||
|
@ -639,7 +660,6 @@ buildfilecleanup() {
|
|||
|
||||
|
||||
prepbuildoutput() {
|
||||
|
||||
# Get the build completion time and store it in a variable
|
||||
finishdate=$(date '+%a, %d %b %Y, %T')
|
||||
|
||||
|
@ -690,7 +710,7 @@ prepbuildoutput() {
|
|||
# If distcc was used, cut out --randomize and output rest of the DISTCC_HOSTS variable
|
||||
distccvar=$(echo "$DISTCC_HOSTS" | sed 's@--randomize@@')
|
||||
distccstats="Yes, $distccvar"
|
||||
# Else If distcc is unset, set distccstats in the build summary
|
||||
# Else if distcc is unset, set distccstats in the build summary
|
||||
elif [[ -z $distcc ]] || [[ $distcc = 0 ]]; then
|
||||
distccstats="No, disabled"
|
||||
fi
|
||||
|
@ -757,10 +777,8 @@ prepbuildoutput() {
|
|||
|
||||
elif [[ $wasinterrupted = 1 ]]; then
|
||||
bldstatus="$coloury ** INTERRUPTED ** :-/ $colourd"
|
||||
|
||||
else
|
||||
bldstatus="$colourr !! FAILED !! :-( $colourd"
|
||||
|
||||
fi
|
||||
|
||||
# Finally prepare the summary
|
||||
|
@ -812,7 +830,6 @@ EOF
|
|||
|
||||
# Prompt user for extracting/installing the package if the build has succeeded
|
||||
promptuser
|
||||
|
||||
}
|
||||
|
||||
# Then source the configuration file holding all values
|
||||
|
@ -880,7 +897,7 @@ elif [[ $OPTIND -gt 1 ]] ; then
|
|||
|
||||
# If MAKEFLAGS and custommakeflags is set, let custommakeflags take precedence
|
||||
if [[ -n $custommakeflags ]] ; then
|
||||
validatemakeflags $custommakeflags
|
||||
validatemakeflags $custommakeflags
|
||||
MAKEFLAGS="-j$custommakeflags"
|
||||
|
||||
elif [[ -n $MAKEFLAGS ]] ; then
|
||||
|
@ -890,9 +907,7 @@ elif [[ $OPTIND -gt 1 ]] ; then
|
|||
# Or fetch the number from nproc
|
||||
MAKEFLAGS="-j$(nproc --all)"
|
||||
fi
|
||||
export MAKEFLAGS
|
||||
|
||||
|
||||
# If $origbuildfile is set and is a file, check if $setbuildfile and $origbuildfile are the same
|
||||
if [[ -n $origbuildfile ]] ; then
|
||||
if [[ ! -f $origbuildfile ]] ; then
|
||||
|
@ -1178,16 +1193,9 @@ elif [[ -n $debug ]]; then
|
|||
fi
|
||||
|
||||
CXXFLAGS="$CFLAGS"
|
||||
export hostdist builddist CC CXX CFLAGS CXXFLAGS
|
||||
export hostdist builddist CC CXX CFLAGS CXXFLAGS MAKEFLAGS
|
||||
|
||||
# Inside a function, validate the compilers that have been set as CC and CXX in bldpkg.conf
|
||||
# A small C/CXX program is being used to print a random number
|
||||
|
||||
# Generate a random number using shuf. We'll output this same number inside the C/CXX program.
|
||||
# If the numbers match, the compiler looks sane, else error out.
|
||||
randomnum="$(shuf -i 100-9999 -n1)"
|
||||
|
||||
# Quotes are important while passing C/CXXFLAGS
|
||||
# Validate available compilers. Quotes are important while passing C/CXXFLAGS
|
||||
compilertestfile "$CC" "$CFLAGS" cc-test.c cc-test
|
||||
compilertestfile "$CXX" "$CXXFLAGS" cxx-test.cpp cxx-test
|
||||
|
||||
|
|
Loading…
Reference in a new issue