From 8206a9ba99b321c98a7a8a6b5523deaa349dfbf4 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Fri, 24 Jun 2022 10:23:12 +0200 Subject: [PATCH] Allow for manually overriding the compiler and some flags using make-style environment variables This adds support for using the CXX and CXXFLAGS environment varibles, they work as you would expect. --- build.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index d75fb4a..52967e3 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,18 @@ #!/bin/bash +if [ -z "$CXX" ]; then + CXX="c++" +fi +if [ -z "$CXXFLAGS" ]; then + CXXFLAGS="-std=c++20 -Wall" +fi +CXX_WITH_FLAGS="$CXX $CXXFLAGS" + # `.cpp` files in src/lib will be automatically picked up and compiled into dynamic libraries. echo "Building libs..." mkdir -pv bin/lib for lib in $(find ./src/lib -name "*.cpp"); do - COMPILE_COMMAND="c++ -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib" + COMPILE_COMMAND="$CXX_WITH_FLAGS -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib" echo $COMPILE_COMMAND $COMPILE_COMMAND done @@ -27,6 +35,6 @@ mkdir -pv bin/tools # add compile commands to this variable COMPILE_COMMANDS=" set -v -c++ src/tools/dumpnbt.cpp -Lbin/lib -lnbt -o bin/tools/dumpnbt +$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -lnbt -o bin/tools/dumpnbt " sh <<< $COMPILE_COMMANDS