Initial import.
[Faustine.git] / interpretor / faust-0.9.47mr3 / tools / faust2appls / faust2puredata
1 #!/bin/bash
2
3 #####################################################################
4 # #
5 # Compiles Faust programs to puredata #
6 # (c) Grame, 2009 #
7 # #
8 #####################################################################
9
10
11 #-------------------------------------------------------------------
12 # Analyze command arguments :
13 # faust options -> OPTIONS
14 # if -omp : -openmp or -fopenmp -> OPENMP
15 # existing *.dsp files -> FILES
16 #
17
18 # PHASE 1 : Look for -icc option to force use of intel icc (actually icpc)
19 # without having to configure CXX and CXXFLAGS
20 for p in $@; do
21 if [ "$p" = -icc ]; then
22 CXX=icpc
23 CXXFLAGS='-O3 -xHost -ftz -fno-alias -fp-model fast=2'
24 fi
25 done
26
27 #PHASE 2 : dispatch command arguments
28 for p in $@; do
29 if [ "$p" = -omp ]; then
30 if [[ $CXX == "icpc" ]]; then
31 OMP="-openmp"
32 else
33 OMP="-fopenmp"
34 fi
35 fi
36
37 if [ "$p" = -icc ]; then
38 ignore=" "
39 elif [ ${p:0:1} = "-" ]; then
40 OPTIONS="$OPTIONS $p"
41 elif [[ -e "$p" ]]; then
42 FILES="$FILES $p"
43 else
44 OPTIONS="$OPTIONS $p"
45 fi
46 done
47
48
49 #-------------------------------------------------------------------
50 # Check darwin specifics
51 #
52 if [[ $(uname) == Darwin ]]; then
53 CXXFLAGS="-O3 -mfpmath=sse -msse -ffast-math"
54 LIB="-I/Applications/Pd-extended.app/Contents/Resources/include/ -bundle -undefined suppress -flat_namespace"
55 EXT="~.pd_darwin"
56 else
57 CXXFLAGS="-O3 -march=native -mfpmath=sse -msse -ffast-math"
58 LIB="-I/usr/include/pd -I/usr/include/pdextended -fPIC -shared"
59 EXT="~.pd_linux"
60 fi
61
62
63
64
65 #-------------------------------------------------------------------
66 # compile the *.dsp files
67 #
68 for p in $FILES; do
69
70 CUR=$(pwd)
71 f=$(basename "$p")
72 SRCDIR=$(dirname "$p")
73
74 # creates a temporary dir
75 TDR=$(mktemp -d faust.XXX)
76 TMP=$TDR/${f%.dsp}
77 mkdir "$TMP"
78
79 # compile faust to c++ and xml
80 faust -xml "$SRCDIR/$f" -o /dev/null;
81 mv "$SRCDIR/$f.xml" $TMP/
82 faust -a puredata.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}.cpp"
83
84 # compile c++ to binary
85 (
86 cd "$TMP"
87 if [[ $(uname) == Darwin ]]; then
88 # On Darwin we build 32-bits and 64-bits plugins combined with lipo
89 ${CXX=g++} -arch i386 $CXXFLAGS $OMP $LIB -Dmydsp=${f%.dsp} -o ${f%.dsp}.i386 ${f%.dsp}.cpp
90 ${CXX=g++} -arch x86_64 $CXXFLAGS $OMP $LIB -Dmydsp=${f%.dsp} -o ${f%.dsp}.x86_64 ${f%.dsp}.cpp
91 lipo -create "${f%.dsp}.i386" "${f%.dsp}.x86_64" -output "${f%.dsp}$EXT"
92 else
93 ${CXX=g++} $CXXFLAGS $OMP $LIB -Dmydsp=${f%.dsp} -o ${f%.dsp}$EXT ${f%.dsp}.cpp
94 fi
95 if [ $(which faust2pd) ]; then
96 faust2pd -s $f.xml
97 fi
98 ) > /dev/null
99
100 ##rm -rf "$SRCDIR/${f%.dsp}$EXT"
101 cp "$TMP/${f%.dsp}$EXT" "$SRCDIR/${f%.dsp}$EXT"
102 # collects all the files produced
103 BINARIES="$BINARIES$SRCDIR/${f%.dsp}$EXT;"
104 if [ $(which faust2pd) ]; then
105 cp "$TMP/${f%.dsp}.pd" "$SRCDIR/${f%.dsp}.pd"
106 BINARIES="$BINARIES$SRCDIR/${f%.dsp}.pd;"
107 fi
108 rm -rf "$TDR"
109
110
111 done
112
113 # return the binaries names
114 echo "$BINARIES"
115
116