Skip to content

Instantly share code, notes, and snippets.

@mndrix
Last active November 13, 2021 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mndrix/53f258213d54b1937eff889beb73537c to your computer and use it in GitHub Desktop.
Save mndrix/53f258213d54b1937eff889beb73537c to your computer and use it in GitHub Desktop.
Scripts for building GNAT, et al on OpenBSD
#/bin/sh
#
# Build gnatcoll-bindings from source.
#
# Make sure that the first element of PATH is /usr/local and the
# second element is the GNAT toolchain you want to use.
set -e
usage() {
echo "usage: build-gnatcoll-bindings gnatcoll-bindings-src"
exit 1
}
if [ -z "$1" ]; then
usage;
fi
src="$(readlink -f $1)"
export GPR_PROJECT_PATH=/usr/local/share/gpr
whoami="$(whoami)"
case "$(uname)" in
OpenBSD)
# help C find libraries for gmp and iconv. Hints about the
# C_INCLUDE_PATH incantation came from
# https://github.com/AdaCore/gnatcoll-bindings/issues/3#issuecomment-412502668
export C_INCLUDE_PATH=/usr/local/include
# on OpenBSD, root's default PATH and GPR_PROJECT_PATH are
# acceptable as is
sudo="doas"
;;
*)
sudo="sudo --preserve-env=PATH,GPR_PROJECT_PATH"
;;
esac
echo "Cleaning gnatcoll-bindings…"
cd "$src"
$sudo chown -R $whoami:$whoami .
git clean -qxdf
git reset --hard
for component in gmp iconv readline syslog; do
echo "Building $component…"
cd $component
args=""
#args="--library-types=static"
case "$component" in
readline)
args="$args --accept-gpl"
;;
esac
python2 setup.py build -j0 --prefix=/usr/local $args
echo "Installing $component…"
$sudo python2 setup.py install --prefix=/usr/local
cd ..
done
#/bin/sh
#
# Build gnatcoll-core from source.
#
# Make sure that the first element of PATH is /usr/local and the
# second element is the GNAT toolchain you want to use.
set -e
usage() {
echo "usage: build-gnatcoll-core gnatcoll-core-src"
exit 1
}
if [ -z "$1" ]; then
usage;
fi
src="$(readlink -f $1)"
export GPR_PROJECT_PATH=/usr/local/share/gpr
whoami="$(whoami)"
case "$(uname)" in
OpenBSD)
make="gmake"
# on OpenBSD, root's default PATH and GPR_PROJECT_PATH are
# acceptable as is
sudo="doas"
;;
*)
make="make"
sudo="sudo --preserve-env=PATH,GPR_PROJECT_PATH"
;;
esac
echo "Cleaning gnatcoll-core…"
cd "$src"
$sudo chown -R $whoami:$whoami .
git clean -qxdf
git reset --hard
echo "Building gnatcoll-core…"
args=""
#args="ENABLE_SHARED=no"
$make prefix=/usr/local $args setup
$make
echo "Installing gnatcoll-core…"
$sudo $make install
#/bin/sh
#
# Build gnatcoll-db from source.
#
# Make sure that the first element of PATH is /usr/local and the
# second element is the GNAT toolchain you want to use.
set -e
usage() {
echo "usage: build-gnatcoll-db gnatcoll-db-src"
exit 1
}
if [ -z "$1" ]; then
usage;
fi
src="$(readlink -f $1)"
export GPR_PROJECT_PATH=/usr/local/share/gpr
whoami="$(whoami)"
case "$(uname)" in
OpenBSD)
make="gmake"
# on OpenBSD, root's default PATH and GPR_PROJECT_PATH are
# acceptable as is
sudo="doas"
;;
*)
make="make"
sudo="sudo --preserve-env=PATH,GPR_PROJECT_PATH"
;;
esac
echo "Cleaning gnatcoll-db…"
cd "$src"
$sudo chown -R $whoami:$whoami .
git clean -qxdf
git reset --hard
for component in sql sqlite xref; do
echo "Building $component…"
cd $component
args=""
#args="ENABLE_SHARED=no"
$make "prefix=/usr/local" $args setup
$make
echo "Installing $component…"
$sudo $make install
cd ..
done
#/bin/sh
#
# Build gprbuild (and its dependency xmldata) from scratch.
#
# The first element of PATH must be /usr/local and the second element
# must be the GNAT toolchain you want to use. If those paths are the
# same, PATH only needs the path once.
#
# I recent copy of the gprconfig_kb repository is assumed to be
# checked out in ~/src/gprconfig_kb.
set -e
usage() {
echo "usage: build-gprbuild gprbuild-src xmlada-src"
exit 1
}
gprconfig_kb_src="$(readlink -f $HOME/src/gprconfig_kb)"
if [ -z "$1" ]; then
usage;
fi
gprbuild_src="$(readlink -f $1)" # get absolute path
if [ -z "$2" ]; then
usage;
fi
xmlada_src="$(readlink -f $2)" # get absolute path
whoami="$(whoami)"
# gprbuild invokes gprconfig and gprinstall, both of which need
# accurate PATH and GPR_PROJECT_PATH values to function correctly.
# Without these values, neither tool can find the Ada compiler or the
# *.gpr files describing the project.
case "$(uname)" in
OpenBSD)
make="gmake"
# on OpenBSD, root's default PATH and GPR_PROJECT_PATH are
# acceptable as is
sudo="doas"
;;
*)
make="make"
sudo="sudo --preserve-env=PATH,GPR_PROJECT_PATH"
;;
esac
# install a barely-functional gprbuild in /usr/local. This is just
# enough to build xmlada (a dependency for gprbuild), so the rest of
# the build steps can proceed.
echo "Cleaning gprbuild…"
cd "$gprbuild_src"
$sudo chown -R $whoami:$whoami . # undo install owning some as root
git clean -qxdf
git reset --hard
echo "Building bootstrap gprbuild…"
bash bootstrap.sh --build --with-xmlada="$xmlada_src" \
--with-kb="$gprconfig_kb_src" --prefix=/usr/local
echo "Installing bootstrap gprbuild…"
$sudo bash bootstrap.sh --install --with-xmlada="$xmlada_src" \
--with-kb="$gprconfig_kb_src" --prefix=/usr/local
# use the bootstrapped gprbuild to install xmlada
echo "Cleaning xmlada…"
cd "$xmlada_src"
$sudo chown -R $whoami:$whoami .
git clean -qxdf
git reset --hard
echo "Building xmlada…"
./configure --prefix=/usr/local
$make all
echo "Installing xmlada…"
$sudo $make install
# now that xmlada in installed, we can use the bootstrapped gprbuild
# to build the real gprbuild and perform a full install.
echo "Building gprbuild…"
cd "$gprbuild_src"
export GPR_PROJECT_PATH=/usr/local/share/gpr
$make prefix=/usr/local setup
$make all
echo "Installing gprbuild…"
$sudo $make install
# many tools need libgpr, not just the gprbuild binary
echo "Building gprbuild library…"
$make libgpr.build
echo "Installing gprbuild library…"
$sudo $make libgpr.install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment