File: faust2androidunity

package info (click to toggle)
faust 2.81.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 431,496 kB
  • sloc: cpp: 283,941; ansic: 116,215; javascript: 18,529; sh: 14,356; vhdl: 14,052; java: 5,900; python: 5,091; objc: 3,852; makefile: 2,725; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 111; tcl: 26
file content (123 lines) | stat: -rwxr-xr-x 4,255 bytes parent folder | download | duplicates (3)
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
117
118
119
120
121
122
123
#! /bin/bash -e

#############################################################################################################
#                                                                                                           #
#   Compiles Faust programs to Android libraries for the Unity environment                                  #
#       suitable for armeabi-v7a and x86 Android architectures                                              #
#                                                                                                           #
#   (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 functional
#   These files are automatically generated by the "faust2unity" script

. faustpath
. faustoptflags
. usage.sh

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

NVOICES=-1
ANDROID_MK=Android.mk

echoHelp() 
{
    usage faust2androidunity "[options] [Faust options] <file1.dsp> [<file2.dsp>]"
    platform Android Unity
    require Android SDK "Make sure the ANDROID_HOME environment variable is set to the sdk folder."
    echo "Creates android libraries (armeabi-v7a and x86) for faust unity plugin."
    echo "If you need other android architectures, open architecture/unity/Android/Application.mk and modify APP_ABI."
    echo "See architecture/unity/README.md for more info (also available from the compile folder)"
    option
    option "-nvoices <num>"
    option -android "creates also the c# and JSON files"
    option "Faust options"
    exit
}

if [ "$#" -eq 0 ]; then
    echo 'Please, provide a Faust file to process !'
    echo ''
    echoHelp
fi

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

SOURCE="0"

while [ $1 ]
do
    p=$1

    if [ $p = "-help" ] || [ $p = "-h" ]; then
        echoHelp
    elif [ $p = "-nvoices" ]; then
        shift
        NVOICES=$1
        if [ $NVOICES != -1 ]; then
            ANDROID_MK=AndroidPoly.mk
        fi
    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

#-------------------------------------------------------------------
# compiles the *.dsp files

for p in $FILES; do

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

    # creates a temporary dir
    TMP=$(mktemp -d android.XXXX)

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

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

    # compiles c++ to binary
    cd "$TMP"

    # Android.mk and Application.mk contains the compilation settings.
    # They are moved to the working directory for compilation then deleted
    cp -r "$FAUSTLIB/unity/Android/$ANDROID_MK" "Android.mk"
    cp -r "$FAUSTLIB/unity/Android/Application.mk" "Application.mk"
    $ANDROID_HOME/ndk-bundle/ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk FILE=$NAME > /dev/null || (echo "$f : C++ to armeabi-v7a and x86 library compilations failed in faust2androidunity"; exit 1)
    rm -rf "Android.mk"
    rm -rf "Application.mk"
    rm -rf "obj"
    rm -rf "$NAME.cpp"
    cd ..

    # moves binaries to final dir and deletes libs/
    mv $TMP/libs/* $TMP
    rm -rf $TMP/libs

    mv $TMP/* $FIN/
    rm -rf $TMP

    echo "$f : Android armeabi-v7a and x86 compilations completed"

done