source-foundry / ttfautohint-build

Build ttfautohint from source on Linux and macOS platforms
MIT License
27 stars 12 forks source link

Make variables overwritable by environment #44

Open CodingMarkus opened 2 years ago

CodingMarkus commented 2 years ago

Variables like

BUILD="$HOME/ttfautohint-build"
INST="$BUILD/local"

should be customizable without having to alter your build script. An easy way to do that is by allowing them to be overwritten through environment variables. So if I want a custom build dir, I would just run

BUILD="/tmp/build" ./ttautohint-build.sh

To make that possible, you want to have your code work like this

if [ -z "$BUILD" ]
then
    BUILD="$HOME/ttfautohint-build"
fi

so if $BUILD is already set, just take the value and don't set your own one. Only set a value if no value is set in environment.

And there exists a much easier way to write the code above, which is even POSIX shell conform and thus supported by all shells:

: "${BUILD:="$HOME/ttfautohint-build"}"

That's it. It will set $BUILD only if not already set.