| 1 | #! /bin/bash -e |
| 2 | |
| 3 | ##################################################################### |
| 4 | # # |
| 5 | # Compiles Faust programs to plotters # |
| 6 | # (c) Grame, 2009-2022 # |
| 7 | # # |
| 8 | ##################################################################### |
| 9 | |
| 10 | . faustpath |
| 11 | . faustoptflags |
| 12 | . usage.sh |
| 13 | |
| 14 | CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used |
| 15 | |
| 16 | ARCHFILE=$FAUSTARCH/matlabplot.cpp |
| 17 | ARCHLIB+=" -pthread" |
| 18 | |
| 19 | FAUSTFLOAT=float |
| 20 | |
| 21 | echoHelp() |
| 22 | { |
| 23 | usage faust2plot "[options] [Faust options] <file.dsp>" |
| 24 | echo "Compiles Faust programs to plotters, additional control parameters depend of the DSP, the following 4 options are given at runtime:" |
| 25 | options -dyn |
| 26 | option "-s <n>" "start at the sample number <n> (default is 0)" |
| 27 | option "-n <n>" "render <n> samples (default is 16)" |
| 28 | option "-r <rate>" "change the sample rate (default is 44100 Hz)" |
| 29 | option "Faust options" |
| 30 | exit |
| 31 | } |
| 32 | |
| 33 | if [ "$#" -eq 0 ]; then |
| 34 | echo 'Please, provide a Faust file to process !' |
| 35 | echo '' |
| 36 | echoHelp |
| 37 | fi |
| 38 | |
| 39 | #------------------------------------------------------------------- |
| 40 | # Analyze command arguments : |
| 41 | # faust options -> OPTIONS |
| 42 | # if -omp : -openmp or -fopenmp -> OPENMP |
| 43 | # existing *.dsp files -> FILES |
| 44 | |
| 45 | # dispatch command arguments |
| 46 | for p in $@; do |
| 47 | |
| 48 | if [ $p = "-help" ] || [ $p = "-h" ]; then |
| 49 | echoHelp |
| 50 | elif [ $p = "-arch32" ]; then |
| 51 | PROCARCH="-m32 -L/usr/lib32" |
| 52 | elif [ $p = "-arch64" ]; then |
| 53 | PROCARCH="-m64" |
| 54 | elif [ $p = "-double" ]; then |
| 55 | OPTIONS="$OPTIONS $p" |
| 56 | FAUSTFLOAT="double" |
| 57 | elif [ $p = "-dyn" ]; then |
| 58 | OPTIONS="$OPTIONS -inj template-llvm.cpp" |
| 59 | LLVM_LIBS="$STRIP $FAUSTLDDIR/libfaust.a `llvm-config --link-static --ldflags --libs all --system-libs`" |
| 60 | elif [ ${p:0:1} = "-" ]; then |
| 61 | OPTIONS="$OPTIONS $p" |
| 62 | elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then |
| 63 | FILES="$FILES $p" |
| 64 | else |
| 65 | OPTIONS="$OPTIONS $p" |
| 66 | fi |
| 67 | |
| 68 | done |
| 69 | |
| 70 | #------------------------------------------------------------------- |
| 71 | # compile the *.dsp files |
| 72 | |
| 73 | for f in $FILES; do |
| 74 | |
| 75 | # compile faust to c++ |
| 76 | faust -i -a $ARCHFILE $OPTIONS "$f" -o "$f.cpp" || exit |
| 77 | |
| 78 | # compile c++ to binary |
| 79 | ( |
| 80 | $CXX $CXXFLAGS $PROCARCH $OMP $LLVM_LIBS $ARCHLIB -DFAUSTFLOAT=$FAUSTFLOAT "$f.cpp" -o "${f%.dsp}" |
| 81 | ) > /dev/null || exit |
| 82 | rm "$f.cpp" |
| 83 | |
| 84 | # collect binary file name for FaustWorks |
| 85 | BINARIES="$BINARIES${f%.dsp};" |
| 86 | done |
| 87 | echo $BINARIES |