#!/bin/bash cc=gcc cflags=(-Wall -Wextra -std=gnu99 -O2) ldflags=(-lm) platform=gl debug= run= clean= tags= for flag in $@; do case "$flag" in '-run') run=true ;; '-debug') debug=true ;; '-clean') clean=true ;; '-use-x11') platform=x11 ;; '-use-gl') platform=gl ;; esac done if [ ! -z "$clean" ]; then rm demonchime rm libteensy.so exit fi [ ! -z "$debug" ] && cflags+=(-g -ggdb -rdynamic) teensy_cflags=(${cflags[@]} -fPIC -Iteensy -Iplatform/$platform) [ ! -z "$debug" ] && teensy_cflags+=(-DTEENSY_DEBUG) teensy_ldflags=(${ldflags[@]}) case "$platform" in 'x11') teensy_ldflags+=(-lX11) ;; 'gl') teensy_ldflags+=(-lglfw) ;; esac dc_cflags=(${cflags[@]} -Iteensy -Idc) [ ! -z "$debug" ] && teensy_cflags+=(-DDC_DEBUG) dc_ldflags=(${ldflags[@]} -L. -lteensy) dc_src=$(find dc -name '*.c') teensy_src=$(find teensy -name '*.c') platform_src=$(find platform/$platform -name '*.c') echo -e "dc:\t\t$(tr '\n' ' ' <<< "$dc_src")" echo -e "teensy:\t\t$(tr '\n' ' ' <<< "$teensy_src")" echo -e "platform:\t$(tr '\n' ' ' <<< "$platform_src")" time ( echo -e "building libteensy\t: ${teensy_ldflags[@]} ${teensy_cflags[@]}" $cc -shared -o libteensy.so \ ${teensy_ldflags[@]} \ ${teensy_cflags[@]} \ ${teensy_src[@]} ${platform_src[@]} || exit 1 echo -e "building demonchime\t: ${dc_ldflags[@]} ${dc_cflags[@]}" $cc -o demonchime \ ${dc_ldflags[@]} \ ${dc_cflags[@]} \ ${dc_src[@]} || exit 1 ) [ $? -eq 0 ] && [ ! -z "$run" ] && LD_LIBRARY_PATH=. $RUN_CMD ./demonchime