diff --git a/.build.sh b/.build.sh new file mode 100644 index 0000000..31b14ea --- /dev/null +++ b/.build.sh @@ -0,0 +1,25 @@ +#!/bin/echo Must be sourced from a bash script ** + +# strict mode +export IFS=$'\n' +set -eu -o pipefail + +# git clone wrapper +clone () { + if ! [ -e "$2" ]; then + git clone \ + --single-branch --depth 1 \ + --recurse-submodules \ + "$1" \ + "$2" + else + echo " ** '$2/' already exists" + fi +} + +# make -j12 +make_maxthreads() { + [ -v JOBS ] || JOBS=$(nproc || echo 4) + JOBS="${JOBS//[^0-9]/}" + make -j"$JOBS" +} diff --git a/build_dig.sh b/build_dig.sh index 89bede2..bf3461e 100755 --- a/build_dig.sh +++ b/build_dig.sh @@ -1,7 +1,6 @@ #!/bin/bash -IFS=$'\n' -set -eu -o pipefail +source .build.sh echo echo '==> Checking deps' @@ -12,13 +11,10 @@ which gcc || which clang echo echo '==> Cloning repo' -if ! [ -e bind9 ]; then - git clone --single-branch --depth 1 https://gitlab.isc.org/isc-projects/bind9.git bind9 -else - echo ' ** bind9/ already exists' -fi +clone https://gitlab.isc.org/isc-projects/bind9.git bind9 cd bind9 +trap 'cd ..' EXIT export CFLAGS="-O3" CPPFLAGS="-O3" echo @@ -38,10 +34,7 @@ echo '==> ./configure (check deps, generate config)' echo echo '==> make' -make -j$(nproc) - -unset CFLAGS CPPFLAGS -cd .. +make_maxthreads echo echo '==> Done' diff --git a/build_drill.sh b/build_drill.sh index 8d91f9c..cf020a2 100755 --- a/build_drill.sh +++ b/build_drill.sh @@ -1,7 +1,6 @@ #!/bin/bash -IFS=$'\n' -set -eu -o pipefail +source .build.sh echo echo '==> Checking deps' @@ -13,13 +12,10 @@ which gcc || which clang echo echo '==> Cloning repo' -if ! [ -e ldns ]; then - git clone --single-branch --depth 1 --recurse-submodules https://github.com/NLnetLabs/ldns.git ldns -else - echo ' ** ldns/ already exists' -fi +clone https://github.com/NLnetLabs/ldns.git ldns cd ldns +trap 'cd ..' EXIT export CFLAGS="-O3" echo @@ -42,10 +38,7 @@ echo '==> ./configure (check deps, generate config)' echo echo '==> make' -make -j$(nproc || echo 4) - -unset CFLAGS -cd .. +make_maxthreads echo echo '==> Done' diff --git a/build_hr.sh b/build_hr.sh index 477c756..9fb25f3 100755 --- a/build_hr.sh +++ b/build_hr.sh @@ -1,7 +1,6 @@ #!/bin/bash -IFS=$'\n' -set -eu -o pipefail +source .build.sh echo echo '==> Checking deps' @@ -10,18 +9,19 @@ which cargo echo echo '==> Cloning repo' -git clone --single-branch --depth 1 https://github.com/hickory-dns/hickory-dns.git hickory-dns +clone https://github.com/hickory-dns/hickory-dns.git hickory-dns + +cd hickory-dns +trap 'cd ..' EXIT echo echo '==> Building resolve' -cd hickory-dns cargo build \ --release \ --bin resolve \ --features dnssec-ring \ --config 'panic="abort"' \ --config 'lto="fat"' -cd .. echo echo '==> Done'