|
@ -3,38 +3,50 @@ set -eu -o pipefail |
|
|
|
|
|
|
|
|
print_usage() { |
|
|
print_usage() { |
|
|
cat <<EOF |
|
|
cat <<EOF |
|
|
Usage: tool [options] command [args] |
|
|
Usage: tool <command> [options] [arguments] |
|
|
|
|
|
Example: |
|
|
|
|
|
tool build --portmidi orca |
|
|
Commands: |
|
|
Commands: |
|
|
build <config> <target> |
|
|
build <target> |
|
|
Compile orca. |
|
|
Compiles the livecoding environment or the CLI tool. |
|
|
Configs: debug, release |
|
|
|
|
|
Targets: orca, cli |
|
|
Targets: orca, cli |
|
|
Output: build/<config>/<target> |
|
|
Output: build/<target> |
|
|
clean |
|
|
clean |
|
|
Removes build/ |
|
|
Removes build/ |
|
|
info |
|
|
info |
|
|
Prints information about the detected build environment. |
|
|
Prints information about the detected build environment. |
|
|
Options: |
|
|
Options: |
|
|
-v Print important commands as they're executed. |
|
|
-c <name> Use a specific compiler binary. Default: \$CC, or cc |
|
|
-c <name> Use a specific compiler binary. |
|
|
-d Build with debug features. Output changed to: |
|
|
Default: \$CC, or cc |
|
|
build/debug/<target> |
|
|
-d Enable compiler safeguards like -fstack-protector. |
|
|
--harden Enable compiler safeguards like -fstack-protector. |
|
|
You should probably do this if you plan to give the |
|
|
You should probably do this if you plan to give the |
|
|
compiled binary to other people. |
|
|
compiled binary to other people. |
|
|
--static Build static binary. |
|
|
--static Build static binary. |
|
|
--pie Enable PIE (ASLR). |
|
|
--pie Enable PIE (ASLR). |
|
|
Note: --pie and --static cannot be mixed. |
|
|
Note: --pie and --static cannot be mixed. |
|
|
-s Print statistics about compile time and binary size. |
|
|
-s Print statistics about compile time and binary size. |
|
|
|
|
|
-v Print important commands as they're executed. |
|
|
-h or --help Print this message and exit. |
|
|
-h or --help Print this message and exit. |
|
|
Optional Features: |
|
|
Optional Features: |
|
|
--portmidi Enable hardware MIDI output support with PortMIDI. |
|
|
--portmidi Enable or disable hardware MIDI output support with |
|
|
Default: not enabled |
|
|
--no-portmidi PortMIDI. Note: PortMIDI has memory leaks and bugs. |
|
|
Note: PortMIDI has memory leaks and bugs. |
|
|
Default: disabled. |
|
|
--nomouse Disables mouse clicks. |
|
|
--mouse Enable or disable mouse features in the livecoding |
|
|
Default: not enabled (mouse enabled). |
|
|
--no-mouse environment. |
|
|
|
|
|
Default: enabled. |
|
|
EOF |
|
|
EOF |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if [[ -z "${1:-}" ]]; then |
|
|
|
|
|
echo "Error: Command required" >&2 |
|
|
|
|
|
print_usage >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
cmd=$1 |
|
|
|
|
|
shift |
|
|
|
|
|
|
|
|
os= |
|
|
os= |
|
|
case $(uname -s | awk '{print tolower($0)}') in |
|
|
case $(uname -s | awk '{print tolower($0)}') in |
|
|
linux*) os=linux;; |
|
|
linux*) os=linux;; |
|
@ -53,16 +65,20 @@ pie_enabled=0 |
|
|
static_enabled=0 |
|
|
static_enabled=0 |
|
|
portmidi_enabled=0 |
|
|
portmidi_enabled=0 |
|
|
mouse_disabled=0 |
|
|
mouse_disabled=0 |
|
|
|
|
|
config_mode=release |
|
|
|
|
|
|
|
|
while getopts c:dhsv-: opt_val; do |
|
|
while getopts c:dhsv-: opt_val; do |
|
|
case "$opt_val" in |
|
|
case "$opt_val" in |
|
|
-) |
|
|
-) |
|
|
case "$OPTARG" in |
|
|
case "$OPTARG" in |
|
|
|
|
|
harden) protections_enabled=1;; |
|
|
help) print_usage; exit 0;; |
|
|
help) print_usage; exit 0;; |
|
|
static) static_enabled=1;; |
|
|
static) static_enabled=1;; |
|
|
pie) pie_enabled=1;; |
|
|
pie) pie_enabled=1;; |
|
|
portmidi) portmidi_enabled=1;; |
|
|
portmidi) portmidi_enabled=1;; |
|
|
nomouse) mouse_disabled=1;; |
|
|
no-portmidi|noportmidi) portmidi_enabled=0;; |
|
|
|
|
|
mouse) mouse_disabled=0;; |
|
|
|
|
|
no-mouse|nomouse) mouse_disabled=1;; |
|
|
*) |
|
|
*) |
|
|
echo "Unknown long option --$OPTARG" >&2 |
|
|
echo "Unknown long option --$OPTARG" >&2 |
|
|
print_usage >&2 |
|
|
print_usage >&2 |
|
@ -71,7 +87,7 @@ while getopts c:dhsv-: opt_val; do |
|
|
esac |
|
|
esac |
|
|
;; |
|
|
;; |
|
|
c) cc_exe="$OPTARG";; |
|
|
c) cc_exe="$OPTARG";; |
|
|
d) protections_enabled=1;; |
|
|
d) config_mode=debug;; |
|
|
h) print_usage; exit 0;; |
|
|
h) print_usage; exit 0;; |
|
|
s) stats_enabled=1;; |
|
|
s) stats_enabled=1;; |
|
|
v) verbose=1;; |
|
|
v) verbose=1;; |
|
@ -202,7 +218,6 @@ try_make_dir() { |
|
|
build_dir=build |
|
|
build_dir=build |
|
|
|
|
|
|
|
|
build_target() { |
|
|
build_target() { |
|
|
local build_subdir |
|
|
|
|
|
local cc_flags=() |
|
|
local cc_flags=() |
|
|
local libraries=() |
|
|
local libraries=() |
|
|
local source_files=() |
|
|
local source_files=() |
|
@ -228,9 +243,8 @@ build_target() { |
|
|
if [[ $static_enabled = 1 ]]; then |
|
|
if [[ $static_enabled = 1 ]]; then |
|
|
add cc_flags -static |
|
|
add cc_flags -static |
|
|
fi |
|
|
fi |
|
|
case "$1" in |
|
|
case $config_mode in |
|
|
debug) |
|
|
debug) |
|
|
build_subdir=debug |
|
|
|
|
|
add cc_flags -DDEBUG -ggdb |
|
|
add cc_flags -DDEBUG -ggdb |
|
|
# cygwin gcc doesn't seem to have this stuff, just elide for now |
|
|
# cygwin gcc doesn't seem to have this stuff, just elide for now |
|
|
if [[ $os != cygwin ]]; then |
|
|
if [[ $os != cygwin ]]; then |
|
@ -249,7 +263,6 @@ build_target() { |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
release) |
|
|
release) |
|
|
build_subdir=release |
|
|
|
|
|
add cc_flags -DNDEBUG -O2 -g0 |
|
|
add cc_flags -DNDEBUG -O2 -g0 |
|
|
if [[ $protections_enabled != 1 ]]; then |
|
|
if [[ $protections_enabled != 1 ]]; then |
|
|
add cc_flags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector |
|
|
add cc_flags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector |
|
@ -262,7 +275,7 @@ build_target() { |
|
|
add cc_flags -flto -s |
|
|
add cc_flags -flto -s |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
*) fatal "Unknown build config \"$1\"";; |
|
|
*) fatal "Unknown build config \"$config_mode\"";; |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|
case $arch in |
|
|
case $arch in |
|
@ -287,7 +300,7 @@ build_target() { |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|
add source_files gbuffer.c field.c bank.c sim.c |
|
|
add source_files gbuffer.c field.c bank.c sim.c |
|
|
case "$2" in |
|
|
case $1 in |
|
|
cli) |
|
|
cli) |
|
|
add source_files cli_main.c |
|
|
add source_files cli_main.c |
|
|
out_exe=cli |
|
|
out_exe=cli |
|
@ -339,7 +352,7 @@ build_target() { |
|
|
if [[ $portmidi_enabled = 1 ]]; then |
|
|
if [[ $portmidi_enabled = 1 ]]; then |
|
|
add libraries -lportmidi |
|
|
add libraries -lportmidi |
|
|
add cc_flags -DFEAT_PORTMIDI |
|
|
add cc_flags -DFEAT_PORTMIDI |
|
|
if [[ $1 = debug ]]; then |
|
|
if [[ $config_mode = debug ]]; then |
|
|
echo -e "Warning: The PortMIDI library contains bugs.\\nIt may trigger address sanitizer in debug builds.\\nThese are not bugs in orca." >&2 |
|
|
echo -e "Warning: The PortMIDI library contains bugs.\\nIt may trigger address sanitizer in debug builds.\\nThese are not bugs in orca." >&2 |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
@ -347,10 +360,17 @@ build_target() { |
|
|
add cc_flags -DFEAT_NOMOUSE |
|
|
add cc_flags -DFEAT_NOMOUSE |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
echo -e "Unknown build target '$1'\\nValid targets: orca, cli" >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
;; |
|
|
esac |
|
|
esac |
|
|
try_make_dir "$build_dir" |
|
|
try_make_dir "$build_dir" |
|
|
try_make_dir "$build_dir/$build_subdir" |
|
|
if [[ $config_mode = debug ]]; then |
|
|
local out_path=$build_dir/$build_subdir/$out_exe |
|
|
build_dir=$build_dir/debug |
|
|
|
|
|
try_make_dir "$build_dir" |
|
|
|
|
|
fi |
|
|
|
|
|
local out_path=$build_dir/$out_exe |
|
|
# bash versions quirk: empty arrays might give error on expansion, use + |
|
|
# bash versions quirk: empty arrays might give error on expansion, use + |
|
|
# trick to avoid expanding second operand |
|
|
# trick to avoid expanding second operand |
|
|
verbose_echo timed_stats "$cc_exe" "${cc_flags[@]}" -o "$out_path" "${source_files[@]}" ${libraries[@]+"${libraries[@]}"} |
|
|
verbose_echo timed_stats "$cc_exe" "${cc_flags[@]}" -o "$out_path" "${source_files[@]}" ${libraries[@]+"${libraries[@]}"} |
|
@ -379,34 +399,31 @@ EOF |
|
|
|
|
|
|
|
|
shift $((OPTIND - 1)) |
|
|
shift $((OPTIND - 1)) |
|
|
|
|
|
|
|
|
if [[ -z "${1:-}" ]]; then |
|
|
case $cmd in |
|
|
echo "Error: Command required" >&2 |
|
|
|
|
|
print_usage >&2 |
|
|
|
|
|
exit 1 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
case "$1" in |
|
|
|
|
|
info) |
|
|
info) |
|
|
if [[ "$#" -gt 1 ]]; then |
|
|
if [[ "$#" -gt 1 ]]; then |
|
|
fatal "Too many arguments for 'info'" |
|
|
fatal "Too many arguments for 'info'" |
|
|
fi |
|
|
fi |
|
|
print_info |
|
|
print_info; exit 0;; |
|
|
exit 0 |
|
|
|
|
|
;; |
|
|
|
|
|
build) |
|
|
build) |
|
|
if [[ "$#" -lt 3 ]]; then |
|
|
if [[ "$#" -lt 1 ]]; then |
|
|
fatal "Too few arguments for 'build'" |
|
|
fatal "Too few arguments for 'build'" |
|
|
fi |
|
|
fi |
|
|
if [[ "$#" -gt 3 ]]; then |
|
|
if [[ "$#" -gt 1 ]]; then |
|
|
fatal "Too many arguments for 'build'" |
|
|
echo "Too many arguments for 'build'" >&2 |
|
|
|
|
|
echo "The syntax has changed. Updated usage examples:" >&2 |
|
|
|
|
|
echo "./tool build --portmidi orca (release)" >&2 |
|
|
|
|
|
echo "./tool build -d orca (debug)" >&2 |
|
|
|
|
|
exit 1 |
|
|
fi |
|
|
fi |
|
|
build_target "$2" "$3" |
|
|
build_target "$1" |
|
|
;; |
|
|
;; |
|
|
clean) |
|
|
clean) |
|
|
if [[ -d "$build_dir" ]]; then |
|
|
if [[ -d "$build_dir" ]]; then |
|
|
verbose_echo rm -rf "$build_dir" |
|
|
verbose_echo rm -rf "$build_dir" |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
*) fatal "Unrecognized command $1";; |
|
|
help) print_usage; exit 0;; |
|
|
|
|
|
*) fatal "Unrecognized command $cmd";; |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|