Changes to bldpkg:
-> Added version number to the script -> Added double quotes next to variable values in few places -> Discarded buggy code that validated the download variable for a sane URL -> Removed double quotes inside [[ ]] since it is safe to do so in bash -> Optimised code responsible for extracting hosts in DISTCC_HOSTS variable -> netcat binary now checks for a running sccache server on localhost -> Added code to check if CC and CXX variables are populated -> Added back ignoreusr variable -> Discarded code that checked and moved the documentation directory in its proper place in the staging directory -> Discarded code that moved pkgconfig directory from share to lib -> Discarded code that checked for ELF objects in the build directory before any action was performed using mkfinalpkg in the staging directory
This commit is contained in:
parent
03da9ec93f
commit
17c70a05c1
1 changed files with 40 additions and 81 deletions
121
bldpkg
121
bldpkg
|
@ -3,6 +3,7 @@
|
|||
# Part of the SMLinux distribution
|
||||
# http://git.pktsurf.in/smlinux
|
||||
#
|
||||
# /bin/bldpkg version 0.1
|
||||
# Bash script to build SMLinux-specific packages
|
||||
#
|
||||
# Copyright (c) 2022-2023 PktSurf <smlinux@pktsurf.in>
|
||||
|
@ -133,7 +134,7 @@ fi
|
|||
# Function to validate the build file.
|
||||
validatebldfile() {
|
||||
local buildfile
|
||||
buildfile=$1
|
||||
buildfile="$1"
|
||||
|
||||
if [[ ! -f $buildfile ]] ; then
|
||||
err "No build file to validate from!"
|
||||
|
@ -151,17 +152,6 @@ validatebldfile() {
|
|||
elif ! grep -E -q '^homepage="\(https|http||ftp)://' "$buildfile" ; then
|
||||
err "Invalid URL in the 'homepage' variable in the build file."
|
||||
|
||||
# Validate $download, first the URL type
|
||||
#elif grep -E -q '^download=' "$buildfile" ; then
|
||||
# if ! grep -E -q '^download="\(http|https|ftp)://' "$buildfile" ; then
|
||||
# err "Invalid URL in the 'download' variable in the build file."
|
||||
# fi
|
||||
|
||||
# Then check for single quotes
|
||||
# if grep -E -q "^download='*'" "$buildfile" ; then
|
||||
# err "Single quotes disallowed in the 'download' variable in the build file"
|
||||
# fi
|
||||
|
||||
# Validate $desc using bash shell's ability to count variable length
|
||||
elif [[ ${#desc} -gt 100 ]] ; then
|
||||
err "Package description should not exceed 100 characters in the build file."
|
||||
|
@ -252,7 +242,7 @@ elif [[ $OPTIND -gt 1 ]] ; then
|
|||
err "Original build file '$origbuildfile' does not exist!"
|
||||
|
||||
elif [[ -n $setbuildfile ]] && [[ -f $setbuildfile ]] ; then
|
||||
if [[ $origbuildfile = "$setbuildfile" ]] ; then
|
||||
if [[ $origbuildfile = $setbuildfile ]] ; then
|
||||
err "Original build file and alternate build file are the same!"
|
||||
fi
|
||||
|
||||
|
@ -275,7 +265,7 @@ elif [[ $OPTIND -gt 1 ]] ; then
|
|||
err "Build file '$setbuildfile' not found!"
|
||||
|
||||
# If the above two conditions don't meet, get the presumed $buildfile value as a file and source it
|
||||
elif [[ -f "$buildfile" ]] ; then
|
||||
elif [[ -f $buildfile ]] ; then
|
||||
if ! validatebldfile "$buildfile" ; then
|
||||
err "'$buildfile' validation failed!"
|
||||
else
|
||||
|
@ -477,8 +467,8 @@ fi
|
|||
# declare a variable for the build summary.
|
||||
if [[ $usetmpfs = 1 ]] && [[ -n $tmpfsdir ]]; then
|
||||
if [[ ! -d $tmpfsdir ]] || ! touch "$tmpfsdir/.smlinuxtmpwritetest" \
|
||||
|| [[ $(findmnt -no TARGET "$tmpfsdir") != "$tmpfsdir" ]] \
|
||||
|| [[ $(findmnt -no FSTYPE "$tmpfsdir") != "tmpfs" ]]; then
|
||||
|| [[ $(findmnt -no TARGET $tmpfsdir) != $tmpfsdir ]] \
|
||||
|| [[ $(findmnt -no FSTYPE $tmpfsdir) != tmpfs ]]; then
|
||||
tmpfscheckfailed=1
|
||||
fi
|
||||
|
||||
|
@ -579,9 +569,9 @@ validatecompiler() {
|
|||
|
||||
# Function called as: validatecompiler distcc $distccsympath $f
|
||||
if [[ $validatecompilers = 1 ]] ; then
|
||||
compiler=$1
|
||||
compilerpath=$2
|
||||
maincompiler=$3
|
||||
compiler="$1"
|
||||
compilerpath="$2"
|
||||
maincompiler="$3"
|
||||
randomnum=$(shuf -i 100-999 -n1)
|
||||
|
||||
echo "Validating $compiler compiler... "
|
||||
|
@ -627,7 +617,7 @@ Kindly create it and create symlinks based on instructions in bldpkg.conf!"
|
|||
for f in gcc g++ cc c++ ; do
|
||||
if [[ -e $distccsympath/$f ]] && [[ -L $distccsympath/$f ]]; then
|
||||
# We use "realpath" to follow the $distccsympath/$f symlink and act on the exit code.
|
||||
if [[ $(realpath -e "$distccsympath/$f") != "$distccbinpath" ]] ; then
|
||||
if [[ $(realpath -e $distccsympath/$f) != $distccbinpath ]] ; then
|
||||
err "'$distccsympath/$f' does not point to '$distccbinpath'. Kindly fix this!"
|
||||
fi
|
||||
else
|
||||
|
@ -636,7 +626,6 @@ Kindly create it and create symlinks based on instructions in bldpkg.conf!"
|
|||
fi
|
||||
|
||||
validatecompiler distcc $distccsympath $f
|
||||
|
||||
done
|
||||
|
||||
# If distcc=0 is set in the package build file to disable distcc, remove the value of $distccsympath from
|
||||
|
@ -651,7 +640,7 @@ Kindly create it and create symlinks based on instructions in bldpkg.conf!"
|
|||
warn "nc does not exist! Ignoring this..."
|
||||
else
|
||||
# Remove the common options along with the slash and the numbers after it
|
||||
hosts=$(echo "$DISTCC_HOSTS" | sed -e 's@/[a-z0-9]*@@g' -e 's@--randomize@@' -e 's@localhost@@' -e 's@,lzo@@g')
|
||||
hosts=$(echo "$DISTCC_HOSTS" | sed -e 's@/[a-z0-9,]*@@g' -e 's@--randomize@@' -e 's@localhost@@')
|
||||
for host in ${hosts[@]} ; do
|
||||
# We only run distccd on TCP port 3632
|
||||
if ! /bin/nc -z -w 1 "$host" 3632 > /dev/null 2>&1 ; then
|
||||
|
@ -676,7 +665,7 @@ if [[ $globalccache = 1 ]]; then
|
|||
Either ensure ccache is in your $PATH or disable this option in bldpkg.conf."
|
||||
fi
|
||||
|
||||
if [[ ! $(echo "$PATH" | grep "$ccachesympath") ]] ; then
|
||||
if [[ ! $(echo $PATH | grep $ccachesympath) ]] ; then
|
||||
err "'"$ccachesympath"' directory not found in your env PATH"
|
||||
elif [[ ! -d $ccachesympath ]] ; then
|
||||
err "'$ccachesympath' directory containing symlinks to ccache does not exist!
|
||||
|
@ -686,7 +675,7 @@ Kindly create it and create symlinks based on instructions in bldpkg.conf."
|
|||
for f in gcc g++ cc c++ ; do
|
||||
if [[ -e $ccachesympath/$f ]] && [[ -L $ccachesympath/$f ]]; then
|
||||
# We use "realpath" to follow the $ccachesympath/$f symlink and act on the exit code
|
||||
if [[ $(realpath -e "$ccachesympath/$f") != "$ccachebinpath" ]] ; then
|
||||
if [[ $(realpath -e $ccachesympath/$f) != $ccachebinpath ]] ; then
|
||||
err "'$ccachesympath/$f' does not point to '$ccachebinpath'. Kindly fix this!"
|
||||
fi
|
||||
else
|
||||
|
@ -727,7 +716,10 @@ rustc-wrapper = "/bin/sccache"'
|
|||
RUSTC_WRAPPER="$sccachebinpath"
|
||||
export RUSTC_WRAPPER
|
||||
|
||||
/bin/sccache --start-server
|
||||
# Check whether sccache is running on TCP port 4226 via nc
|
||||
if ! nc -z -w 1 localhost 4226 > /dev/null 2>&1 ; then
|
||||
/bin/sccache --start-server
|
||||
fi
|
||||
fi
|
||||
|
||||
# Apply CPU-specific compiler variables defined inside bldpkg.conf
|
||||
|
@ -736,9 +728,16 @@ fi
|
|||
# noarch is set inside initfs, pkgtools, GTK themes and some other stuff.
|
||||
|
||||
# If $arch has not been exported by autobuild or not set in the individual build files that have
|
||||
# arch=noarch, we set our own $HOSTTYPE is only set in the bash shell.
|
||||
# arch=noarch, we set our own. $HOSTTYPE is only set in the bash shell.
|
||||
[[ -z $arch ]] && arch="$HOSTTYPE"
|
||||
|
||||
# Validate declared compiler variables
|
||||
if [[ -z $CC ]] || [[ -z $CXX ]] ; then
|
||||
err "CC / CXX variables not set in bldpkg.conf!"
|
||||
else
|
||||
export CC CXX
|
||||
fi
|
||||
|
||||
if [[ $arch = noarch ]]; then
|
||||
CFLAGS=""
|
||||
export CFLAGS
|
||||
|
@ -805,7 +804,7 @@ compileonlyfor() {
|
|||
archname="$(uname -m)"
|
||||
archargument="$1"
|
||||
|
||||
if [[ $archname != "$archargument" ]]; then
|
||||
if [[ $archname != $archargument ]]; then
|
||||
echo ""
|
||||
echo "[INFO]'$app' not supported on '$archname' and hence not not being built. Exiting."
|
||||
exit 0
|
||||
|
@ -849,7 +848,7 @@ fixbuilddirpermissions() {
|
|||
# Function to calculate elapsed build time. runtime takes the $SECONDS variable as an argument. $SECONDS is an
|
||||
# environment variable set by bash to show the number of whole seconds the shell has been running.
|
||||
runtime() {
|
||||
timer=$1
|
||||
timer="$1"
|
||||
[[ -z $timer ]] && return 1
|
||||
|
||||
local day=$(( timer / 86400 ))
|
||||
|
@ -936,13 +935,15 @@ Please fix the build options and ensure the /lib64 is not created."
|
|||
fi
|
||||
|
||||
# Check if /usr and /sbin were created inside staging directory $pkg
|
||||
# of its build file
|
||||
for directory in usr sbin ; do
|
||||
if [[ -d $pkg/$directory ]] ; then
|
||||
err "'$app' has '$directory' directory within the staging directory which is a symlink to /bin on SMLinux.
|
||||
# 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
|
||||
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
|
||||
done
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
info "Copying post-install files..."
|
||||
|
||||
|
@ -966,7 +967,7 @@ EOF
|
|||
fi
|
||||
|
||||
# Compress and link manpages
|
||||
if [[ -d "$pkg/share/man" ]]; then
|
||||
if [[ -d $pkg/share/man ]]; then
|
||||
info "Compressing and linking man pages..."
|
||||
( cd "$pkg/share/man"
|
||||
for manpagedir in $(find . -type d -name "man*") ; do
|
||||
|
@ -992,46 +993,6 @@ EOF
|
|||
install -Dm 644 "$srcdir/$buildfile" "$pkgdocs/$app.SMBuild"
|
||||
fi
|
||||
|
||||
|
||||
# We don't want multiple directories for documentation. Detect if $pkg/share/doc/<app-name> was created.
|
||||
# If it has been created, move its contents into $pkgdocs and discard the old doc directory.
|
||||
if [[ -d "$pkg/share/doc/$app" ]] ; then
|
||||
info "Found share/doc/$app documentation directory.
|
||||
Moving its contents into share/doc/$app-$version/"
|
||||
mv "$pkg/share/doc/$app/"* "$pkgdocs"/
|
||||
rmdir "$pkg/share/doc/$app"
|
||||
fi
|
||||
|
||||
# We'd like pkgconfig files to only go into /lib; some packages have other ideas.
|
||||
if [[ -d $pkg/share/pkgconfig ]] ; then
|
||||
warn "Moving /share/pkgconfig directory created by '$app' into /lib"
|
||||
(
|
||||
cd $pkg
|
||||
mkdir -p lib/pkgconfig
|
||||
mv share/pkgconfig/* lib/pkgconfig/
|
||||
rmdir share/pkgconfig
|
||||
)
|
||||
fi
|
||||
|
||||
# Normally we'd expect some debug symbols in the newly-produced binaries. But that isn't always the
|
||||
# case with some packages whose build systems strip objects before hand
|
||||
if [[ $debug = 1 ]] ; then
|
||||
for file in \
|
||||
$( find "$pkg" -type f )
|
||||
do
|
||||
file -m /etc/file/magic/elf "$file" | \
|
||||
grep -E "executable|shared object" | \
|
||||
grep ", stripped" | cut -d: -f1 >> "$pkg/install/package.$app.debugfailedfilenames"
|
||||
done
|
||||
|
||||
debugfilecount=$(wc -l < "$pkg/install/package.$app.debugfailedfilenames")
|
||||
if [[ $debugfilecount -ge 1 ]]; then
|
||||
debugwarning=1
|
||||
else
|
||||
rm "$pkg/install/package.$app.debugfailedfilenames"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Now strip the binaries and shared libraries. --strip-unneeded is unnecessary for binutils 2.34+
|
||||
if [[ -z $debug ]] && [[ $debug != 1 ]]; then
|
||||
find "$pkg" -type f -print0 | xargs -0 file -m /etc/file/magic/elf | \
|
||||
|
@ -1177,7 +1138,7 @@ prepbuildoutput() {
|
|||
# Stick to 8/16 colours, those are supported on most terminals
|
||||
if [[ $colours = 1 ]]; then
|
||||
colourscheck=$(tput colors 2>/dev/null)
|
||||
if [[ "$?" = 0 ]] && [[ $colourscheck -gt 2 ]] ; then
|
||||
if [[ $? = 0 ]] && [[ $colourscheck -gt 2 ]] ; then
|
||||
# Red when the build fails
|
||||
colourr=$(printf '\e[41m')
|
||||
# Yellow when the build is interrupted
|
||||
|
@ -1239,10 +1200,8 @@ prepbuildoutput() {
|
|||
|
||||
|
||||
# Determine the build type
|
||||
if [[ $debug = 1 ]] && [[ -z $debugwarning ]] ; then
|
||||
if [[ $debug = 1 ]] ; then
|
||||
bldtype="*DEBUG* build"
|
||||
elif [[ $debug = 1 ]] && [[ $debugwarning = 1 ]]; then
|
||||
bldtype="*DEBUG* build[WARNING]"
|
||||
else
|
||||
bldtype="General build, no debug symbols"
|
||||
fi
|
||||
|
@ -1348,6 +1307,7 @@ EOF
|
|||
|
||||
}
|
||||
|
||||
# Prepare a nice HTML file that can be used to view status of the build process from a web browser
|
||||
prephtmloutput() {
|
||||
if [[ $htmloutput = 1 ]] ; then
|
||||
if [[ $pkgstatus = 0 ]] ; then
|
||||
|
@ -1367,7 +1327,6 @@ EOF
|
|||
}
|
||||
|
||||
promptuser() {
|
||||
|
||||
# Extract package at the end of a build if autoextract is set to 1
|
||||
if [[ $autoextract = 1 ]] && [[ -z $autobuild ]] && [[ -n $newpkglocation ]] ; then
|
||||
info "Extracting package installer inside $srcdir/test..."
|
||||
|
@ -1409,7 +1368,7 @@ promptuser() {
|
|||
# This function will set the interrupt variable so prepbuildoutput can output the right build status
|
||||
# on receiving ctrl-c from the user during a manual build.
|
||||
interruptoutput() {
|
||||
echo ""
|
||||
echo
|
||||
info "Caught Keyboard Interrupt"
|
||||
wasinterrupted="1"
|
||||
|
||||
|
|
Loading…
Reference in a new issue