File: faust2linuxunity

package info (click to toggle)
faust 2.30.5~ds0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 279,348 kB
  • sloc: cpp: 239,368; javascript: 32,310; ansic: 17,442; sh: 11,925; java: 5,903; objc: 3,879; makefile: 3,030; cs: 1,139; python: 987; ruby: 951; xml: 693; yacc: 537; lex: 239; lisp: 201; awk: 110
file content (116 lines) | stat: -rwxr-xr-x 3,628 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/bash -e

#############################################################################################################
#                                                                                                           #
#   Compiles Faust programs to Linux x86_64 library suitable for the Unity environment                      #
#                                                                                                           #
#   (c) Grame, 2017                                                                                         #
#                                                                                                           #
#############################################################################################################

#   This script shouldn't be used on its own, use the "faust2unity" script instead
#   The libraries are firstly wrapped by the unityplugin.cpp architecture file
#   They have to be used in the Unity environment
#   The libraries does not work by themselves, they need the FaustPlugin_<dspname>.cs and FaustUtilities_<dspname>.cs files to be functionnal
#   These files are automatically generated by the "faust2unity" script

. faustpath
. faustoptflags
. usage.sh

CXXFLAGS+=" $MYGCCFLAGS"  # So that additional CXXFLAGS can be used

NVOICES=-1

#-------------------------------------------------------------------
# Dispatch command arguments

while [ $1 ] 
do
    p=$1
    
    if [ $p = "-help" ] || [ $p = "-h" ]; then
        usage faust2linuxunity "[options] [Faust options] <file.dsp>"
        platform Linux
        require Jack, Unity
        echo "Compiles Faust programs to Linux x86_64 library suitable for the Unity environment"
        option
        option "-nvoices <num>"
        option "Faust options"
        exit
    fi

	if [ $p = "-nvoices" ]; then
        shift
        NVOICES=$1
    elif [ ${p:0:1} = "-" ]; then
	    OPTIONS="$OPTIONS $p"
	elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
	    FILES="$FILES $p"
	else
	    OPTIONS="$OPTIONS $p"        
	fi
	
shift
done

#------------------------------------------------------------------------------
# Compiler g++
#

CXX="g++"
(which "$CXX" >/dev/null) || (echo "compiler $CXX not found. See -help for more info"; exit 1)

#-------------------------------------------------------------------
# Compiler settings

CXXFLAGS+=" -fPIC"
LIB="-shared"
EXT=".so"

#-------------------------------------------------------------------
# compile the *.dsp files

for p in $FILES; do

    CUR=$(pwd)
    f=$(basename "$p")
    NAME=${f%.dsp}
    FNAME=FaustPlugin_$NAME
    LIBNAME=lib$FNAME$EXT
    SRCDIR=$(dirname "$p")
    FIN=$FNAME/Linux

    # creates a temporary dir 
    TDR=$(mktemp -d faust.XXXXXX)
    TMP=$TDR/${f%.dsp}
    mkdir "$TMP"

    # checks if final dir exists, if not creates it
    if [ ! -d "$FIN" ]; then
        mkdir -p "$FIN"
    fi

    # compile faust to c++
    faust -uim -i -a $FAUSTARCH/unity/unityplugin.cpp $OPTIONS "$SRCDIR/$f" -o "$TMP/$NAME.cpp" || (echo "$f : Faust to C++ compilation failed in faust2linuxunity"; exit 1)

    # compile c++ to binary
    (
        cd "$TMP"
        if [ $NVOICES == -1 ]; then
        	$CXX $CXXFLAGS $LIB -Dmydsp=$NAME -o $LIBNAME $NAME.cpp
		else
			$CXX $CXXFLAGS $LIB -Dmydsp=$NAME -DPOLY -o $LIBNAME $NAME.cpp
		fi
	) > /dev/null || (echo "$f : C++ to linux library compilation failed in faust2linuxunity"; exit 1)

    # moves binary to final dir
    rm -rf "$SRCDIR/$LIBNAME"
    mv "$TMP/$LIBNAME" "$FIN/$LIBNAME"
    rm -rf "$TDR"

    echo "$f : linux compilation completed"
done