Debian Codegraph @

tools/faust2appls/faust2androidunity

raw symbols SCIP
1 #! /bin/bash -e
2
3 #############################################################################################################
4 # #
5 # Compiles Faust programs to Android libraries for the Unity environment #
6 # suitable for armeabi-v7a and x86 Android architectures #
7 # #
8 # (c) Grame, 2017 #
9 # #
10 #############################################################################################################
11
12 # This script shouldn't be used on its own, use the "faust2unity" script instead
13 # The libraries are firstly wrapped by the unityplugin.cpp architecture file
14 # They have to be used in the Unity environment
15 # The libraries does not work by themselves, they need the FaustPlugin_<dspname>.cs and FaustUtilities_<dspname>.cs files to be functional
16 # These files are automatically generated by the "faust2unity" script
17
18 . faustpath
19 . faustoptflags
20 . usage.sh
21
22 CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
23
24 NVOICES=-1
25 ANDROID_MK=Android.mk
26
27 echoHelp()
28 {
29 usage faust2androidunity "[options] [Faust options] <file1.dsp> [<file2.dsp>]"
30 platform Android Unity
31 require Android SDK "Make sure the ANDROID_HOME environment variable is set to the sdk folder."
32 echo "Creates android libraries (armeabi-v7a and x86) for faust unity plugin."
33 echo "If you need other android architectures, open architecture/unity/Android/Application.mk and modify APP_ABI."
34 echo "See architecture/unity/README.md for more info (also available from the compile folder)"
35 option
36 option "-nvoices <num>"
37 option -android "creates also the c# and JSON files"
38 option "Faust options"
39 exit
40 }
41
42 if [ "$#" -eq 0 ]; then
43 echo 'Please, provide a Faust file to process !'
44 echo ''
45 echoHelp
46 fi
47
48 #-------------------------------------------------------------------
49 # Dispatch command arguments
50
51 SOURCE="0"
52
53 while [ $1 ]
54 do
55 p=$1
56
57 if [ $p = "-help" ] || [ $p = "-h" ]; then
58 echoHelp
59 elif [ $p = "-nvoices" ]; then
60 shift
61 NVOICES=$1
62 if [ $NVOICES != -1 ]; then
63 ANDROID_MK=AndroidPoly.mk
64 fi
65 elif [ ${p:0:1} = "-" ]; then
66 OPTIONS="$OPTIONS $p"
67 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
68 FILES="$FILES $p"
69 else
70 OPTIONS="$OPTIONS $p"
71 fi
72
73 shift
74 done
75
76 #-------------------------------------------------------------------
77 # compiles the *.dsp files
78
79 for p in $FILES; do
80
81 CUR=$(pwd)
82 f=$(basename "$p")
83 NAME=${f%.dsp}
84 FNAME=FaustPlugin_$NAME
85 SRCDIR=$(dirname "$p")
86 FIN=$FNAME/Android
87
88 # creates a temporary dir
89 TMP=$(mktemp -d android.XXXX)
90
91 # checks if final dir exists
92 if [ ! -d "$FIN" ]; then
93 mkdir -p "$FIN"
94 fi
95
96 # compiles faust to c++
97 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)
98
99 # compiles c++ to binary
100 cd "$TMP"
101
102 # Android.mk and Application.mk contains the compilation settings.
103 # They are moved to the working directory for compilation then deleted
104 cp -r "$FAUSTLIB/unity/Android/$ANDROID_MK" "Android.mk"
105 cp -r "$FAUSTLIB/unity/Android/Application.mk" "Application.mk"
106 $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)
107 rm -rf "Android.mk"
108 rm -rf "Application.mk"
109 rm -rf "obj"
110 rm -rf "$NAME.cpp"
111 cd ..
112
113 # moves binaries to final dir and deletes libs/
114 mv $TMP/libs/* $TMP
115 rm -rf $TMP/libs
116
117 mv $TMP/* $FIN/
118 rm -rf $TMP
119
120 echo "$f : Android armeabi-v7a and x86 compilations completed"
121
122 done
123