Update readme, install and license files.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / tools / faust2appls / faust2msp
1 #!/bin/bash
2
3 #####################################################################
4 # #
5 # Compiles Faust programs to Max/MSP #
6 # (c) Grame, 2010 #
7 # #
8 #####################################################################
9
10 createInfoPList() {
11 (
12 echo '<?xml version="1.0" encoding="UTF-8"?>'
13 echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
14 echo '<plist version="1.0">'
15 echo '<dict>'
16 echo ' <key>CFBundleExecutable</key>'
17 echo " <string>$1</string>"
18 echo ' <key>CFBundleName</key>'
19 echo " <string>$1</string>"
20 echo ' <key>CFBundlePackageType</key>'
21 echo ' <string>iLaX</string>'
22 echo '</dict>'
23 echo '</plist>'
24 ) > "$2"
25 }
26
27
28 #-------------------------------------------------------------------
29 # Analyze command arguments :
30 # faust options -> OPTIONS
31 # if -omp : -openmp or -fopenmp -> OPENMP
32 # existing *.dsp files -> FILES
33 #
34
35 # PHASE 1 : Look for -icc option to force use of intel icc (actually icpc)
36 # without having to configure CXX and CXXFLAGS
37 for p in $@; do
38 if [ "$p" = -icc ]; then
39 CXX=icpc
40 CXXFLAGS='-O3 -xT -ftz -fno-alias -fp-model fast=2'
41 fi
42 done
43
44 #PHASE 2 : dispatch command arguments
45 for p in $@; do
46 if [ "$p" = -omp ]; then
47 if [[ $CXX == "icpc" ]]; then
48 OMP="-openmp"
49 else
50 OMP="-fopenmp"
51 fi
52 fi
53
54 if [ "$p" = -icc ]; then
55 ignore=" "
56 elif [ ${p:0:1} = "-" ]; then
57 OPTIONS="$OPTIONS $p"
58 elif [[ -e "$p" ]]; then
59 FILES="$FILES $p"
60 else
61 OPTIONS="$OPTIONS $p"
62 fi
63 done
64
65
66
67 #-------------------------------------------------------------------
68 # Check darwin specifics
69 #
70 if [[ $(uname) == Darwin ]]; then
71 SPEC="-spec macx-g++"
72 EXT="~.mxo"
73 fi
74
75 #-------------------------------------------------------------------
76 # compile the *.dsp files
77 #
78 PATH=$PATH:/usr/local/bin
79
80 for p in $FILES; do
81
82 #INC=-I/usr/local/include/c74support/max-includes -I/usr/local/include/c74support/msp-includes
83 CC=g++
84
85 CUR=$(pwd)
86 f=$(basename "$p")
87 SRCDIR=$(dirname "$p")
88
89 # creates a temporary dir
90 TDR=$(mktemp -d faust.XXX)
91 TMP="$TDR/${f%.dsp}"
92 mkdir "$TMP"
93
94 # compile faust to c++
95 faust -a max-msp.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}.cpp"
96
97 # compile c++ to binary
98 (
99 cd "$TMP"
100 install -d "${f%.dsp}$EXT/Contents/MacOS"
101 $CC -arch i386 -fpascal-strings -fasm-blocks -g -O3 -I/usr/local/lib/faust -I/usr/local/include/c74support/max-includes -I/usr/local/include/c74support/msp-includes -c "${f%.dsp}.cpp" -o "${f%.dsp}.i386.o"
102 $CC -framework MaxAPI -framework Carbon -framework MaxAudioAPI -arch i386 -Wl,-Y,1455 -bundle "${f%.dsp}.i386.o" -o "${f%.dsp}.i386~"
103 #$CC -arch ppc -fpascal-strings -fasm-blocks -g -O3 -I/usr/local/lib/faust -I/usr/local/include/c74support/max-includes -I/usr/local/include/c74support/msp-includes -c "${f%.dsp}.cpp" -o "${f%.dsp}.ppc.o"
104 #$CC -framework Carbon -framework MaxAPI -framework MaxAudioAPI -arch ppc -Wl,-Y,1455 -bundle "${f%.dsp}.ppc.o" -o "${f%.dsp}.ppc~"
105 createInfoPList "${f%.dsp}~" "${f%.dsp}$EXT/Contents/Info.plist"
106 #lipo -create "${f%.dsp}.i386~" "${f%.dsp}.ppc~" -output "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~"
107 lipo -create "${f%.dsp}.i386~" -output "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~"
108
109 ) > /dev/null
110
111 rm -rf "$SRCDIR/${f%.dsp}$EXT"
112
113 # Keep .dsp and .cpp files in the plug-in
114 cp "$TMP/${f%.dsp}.cpp" "$TMP/${f%.dsp}$EXT"
115 cp "$SRCDIR/$f" "$TMP/${f%.dsp}$EXT"
116
117 cp -r "$TMP/${f%.dsp}$EXT" "$SRCDIR/${f%.dsp}$EXT"
118 rm -rf "$TDR"
119
120 # collect binary file name for FaustGIDE
121 BINARIES="$BINARIES$SRCDIR/${f%.dsp}$EXT;"
122 done
123
124 echo $BINARIES
125
126