code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(48 lines)
1 #!/bin/sh
3 error() {
4 printf "\033[31;1m%s\033[m\n" "$@"
5 exit 1
6 }
8 default_prefix='/usr/local'
9 if echo "$PATH" | tr ':' '\n' | grep -qx "$HOME/.local/bin"; then
10 default_prefix="$HOME/.local"
11 fi
13 printf '\033[1mChoose where to install Tomo (default: %s):\033[m ' "$default_prefix"
14 read -r PREFIX
15 if [ -z "$PREFIX" ]; then PREFIX="$default_prefix"; fi
17 if ! echo "$PATH" | tr ':' '\n' | grep -qx "$PREFIX/bin"; then
18 error "Your \$PATH does not include this prefix, so you won't be able to run tomo!" \
19 "Please put this in your .profile or .bashrc: export PATH=\"$PREFIX/bin:\$PATH\""
20 fi
22 if command -v doas >/dev/null; then
23 SUDO=doas
24 else
25 SUDO=sudo
26 fi
28 default_cc="cc"
29 printf '\033[1mChoose which C compiler to use by default (default: %s):\033[m ' "$default_cc"
30 read -r DEFAULT_C_COMPILER
31 if [ -z "$DEFAULT_C_COMPILER" ]; then DEFAULT_C_COMPILER="cc"; fi
33 printf '\033[1mDo you want to build the compiler with Link Time Optimization (LTO)?\033[m\n\033[2m(This makes building the Tomo compiler slower, but makes running Tomo programs faster)\033[m\n\033[1m[y/N]\033[m '
34 read -r USE_LTO
35 if [ "$USE_LTO" = "y" ] || [ "$USE_LTO" = "Y" ]; then
36 if $DEFAULT_C_COMPILER -v 2>&1 | grep -q "gcc version"; then
37 LTO="-flto=auto -fno-fat-lto-objects -Wl,-flto";
38 elif $DEFAULT_C_COMPILER -v 2>&1 | grep -q "clang version"; then
39 LTO="-flto=thin";
40 fi
41 fi
43 cat <<END >config.mk
44 PREFIX=$PREFIX
45 DEFAULT_C_COMPILER=$DEFAULT_C_COMPILER
46 SUDO=$SUDO
47 LTO=$LTO
48 END