Debian Codegraph @

tools/faust2appls/faust2winunity

raw symbols SCIP
1 #! /bin/bash -e
2
3 #############################################################################################
4 # #
5 # Compiles Faust programs to Microsoft libraries 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 . usage.sh
19 . faustoptflags
20
21 CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
22
23 NVOICES=-1
24
25 echoHelp()
26 {
27 echo "faust2unitywin -32 -64 [Faust options] <file1.dsp> [<file2.dsp>]"
28 echo "Create Microsoft 32/64bits library for Faust Unity plugins"
29 echo "Mingw crosscompiler should be installed ('mingw32' package on Ubuntu)"
30 echo "Use 'faust2unity -w32 -w64' to also create the C# and JSON files"
31 echo "Use '-nvoices <num>' to produce a polyphonic self-contained DSP with <num> voices, ready to be used with MIDI"
32 echo "See architecture/unity/README.md for more info"
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 = "-32" ]; then
53 BITS="$BITS 32"
54 CXXFLAGS+=" -march=i686"
55 elif [ $p = "-64" ]; then
56 BITS="$BITS 64"
57 CXXFLAGS+=" -march=x86-64 -fno-asynchronous-unwind-tables -fno-exceptions"
58 elif [ $p = "-nvoices" ]; then
59 shift
60 NVOICES=$1
61 elif [ ${p:0:1} = "-" ]; then
62 OPTIONS="$OPTIONS $p"
63 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
64 FILES="$FILES $p"
65 else
66 OPTIONS="$OPTIONS $p"
67 fi
68
69 shift
70 done
71
72 # Check at least one bit setting has been specified
73 if [ -z "$BITS" ]; then
74 echo "bits not specified, pass -32 and/or -64"
75 exit
76 fi
77
78 #-----------------------------------------------------------------------
79 # Compiler settings
80
81 CXXFLAGS+=" -Wl,--enable-auto-import"
82 LIB="-shared"
83 EXT=".dll"
84
85 #-----------------------------------------------------------------------
86 # compiles the *.dsp files
87
88 for p in $FILES; do
89
90 CUR=$(pwd)
91 f=$(basename "$p")
92 NAME=${f%.dsp}
93 FNAME=FaustPlugin_$NAME
94 LIBNAME="lib$FNAME$EXT"
95
96 SRCDIR=$(dirname "$p")
97
98 # create a temporary dir
99 TDR=$(mktemp -d faust.XXXXXX)
100 TMP=$TDR/$NAME
101 mkdir "$TMP"
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 faust2unitywin"; exit 1)
105
106 for BIT in $BITS; do
107 #-----------------------------------------------------------------------
108 # mingw crosscompiler should be installed ('mingw32' package on Ubuntu)
109 # the exact prefix should be specified in the environment variable MINGW
110 if [ $BIT = "32" ]; then
111 FIN=$FNAME/Windows/x86
112 MINGWPREFIX="i686-w64-mingw32-"
113 elif [ $BIT = "64" ]; then
114 FIN=$FNAME/Windows/x64
115 MINGWPREFIX="x86_64-w64-mingw32-"
116 fi
117
118 # checks if final dir exists, if not creates it
119 if [ ! -d "$FIN" ]; then
120 mkdir -p "$FIN"
121 fi
122
123 CXX="${MINGWPREFIX}g++"
124 (which "$CXX" >/dev/null) || (echo "MingW compiler $CXX not found. See -help for more info"; exit 1)
125
126 # compile c++ to binary
127 (
128 cd "$TMP"
129 if [ $NVOICES == -1 ]; then
130 $CXX $CXXFLAGS $PROCARCH $LIB $OMP -static-libstdc++ -static-libgcc -Dmydsp=$NAME -o $LIBNAME $NAME.cpp
131 else
132 $CXX $CXXFLAGS $PROCARCH $LIB $OMP -static-libstdc++ -static-libgcc -DPOLY -Dmydsp=$NAME -o $LIBNAME $NAME.cpp
133 fi
134 ) > /dev/null || (echo "$f : C++ to win$BIT library compilation failed in faust2unitywin"; exit 1)
135
136 # moves binary to final dir
137 mv "$TMP/$LIBNAME" "$FIN/$LIBNAME"
138 echo "$f : w$BIT compilation completed"
139 done
140
141 # remove intermediary files
142 rm -rf "$SRCDIR/$LIBNAME"
143 rm -rf "$TDR"
144
145 done
146