diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 16:52:55 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 16:52:55 -0400 |
| commit | 0e0808bce2160eb1382a2cf9499d943d4e51bdf4 (patch) | |
| tree | cbfe0cf941048121c07396bc5375aa6dc5eb59c8 /configure.sh | |
| parent | d6651e0d8f5bbc7dba12003ccda023c97273ce86 (diff) | |
Add configuration script to choose install paths and default C compiler
and bake those into the compiled Tomo code
Diffstat (limited to 'configure.sh')
| -rwxr-xr-x | configure.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/configure.sh b/configure.sh new file mode 100755 index 00000000..9ad06fb0 --- /dev/null +++ b/configure.sh @@ -0,0 +1,44 @@ +#!/bin/env bash + +# if [ "$1" = '--lazy' -a ! -f 'config.mk' ]; then +# echo "Already configured!" +# exit 0 +# fi + +error() { + printf "\033[31;1m%s\033[m\n" "$@" + exit 1 +} + +default_prefix='/usr/local' +if echo "$PATH" | tr ':' '\n' | grep -qx "$HOME/.local/bin"; then + default_prefix="~/.local" +fi + +printf '\033[1mChoose where to install Tomo (default: %s):\033[m ' "$default_prefix" +read PREFIX +if [ -z "$PREFIX" ]; then PREFIX="$default_prefix"; fi +PREFIX="${PREFIX/#\~/$HOME}" + +if ! echo "$PATH" | tr ':' '\n' | grep -qx "$PREFIX/bin"; then + error "Your \$PATH does not include this prefix, so you won't be able to run tomo!" \ + "Please put this in your .profile or .bashrc: export PATH=\"$PREFIX:\$PATH\"" +fi + +default_home="~/.local/share/tomo" +printf '\033[1mChoose where to install Tomo libraries (default: %s):\033[m ' "$default_home" +read TOMO_HOME +if [ -z "$TOMO_HOME" ]; then TOMO_HOME="$default_home"; fi +TOMO_HOME="${TOMO_HOME/#\~/$HOME}" + +default_cc="cc" +printf '\033[1mChoose which C compiler to use by default (default: %s):\033[m ' "$default_cc" +read DEFAULT_C_COMPILER +if [ -z "$DEFAULT_C_COMPILER" ]; then DEFAULT_C_COMPILER="$default_home"; fi +DEFAULT_C_COMPILER="${DEFAULT_C_COMPILER/#\~/$HOME}" + +cat <<END >config.mk +PREFIX=$PREFIX +TOMO_HOME=$TOMO_HOME +DEFAULT_C_COMPILER=$DEFAULT_C_COMPILER +END |
