200 lines
5.5 KiB
Bash
Executable File
200 lines
5.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
guix_source_dir=${GUIX_SOURCE_DIR:-"$HOME/repos/guix"}
|
|
hello_version=${HELLO_VERSION:-2.12.3}
|
|
expected_nix_base32=${HELLO_NIX_BASE32:-183a6rxnhixiyykd7qis0y9g9cfqhpkk872a245y3zl28can0pqd}
|
|
source_url=${HELLO_SOURCE_URL:-"https://ftp.gnu.org/gnu/hello/hello-$hello_version.tar.gz"}
|
|
prefix=${PREFIX:-/usr/local}
|
|
cc_bin=${CC_BIN:-cc}
|
|
make_bin=${MAKE_BIN:-make}
|
|
|
|
if [ ! -d "$guix_source_dir/guix" ]; then
|
|
echo "Guix source tree not found at $guix_source_dir" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "${GUILE_BIN:-}" ]; then
|
|
guile_bin=$GUILE_BIN
|
|
elif command -v guile3 >/dev/null 2>&1; then
|
|
guile_bin=$(command -v guile3)
|
|
elif command -v guile-3.0 >/dev/null 2>&1; then
|
|
guile_bin=$(command -v guile-3.0)
|
|
else
|
|
echo "Unable to find GUILE_BIN, guile3, or guile-3.0 in PATH" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -x "$guile_bin" ]; then
|
|
echo "Guile binary is not executable: $guile_bin" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v fetch >/dev/null 2>&1; then
|
|
echo "fetch not found in PATH" >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v sha256 >/dev/null 2>&1; then
|
|
echo "sha256 not found in PATH" >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v bsdtar >/dev/null 2>&1; then
|
|
echo "bsdtar not found in PATH" >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v "$cc_bin" >/dev/null 2>&1; then
|
|
echo "C compiler not found: $cc_bin" >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v "$make_bin" >/dev/null 2>&1; then
|
|
echo "make tool not found: $make_bin" >&2
|
|
exit 1
|
|
fi
|
|
|
|
jobs=${JOBS:-$(sysctl -n hw.ncpu 2>/dev/null || echo 1)}
|
|
guile_prefix=$(CDPATH= cd -- "$(dirname "$guile_bin")/.." && pwd)
|
|
guile_lib_dir=$guile_prefix/lib
|
|
if [ -e "$guile_lib_dir/libguile-3.0.so.1" ]; then
|
|
if [ -n "${LD_LIBRARY_PATH:-}" ]; then
|
|
export LD_LIBRARY_PATH="$guile_lib_dir:$LD_LIBRARY_PATH"
|
|
else
|
|
export LD_LIBRARY_PATH="$guile_lib_dir"
|
|
fi
|
|
fi
|
|
|
|
cleanup=0
|
|
if [ -n "${WORKDIR:-}" ]; then
|
|
workdir=$WORKDIR
|
|
mkdir -p "$workdir"
|
|
else
|
|
workdir=$(mktemp -d /tmp/fruix-gnu-hello.XXXXXX)
|
|
cleanup=1
|
|
fi
|
|
|
|
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
|
|
cleanup=0
|
|
fi
|
|
|
|
cleanup_workdir() {
|
|
if [ "$cleanup" -eq 1 ]; then
|
|
rm -rf "$workdir"
|
|
fi
|
|
}
|
|
trap cleanup_workdir EXIT INT TERM
|
|
|
|
expected_sha256_hex=$(GUILE_AUTO_COMPILE=0 \
|
|
GUILE_LOAD_PATH="$guix_source_dir${GUILE_LOAD_PATH:+:$GUILE_LOAD_PATH}" \
|
|
"$guile_bin" -c "(use-modules (guix base32) (rnrs bytevectors) (ice-9 format)) (for-each (lambda (b) (format #t \"~2,'0x\" b)) (bytevector->u8-list (nix-base32-string->bytevector (cadr (command-line))))) (newline)" \
|
|
"$expected_nix_base32")
|
|
|
|
src_tarball=$workdir/hello-$hello_version.tar.gz
|
|
src_dir=$workdir/hello-$hello_version
|
|
build_dir=$workdir/build
|
|
stage_dir=$workdir/stage
|
|
metadata_file=$workdir/gnu-hello-build-metadata.txt
|
|
configure_log=$workdir/configure.log
|
|
build_log=$workdir/build.log
|
|
install_log=$workdir/install.log
|
|
|
|
printf 'Using Guile: %s\n' "$guile_bin"
|
|
printf 'Using LD_LIBRARY_PATH: %s\n' "${LD_LIBRARY_PATH:-<unset>}"
|
|
printf 'Working directory: %s\n' "$workdir"
|
|
printf 'Fetching: %s\n' "$source_url"
|
|
fetch -o "$src_tarball" "$source_url"
|
|
|
|
actual_sha256_hex=$(sha256 -q "$src_tarball")
|
|
if [ "$actual_sha256_hex" != "$expected_sha256_hex" ]; then
|
|
echo "sha256 mismatch for $src_tarball" >&2
|
|
echo "expected: $expected_sha256_hex" >&2
|
|
echo "actual: $actual_sha256_hex" >&2
|
|
exit 1
|
|
fi
|
|
|
|
bsdtar -xf "$src_tarball" -C "$workdir"
|
|
mkdir -p "$build_dir" "$stage_dir"
|
|
|
|
host_triplet=$(sh "$src_dir/build-aux/config.guess")
|
|
configure_cmd="CC=$cc_bin $src_dir/configure --prefix=$prefix"
|
|
|
|
(
|
|
cd "$build_dir"
|
|
env CC="$cc_bin" "$src_dir/configure" --prefix="$prefix"
|
|
) >"$configure_log" 2>&1
|
|
|
|
(
|
|
cd "$build_dir"
|
|
env CC="$cc_bin" "$make_bin" -j"$jobs"
|
|
) >"$build_log" 2>&1
|
|
|
|
(
|
|
cd "$build_dir"
|
|
env CC="$cc_bin" "$make_bin" DESTDIR="$stage_dir" install
|
|
) >"$install_log" 2>&1
|
|
|
|
installed_binary=$stage_dir$prefix/bin/hello
|
|
if [ ! -x "$installed_binary" ]; then
|
|
echo "installed hello binary not found: $installed_binary" >&2
|
|
exit 1
|
|
fi
|
|
|
|
hello_output=$(env LC_ALL=C "$installed_binary")
|
|
if [ "$hello_output" != "Hello, world!" ]; then
|
|
echo "unexpected hello output: $hello_output" >&2
|
|
exit 1
|
|
fi
|
|
|
|
binary_file=$(file "$installed_binary")
|
|
runtime_deps=$(ldd "$installed_binary")
|
|
cc_version=$($cc_bin --version | sed -n '1p')
|
|
make_version=$($make_bin -V MAKE_VERSION 2>/dev/null || $make_bin --version 2>/dev/null | sed -n '1p' || echo unknown)
|
|
uname_string=$(uname -a)
|
|
|
|
cat >"$metadata_file" <<EOF
|
|
hello_version=$hello_version
|
|
source_url=$source_url
|
|
expected_nix_base32=$expected_nix_base32
|
|
expected_sha256_hex=$expected_sha256_hex
|
|
actual_sha256_hex=$actual_sha256_hex
|
|
guix_source_dir=$guix_source_dir
|
|
guile_bin=$guile_bin
|
|
cc_bin=$cc_bin
|
|
cc_version=$cc_version
|
|
make_bin=$make_bin
|
|
make_version=$make_version
|
|
host_triplet=$host_triplet
|
|
configure_command=$configure_cmd
|
|
workdir=$workdir
|
|
source_dir=$src_dir
|
|
build_dir=$build_dir
|
|
stage_dir=$stage_dir
|
|
installed_binary=$installed_binary
|
|
hello_output=$hello_output
|
|
binary_file=$binary_file
|
|
configure_log=$configure_log
|
|
build_log=$build_log
|
|
install_log=$install_log
|
|
uname=$uname_string
|
|
runtime_deps_begin
|
|
$runtime_deps
|
|
runtime_deps_end
|
|
EOF
|
|
|
|
if [ -n "${METADATA_OUT:-}" ]; then
|
|
mkdir -p "$(dirname "$METADATA_OUT")"
|
|
cp "$metadata_file" "$METADATA_OUT"
|
|
fi
|
|
|
|
printf 'PASS gnu-hello-native-build\n'
|
|
printf 'Hello output: %s\n' "$hello_output"
|
|
if [ "$cleanup" -eq 0 ]; then
|
|
printf 'Installed binary: %s\n' "$installed_binary"
|
|
printf 'Metadata file: %s\n' "$metadata_file"
|
|
else
|
|
printf '%s\n' 'Work directory will be removed on exit (set KEEP_WORKDIR=1 to preserve it).'
|
|
fi
|
|
if [ -n "${METADATA_OUT:-}" ]; then
|
|
printf 'Copied metadata to: %s\n' "$METADATA_OUT"
|
|
fi
|
|
printf '%s\n' '--- metadata ---'
|
|
cat "$metadata_file"
|