New Makefile for libsndfile-ocaml library integration; Makefiles chain modified.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / tools / faust2appls / faust2supercollider
1 #!/bin/bash
2
3 #####################################################################
4 # #
5 # Compiles Faust programs to supercollider #
6 # (c) Grame, 2010 #
7 # #
8 #####################################################################
9
10 #-------------------------------------------------------------------
11 # Supercollider headers : path to the folder containing :
12 # plugin_interface/, common/ and server/ headers
13
14 # Possible path
15
16 SC0=$SUPERCOLLIDER_HEADERS
17 SC1="/usr/local/include/SuperCollider"
18 SC2="/usr/local/include/supercollider"
19 SC3="/usr/include/SuperCollider"
20 SC4="/usr/include/supercollider"
21
22 # check if directory exists
23
24 if [ -d $SC0/plugin_interface ]; then
25 SC=$SC0
26 elif [ -d $SC1 ]; then
27 SC=$SC1
28 elif [ -d $SC2 ]; then
29 SC=$SC2
30 elif [ -d $SC3 ]; then
31 SC=$SC3
32 elif [ -d $SC4 ]; then
33 SC=$SC4
34 else
35 echo "Can't find SuperCollider headers"
36 exit 1
37 fi
38 echo Using SC Headers in $SC
39
40 INCLUDE="-I$SC/plugin_interface/ -I$SC/common/ -I$SC/server/"
41
42 if [ $# = 0 ]; then
43 echo USAGE:
44 echo "$0 [-d[ebug]] [-icc] [-omp] [-sd] file1.dsp [file2.dsp ...]"
45 exit 1
46 fi
47
48 #-------------------------------------------------------------------
49 # Analyze command arguments :
50 # faust options -> OPTIONS
51 # if -omp : -openmp or -fopenmp -> OPENMP
52 # if -d or -debug -> F2SC_DEBUG
53 # if -sd or -synthdef -> SYNTHDEF
54 # existing *.dsp files -> FILES
55 #
56
57 # PHASE 1 : Look for -icc option to force use of intel icc (actually icpc)
58 # without having to configure CXX and CXXFLAGS
59 for p in $@; do
60 if [ "$p" = -icc ]; then
61 CXX=icpc
62 CXXFLAGS='-O3 -xT -ftz -fno-alias -fp-model fast=2'
63 fi
64 done
65
66 #PHASE 2 : dispatch command arguments
67 F2SC_DEBUG=0
68 SYNTHDEF=""
69 for p in $@; do
70 if [ "$p" = -omp ]; then
71 if [[ $CXX == "icpc" ]]; then
72 OMP="-openmp"
73 else
74 OMP="-fopenmp"
75 fi
76 fi
77
78 if [ "$p" = -debug ] || [ "$p" = -d ]; then
79 F2SC_DEBUG=1
80 elif [ "$p" = -sd ] || [ "$p" = -synthdef ]; then
81 SYNTHDEF="--synthdef"
82 elif [ "$p" = -icc ]; then
83 ignore=" "
84 elif [ ${p:0:1} = "-" ]; then
85 OPTIONS="$OPTIONS $p"
86 elif [[ -e "$p" ]]; then
87 FILES="$FILES $p"
88 else
89 echo "*** Faust source-file '$p' not found"
90 OPTIONS="$OPTIONS $p"
91 fi
92 done
93
94 if [ $F2SC_DEBUG = 1 ]; then
95 OUTDEV=/dev/tty
96 DNDEBUG=""
97 else
98 OUTDEV=/dev/null
99 DNDEBUG="-DNDEBUG"
100 fi
101
102 if [ "$FILES" = "" ]; then
103 echo USAGE:
104 echo "$0 [-d[ebug]] [-icc] [-omp] file1.dsp [file2.dsp ...]"
105 exit 1
106 fi
107
108 #-------------------------------------------------------------------
109 # Check plateform specifics
110 #
111 if [[ $(uname) == Darwin ]]; then
112 EXT="scx"
113 SCFLAGS="-DNO_LIBSNDFILE -DSC_DARWIN $DNDEBUG -bundle "
114 elif [[ $(uname) == Linux ]]; then
115 EXT="so"
116 SCFLAGS="-DNO_LIBSNDFILE -DSC_LINUX $DNDEBUG -shared -fPIC"
117 else
118 echo "unsupported plateform"
119 exit 1
120 fi
121
122 #-------------------------------------------------------------------
123 # compile the *.dsp files
124 #
125 for p in $FILES; do
126
127 CUR=$(pwd)
128 f=$(basename "$p")
129 SRCDIR=$(dirname "$p")
130
131 # creates a temporary dir
132 TDR=$(mktemp -d faust.XXX)
133 TMP=$TDR/${f%.dsp}
134 mkdir "$TMP"
135
136 # compile the .dsp file to c++ and xml
137 faust -xml "$SRCDIR/$f" -o /dev/null;
138 mv "$SRCDIR/$f.xml" $TMP/
139 faust -a supercollider.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}.cpp"
140
141 # compile c++ to binary; --prefix should be same as in ../../examples/Makefile.sccompile
142 (
143 cd "$TMP"
144 faust2sc --prefix=Faust $SYNTHDEF $f.xml > "${f%.dsp}.sc" 2>$OUTDEV
145 ${CXX=g++} -O3 $SCFLAGS -I$CUR $INCLUDE $CXXFLAGS $OMP -Dmydsp=${f%.dsp} -o ${f%.dsp}.$EXT ${f%.dsp}.cpp
146 )> $OUTDEV
147
148 ## move the produced files from tmp to source dir
149 cp "$TMP/${f%.dsp}.$EXT" "$SRCDIR/${f%.dsp}.$EXT"
150 cp "$TMP/${f%.dsp}.sc" "$SRCDIR/${f%.dsp}.sc"
151
152
153 if [ $F2SC_DEBUG = 1 ]; then
154 echo "Retaining intermediate products directory '$TDR'"
155 OUTDEV=/dev/tty
156 else
157 rm -rf "$TDR"
158 fi
159
160 # collects all the files produced
161 BINARIES="$BINARIES$SRCDIR/${f%.dsp}.$EXT;$SRCDIR/${f%.dsp}.sc;"
162
163 done
164
165 # return the binaries names
166 echo "$BINARIES"