| 1 | #! /bin/bash -e |
| 2 | |
| 3 | ############################################################################################################# |
| 4 | # # |
| 5 | # Compiles Faust programs to Linux x86_64 library suitable for the Unity environment # |
| 6 | # # |
| 7 | # (c) Grame, 2017 # |
| 8 | # # |
| 9 | ############################################################################################################# |
| 10 | |
| 11 | # This script shouldn't be used on its own, use the "faust2unity" script instead |
| 12 | # The libraries are firstly wrapped by the unityplugin.cpp architecture file |
| 13 | # They have to be used in the Unity environment |
| 14 | # The libraries does not work by themselves, they need the FaustPlugin_<dspname>.cs and FaustUtilities_<dspname>.cs files to be functional |
| 15 | # These files are automatically generated by the "faust2unity" script |
| 16 | |
| 17 | . faustpath |
| 18 | . faustoptflags |
| 19 | . usage.sh |
| 20 | |
| 21 | CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used |
| 22 | |
| 23 | NVOICES=-1 |
| 24 | |
| 25 | echoHelp() |
| 26 | { |
| 27 | usage faust2linuxunity "[options] [Faust options] <file.dsp>" |
| 28 | platform Linux |
| 29 | require Jack, Unity |
| 30 | echo "Compiles Faust programs to Linux x86_64 libraries suitable for the Unity environment" |
| 31 | option |
| 32 | option "-nvoices <num>" |
| 33 | option "Faust options" |
| 34 | exit |
| 35 | } |
| 36 | |
| 37 | if [ "$#" -eq 0 ]; then |
| 38 | echo 'Please, provide a Faust file to process !' |
| 39 | echo '' |
| 40 | echoHelp |
| 41 | fi |
| 42 | |
| 43 | #------------------------------------------------------------------- |
| 44 | # Dispatch command arguments |
| 45 | |
| 46 | while [ $1 ] |
| 47 | do |
| 48 | p=$1 |
| 49 | |
| 50 | if [ $p = "-help" ] || [ $p = "-h" ]; then |
| 51 | echoHelp |
| 52 | elif [ $p = "-nvoices" ]; then |
| 53 | shift |
| 54 | NVOICES=$1 |
| 55 | elif [ ${p:0:1} = "-" ]; then |
| 56 | OPTIONS="$OPTIONS $p" |
| 57 | elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then |
| 58 | FILES="$FILES $p" |
| 59 | else |
| 60 | OPTIONS="$OPTIONS $p" |
| 61 | fi |
| 62 | |
| 63 | shift |
| 64 | done |
| 65 | |
| 66 | #------------------------------------------------------------------------------ |
| 67 | # Compiler g++ |
| 68 | # |
| 69 | |
| 70 | CXX="g++" |
| 71 | (which "$CXX" >/dev/null) || (echo "compiler $CXX not found. See -help for more info"; exit 1) |
| 72 | |
| 73 | #------------------------------------------------------------------- |
| 74 | # Compiler settings |
| 75 | |
| 76 | CXXFLAGS+=" -fPIC" |
| 77 | LIB="-shared" |
| 78 | EXT=".so" |
| 79 | |
| 80 | #------------------------------------------------------------------- |
| 81 | # compile the *.dsp files |
| 82 | |
| 83 | for p in $FILES; do |
| 84 | |
| 85 | CUR=$(pwd) |
| 86 | f=$(basename "$p") |
| 87 | NAME=${f%.dsp} |
| 88 | FNAME=FaustPlugin_$NAME |
| 89 | LIBNAME=lib$FNAME$EXT |
| 90 | SRCDIR=$(dirname "$p") |
| 91 | FIN=$FNAME/Linux |
| 92 | |
| 93 | # creates a temporary dir |
| 94 | TDR=$(mktemp -d faust.XXXXXX) |
| 95 | TMP=$TDR/${f%.dsp} |
| 96 | mkdir "$TMP" |
| 97 | |
| 98 | # checks if final dir exists, if not creates it |
| 99 | if [ ! -d "$FIN" ]; then |
| 100 | mkdir -p "$FIN" |
| 101 | fi |
| 102 | |
| 103 | # compile faust to c++ |
| 104 | faust -uim -i -a $FAUSTARCH/unity/unityplugin.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/$NAME.cpp" || (echo "$f : Faust to C++ compilation failed in faust2linuxunity"; exit 1) |
| 105 | |
| 106 | # compile c++ to binary |
| 107 | ( |
| 108 | cd "$TMP" |
| 109 | if [ $NVOICES == -1 ]; then |
| 110 | $CXX $CXXFLAGS $LIB -Dmydsp=$NAME -o $LIBNAME $NAME.cpp |
| 111 | else |
| 112 | $CXX $CXXFLAGS $LIB -Dmydsp=$NAME -DPOLY -o $LIBNAME $NAME.cpp |
| 113 | fi |
| 114 | ) > /dev/null || (echo "$f : C++ to linux library compilation failed in faust2linuxunity"; exit 1) |
| 115 | |
| 116 | # moves binary to final dir |
| 117 | rm -rf "$SRCDIR/$LIBNAME" |
| 118 | mv "$TMP/$LIBNAME" "$FIN/$LIBNAME" |
| 119 | rm -rf "$TDR" |
| 120 | |
| 121 | echo "$f : linux compilation completed" |
| 122 | done |
| 123 | |
| 124 | |
| 125 |