Debian Codegraph @

tools/faust2appls/faust2osxiosunity

raw symbols SCIP
1 #! /bin/bash -e
2
3 #########################################################################################
4 # #
5 # Compiles Faust programs to OSX/iOS libraries suitable for the Unity environment #
6 # (c) Grame, 2017-2024 #
7 # #
8 # #
9 #########################################################################################
10
11
12 # This script shouldn't be used on its own, use the "faust2unity" script instead
13 # The libraries are firstly wrapped by the unityplugin.cpp architecture file
14 # They have to be used in the Unity environment
15 # The libraries does not work by themselves, they need the FaustPlugin_<dspname>.cs and FaustUtilities_<dspname>.cs files to be functional
16 # These files are automatically generated by the "faust2unity" script
17 #
18 #
19 # Structure of a plugin for OSX
20 #-----------------------------------------
21 # libFaustPlugin_foo.bundle/
22 # Contents/
23 # MacOS/
24 # AudioPlugin<dspname>
25 # Info.plist
26 #
27
28 . faustpath
29 . faustoptflags
30 . usage.sh
31
32 CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
33
34 NVOICES=-1
35
36 #------------------------------------------------
37 # Compiler settings
38 ARCH="-arch x86_64"
39 CXXFLAGS+=" -fPIC"
40 LDFLAGS="-bundle"
41 CXX="c++"
42
43 #------------------------------------------------
44 # Generates the info.plist file
45
46 createInfoPList() {
47 cat > "$2" << DELIM
48 <?xml version="1.0" encoding="UTF-8"?>
49 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
50 <plist version="1.0">
51 <dict>
52 <key>BuildMachineOSBuild</key>
53 <string>16D32</string>
54 <key>CFBundleDevelopmentRegion</key>
55 <string>English</string>
56 <key>CFBundleExecutable</key>
57 <string>$1</string>
58 <key>CFBundleIdentifier</key>
59 <string>com.yourcompany.$1</string>
60 <key>CFBundleInfoDictionaryVersion</key>
61 <string>6.0</string>
62 <key>CFBundleName</key>
63 <string>$1</string>
64 <key>CFBundlePackageType</key>
65 <string>BNDL</string>
66 <key>CFBundleShortVersionString</key>
67 <string>1.0</string>
68 <key>CFBundleSignature</key>
69 <string>????</string>
70 <key>CFBundleSupportedPlatforms</key>
71 <array>
72 <string>MacOSX</string>
73 </array>
74 <key>CFBundleVersion</key>
75 <string>1</string>
76 <key>CFPlugInDynamicRegisterFunction</key>
77 <string></string>
78 <key>CFPlugInDynamicRegistration</key>
79 <string>NO</string>
80 <key>CFPlugInFactories</key>
81 <dict>
82 <key>00000000-0000-0000-0000-000000000000</key>
83 <string>MyFactoryFunction</string>
84 </dict>
85 <key>CFPlugInTypes</key>
86 <dict>
87 <key>00000000-0000-0000-0000-000000000000</key>
88 <array>
89 <string>00000000-0000-0000-0000-000000000000</string>
90 </array>
91 </dict>
92 <key>CFPlugInUnloadFunction</key>
93 <string></string>
94 <key>DTCompiler</key>
95 <string>com.apple.compilers.llvm.clang.1_0</string>
96 <key>DTPlatformBuild</key>
97 <string>8C1002</string>
98 <key>DTPlatformVersion</key>
99 <string>GM</string>
100 <key>DTSDKBuild</key>
101 <string>16C58</string>
102 <key>DTSDKName</key>
103 <string>macosx10.12</string>
104 <key>DTXcode</key>
105 <string>0821</string>
106 <key>DTXcodeBuild</key>
107 <string>8C1002</string>
108 </dict>
109 </plist>
110 DELIM
111 }
112
113 echoHelp()
114 {
115 usage faust2osxiosunity "[options] [Faust options] <file.dsp>"
116 platform MacOSX
117 require Unity
118 echo "Compiles Faust programs to OSX/iOS libraries suitable for the Unity environment"
119 option
120 option "-nvoices <num>"
121 option -ios "creates an iOS static library"
122 option -universal "generates an universal (arm/intel) external on OSX"
123 option "Faust options"
124 # echo "Use 'faust2unity -osx -ios' to also create the c# and JSON files"
125 echo "See architecture/unity/README.md for more info."
126 exit
127 }
128
129 if [ "$#" -eq 0 ]; then
130 echo 'Please, provide a Faust file to process !'
131 echo ''
132 echoHelp
133 fi
134
135 #---------------------------------------
136 # Dispatch command arguments
137
138 CUR=$(pwd)
139 SOURCE=0
140
141 while [ $1 ]
142 do
143 p=$1
144
145 if [ $p = "-help" ] || [ $p = "-h" ]; then
146 echoHelp
147 elif [ $p = "-ios" ]; then
148 IOS=1
149 CXXFLAGS="-arch armv7 -arch armv7s -arch arm64 -pipe -O3 -gdwarf-2"
150 elif [ $p = "-nvoices" ]; then
151 shift
152 NVOICES=$1
153 elif [ $p = "-source" ]; then
154 SOURCE=1
155 elif [ $p = "-universal" ]; then
156 ARCH="-arch arm64 -arch x86_64"
157 elif [ ${p:0:1} = "-" ]; then
158 OPTIONS="$OPTIONS $p"
159 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
160 FILES="$FILES $p"
161 else
162 OPTIONS="$OPTIONS $p"
163 fi
164
165 shift
166 done
167
168 #--------------------------------------
169 # Compiles all *.dsp files
170
171 for p in $FILES; do
172 CUR=$(pwd)
173 f=$(basename "$p")
174 NAME=${f%.dsp}
175 FNAME=FaustPlugin_$NAME
176 SRCDIR=$(dirname "$p")
177
178 if [ "$IOS" = "1" ]; then # iOS part
179
180 FIN=$FNAME/iOS
181
182 # creates a temporary dir
183 TMP=$(mktemp -d iOS.XXXX)
184
185 # checks if final dir exists, if not creates it
186 if [ ! -d "$FIN" ]; then
187 mkdir -p "$FIN"
188 fi
189
190 # compiles faust to c++
191 faust -uim -i -a $FAUSTARCH/unity/unityplugin.cpp "$SRCDIR/$NAME.dsp" -o $TMP/$NAME.cpp || (echo "$FNAME : Faust to C++ compilation failed in faust2osxiosunity -ios"; exit 1)
192
193 $CXX $CXXFLAGS -DAPPLE -fembed-bitcode -DPLUGINNAME="libFaustPlugin_$NAME" -std=c++11 -stdlib=libc++ -c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk $TMP/$NAME.cpp -o $TMP/$NAME.o || (echo "$FNAME : C++ to iOS library compilation failed in faust2osxiosunity -ios"; exit 1)
194 libtool $TMP/$NAME.o -o $TMP/libFaustPlugin_$NAME.a
195 rm $TMP/$NAME.o $TMP/$NAME.cpp
196
197 # moves binary to final
198 mv $TMP/* $FIN/
199 rm -rf $TMP
200
201 echo "$f : iOS compilation completed"
202
203 else # MacOS part
204
205 FIN=$FNAME/MacOS
206
207 # creates a temporary dir
208 TDR=$(mktemp -d faust.XXX)
209
210 # creates the bundle inside
211 BNDL="$TDR/lib$FNAME.bundle"
212 MOS="$BNDL/Contents/MacOS/"
213 mkdir -p "$MOS"
214
215 # checks if final dir exists, if not creates it
216 if [ ! -d "$FIN" ]; then
217 mkdir -p "$FIN"
218 fi
219
220 # compile Faust DSP to c++
221 faust -uim -i -a $FAUSTARCH/unity/unityplugin.cpp "$SRCDIR/$NAME.dsp" -o "$MOS/$NAME.cpp" || (echo "$FNAME : Faust to C++ compilation failed in faust2osxiosunity"; exit 1)
222
223 if [ $NVOICES == -1 ]; then
224 $CXX $CXXFLAGS $ARCH $LDFLAGS -DAPPLE -DPLUGINNAME="$NAME" "$MOS/$NAME.cpp" -o "$MOS/lib$FNAME" || (echo "$FNAME : C++ to OSX library compilation failed in faust2osxiosunity"; exit 1)
225 else
226 $CXX $CXXFLAGS $ARCH $LDFLAGS -DPOLY -DAPPLE -DPLUGINNAME="$NAME" "$MOS/$NAME.cpp" -o "$MOS/lib$FNAME" || (echo "$FNAME : C++ to OSX library compilation failed in faust2osxiosunity"; exit 1)
227 fi
228
229 rm "$MOS/$NAME.cpp"
230 createInfoPList "lib$FNAME" "$BNDL/Contents/Info.plist" || (echo "$FNAME : Info.plist gerenation failed in faust2osxiosunity"; exit 1)
231
232 rm -rf "$SRCDIR/lib$FNAME.bundle"
233
234 # moves binary to final
235 mv $BNDL $FIN/
236 rm -rf $TDR
237
238 echo "$f : OSX compilation completed"
239
240 fi
241
242 done