1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#! /bin/bash -e
#############################################################################################
# #
# Compiles Faust programs to Microsoft libraries suitable for the Unity environment #
# #
# (c) Grame, 2017 #
# #
#############################################################################################
# This script shouldn't be used on its own, use the "faust2unity" script instead
# The libraries are firstly wrapped by the unityplugin.cpp architecture file
# They have to be used in the Unity environment
# The libraries does not work by themselves, they need the FaustPlugin_<dspname>.cs and FaustUtilities_<dspname>.cs files to be functional
# These files are automatically generated by the "faust2unity" script
. faustpath
. usage.sh
. faustoptflags
CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
NVOICES=-1
echoHelp()
{
echo "faust2unitywin -32 -64 [Faust options] <file1.dsp> [<file2.dsp>]"
echo "Create Microsoft 32/64bits library for Faust Unity plugins"
echo "Mingw crosscompiler should be installed ('mingw32' package on Ubuntu)"
echo "Use 'faust2unity -w32 -w64' to also create the C# and JSON files"
echo "Use '-nvoices <num>' to produce a polyphonic self-contained DSP with <num> voices, ready to be used with MIDI"
echo "See architecture/unity/README.md for more info"
option "Faust options"
exit
}
if [ "$#" -eq 0 ]; then
echo 'Please, provide a Faust file to process !'
echo ''
echoHelp
fi
#-----------------------------------------------------------------------
# Dispatch command arguments
while [ $1 ]
do
p=$1
if [ $p = "-help" ] || [ $p = "-h" ]; then
echoHelp
elif [ $p = "-32" ]; then
BITS="$BITS 32"
CXXFLAGS+=" -march=i686"
elif [ $p = "-64" ]; then
BITS="$BITS 64"
CXXFLAGS+=" -march=x86-64 -fno-asynchronous-unwind-tables -fno-exceptions"
elif [ $p = "-nvoices" ]; then
shift
NVOICES=$1
elif [ ${p:0:1} = "-" ]; then
OPTIONS="$OPTIONS $p"
elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
FILES="$FILES $p"
else
OPTIONS="$OPTIONS $p"
fi
shift
done
# Check at least one bit setting has been specified
if [ -z "$BITS" ]; then
echo "bits not specified, pass -32 and/or -64"
exit
fi
#-----------------------------------------------------------------------
# Compiler settings
CXXFLAGS+=" -Wl,--enable-auto-import"
LIB="-shared"
EXT=".dll"
#-----------------------------------------------------------------------
# compiles the *.dsp files
for p in $FILES; do
CUR=$(pwd)
f=$(basename "$p")
NAME=${f%.dsp}
FNAME=FaustPlugin_$NAME
LIBNAME="lib$FNAME$EXT"
SRCDIR=$(dirname "$p")
# create a temporary dir
TDR=$(mktemp -d faust.XXXXXX)
TMP=$TDR/$NAME
mkdir "$TMP"
# compile faust to c++
faust -uim -i -a $FAUSTARCH/unity/unityplugin.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/$NAME.cpp" || (echo "$f : Faust to C++ compilation failed in faust2unitywin"; exit 1)
for BIT in $BITS; do
#-----------------------------------------------------------------------
# mingw crosscompiler should be installed ('mingw32' package on Ubuntu)
# the exact prefix should be specified in the environment variable MINGW
if [ $BIT = "32" ]; then
FIN=$FNAME/Windows/x86
MINGWPREFIX="i686-w64-mingw32-"
elif [ $BIT = "64" ]; then
FIN=$FNAME/Windows/x64
MINGWPREFIX="x86_64-w64-mingw32-"
fi
# checks if final dir exists, if not creates it
if [ ! -d "$FIN" ]; then
mkdir -p "$FIN"
fi
CXX="${MINGWPREFIX}g++"
(which "$CXX" >/dev/null) || (echo "MingW compiler $CXX not found. See -help for more info"; exit 1)
# compile c++ to binary
(
cd "$TMP"
if [ $NVOICES == -1 ]; then
$CXX $CXXFLAGS $PROCARCH $LIB $OMP -static-libstdc++ -static-libgcc -Dmydsp=$NAME -o $LIBNAME $NAME.cpp
else
$CXX $CXXFLAGS $PROCARCH $LIB $OMP -static-libstdc++ -static-libgcc -DPOLY -Dmydsp=$NAME -o $LIBNAME $NAME.cpp
fi
) > /dev/null || (echo "$f : C++ to win$BIT library compilation failed in faust2unitywin"; exit 1)
# moves binary to final dir
mv "$TMP/$LIBNAME" "$FIN/$LIBNAME"
echo "$f : w$BIT compilation completed"
done
# remove intermediary files
rm -rf "$SRCDIR/$LIBNAME"
rm -rf "$TDR"
done
|