2020-05-10 15:58:05 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Type `build -h` for help and see https://github.com/romkatv/gitstatus
|
|
|
|
# for full documentation.
|
|
|
|
|
|
|
|
set -ue
|
|
|
|
|
|
|
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
|
|
|
emulate sh -o err_exit -o no_unset
|
|
|
|
fi
|
|
|
|
|
2020-06-13 11:15:44 +02:00
|
|
|
export LC_ALL=C
|
|
|
|
|
2020-11-17 11:02:15 +02:00
|
|
|
if [ -z "${ZSH_VERSION-}" ] && command -v zsh >/dev/null 2>&1; then
|
2022-01-04 13:14:19 +02:00
|
|
|
# Avoid bash 3.*.
|
2020-11-17 11:02:15 +02:00
|
|
|
case "${BASH_VERSION-}" in
|
|
|
|
[0-3].*) exec zsh "$0" "$@";;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2022-01-04 13:14:19 +02:00
|
|
|
# Avoid ksh: https://github.com/romkatv/gitstatus/issues/282.
|
|
|
|
if [ -n "${KSH_VERSION-}" ]; then
|
|
|
|
if [ -z "${ZSH_VERSION-}" ] && command -v zsh >/dev/null 2>&1; then
|
|
|
|
exec zsh "$0" "$@"
|
|
|
|
elif [ -z "${BASH_VERSION-}" ] && command -v bash >/dev/null 2>&1 &&
|
|
|
|
bash_version="$(bash --version 2>&1)"; then
|
|
|
|
case "$bash_version" in
|
|
|
|
*version\ [4-9]*|*version\ [1-9][0-9]*) exec bash "$0" "$@";;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
usage="$(command cat <<\END
|
2020-05-10 15:58:05 +02:00
|
|
|
Usage: build [-m ARCH] [-c CPU] [-d CMD] [-i IMAGE] [-s] [-w]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
-m ARCH `uname -m` from the target machine; defaults to `uname -m`
|
|
|
|
from the local machine
|
|
|
|
-c CPU generate machine instructions for CPU of this type; this
|
2020-05-15 18:06:30 +02:00
|
|
|
value gets passed as `-march` (or `-mcpu` for ppc64le) to gcc;
|
|
|
|
inferred from ARCH if not set explicitly
|
2020-05-10 15:58:05 +02:00
|
|
|
-d CMD build in a Docker container and use CMD as the `docker`
|
|
|
|
command; e.g., `-d docker` or `-d podman`
|
|
|
|
-i IMAGE build in this Docker image; inferred from ARCH if not set
|
|
|
|
explicitly
|
|
|
|
-s install whatever software is necessary for build to
|
|
|
|
succeed; on some operating systems this option is not
|
|
|
|
supported; on others it can have partial effect
|
|
|
|
-w automatically download tarballs for dependencies if they
|
2020-11-17 11:02:15 +02:00
|
|
|
do not already exist in ./deps; dependencies are described
|
2020-05-10 15:58:05 +02:00
|
|
|
in ./build.info
|
|
|
|
END
|
|
|
|
)"
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
build="$(command cat <<\END
|
|
|
|
outdir="$(command pwd)"
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
if command -v mktemp >/dev/null 2>&1; then
|
2020-05-13 09:40:53 +02:00
|
|
|
workdir="$(command mktemp -d "${TMPDIR:-/tmp}"/gitstatus-build.XXXXXXXXXX)"
|
2020-05-10 15:58:05 +02:00
|
|
|
else
|
|
|
|
workdir="${TMPDIR:-/tmp}/gitstatus-build.tmp.$$"
|
2020-05-13 09:40:53 +02:00
|
|
|
command mkdir -- "$workdir"
|
2020-05-10 15:58:05 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd -- "$workdir"
|
2020-05-13 09:40:53 +02:00
|
|
|
workdir="$(command pwd)"
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
narg() { echo $#; }
|
|
|
|
|
2021-07-02 11:02:41 +02:00
|
|
|
if [ "$(narg $workdir)" != 1 -o -z "${workdir##*:*}" -o -z "${workdir##*=*}" ]; then
|
2020-05-10 15:58:05 +02:00
|
|
|
>&2 echo "[error] cannot build in this directory: $workdir"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-13 11:15:44 +02:00
|
|
|
appname=gitstatusd
|
2020-05-10 15:58:05 +02:00
|
|
|
libgit2_tmp="$outdir"/deps/"$appname".libgit2.tmp
|
|
|
|
|
|
|
|
cleanup() {
|
2020-05-13 09:40:53 +02:00
|
|
|
trap - INT QUIT TERM ILL PIPE
|
2020-05-26 08:37:25 +02:00
|
|
|
cd /
|
|
|
|
if ! command rm -rf -- "$workdir" "$outdir"/usrbin/"$appname".tmp "$libgit2_tmp"; then
|
|
|
|
command sleep 5
|
|
|
|
command rm -rf -- "$workdir" "$outdir"/usrbin/"$appname".tmp "$libgit2_tmp"
|
|
|
|
fi
|
2020-05-10 15:58:05 +02:00
|
|
|
}
|
2020-05-13 09:40:53 +02:00
|
|
|
trap cleanup INT QUIT TERM ILL PIPE
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
if [ -n "$gitstatus_install_tools" ]; then
|
|
|
|
case "$gitstatus_kernel" in
|
|
|
|
linux)
|
2020-06-13 11:15:44 +02:00
|
|
|
if command -v apk >/dev/null 2>&1; then
|
|
|
|
command apk update
|
|
|
|
command apk add binutils cmake gcc g++ git make musl-dev perl-utils
|
|
|
|
elif command -v apt-get >/dev/null 2>&1; then
|
|
|
|
apt-get update
|
|
|
|
apt-get install -y binutils cmake gcc g++ make wget
|
|
|
|
else
|
|
|
|
>&2 echo "[error] -s is not supported on this system"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
2022-02-07 09:38:49 +02:00
|
|
|
freebsd|dragonfly)
|
2021-09-12 10:40:43 +02:00
|
|
|
command pkg install -y cmake gmake binutils git perl5 wget
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
2021-05-30 10:35:40 +02:00
|
|
|
openbsd)
|
2022-01-04 13:14:19 +02:00
|
|
|
command pkg_add cmake gmake gcc g++ git wget
|
2021-05-30 10:35:40 +02:00
|
|
|
;;
|
2020-05-10 15:58:05 +02:00
|
|
|
netbsd)
|
2020-05-13 09:40:53 +02:00
|
|
|
command pkgin -y install cmake gmake binutils git
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
darwin)
|
|
|
|
if ! command -v make >/dev/null 2>&1 || ! command -v gcc >/dev/null 2>&1; then
|
|
|
|
>&2 echo "[error] please run 'xcode-select --install' and retry"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-12-21 17:19:22 +02:00
|
|
|
if command -v port >/dev/null 2>&1; then
|
|
|
|
sudo port -N install libiconv cmake wget
|
|
|
|
elif command -v brew >/dev/null 2>&1; then
|
|
|
|
for formula in libiconv cmake git wget; do
|
2021-05-30 10:35:40 +02:00
|
|
|
if command brew ls --version "$formula" &>/dev/null; then
|
2020-12-21 17:19:22 +02:00
|
|
|
command brew upgrade "$formula"
|
|
|
|
else
|
|
|
|
command brew install "$formula"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
>&2 echo "[error] please install MacPorts or Homebrew and retry"
|
2020-05-10 15:58:05 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
msys*|mingw*)
|
2020-05-13 09:40:53 +02:00
|
|
|
command pacman -Syu --noconfirm
|
|
|
|
command pacman -S --needed --noconfirm binutils cmake gcc git make perl
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
>&2 echo "[internal error] unhandled kernel: $gitstatus_kernel"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
cpus="$(command getconf _NPROCESSORS_ONLN 2>/dev/null)" ||
|
2022-02-07 09:38:49 +02:00
|
|
|
cpus="$(command sysctl -n hw.ncpu 2>/dev/null)" ||
|
2020-05-13 09:40:53 +02:00
|
|
|
cpus=8
|
2020-05-10 15:58:05 +02:00
|
|
|
|
2020-05-15 18:06:30 +02:00
|
|
|
case "$gitstatus_cpu" in
|
2022-01-26 15:45:50 +02:00
|
|
|
powerpc64|powerpc64le)
|
|
|
|
archflag="-mcpu"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
archflag="-march"
|
|
|
|
;;
|
2020-05-15 18:06:30 +02:00
|
|
|
esac
|
|
|
|
|
2024-10-03 11:16:46 +02:00
|
|
|
case "$gitstatus_arch" in
|
|
|
|
e2k)
|
|
|
|
nopltflag=""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
nopltflag="-fno-plt"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cflags="$archflag=$gitstatus_cpu $nopltflag -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fpie"
|
2021-07-22 11:19:22 +02:00
|
|
|
ldflags=
|
|
|
|
static_pie=
|
2020-05-26 11:14:53 +02:00
|
|
|
|
2021-09-12 10:40:43 +02:00
|
|
|
if [ -z "${CC-}" ]; then
|
|
|
|
case "$gitstatus_kernel" in
|
|
|
|
freebsd) export CC=clang;;
|
|
|
|
*) export CC=cc;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2021-07-22 11:19:22 +02:00
|
|
|
printf 'int main() {}\n' >"$workdir"/cc-test.c
|
2021-09-12 10:40:43 +02:00
|
|
|
if 2>/dev/null "$CC" \
|
2021-07-22 11:19:22 +02:00
|
|
|
-ffile-prefix-map=x=y \
|
|
|
|
-Werror \
|
|
|
|
-c "$workdir"/cc-test.c \
|
|
|
|
-o "$workdir"/cc-test.o; then
|
2021-07-02 11:02:41 +02:00
|
|
|
cflags="$cflags -ffile-prefix-map=$workdir/="
|
|
|
|
fi
|
|
|
|
|
2021-07-22 11:19:22 +02:00
|
|
|
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
2022-02-07 09:38:49 +02:00
|
|
|
if 2>/dev/null "$CC" \
|
|
|
|
-fstack-clash-protection \
|
|
|
|
-Werror \
|
|
|
|
-c "$workdir"/cc-test.c \
|
2021-07-22 11:19:22 +02:00
|
|
|
-o "$workdir"/cc-test.o; then
|
2022-02-07 09:38:49 +02:00
|
|
|
cflags="$cflags -fstack-clash-protection"
|
|
|
|
fi
|
|
|
|
|
|
|
|
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
|
|
|
if 2>/dev/null "$CC" \
|
|
|
|
-fcf-protection \
|
|
|
|
-Werror \
|
|
|
|
-c "$workdir"/cc-test.c \
|
|
|
|
-o "$workdir"/cc-test.o; then
|
|
|
|
cflags="$cflags -fcf-protection"
|
2021-07-22 11:19:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
2021-09-12 10:40:43 +02:00
|
|
|
if 2>/dev/null "$CC" \
|
2021-07-22 11:19:22 +02:00
|
|
|
-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now \
|
|
|
|
-Werror \
|
|
|
|
"$workdir"/cc-test.c \
|
|
|
|
-o "$workdir"/cc-test; then
|
|
|
|
ldflags="$ldflags -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
|
|
|
|
fi
|
|
|
|
|
|
|
|
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
2021-09-12 10:40:43 +02:00
|
|
|
if 2>/dev/null "$CC" \
|
2021-07-22 11:19:22 +02:00
|
|
|
-fpie -static-pie \
|
|
|
|
-Werror \
|
|
|
|
"$workdir"/cc-test.c \
|
|
|
|
-o "$workdir"/cc-test; then
|
|
|
|
static_pie='-static-pie'
|
|
|
|
fi
|
|
|
|
|
2020-05-26 11:14:53 +02:00
|
|
|
if [ "$gitstatus_cpu" = x86-64 ]; then
|
|
|
|
cflags="$cflags -mtune=generic"
|
|
|
|
fi
|
|
|
|
|
2020-05-10 15:58:05 +02:00
|
|
|
libgit2_cmake_flags=
|
2021-07-22 11:19:22 +02:00
|
|
|
libgit2_cflags="${CFLAGS-} $cflags -O3 -DNDEBUG"
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
gitstatus_cxx=g++
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_cxxflags="${CXXFLAGS-} $cflags -I${workdir}/libgit2/include -DGITSTATUS_ZERO_NSEC -D_GNU_SOURCE -D_GLIBCXX_ASSERTIONS"
|
|
|
|
gitstatus_ldflags="${LDFLAGS-} $ldflags -L${workdir}/libgit2/build"
|
2020-05-10 15:58:05 +02:00
|
|
|
gitstatus_ldlibs=
|
|
|
|
gitstatus_make=make
|
|
|
|
|
|
|
|
case "$gitstatus_kernel" in
|
|
|
|
linux)
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
freebsd)
|
2021-09-12 10:40:43 +02:00
|
|
|
gitstatus_cxx=clang++
|
2020-05-10 15:58:05 +02:00
|
|
|
gitstatus_make=gmake
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
2022-02-07 09:38:49 +02:00
|
|
|
dragonfly)
|
|
|
|
gitstatus_cxx=clang++12
|
|
|
|
gitstatus_make=gmake
|
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
|
|
|
;;
|
2021-05-30 10:35:40 +02:00
|
|
|
openbsd)
|
|
|
|
gitstatus_cxx=eg++
|
|
|
|
gitstatus_make=gmake
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2021-05-30 10:35:40 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
|
|
|
;;
|
2020-05-10 15:58:05 +02:00
|
|
|
netbsd)
|
|
|
|
gitstatus_make=gmake
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
darwin)
|
2020-05-13 09:40:53 +02:00
|
|
|
command mkdir -- "$workdir"/lib
|
2020-12-21 17:19:22 +02:00
|
|
|
if [ -e /opt/local/lib/libiconv.a ]; then
|
|
|
|
command ln -s -- /opt/local/lib/libiconv.a "$workdir"/lib
|
|
|
|
libgit2_cflags="$libgit2_cflags -I/opt/local/include"
|
|
|
|
gitstatus_cxxflags="$gitstatus_cxxflags -I/opt/local/include"
|
|
|
|
else
|
|
|
|
brew_prefix="$(command brew --prefix)"
|
|
|
|
command ln -s -- "$brew_prefix"/opt/libiconv/lib/libiconv.a "$workdir"/lib
|
|
|
|
libgit2_cflags="$libgit2_cflags -I"$brew_prefix"/opt/libiconv/include"
|
|
|
|
gitstatus_cxxflags="$gitstatus_cxxflags -I"$brew_prefix"/opt/libiconv/include"
|
|
|
|
fi
|
2020-05-10 15:58:05 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DUSE_ICONV=ON"
|
|
|
|
gitstatus_ldlibs="$gitstatus_ldlibs -liconv"
|
|
|
|
gitstatus_ldflags="$gitstatus_ldflags -L${workdir}/lib"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=OFF"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
msys*|mingw*)
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
cygwin*)
|
2021-07-22 11:19:22 +02:00
|
|
|
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
2020-05-26 11:14:53 +02:00
|
|
|
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
2020-05-10 15:58:05 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
>&2 echo "[internal error] unhandled kernel: $gitstatus_kernel"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-09-12 10:40:43 +02:00
|
|
|
for cmd in cat cmake git ld ln mkdir rm strip tar "$gitstatus_make"; do
|
2020-05-10 15:58:05 +02:00
|
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
|
|
if [ -n "$gitstatus_install_tools" ]; then
|
|
|
|
>&2 echo "[internal error] $cmd not found"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
>&2 echo "[error] command not found: $cmd"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
. "$outdir"/build.info
|
2020-05-13 09:40:53 +02:00
|
|
|
if [ -z "${libgit2_version:-}" ]; then
|
2020-05-10 15:58:05 +02:00
|
|
|
>&2 echo "[internal error] libgit2_version not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-13 09:40:53 +02:00
|
|
|
if [ -z "${libgit2_sha256:-}" ]; then
|
|
|
|
>&2 echo "[internal error] libgit2_sha256 not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-10 15:58:05 +02:00
|
|
|
libgit2_tarball="$outdir"/deps/libgit2-"$libgit2_version".tar.gz
|
|
|
|
if [ ! -e "$libgit2_tarball" ]; then
|
|
|
|
if [ -n "$gitstatus_download_deps" ]; then
|
2020-05-13 09:40:53 +02:00
|
|
|
if ! command -v wget >/dev/null 2>&1; then
|
|
|
|
if [ -n "$gitstatus_install_tools" ]; then
|
|
|
|
>&2 echo "[internal error] wget not found"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
>&2 echo "[error] command not found: wget"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2020-05-10 15:58:05 +02:00
|
|
|
libgit2_url=https://github.com/romkatv/libgit2/archive/"$libgit2_version".tar.gz
|
2021-08-23 10:30:28 +02:00
|
|
|
if ! >"$libgit2_tmp" command wget --no-config -qO- -- "$libgit2_url" &&
|
|
|
|
! >"$libgit2_tmp" command wget -qO- -- "$libgit2_url"; then
|
|
|
|
set -x
|
|
|
|
>&2 command which wget
|
|
|
|
>&2 command ls -lAd -- "$(command which wget)"
|
|
|
|
>&2 command ls -lAd -- "$outdir"
|
|
|
|
>&2 command ls -lA -- "$outdir"
|
|
|
|
>&2 command ls -lAd -- "$outdir"/deps
|
|
|
|
>&2 command ls -lA -- "$outdir"/deps
|
|
|
|
set +x
|
2021-08-18 17:05:04 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-13 09:40:53 +02:00
|
|
|
command mv -f -- "$libgit2_tmp" "$libgit2_tarball"
|
2020-05-10 15:58:05 +02:00
|
|
|
else
|
|
|
|
>&2 echo "[error] file not found: deps/libgit2-"$libgit2_version".tar.gz"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
libgit2_actual_sha256=
|
|
|
|
if command -v shasum >/dev/null 2>/dev/null; then
|
|
|
|
libgit2_actual_sha256="$(command shasum -b -a 256 -- "$libgit2_tarball")"
|
|
|
|
libgit2_actual_sha256="${libgit2_actual_sha256%% *}"
|
|
|
|
elif command -v sha256sum >/dev/null 2>/dev/null; then
|
|
|
|
libgit2_actual_sha256="$(command sha256sum -b -- "$libgit2_tarball")"
|
|
|
|
libgit2_actual_sha256="${libgit2_actual_sha256%% *}"
|
|
|
|
elif command -v sha256 >/dev/null 2>/dev/null; then
|
|
|
|
libgit2_actual_sha256="$(command sha256 -- "$libgit2_tarball" </dev/null)"
|
|
|
|
# Ignore sha256 output if it's from hashalot. It's incompatible.
|
|
|
|
if [ ${#libgit2_actual_sha256} -lt 64 ]; then
|
|
|
|
libgit2_actual_sha256=
|
|
|
|
else
|
|
|
|
libgit2_actual_sha256="${libgit2_actual_sha256##* }"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$libgit2_actual_sha256" ]; then
|
|
|
|
>&2 echo "[error] command not found: shasum or sha256sum"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$libgit2_actual_sha256" != "$libgit2_sha256" ]; then
|
|
|
|
>&2 echo "[error] sha256 mismatch"
|
|
|
|
>&2 echo ""
|
|
|
|
>&2 echo " file : deps/libgit2-$libgit2_version.tar.gz"
|
|
|
|
>&2 echo " expected: $libgit2_sha256"
|
|
|
|
>&2 echo " actual : $libgit2_actual_sha256"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-10 15:58:05 +02:00
|
|
|
cd -- "$workdir"
|
2020-05-13 09:40:53 +02:00
|
|
|
command tar -xzf "$libgit2_tarball"
|
|
|
|
command mv -- libgit2-"$libgit2_version" libgit2
|
|
|
|
command mkdir libgit2/build
|
2020-05-10 15:58:05 +02:00
|
|
|
cd libgit2/build
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
CFLAGS="$libgit2_cflags" command cmake \
|
2021-07-22 11:19:22 +02:00
|
|
|
-DCMAKE_BUILD_TYPE=None \
|
2020-05-13 09:40:53 +02:00
|
|
|
-DZERO_NSEC=ON \
|
|
|
|
-DTHREADSAFE=ON \
|
|
|
|
-DUSE_BUNDLED_ZLIB=ON \
|
|
|
|
-DREGEX_BACKEND=builtin \
|
|
|
|
-DUSE_HTTP_PARSER=builtin \
|
|
|
|
-DUSE_SSH=OFF \
|
|
|
|
-DUSE_HTTPS=OFF \
|
|
|
|
-DBUILD_CLAR=OFF \
|
|
|
|
-DUSE_GSSAPI=OFF \
|
|
|
|
-DUSE_NTLMCLIENT=OFF \
|
|
|
|
-DBUILD_SHARED_LIBS=OFF \
|
2024-10-03 11:16:46 +02:00
|
|
|
-G "Unix Makefiles" \
|
2020-05-13 09:40:53 +02:00
|
|
|
$libgit2_cmake_flags \
|
2020-05-10 15:58:05 +02:00
|
|
|
..
|
2020-05-13 09:40:53 +02:00
|
|
|
command make -j "$cpus" VERBOSE=1
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
APPNAME="$appname".tmp \
|
|
|
|
OBJDIR="$workdir"/gitstatus \
|
2021-07-25 09:31:56 +02:00
|
|
|
CXX="${CXX:-$gitstatus_cxx}" \
|
2020-05-10 15:58:05 +02:00
|
|
|
CXXFLAGS="$gitstatus_cxxflags" \
|
|
|
|
LDFLAGS="$gitstatus_ldflags" \
|
|
|
|
LDLIBS="$gitstatus_ldlibs" \
|
2020-05-13 09:40:53 +02:00
|
|
|
command "$gitstatus_make" -C "$outdir" -j "$cpus"
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
app="$outdir"/usrbin/"$appname"
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
command strip "$app".tmp
|
2020-05-10 15:58:05 +02:00
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
command mkdir -- "$workdir"/repo
|
2021-06-11 09:23:27 +02:00
|
|
|
printf '[init]\n defaultBranch = master\n' >"$workdir"/.gitconfig
|
|
|
|
(
|
|
|
|
cd -- "$workdir"/repo
|
|
|
|
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git init
|
|
|
|
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git config user.name "Your Name"
|
|
|
|
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git config user.email "you@example.com"
|
|
|
|
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git commit \
|
|
|
|
--allow-empty --allow-empty-message --no-gpg-sign -m ''
|
|
|
|
)
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
resp="$(printf "hello\037$workdir/repo\036" | "$app".tmp)"
|
2021-06-11 09:23:27 +02:00
|
|
|
case "$resp" in
|
|
|
|
hello*1*/repo*master*);;
|
|
|
|
*)
|
|
|
|
>&2 echo 'error: invalid gitstatusd response for a git repo'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
resp="$(printf 'hello\037\036' | "$app".tmp)"
|
2021-06-11 09:23:27 +02:00
|
|
|
case "$resp" in
|
|
|
|
hello*0*);;
|
|
|
|
*)
|
|
|
|
>&2 echo 'error: invalid gitstatusd response for a non-repo'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-10 15:58:05 +02:00
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
command mv -f -- "$app".tmp "$app"
|
2020-05-10 15:58:05 +02:00
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
2020-05-13 09:40:53 +02:00
|
|
|
command cat >&2 <<-END
|
2020-05-10 15:58:05 +02:00
|
|
|
-------------------------------------------------
|
|
|
|
SUCCESS: created usrbin/$appname
|
|
|
|
END
|
|
|
|
END
|
|
|
|
)"
|
|
|
|
|
|
|
|
docker_image=
|
|
|
|
docker_cmd=
|
|
|
|
|
|
|
|
gitstatus_arch=
|
|
|
|
gitstatus_cpu=
|
|
|
|
gitstatus_install_tools=
|
|
|
|
gitstatus_download_deps=
|
|
|
|
|
|
|
|
while getopts ':m:c:i:d:swh' opt "$@"; do
|
|
|
|
case "$opt" in
|
|
|
|
h)
|
|
|
|
printf '%s\n' "$usage"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
m)
|
|
|
|
if [ -n "$gitstatus_arch" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$OPTARG" ]; then
|
|
|
|
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gitstatus_arch="$OPTARG"
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
if [ -n "$gitstatus_cpu" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$OPTARG" ]; then
|
|
|
|
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gitstatus_cpu="$OPTARG"
|
|
|
|
;;
|
|
|
|
i)
|
|
|
|
if [ -n "$docker_image" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$OPTARG" ]; then
|
|
|
|
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
docker_image="$OPTARG"
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
if [ -n "$docker_cmd" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$OPTARG" ]; then
|
|
|
|
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
docker_cmd="$OPTARG"
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
if [ -n "$gitstatus_install_tools" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gitstatus_install_tools=1
|
|
|
|
;;
|
|
|
|
w)
|
|
|
|
if [ -n "$gitstatus_download_deps" ]; then
|
|
|
|
>&2 echo "[error] duplicate option: -$opt"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gitstatus_download_deps=1
|
|
|
|
;;
|
|
|
|
\?) >&2 echo "[error] invalid option: -$OPTARG" ; exit 1;;
|
|
|
|
:) >&2 echo "[error] missing required argument: -$OPTARG"; exit 1;;
|
|
|
|
*) >&2 echo "[internal error] unhandled option: -$opt" ; exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$OPTIND" -le $# ]; then
|
|
|
|
>&2 echo "[error] unexpected positional argument"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$docker_image" -a -z "$docker_cmd" ]; then
|
|
|
|
>&2 echo "[error] cannot use -i without -d"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$gitstatus_arch" ]; then
|
|
|
|
gitstatus_arch="$(uname -m)"
|
|
|
|
gitstatus_arch="$(printf '%s' "$gitstatus_arch" | tr '[A-Z]' '[a-z]')"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$gitstatus_cpu" ]; then
|
|
|
|
case "$gitstatus_arch" in
|
2021-07-02 11:02:41 +02:00
|
|
|
armel) gitstatus_cpu=armv5;;
|
|
|
|
armv6l|armhf) gitstatus_cpu=armv6;;
|
2020-05-10 15:58:05 +02:00
|
|
|
armv7l) gitstatus_cpu=armv7;;
|
2021-07-25 09:31:56 +02:00
|
|
|
arm64|aarch64) gitstatus_cpu=armv8-a;;
|
2022-01-26 15:45:50 +02:00
|
|
|
ppc64|ppc64le) gitstatus_cpu=powerpc64le;;
|
2020-05-15 18:06:30 +02:00
|
|
|
riscv64) gitstatus_cpu=rv64imafdc;;
|
2022-01-04 13:14:19 +02:00
|
|
|
loongarch64) gitstatus_cpu=loongarch64;;
|
2020-05-10 15:58:05 +02:00
|
|
|
x86_64|amd64) gitstatus_cpu=x86-64;;
|
2021-07-02 11:02:41 +02:00
|
|
|
x86) gitstatus_cpu=i586;;
|
|
|
|
s390x) gitstatus_cpu=z900;;
|
2024-10-03 11:16:46 +02:00
|
|
|
e2k) gitstatus_cpu=native;;
|
2020-05-10 15:58:05 +02:00
|
|
|
i386|i586|i686) gitstatus_cpu="$gitstatus_arch";;
|
|
|
|
*)
|
|
|
|
>&2 echo '[error] unable to infer target CPU architecture'
|
|
|
|
>&2 echo 'Please specify explicitly with `-c CPU`.'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
gitstatus_kernel="$(uname -s)"
|
|
|
|
gitstatus_kernel="$(printf '%s' "$gitstatus_kernel" | tr '[A-Z]' '[a-z]')"
|
|
|
|
|
|
|
|
case "$gitstatus_kernel" in
|
|
|
|
linux)
|
|
|
|
if [ -n "$docker_cmd" ]; then
|
|
|
|
if [ -z "${docker_cmd##*/*}" ]; then
|
|
|
|
if [ ! -x "$docker_cmd" ]; then
|
|
|
|
>&2 echo "[error] not an executable file: $docker_cmd"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if ! command -v "$docker_cmd" >/dev/null 2>&1; then
|
|
|
|
>&2 echo "[error] command not found: $docker_cmd"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -z "$docker_image" ]; then
|
|
|
|
case "$gitstatus_arch" in
|
2021-07-02 11:02:41 +02:00
|
|
|
x86_64) docker_image=alpine:3.11.6;;
|
|
|
|
x86|i386|i586|i686) docker_image=i386/alpine:3.11.6;;
|
|
|
|
armv6l|armhf) docker_image=arm32v6/alpine:3.11.6;;
|
|
|
|
armv7l) docker_image=arm32v7/alpine:3.11.6;;
|
|
|
|
aarch64) docker_image=arm64v8/alpine:3.11.6;;
|
2022-01-26 15:45:50 +02:00
|
|
|
ppc64|ppc64le) docker_image=ppc64le/alpine:3.11.6;;
|
2021-07-02 11:02:41 +02:00
|
|
|
s390x) docker_image=s390x/alpine:3.11.6;;
|
2020-05-10 15:58:05 +02:00
|
|
|
*)
|
|
|
|
>&2 echo '[error] unable to infer docker image'
|
|
|
|
>&2 echo 'Please specify explicitly with `-i IMAGE`.'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2022-02-07 09:38:49 +02:00
|
|
|
freebsd|openbsd|netbsd|darwin|dragonfly)
|
2020-05-10 15:58:05 +02:00
|
|
|
if [ -n "$docker_cmd" ]; then
|
|
|
|
>&2 echo "[error] docker (-d) is not supported on $gitstatus_kernel"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
msys_nt-*|mingw32_nt-*|mingw64_nt-*|cygwin_nt-*)
|
|
|
|
if ! printf '%s' "$gitstatus_kernel" | grep -Eqx '[^-]+-[0-9]+\.[0-9]+(-.*)?'; then
|
|
|
|
>&2 echo '[error] unsupported kernel, sorry!'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gitstatus_kernel="$(printf '%s' "$gitstatus_kernel" | sed 's/^\([^-]*-[0-9]*\.[0-9]*\).*/\1/')"
|
|
|
|
if [ -n "$docker_cmd" ]; then
|
|
|
|
>&2 echo '[error] docker (-d) is not supported on windows'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -n "$gitstatus_install_tools" -a -z "${gitstatus_kernel##cygwin_nt-*}" ]; then
|
|
|
|
>&2 echo '[error] -s is not supported on cygwin'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
>&2 echo '[error] unsupported kernel, sorry!'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
dir="$(dirname -- "$0")"
|
|
|
|
cd -- "$dir"
|
|
|
|
dir="$(pwd)"
|
|
|
|
|
|
|
|
>&2 echo "Building gitstatusd..."
|
|
|
|
>&2 echo ""
|
|
|
|
>&2 echo " kernel := $gitstatus_kernel"
|
|
|
|
>&2 echo " arch := $gitstatus_arch"
|
|
|
|
>&2 echo " cpu := $gitstatus_cpu"
|
|
|
|
[ -z "$docker_cmd" ] || >&2 echo " docker command := $docker_cmd"
|
|
|
|
[ -z "$docker_image" ] || >&2 echo " docker image := $docker_image"
|
|
|
|
if [ -n "$gitstatus_install_tools" ]; then
|
|
|
|
>&2 echo " install tools := yes"
|
|
|
|
else
|
|
|
|
>&2 echo " install tools := no"
|
|
|
|
fi
|
|
|
|
if [ -n "$gitstatus_download_deps" ]; then
|
|
|
|
>&2 echo " download deps := yes"
|
|
|
|
else
|
|
|
|
>&2 echo " download deps := no"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$docker_cmd" ]; then
|
|
|
|
"$docker_cmd" run \
|
2020-05-26 11:14:53 +02:00
|
|
|
-e docker_cmd="$docker_cmd" \
|
|
|
|
-e docker_image="$docker_image" \
|
2020-05-10 15:58:05 +02:00
|
|
|
-e gitstatus_kernel="$gitstatus_kernel" \
|
|
|
|
-e gitstatus_arch="$gitstatus_arch" \
|
|
|
|
-e gitstatus_cpu="$gitstatus_cpu" \
|
|
|
|
-e gitstatus_install_tools="$gitstatus_install_tools" \
|
|
|
|
-e gitstatus_download_deps="$gitstatus_download_deps" \
|
|
|
|
-v "$dir":/out \
|
|
|
|
-w /out \
|
|
|
|
--rm \
|
|
|
|
-- "$docker_image" /bin/sh -uexc "$build"
|
|
|
|
else
|
|
|
|
eval "$build"
|
|
|
|
fi
|