Changes to bldpkg:
-> Moved rqfiles out of bldpkg and into bldpkg.conf in previous commit -> Moved code related to CPU architecture detection near export MAKEFLAGS -> Reintroduced and optimised code to validate a compiler defined as CC and CXX -> Discarded unnecessary if/else condition inside fixbuilddirpermissions function
This commit is contained in:
parent
c7954fdcc4
commit
1cf767e805
1 changed files with 98 additions and 67 deletions
165
bldpkg
165
bldpkg
|
@ -179,10 +179,7 @@ srcdir="$PWD"
|
|||
# unless otherwise overridden using -f <buildfile>
|
||||
buildfile="${srcdir##*/}.SMBuild"
|
||||
|
||||
# Find all required files. If either of them don't exist, abort.
|
||||
rqfiles=( installpkg upgradepkg sha512sum patch find findmnt patch tput bc tar )
|
||||
|
||||
# Run a for loop to find the files
|
||||
# Run a for loop to find compile and build-related files
|
||||
for requiredfile in "${rqfiles[@]}"; do
|
||||
if [[ ! -x $(type -p "$requiredfile") ]] ; then
|
||||
err "Could not find required program '$requiredfile'!"
|
||||
|
@ -571,9 +568,97 @@ else
|
|||
export MAKEFLAGS
|
||||
fi
|
||||
|
||||
# Apply CPU-specific compiler variables defined inside bldpkg.conf
|
||||
# https://github.com/sakaki-/gentoo-on-rpi-64bit/blob/master/reference/compile_run_benchmarks.sh
|
||||
# https://www.raspberrypi.org/forums/viewtopic.php?t=11629
|
||||
# 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.
|
||||
[[ -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
|
||||
|
||||
elif [[ $arch = aarch64 ]]; then
|
||||
hostdist="$aarch64hostdist"
|
||||
builddist="$aarch64builddist"
|
||||
|
||||
if [[ -n $debug ]]; then
|
||||
CFLAGS="$gccdebug $aarch64cflags"
|
||||
else
|
||||
CFLAGS="$aarch64cflags"
|
||||
fi
|
||||
|
||||
CXXFLAGS="$CFLAGS"
|
||||
export hostdist builddist CFLAGS CXXFLAGS
|
||||
|
||||
elif [[ $arch = x86_64 ]]; then
|
||||
builddist="$x8664builddist"
|
||||
|
||||
if [[ -n $debug ]]; then
|
||||
CFLAGS="$gccdebug $x8664cflags"
|
||||
else
|
||||
CFLAGS="$x8664cflags"
|
||||
fi
|
||||
|
||||
CXXFLAGS="$CFLAGS"
|
||||
export builddist CFLAGS CXXFLAGS
|
||||
|
||||
else
|
||||
err "Sorry! '$arch' CPU architecture not supported by SMLinux!"
|
||||
fi
|
||||
|
||||
# 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)"
|
||||
|
||||
# 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"
|
||||
|
||||
printf "[INFO] Validating '$compiler'... "
|
||||
|
||||
cat << EOF > "$parenttmp/$compilerfile"
|
||||
#include <stdio.h>
|
||||
int main() { printf("$randomnum\n"); }
|
||||
EOF
|
||||
|
||||
$compiler $compilerflags -o "$parenttmp/$compileroutput" $compileraddonflags "$parenttmp/$compilerfile"
|
||||
finaloutput="$($parenttmp/$compileroutput)"
|
||||
|
||||
# Error out if the outputs don't match
|
||||
if [[ $finaloutput != $randomnum ]] ;then
|
||||
err "Compiler validation failed!"
|
||||
else
|
||||
rm "$parenttmp/$compileroutput"*
|
||||
printf " done\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Quotes are important while passing C/CXXFLAGS
|
||||
compilertestfile "$CC" "$CFLAGS" cc-test.c cc-test
|
||||
compilertestfile "$CXX" "$CXXFLAGS" cxx-test.cpp cxx-test
|
||||
|
||||
# Function to validate symlinks.
|
||||
# Usage: checkcompilersymlink symlink symlink_target
|
||||
checkcompilersymlink() {
|
||||
# Usage: checkcompilersymlink symlink symlink_target
|
||||
symlinkdir="$1"
|
||||
symlinktgt="$2"
|
||||
|
||||
|
@ -663,56 +748,14 @@ if [[ $globaldistcc = 1 ]] ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# Apply CPU-specific compiler variables defined inside bldpkg.conf
|
||||
# https://github.com/sakaki-/gentoo-on-rpi-64bit/blob/master/reference/compile_run_benchmarks.sh
|
||||
# https://www.raspberrypi.org/forums/viewtopic.php?t=11629
|
||||
# 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.
|
||||
[[ -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
|
||||
# If compilerverbosity is set in bldpkg.conf or if verbosity is set to 1 from getopts, set V and
|
||||
# VERBOSE environment variables for make and cmake build systems to pick up.
|
||||
if [[ $compilerverbosity = 1 ]] || [[ $getoptscompilerverbosity = 1 ]] ; then
|
||||
V=1
|
||||
VERBOSE=1
|
||||
export V VERBOSE
|
||||
fi
|
||||
|
||||
if [[ $arch = noarch ]]; then
|
||||
CFLAGS=""
|
||||
export CFLAGS
|
||||
|
||||
elif [[ $arch = aarch64 ]]; then
|
||||
hostdist="$aarch64hostdist"
|
||||
builddist="$aarch64builddist"
|
||||
|
||||
if [[ -n $debug ]]; then
|
||||
CFLAGS="$gccdebug $aarch64cflags"
|
||||
else
|
||||
CFLAGS="$aarch64cflags"
|
||||
fi
|
||||
|
||||
CXXFLAGS="$CFLAGS"
|
||||
export hostdist builddist CFLAGS CXXFLAGS
|
||||
|
||||
elif [[ $arch = x86_64 ]]; then
|
||||
builddist="$x8664builddist"
|
||||
|
||||
if [[ -n $debug ]]; then
|
||||
CFLAGS="$gccdebug $x8664cflags"
|
||||
else
|
||||
CFLAGS="$x8664cflags"
|
||||
fi
|
||||
|
||||
CXXFLAGS="$CFLAGS"
|
||||
export builddist CFLAGS CXXFLAGS
|
||||
|
||||
else
|
||||
err "Sorry! '$arch' CPU architecture not supported by SMLinux!"
|
||||
fi
|
||||
|
||||
|
||||
# If $noautoconfsite is unset in an individual package build file, export CONFIG_SITE variable into the build
|
||||
# environment for a package's configure script to pickup. Most autoconf-compatible configure scripts will
|
||||
# automatically pick up this variable from the environment and speed up the initial configure process.
|
||||
|
@ -723,14 +766,6 @@ if [[ -z $noautoconfsite ]] ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# If compilerverbosity is set in bldpkg.conf or if verbosity is set to 1 from getopts, set V and
|
||||
# VERBOSE environment variables for make and cmake build systems to pick up.
|
||||
if [[ $compilerverbosity = 1 ]] || [[ $getoptscompilerverbosity = 1 ]] ; then
|
||||
V=1
|
||||
VERBOSE=1
|
||||
export V VERBOSE
|
||||
fi
|
||||
|
||||
# Condition to reuse the autobuildtemp file if set from autobuild or make a new temporary file
|
||||
if [[ -n $autobuildtemp ]]; then
|
||||
tempfile="$autobuildtemp"
|
||||
|
@ -778,12 +813,8 @@ fixbuilddirpermissions() {
|
|||
find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
|
||||
\! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+ || true
|
||||
|
||||
# Only put $app-$version.extraction.complete file if $extractioncomplete is unset.
|
||||
# This ensures that the file is only set once.
|
||||
if [[ -z $extractioncomplete ]] ; then
|
||||
touch ".$app-$version.extraction.complete"
|
||||
extractioncomplete=1
|
||||
fi
|
||||
# Place an extraction.complete file so that we know at which point to resume our build
|
||||
touch ".$app-$version.extraction.complete"
|
||||
}
|
||||
|
||||
# Function to calculate elapsed build time. runtime takes the $SECONDS variable as an argument. $SECONDS is an
|
||||
|
|
Loading…
Reference in a new issue