Changes to bldpkg:

* Added more stuff in TODO
* Rearranged code that sources bldpkg.conf a few lines up
* Renamed function debugmode to tracemode
* Defined setbuildfile, autoextractmode, displaysummary and setcputhreads functions and added corresponding option letters to getopts
* Added explanation in the help function
* Added temporary commented code for detecting stripped binaries and libraries before they are actually stripped
* Discarded -exec rm -v since the find command already contains -delete
* Discarded --strip-unneeded option from strip command
* Miscellaneous fixes
This commit is contained in:
PktSurf 2022-08-08 22:52:50 +05:30
parent 9132b697fe
commit 00b7252c7d
3 changed files with 166 additions and 65 deletions

226
bldpkg
View file

@ -22,6 +22,12 @@
# TODO
# -> Uncomment entirety of the code where compilers are to be hard-validated and improve C code
# in the test files and also add suitable bldpkg.conf switches for it
# -> Give a warning when more than two directories, a source and a staging directory
# not belonging to the current build are present inside tmpfs
# -> Warn user when /share/icons or /share/applications directory is present but
# a doinst.sh file that should update the icon caching is absent in the source directory
# -> Warn users if mkfinalpkg finds binaries and shared libraries that are already stripped
# prior to us stripping them manually ; a file count would be useful.
# Begin subshell
(
@ -33,6 +39,14 @@ set -e
# into package build summary.
commencedate="$(date '+%a, %d %b %Y, %T')"
# Then source the configuration file holding all values
if [ -f /etc/bldpkg.conf ] ; then
source /etc/bldpkg.conf
else
echo "[ERROR] /etc/bldpkg.conf not found!"
exit 1
fi
# Store the source directory path the build was initiated from
srcdir="$PWD"
@ -40,9 +54,60 @@ srcdir="$PWD"
srcdirpath="$(basename $srcdir)"
buildfile="$srcdirpath.SMBuild"
debugmode() {
sourcebuildfile() {
if [ -f "$buildfile" ] ; then
source "$buildfile"
else
# We expect a filename as part of -f argument
echo "[ERROR] No build file to source from! If you used -f argument, make sure it is"
echo "[ERROR] the first argument pointing to a build file before any other argument."
exit 1
fi
}
setbuildfile() {
buildfile0="$OPTARG"
if [ ! -f "$OPTARG" ] ; then
echo "[ERROR] Build file $buildfile0 not found!"
exit 1
fi
buildfile="$buildfile0"
sourcebuildfile
}
# Function to invoke bash shell's -x mode for troubleshooting
tracemode() {
set -x
source "$buildfile"
sourcebuildfile
}
debugmode() {
debug=1
sourcebuildfile
}
autoextractmode() {
# Override extractprompt in bldpkg.conf
extractprompt=0
autoextract=1
sourcebuildfile
}
displaysummary() {
# Override showsummary in bldpkg.conf
showsummary=1
sourcebuildfile
}
setcputhreads() {
cputhreads0="$OPTARG"
# Validate if the argument is a number. If not, throw an error and exit.
if ! echo "$cputhreads0" | egrep -q '^[0-9]+$' ; then
echo "[ERROR] Invalid CPU job number. Please try again."
exit 1
fi
cputhreads="$cputhreads0"
sourcebuildfile
}
# Generate sha512sums in the build file
@ -75,54 +140,82 @@ genchecksum() {
exit 0
}
# Function to generate help message
help() {
cat << EOF
Bash script for building SMLinux-compatible packages from source.
Any option used as an argument with this script overrides the
corresponding option, if present, in /etc/bldpkg.conf
This script takes only one parameter.
If no arguments are provided, this script attempts to build a package
by matching the parent directory name with a build file that matches
that directory's name.
For example, if the build directory is $HOME/smlinux/alsa-lib, this script will
look and source from alsa-lib.SMBuild and build alsa-lib package if the user
has cd'd to $HOME/smlinux/alsa-lib
# pwd
/home/smlinux/alsa-lib
# ls
alsa-lib.SMBuild
# bldpkg
Building package 'alsa-lib' version '1.x' build '1sml'...
...build output...
Usage:
-d : Invoke bash shell debug mode
-h : Show this message
-d : Produce a package with debug symbols preserved
-g : Generate SHA512 checksums of all tarballs and patches and insert them into the package build file
-e : Extract the package installer file in the user's PWD if the build
completes successfully.
-f : Alternate build file to source build variables.
NOTE: This argument, if used, must come before any other argument
-g : Generate SHA512 checksums of all tarballs and patches and insert them
into the package build file
-h : Show this help message
-j<N> : Provide a number of jobs to be run simultaneously
-s : Display build summary. A summary is produced whenever a build is either
interrupted, exits cleanly or aborts due to a build error
-x : Invoke bash shell command trace mode. This one isn't akin to running
bash -x <script> but close enough, because the mode is inserted
half way while bldpkg is running
If no arguments are provided, this script attempts to build a package provided the package build file and the parent directory name matches.
EOF
exit 0
}
while getopts ':dhg' option; do
# Function for providing handy arguments to users
while getopts ':def:ghj:sx' option; do
case "$option" in
d)
debugmode
;;
h)
help
;;
g)
genchecksum
;;
*)
help
;;
d) debugmode ;;
e) autoextractmode ;;
f) setbuildfile "$OPTARG" ;;
g) genchecksum ;;
h) help ;;
j) setcputhreads "$OPTARG" ;;
s) displaysummary ;;
x) tracemode ;;
*) help ;;
esac
done
# If no argument is given, attempt to source the build file matching the parent directory name
if [ "$OPTIND" -eq 1 ] ; then
if [ -f "$buildfile" ] ; then
source "$buildfile"
else
echo "[ERROR] Could not find $srcdirpath build file to source from!"
exit 1
fi
# If no argument is given, or if argument is greater than 1, invoke sourcebuildfile function.
if [ "$OPTIND" -ge 1 ] ; then
sourcebuildfile
fi
# Determine whether we are using bash version 4 and later
if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
echo "[ERROR] You need to upgrade your bash shell to a minimum of 4.0 or higher"
echo "[ERROR] bldpkg requires a minimum of version 4 and later to run"
exit 1
fi
@ -209,25 +302,17 @@ applypatch() {
patch -p1 < "$1"
}
# Then source the configuration file holding all values
if [ -f /etc/bldpkg.conf ] ; then
source /etc/bldpkg.conf
else
echo "[ERROR] /etc/bldpkg.conf not found!"
exit 1
fi
# Do a preliminary package dependency check if checkdependencies is set to 1 in bldpkg.conf
if [ "$checkdependencies" == "1" ] ; then
if [ "$checkdependencies" = "1" ] ; then
echo "[INFO] Parsing $app 's dependency list..."
for packagedep in "$requires"; do
depcount="$(find /share/doc -name $packagedep.SMBuild | wc -l)"
# If count is 1, we are ok
if [ "$depcount" == "1" ] ; then
if [ "$depcount" = "1" ] ; then
echo "[INFO] Found dependency $packagedep"
# If count is 0, we exit, because we are in trouble
elif [ "$depcount" == "0" ] ; then
elif [ "$depcount" = "0" ] ; then
echo "[ERROR] Did not find dependency $packagedep ."
exit 1
# If count is greater than or equal to 2, we are in slightly less trouble
@ -459,7 +544,7 @@ if [ "$globaldistcc" = "1" ] ; then
#checkstatus="$?"
# Discard the files once the validation passes/fails
#if [ "$checkstatus" == "0" ] ; then
#if [ "$checkstatus" = "0" ] ; then
# echo "[OK]"
# rm $parenttmp/distcccheck-"$f"{,.c}
#else
@ -533,7 +618,7 @@ if [ "$globalccache" = "1" ]; then
#checkstatus="$?"
# Discard the files once the validation passes/fails
#if [ "$checkstatus" == "0" ] ; then
#if [ "$checkstatus" = "0" ] ; then
# echo "[OK]"
# rm $parenttmp/ccachecheck-"$f"{,.c}
#else
@ -610,7 +695,7 @@ if [ "$globalsccache" = "1" ]; then
#checkstatus="$?"
# Discard the files once the validation passes/fails
#if [ "$checkstatus" == "0" ] ; then
#if [ "$checkstatus" = "0" ] ; then
# echo "[OK]"
# rm $parenttmp/sccachecheck-"$f"{,.c}
#else
@ -853,40 +938,47 @@ mkfinalpkg() {
# Compress and link manpages
if [ -d "$pkg/share/man" ]; then
echo "[INFO] Compressing and linking man pages..."
( cd "$pkg/share/man"
for manpagedir in $(find . -type d -name "man*") ; do
( cd "$manpagedir"
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s "$( readlink "$eachpage" ).gz" "$eachpage".gz
rm "$eachpage"
done
gzip -9 ./*.? >/dev/null 2>&1 || true
)
done
)
(
cd "$pkg/share/man"
find . -type f -name "*.[0-9]" -o -name "*.[0-9]" | xargs gzip -9
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s "$( readlink "$eachpage" ).gz" "$eachpage".gz
rm "$eachpage"
done
)
fi
# Remove .la files similar to what slackware devs are doing in slackware-current, but in a more efficient manner :)
echo "[INFO] Discarding any libtool archive (.la) files..."
find "$pkg" ! -type d -name "*.la" -exec rm -v {} \;
find "$pkg" -type f -name "*.la" -delete
# Provide a copy of the package build file so that users know the build options that went into compiling the package
install -Dm 644 "$srcdir/$buildfile" "$pkgdocs/$app.SMBuild"
# Now strip the binaries and shared libraries
# Normally we'd expect some debug symbols in the newly-produced binaries.
# But that isn't always the case.
#find "$pkg" -print0 -type f | xargs -0 file -m /etc/file/magic/elf | \
# grep -q "not stripped"
#if [ "$?" = "0" ] ; then
# echo "[WARNING] Binaries were stripped before hand!"
# sleep 2
#fi
# Now strip the binaries and shared libraries. --strip-unneeded is unnecessary for binutils 2.34+
if [ -z "$debug" ] && [ "$debug" != "1" ]; then
find "$pkg" -print0 | xargs -0 file -m /etc/file/magic/elf | \
grep -E "executable|shared object|statically linked" | grep "ELF" | \
cut -d: -f1 | xargs strip --strip-unneeded 2>/dev/null || true
cut -d: -f1 | xargs strip 2>/dev/null || true
fi
# And static libraries separately unconditionally
find "$pkg" -print0 | xargs -0 file -m /etc/file/magic/archive | \
grep -E "current ar archive" | awk '{print $1}' | cut -d: -f1 | \
xargs strip --strip-unneeded 2>/dev/null || true
xargs strip 2>/dev/null || true
# Calculate total files, directories, symlinks and uncompressed staging directory size
if [ "$showsummary" == "1" ] ; then
if [ "$showsummary" = "1" ] ; then
totalfilecount="$(find $pkg -type f | wc -l)"
totaldircount="$(find $pkg -type d | wc -l)"
totalsymcount="$(find $pkg -type l | wc -l)"
@ -912,7 +1004,7 @@ mkfinalpkg() {
cd "$srcdir"
if [ "$showsummary" == "1" ] || [ "$htmloutput" == "1" ] ; then
if [ "$showsummary" = "1" ] || [ "$htmloutput" = "1" ] ; then
# With SECONDS reset, the shell will add in a fresh value, which we can now use to ascertain the packaging time,
# by again passing that value as an argument to the runtime function
packagetimea="$SECONDS"
@ -920,7 +1012,7 @@ mkfinalpkg() {
fi
if [ "$showsummary" == "1" ]; then
if [ "$showsummary" = "1" ]; then
# Determine size of SRCDIR aka source directory
srcdirsize="$(du -s $srcdir | awk '{print $1}')"
# Determine size of tmp aka build directory size
@ -994,7 +1086,7 @@ prepbuildoutput() {
colourg="\e[92m"
# Cyan for the short questions
colourc="\e[96m"
# appNAME/version Colours
# App name/version colours
colourv="\e[92m"
# Restore to default
colourd="\e[0m"
@ -1209,6 +1301,16 @@ EOF
}
promptuser() {
# Extract package at the end of a build if autoextract is set to 1
if [ "$autoextract" = "1" ] && [ -z "$autobuild" ] && [ -n "$packlocation" ] ; then
echo "[INFO] Extracting package installer inside $srcdir/test..."
mkdir -p "$srcdir/test"
tar xvf "$packlocation" -C "$srcdir/test"
echo ""
echo "[INFO] '"$app"' package installer file successfully extracted"
fi
# Prompt the user at the end of a build whether to extract contents of a newly-built installer into a subdirectory
# called "test" inside the package source directory the build was manually initiated from. Has no effect on
# autobuilds since they are simply installed right away.

View file

@ -97,7 +97,6 @@ geoclue
redshift
webkitgtk
libhandy
epiphany
balsa
iperf
ipset

View file

@ -1,6 +1,6 @@
app=samba
version=4.15.5
build=1sml
build=2sml
homepage="https://www.samba.org"
download="https://download.samba.org/pub/samba/stable/samba-4.15.5.tar.gz"
desc="CIFS file and print server, version 4"
@ -26,7 +26,7 @@ build() {
applypatch $srcdir/samba-bgqd-include-signal-h.patch
# Samba doesn't like our C/CXXFLAGS
unset CFLAGS CXXFLAGS
#unset CFLAGS CXXFLAGS
SAMBAJOBS="$(echo $MAKEFLAGS | sed 's@-j@@')"