| 1 | #! /bin/bashscip-shell filesystem . . `/bin/bash`. -e |
| 2 | |
| 3 | ##################################################################### |
| 4 | # # |
| 5 | # Compiles Faust programs to a bench # |
| 6 | # (c) Grame, 2022-2023 # |
| 7 | # # |
| 8 | ##################################################################### |
| 9 | |
| 10 | # Define some common paths |
| 11 | . faustpathscip-shell source . . faustpath. |
| 12 | |
| 13 | # Define compilation flags |
| 14 | . faustoptflagsscip-shell source . . faustoptflags. |
| 15 | |
| 16 | # Helper file to build the 'help' option |
| 17 | . usage.shscip-shell source . . `usage.sh`. |
| 18 | |
| 19 | CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used |
| 20 | |
| 21 | # The architecture file name |
| 22 | ARCHFILE=$FAUSTARCH/bench.cpp |
| 23 | |
| 24 | # Global variables |
| 25 | OPTIONS="" |
| 26 | FILES="" |
| 27 | DOUBLE="0" |
| 28 | |
| 29 | echoHelpscip-shell shell shell-project 0.0.0 echoHelp().() |
| 30 | { |
| 31 | usage faust2bench "[Faust options] <file.dsp>" |
| 32 | echoscip-shell system . . echo. "Compiles Faust programs to a benchmark executable" |
| 33 | option "Faust options" |
| 34 | exit |
| 35 | } |
| 36 | |
| 37 | if [scip-shell system . . `[`. "$#" -eq 0 ]; then |
| 38 | echoscip-shell system . . echo. 'Please, provide a Faust file to process !' |
| 39 | echoscip-shell system . . echo. '' |
| 40 | echoHelpscip-shell shell shell-project 0.0.0 echoHelp(). |
| 41 | fi |
| 42 | |
| 43 | #------------------------------------------------------------------- |
| 44 | # dispatch command arguments |
| 45 | #------------------------------------------------------------------- |
| 46 | |
| 47 | while [scip-shell system . . `[`. $1 ] |
| 48 | do |
| 49 | p=$1 |
| 50 | |
| 51 | if [scip-shell system . . `[`. $p = "-help" ] || [scip-shell system . . `[`. $p = "-h" ]; then |
| 52 | echoHelpscip-shell shell shell-project 0.0.0 echoHelp(). |
| 53 | elif [scip-shell system . . `[`. "$p" = "-double" ]; then |
| 54 | DOUBLE="1" |
| 55 | OPTIONS="$OPTIONS $p" |
| 56 | elif [scip-shell system . . `[`. ${p:0:1} = "-" ]; then |
| 57 | OPTIONS="$OPTIONS $p" |
| 58 | elif [[ -f "$p" ]] && [scip-shell system . . `[`. ${p: -4} == ".dsp" ]; then |
| 59 | FILES="$FILES $p" |
| 60 | else |
| 61 | OPTIONS="$OPTIONS $p" |
| 62 | fi |
| 63 | |
| 64 | shift |
| 65 | |
| 66 | done |
| 67 | |
| 68 | #------------------------------------------------------------------- |
| 69 | # compile the *.dsp files |
| 70 | #------------------------------------------------------------------- |
| 71 | |
| 72 | for f in $FILES; do |
| 73 | |
| 74 | # compile the DSP to c++ using the architecture file |
| 75 | faust -i -a $ARCHFILE $OPTIONS "$f" -o "${f%.dsp}_tmp.cpp"|| exit |
| 76 | |
| 77 | # Create config file |
| 78 | echoscip-shell system . . echo. -n >> Config |
| 79 | if [scip-shell system . . `[`. $DOUBLE == "1" ]; then |
| 80 | echoscip-shell system . . echo. "#define FAUSTFLOAT double" >> Config |
| 81 | else |
| 82 | echoscip-shell system . . echo. "#define FAUSTFLOAT float" >> Config |
| 83 | fi |
| 84 | catscip-shell system . . cat. Config "${f%.dsp}_tmp.cpp" > "${f%.dsp}.cpp" |
| 85 | |
| 86 | # compile c++ to binary |
| 87 | ( |
| 88 | $CXX $CXXFLAGS "${f%.dsp}.cpp" -o "${f%.dsp}" |
| 89 | ) > /dev/nullscip-shell filesystem . . `/dev/null`. || exit |
| 90 | |
| 91 | # remove temporary files |
| 92 | rmscip-shell system . . rm. -f Config "${f%.dsp}.cpp" "${f%.dsp}_tmp.cpp" |
| 93 | |
| 94 | # collect binary file name for FaustWorks |
| 95 | BINARIES="$BINARIES${f%.dsp};" |
| 96 | done |
| 97 | |
| 98 | echoscip-shell system . . echo. $BINARIES |
| 99 | |
| 100 |